Merge pull request #2594 from eed3si9n/wip/reorg

[sbt 1.0] Refactoring
This commit is contained in:
eugene yokota 2016-05-07 22:11:27 -04:00
commit bcd3659935
157 changed files with 314 additions and 757 deletions

View File

@ -1,286 +0,0 @@
= Introduction =
The API discovery component of xsbt analyzes the source code of a project and extracts the API. This discovery component operates as a phase during normal compilation. This phase exists in the 'compiler-interface' subproject and is discussed in section 'API Compiler Phase'. The API of a source file is discussed in 'API Specification'.
The discovery phase provides a representation of the API in the form of a data structure, which is discussed in the section 'API Data Structure'. This data structure is a simple hierarchy of Java classes and enums generated from a definition file. The generated data structure exists in the 'interface' project under the 'xsbti.api' package.
The file that defines the hierarchy is processed by a small datatype generating subproject called 'datatype'. This subproject defines a basic syntax for creating an immutable data structure hierarchy in Java. The output is in Java in order to use the data structure across Scala versions.
Finally, the data structure needs to be persisted. This is currently implemented with standard Java serialization, but will likely use SBinary for a custom implementation for efficiency.
= API Specification =
This section specifies what the API of a source file is. Familiarity with the specification for Scala is assumed. For this specification, let 'classes' include classes, traits, objects, and package objects (2.8+ only).
Loosely, the API consists of the signatures in a source file. This includes packages and types of classes in a source. The type of a class includes its fully qualified name, type parameters, base classes, and member signatures.
Equality of APIs is determined by straightforward structural equality except for type parameter definitions and references.
* The ID of a type parameter does not affect equality between two type parameters. The mapping between IDs of equal type parameters is recorded, however.
* When comparing two type parameter references, the comparison is deferred until initial equality checking (all other equality checking) is done. Then, the IDs are compared according to the mapping determined for type parameters in the initial check.
== Top Level Constructs ==
The top level contributions to the API in a source file are packages and top-level classes. Packages in Scala can be nested, but how they are nested is not important for the API of a source file. That only affects scope within that source file [VERIFY]. A top level class is a class that is not enclosed in another class or a method.
The public API of a source file is then:
* The set of fully qualified package names defined in the file. This includes packages without any classes in them or package objects defined for them.
* The API of the set of top level classes. The API of a class is defined in 'Class API' below.
== Definitions ==
A definition introduces a new named class or a class member. Class members include vars, vals, defs, and types. A definition has modifiers, including access restrictions. Other attributes of definitions are specific to the type of definition. The access modifiers are treated here separately and the effective modifiers are considered. For example, traits and abstract members are always considered to have the 'abstract' modifier. Synthetic refers to whether a definition was generated by the compiler.
The API of a definition is
* The definition's name, which is fully-qualified if it is a class.
* The list of annotations on the definition
* The state of the following modifiers: abstract, override, final, sealed, implicit, lazy, synthetic
* The access restrictions of the definition, one of:
* public
* protected with qualifier
* private with qualifier
A qualifier part is either empty, 'this', or the fully qualified name of an enclosing package or class.
* The API specific to the definition, described below
=== Field-like API ===
A field is a val or a var. Fields contribute setter and getter methods, but the API they contribute cannot be completely defined by these. The presence of a val or var affect the rules for overriding.
The field-specific API (contributed in addition to the parts common to all definitions) is then:
* Whether the field is a val or var.
* The type of the field.
* The API of associated setters and getters.
=== Type Parameters ===
Type parameters are not a definition, but they are used by methods, classes, and type members. The important aspects of a type parameter are its position in its defining parameter list and its upper and lower bounds, which are types. The actual name of a type parameter is not important, but it needs to be uniquely referenced within a source file.
The API contributed by a type parameter section is:
* The API of each type parameter in the type parameter section, in order. The number of type parameters is implicit here.
* The API of a type parameter is:
* A unique ID, which is not significant on its own, but is used to refer to this parameter in types. (the ID is relative, not absolute)
* The lower bound, a type.
* The upper bound, a type.
=== Method API ===
A method is a def. A def consists of type parameters, value parameters and a return type. The value parameters come in sections (parameter lists) and the last section may be declared 'implicit'. A value parameter consists of a name (2.8+ only), a type, and whether a default is specified (2.8+ only). Additionally, a value parameter may be repeated or by-name.
The API specific to a method (contributed in addition to the parts common to all definitions) is:
* The API contributed by its type parameter section, described in the Type Parameters section previously.
* The return type.
* The API contributed by its value parameter lists, in order. The number of lists is implicit in this definition.
* The API of a value parameter list is:
* Whether the list is marked implicit.
* The API of its value parameters, in order. The number of value parameters is implicit here.
* The API of a value parameter is:
* The parameter name (2.8+ only)
* The parameter type. Types are described later
* The modifier for the parameter type. This can be either 'no modifier', 'by-name', or 'repeated'.
* Whether the parameter has default defined (2.8+ only)
=== Type Member API ===
Type members consist of alias types and abstract types. Each can have type parameters.
The API specific to an alias type (contributed in addition to the parts common to all definitions) is:
* The API contributed by its type parameter section, described in the Type Parameters section previously.
* The type aliased.
The API specific to an abstract type (contributed in addition to the parts common to all definitions) is:
* The API contributed by its type parameter section, described in the Type Parameters section previously.
* The lower bound, a type.
* The upper bound, a type.
=== Class API ===
A class has a self type, whether it is a trait, class, object, or package object, and a structure. Its structure includes its base classes and its members, both declared and inherited.
The API specific to a class (contributed in addition to the parts common to all definitions) is:
* The self type of the class.
* Whether the class is a trait, class, object, or package object.
* The structure, which is described by a structural type.
== Types ==
Types can be described as simple, annotated, structural, or existential. Within simple types are projections, singletons, type variable references, parameterized types. Types are well described in the Scala specification. They are described here because they are essential to defining the API of a source file.
The following sections briefly describe the contents of the different types.
=== Projection ===
* A prefix, which is a simple type
* An ID, which is a String
=== Type Variable Reference ===
* The unique ID of the referenced type variable
=== Singleton ===
* The path underlying the singleton.
=== Parameterized ===
* The type arguments, which is an ordered list of simple types.
* The base type, which is a simple type.
=== Annotated ===
* A list of annotations
* The base type, which is a simple type
=== Structural ===
* The base class types, in linearization order.
* The declared members. These are definitions, described above.
* The inherited members. These are definitions, described above.
=== Existential ===
* The base type
* The clause, which is a type parameter section, described previously
=== Polymorphic ===
* The base type
* The type parameter section, described previously
= API Data Structure =
This section and explains the data structure representing the API of a source file described in the previous section.
As mentioned in the introduction, the data structure is defined by the 'definition' file in the 'interface' subproject. Code from the 'datatype' subproject processes this file and generates Java sources in 'src_managed' in the 'interface' subproject. The explanation includes listings from the definition file. These listings are current as of November 24, 2009.
The top-level datatype is `Source`. It represents the API in a single source file. Packages are listed separately from definitions for two reasons. First, packages cannot be inferred from definitions because a source file can introduce a package without a top-level definition in that package. A reasonable alternative would have been including Definitions in Packages. However, it is anticipated that the most common operation will be to iterate directly over definitions.
{{{
Source
packages : Package*
definitions: Definition*
}}}
A package is represented as a simple String. More structure is not required as explained in the API specification section.
{{{
Package
name: String
}}}
Definitions are represented by straightforward subclasses of a Definition class. vals and vars are FieldLike subclasses that differ only by their class name. The remaining definition variants all have type parameters and so they share a common parent that provides this information. Class definitions are represented by a single class and the variants (traits, objects, ...) are distinguished by the 'definitionType' field. The 'selfType' field can be an instance of the special Type EmptyType, which indicates that the self type is not different from the normal self type.
{{{
Definition
name: String
access: Access
modifiers: Modifiers
annotations: Annotation*
FieldLike
tpe : Type
Val
Var
ParameterizedDefinition
typeParameters: TypeParameter*
Def
valueParameters: ParameterList*
returnType: Type
ClassLike
definitionType: DefinitionType
selfType: Type
structure: Structure
TypeMember
TypeAlias
tpe: Type
TypeDeclaration
lowerBound: Type
upperBound: Type
}}}
Types are fairly straightforward representations as well. They are intended to correspond closely to the types defined in the Scala specification. Note that function, infix, and tuple types translate to parameterized types and type designators translate to type projections. Compound types and refinements are represented by the Structure class.
{{{
Type
SimpleType
Projection
prefix : SimpleType
id : String
ParameterRef
id: Int
Singleton
path: Path
EmptyType
Parameterized
baseType : SimpleType
typeArguments: Type*
Annotated
baseType : SimpleType
annotations : Annotation*
Structure
parents : Type*
declarations: Definition*
inherited: Definition*
Existential
baseType : Type
clause: TypeParameter*
Polymorphic
baseType : Type
clause: TypeParameter*
}}}
There is one point to note about the access hierarchy. It includes a Pkg class, which represents Java's package private access. This is only used for Java sources.
{{{
Access
Public
Qualified
qualifier: Qualifier
Protected
Private
Pkg
Qualifier
Unqualified
ThisQualifier
IdQualifier
value: String
}}}
Modifiers are straightforward except that abstract is split into abstract and deferred, according to the Scala compiler's internal representation. Abstract applies to traits and abstract classes, while deferred applies to class members.
{{{
Modifiers
isAbstract: Boolean
isDeferred: Boolean
isOverride: Boolean
isFinal: Boolean
isSealed: Boolean
isImplicit: Boolean
isLazy: Boolean
isSynthetic: Boolean
isMacro: Boolean
}}}
{{{
ParameterList
parameters: MethodParameter*
isImplicit: Boolean
MethodParameter
name: String
tpe: Type
hasDefault: Boolean
modifier: ParameterModifier
TypeParameter
id: Int
typeParameters : TypeParameter*
variance: Variance
lowerBound: Type
upperBound: Type
}}}
The representation of annotations does not express the full information that the compiler has about annotations. The arguments to an annotation are constant expressions. This could be represented in this data structure, but this is not currently done. Rather, the arguments are converted to a String in an unspecified manner.
{{{
Annotation
base: SimpleType
arguments: String*
}}}
enum Variance : Contravariant, Covariant, Invariant
enum ParameterModifier : Repeated, Plain, ByName
enum DefinitionType : Trait, ClassDef, Module, PackageModule
Path
components: PathComponent*
PathComponent
Super
qualifier: Path
This
Id
id: String
}}}
= API Compiler Phase =
= Data Structure Generator =
= API Data Structure Persistence =
The data structure is persisted by standard Java serialization on Source. This is done for simplicity and will be changed to use a more efficient encoding.

View File

@ -109,7 +109,7 @@ lazy val testAgentProj = (project in file("testing") / "agent").
)
// Basic task engine
lazy val taskProj = (project in tasksPath).
lazy val taskProj = (project in file("tasks")).
settings(
testedBaseSettings,
name := "Tasks",
@ -117,7 +117,7 @@ lazy val taskProj = (project in tasksPath).
)
// Standard task system. This provides map, flatMap, join, and more on top of the basic task model.
lazy val stdTaskProj = (project in tasksPath / "standard").
lazy val stdTaskProj = (project in file("tasks-standard")).
dependsOn (taskProj % "compile;test->test").
settings(
testedBaseSettings,
@ -153,7 +153,7 @@ lazy val scriptedPluginProj = (project in scriptedPath / "plugin").
)
// Implementation and support code for defining actions.
lazy val actionsProj = (project in mainPath / "actions").
lazy val actionsProj = (project in file("main-actions")).
dependsOn(runProj, stdTaskProj, taskProj, testingProj).
settings(
testedBaseSettings,
@ -164,7 +164,7 @@ lazy val actionsProj = (project in mainPath / "actions").
)
// General command support and core commands not specific to a build system
lazy val commandProj = (project in mainPath / "command").
lazy val commandProj = (project in file("main-command")).
settings(
testedBaseSettings,
name := "Command",
@ -173,7 +173,7 @@ lazy val commandProj = (project in mainPath / "command").
)
// Fixes scope=Scope for Setting (core defined in collectionProj) to define the settings system used in build definitions
lazy val mainSettingsProj = (project in mainPath / "settings").
lazy val mainSettingsProj = (project in file("main-settings")).
dependsOn(commandProj, stdTaskProj).
settings(
testedBaseSettings,
@ -183,7 +183,7 @@ lazy val mainSettingsProj = (project in mainPath / "settings").
)
// The main integration project for sbt. It brings all of the Projsystems together, configures them, and provides for overriding conventions.
lazy val mainProj = (project in mainPath).
lazy val mainProj = (project in file("main")).
dependsOn(actionsProj, mainSettingsProj, runProj, commandProj).
settings(
testedBaseSettings,
@ -195,7 +195,7 @@ lazy val mainProj = (project in mainPath).
// Strictly for bringing implicits and aliases from subsystems into the top-level sbt namespace through a single package object
// technically, we need a dependency on all of mainProj's dependencies, but we don't do that since this is strictly an integration project
// with the sole purpose of providing certain identifiers without qualification (with a package object)
lazy val sbtProj = (project in sbtPath).
lazy val sbtProj = (project in file("sbt")).
dependsOn(mainProj, scriptedSbtProj % "test->test").
settings(
baseSettings,
@ -297,12 +297,6 @@ def fullDocSettings = Util.baseScalacOptions ++ Docs.settings ++ Sxr.settings ++
dependencyClasspath in (Compile, doc) := (fullClasspath in sxr).value
)
/* Nested Projproject paths */
def sbtPath = file("sbt")
def tasksPath = file("tasks")
def launchPath = file("launch")
def mainPath = file("main")
lazy val safeUnitTests = taskKey[Unit]("Known working tests (for both 2.10 and 2.11)")
lazy val safeProjects: ScopeFilter = ScopeFilter(
inProjects(mainSettingsProj, mainProj,

View File

@ -4,12 +4,13 @@
package sbt
import Keys._
import sbt.internal.{ GCUtil, CommandStrings }
import sbt.internal.util.complete.{ DefaultParsers, Parser }
import sbt.internal.util.AttributeKey
import DefaultParsers._
import Def.{ ScopedKey, Setting }
import Scope.GlobalScope
import CommandStrings.{ CrossCommand, crossHelp, SwitchCommand, switchHelp }
import sbt.internal.CommandStrings.{ CrossCommand, crossHelp, SwitchCommand, switchHelp }
import java.io.File
import sbt.internal.inc.ScalaInstance

View File

@ -4,6 +4,7 @@
package sbt
import scala.concurrent.duration.{ FiniteDuration, Duration }
import sbt.internal._
import sbt.internal.util.Attributed
import sbt.internal.util.Attributed.data
import Scope.{ fillTaskAxis, GlobalScope, ThisScope }
@ -23,7 +24,6 @@ import sbt.internal.inc.{ Analysis, ClassfileManager, ClasspathOptions, Compiler
import testing.{ Framework, Runner, AnnotatedFingerprint, SubclassFingerprint }
import sbt.librarymanagement.{ `package` => _, _ }
import sbt.internal.OldPlugin
import sbt.internal.librarymanagement._
import sbt.internal.librarymanagement.syntax._
import sbt.internal.util._
@ -39,7 +39,7 @@ import java.util.concurrent.{ TimeUnit, Callable }
import sbinary.DefaultProtocol.StringFormat
import sbt.internal.util.Cache.seqFormat
import sbt.util.Logger
import CommandStrings.ExportStream
import sbt.internal.CommandStrings.ExportStream
import xsbti.Maybe
import sbt.util.InterfaceUtil.{ f1, o2m }

View File

@ -3,7 +3,7 @@
*/
package sbt
import sbt.internal.Load
import sbt.internal.{ Load, BuildStructure, TaskTimings, TaskName, GCUtil }
import sbt.internal.util.{ ErrorHandling, RMap, Show, Signals, Types }
import sbt.util.Logger
import sbt.librarymanagement.{ Resolver, UpdateReport }

View File

@ -1,6 +1,6 @@
package sbt
import sbt.internal.Load
import sbt.internal.{ Load, BuildStructure, Act, Aggregation, SessionSettings }
import Project._
import Scope.GlobalScope
import Def.{ ScopedKey, Setting }

View File

@ -19,6 +19,7 @@ import testing.Framework
import sbt.internal.util.Types.Id
import KeyRanks._
import sbt.internal.{ BuildStructure, LoadedBuild, PluginDiscovery, BuildDependencies, SessionSettings }
import sbt.io.FileFilter
import sbt.internal.io.WatchState
import sbt.internal.util.AttributeKey

View File

@ -3,7 +3,8 @@
*/
package sbt
import sbt.internal.Load
import sbt.internal.{ Load, EvaluateConfigurations, LoadedBuildUnit, Aggregation, BuildStructure, Act, Inspect, BuildUnit, Output, PluginsDebug }
import sbt.internal.{ SettingCompletions, CommandStrings, IvyConsole, ProjectNavigation, Script, SessionSettings }
import sbt.internal.util.{ AttributeKey, AttributeMap, complete, ConsoleOut, GlobalLogging, LineRange, MainLogging, SimpleReader, Types }
import sbt.util.{ Level, Logger }
@ -31,7 +32,7 @@ final class xMain extends xsbti.AppMain {
import BasicCommands.early
import BasicCommandStrings.runEarly
import BuiltinCommands.{ initialize, defaults }
import CommandStrings.{ BootCommand, DefaultsCommand, InitCommand }
import sbt.internal.CommandStrings.{ BootCommand, DefaultsCommand, InitCommand }
runManaged(initialState(configuration,
Seq(defaults, early),
runEarly(DefaultsCommand) :: runEarly(InitCommand) :: BootCommand :: Nil)
@ -79,7 +80,7 @@ object StandardMain {
}
import DefaultParsers._
import CommandStrings._
import sbt.internal.CommandStrings._
import BasicCommandStrings._
import BasicCommands._
import CommandUtil._

View File

@ -10,7 +10,7 @@ import Project._
import Keys.{ appConfiguration, stateBuildStructure, commands, configuration, historyPath, projectCommand, sessionSettings, shellPrompt, thisProject, thisProjectRef, watch }
import Scope.{ GlobalScope, ThisScope }
import Def.{ Flattened, Initialize, ScopedKey, Setting }
import sbt.internal.Load
import sbt.internal.{ Load, BuildStructure, LoadedBuild, LoadedBuildUnit, SettingGraph, SettingCompletions, AddSettings, SessionSettings }
import sbt.internal.util.Eval
import sbt.internal.util.Types.{ const, idFun }
import sbt.internal.util.complete.DefaultParsers
@ -354,7 +354,7 @@ object Project extends ProjectExtra {
def isProjectLoaded(state: State): Boolean = (state has sessionSettings) && (state has stateBuildStructure)
def extract(state: State): Extracted = extract(session(state), structure(state))
def extract(se: SessionSettings, st: BuildStructure): Extracted = Extracted(st, se, se.current)(showContextKey(se, st))
private[sbt] def extract(se: SessionSettings, st: BuildStructure): Extracted = Extracted(st, se, se.current)(showContextKey(se, st))
def getProjectForReference(ref: Reference, structure: BuildStructure): Option[ResolvedProject] =
ref match { case pr: ProjectRef => getProject(pr, structure); case _ => None }

View File

@ -1,6 +1,6 @@
package sbt
import sbt.internal.Load
import sbt.internal.{ Load, LoadedBuildUnit }
import sbt.internal.util.{ AttributeKey, Dag, Types }
import sbt.librarymanagement.Configuration

View File

@ -1,17 +0,0 @@
package sbt
import sbt.librarymanagement.Configuration
import internals.{
DslEntry,
DslConfigs,
DslEnablePlugins,
DslDisablePlugins
}
package object dsl {
def enablePlugins(ps: AutoPlugin*): DslEntry = DslEnablePlugins(ps)
def disablePlugins(ps: AutoPlugin*): DslEntry = DslDisablePlugins(ps)
def configs(cs: Configuration*): DslEntry = DslConfigs(cs)
}

View File

@ -1,4 +1,5 @@
package sbt
package internal
import java.io.File
import java.net.{ MalformedURLException, URL }

View File

@ -2,6 +2,7 @@
* Copyright 2011 Mark Harrah
*/
package sbt
package internal
import Def.{ showRelativeKey, ScopedKey }
import Project.showContextKey
@ -11,7 +12,7 @@ import Aggregation.{ KeyValue, Values }
import DefaultParsers._
import sbt.internal.util.Types.idFun
import java.net.URI
import CommandStrings.{ MultiTaskCommand, ShowCommand }
import sbt.internal.CommandStrings.{ MultiTaskCommand, ShowCommand }
import sbt.internal.util.{ AttributeEntry, AttributeKey, AttributeMap, IMap, Settings, Show, Util }
final class ParsedKey(val key: ScopedKey[_], val mask: ScopeMask)

View File

@ -1,7 +1,7 @@
package sbt
package internal
import sbt.internal.util.Types.const
import sbt.internal.OldPlugin
import java.io.File
/**

View File

@ -2,6 +2,7 @@
* Copyright 2011 Mark Harrah
*/
package sbt
package internal
import Def.ScopedKey
import Keys.{ aggregate, showSuccess, showTiming, timingFormat }
@ -9,14 +10,14 @@ import sbt.internal.util.complete.Parser
import sbt.internal.util.{ Dag, HList, Relation, Settings, Show, Util }
import sbt.util.Logger
import java.net.URI
import Parser._
import Parser.{ seq, failure, success }
import collection.mutable
import std.Transform.{ DummyTaskMap, TaskAndValue }
sealed trait Aggregation
final object Aggregation {
final case class ShowConfig(settingValues: Boolean, taskValues: Boolean, print: String => Unit, success: Boolean)
final case class Complete[T](start: Long, stop: Long, results: Result[Seq[KeyValue[T]]], state: State)
final case class Complete[T](start: Long, stop: Long, results: sbt.Result[Seq[KeyValue[T]]], state: State)
final case class KeyValue[+T](key: ScopedKey[_], value: T)
def defaultShow(state: State, showTasks: Boolean): ShowConfig = ShowConfig(settingValues = true, taskValues = showTasks, s => state.log.info(s), success = true)
@ -44,7 +45,7 @@ final object Aggregation {
def showRun[T](complete: Complete[T], show: ShowConfig)(implicit display: Show[ScopedKey[_]]): Unit = {
import complete._
val log = state.log
val extracted = Project extract state
val extracted = Project.extract(state)
val success = results match { case Value(_) => true; case Inc(_) => false }
results.toEither.right.foreach { r => if (show.taskValues) printSettings(r, show.print) }
if (show.success) printSuccess(start, stop, extracted, success, log)

View File

@ -1,4 +1,5 @@
package sbt
package internal
import sbt.internal.util.Types.idFun
import sbt.internal.util.Dag

View File

@ -2,6 +2,7 @@
* Copyright 2011 Mark Harrah
*/
package sbt
package internal
import java.io.File
import java.net.URI
@ -9,7 +10,6 @@ import Def.{ displayFull, ScopedKey, ScopeLocal, Setting }
import BuildPaths.outputDirectory
import Scope.GlobalScope
import BuildStreams.Streams
import sbt.internal.{ BuildDef, Load, OldPlugin }
import sbt.io.syntax._
import sbt.internal.util.{ Attributed, AttributeEntry, AttributeKey, AttributeMap, Settings }
import sbt.internal.util.Attributed.data

View File

@ -1,7 +1,7 @@
package sbt
package internal
import sbt.internal.util.{ Relation, Settings, Dag }
import sbt.internal.Load
import java.net.URI
@ -72,7 +72,7 @@ object BuildUtil {
}
}
def baseImports: Seq[String] = "import scala.xml.{TopScope=>$scope}" :: "import sbt._, Keys._, dsl._, syntax._" :: Nil
def baseImports: Seq[String] = "import scala.xml.{TopScope=>$scope}" :: "import sbt._, Keys._, syntax._" :: Nil
def getImports(unit: BuildUnit): Seq[String] = unit.plugins.detected.imports ++ unit.definitions.dslDefinitions.imports

View File

@ -2,6 +2,7 @@
* Copyright 2010 Mark Harrah
*/
package sbt
package internal
import sbt.io.Path

View File

@ -2,6 +2,7 @@
* Copyright 2011 Mark Harrah
*/
package sbt
package internal
import sbt.util.Logger
import java.io.File

View File

@ -0,0 +1,65 @@
package sbt
package internal
import sbt.internal.util.RangePosition
import sbt.librarymanagement.Configuration
import Def._
/** This reprsents a `Setting` expression configured by the sbt DSL. */
sealed trait DslEntry {
/** Called by the parser. Sets the position where this entry was defined in the build.sbt file. */
def withPos(pos: RangePosition): DslEntry
}
object DslEntry {
implicit def fromSettingsDef(inc: SettingsDefinition): DslEntry =
DslSetting(inc)
implicit def fromSettingsDef(inc: Seq[Setting[_]]): DslEntry =
DslSetting(inc)
/** Represents a DSL entry which adds settings to the current project. */
sealed trait ProjectSettings extends DslEntry {
def toSettings: Seq[Setting[_]]
}
object ProjectSettings {
def unapply(e: DslEntry): Option[Seq[Setting[_]]] =
e match {
case e: ProjectSettings => Some(e.toSettings)
case _ => None
}
}
/** Represents a DSL entry which manipulates the current project. */
sealed trait ProjectManipulation extends DslEntry {
def toFunction: Project => Project
// TODO - Should we store this?
final def withPos(pos: RangePosition): DslEntry = this
}
object ProjectManipulation {
def unapply(e: DslEntry): Option[Project => Project] =
e match {
case e: ProjectManipulation => Some(e.toFunction)
case _ => None
}
}
/** this represents an actually Setting[_] or Seq[Setting[_]] configured by the sbt DSL. */
case class DslSetting(settings: SettingsDefinition) extends ProjectSettings {
def toSettings = settings.settings
final def withPos(pos: RangePosition): DslEntry = DslSetting(settings.settings.map(_.withPos(pos)))
}
/** this represents an `enablePlugins()` in the sbt DSL */
case class DslEnablePlugins(plugins: Seq[AutoPlugin]) extends ProjectManipulation {
override val toFunction: Project => Project = _.enablePlugins(plugins: _*)
}
/** this represents an `disablePlugins()` in the sbt DSL */
case class DslDisablePlugins(plugins: Seq[AutoPlugin]) extends ProjectManipulation {
override val toFunction: Project => Project = _.disablePlugins(plugins: _*)
}
/** Represents registering a set of configurations with the current project. */
case class DslConfigs(cs: Seq[Configuration]) extends ProjectManipulation {
override val toFunction: Project => Project = _.configs(cs: _*)
}
}

View File

@ -2,6 +2,7 @@
* Copyright 2011 Mark Harrah
*/
package sbt
package internal
import sbt.internal.util.{ complete, AttributeEntry, AttributeKey, LineRange, MessageOnlyException, RangePosition, Settings }
@ -10,7 +11,7 @@ import compiler.{ Eval, EvalImports }
import complete.DefaultParsers.validID
import Def.{ ScopedKey, Setting }
import Scope.GlobalScope
import sbt.internals.parser.SbtParser
import sbt.internal.parser.SbtParser
import scala.annotation.tailrec
@ -27,7 +28,7 @@ import sbt.io.IO
*
*
*/
object EvaluateConfigurations {
private[sbt] object EvaluateConfigurations {
type LazyClassLoaded[T] = ClassLoader => T
@ -130,15 +131,15 @@ object EvaluateConfigurations {
}
val (settingsRaw, manipulationsRaw) =
dslEntries map (_.result apply loader) partition {
case internals.ProjectSettings(_) => true
case _ => false
case DslEntry.ProjectSettings(_) => true
case _ => false
}
val settings = settingsRaw flatMap {
case internals.ProjectSettings(settings) => settings
case _ => Nil
case DslEntry.ProjectSettings(settings) => settings
case _ => Nil
}
val manipulations = manipulationsRaw map {
case internals.ProjectManipulation(f) => f
case DslEntry.ProjectManipulation(f) => f
}
// TODO -get project manipulations.
new LoadedSbtFile(settings, projects, importDefs, manipulations, definitions, allGeneratedFiles)
@ -158,8 +159,8 @@ object EvaluateConfigurations {
* The name of the class we cast DSL "setting" (vs. definition) lines to.
*/
val SettingsDefinitionName = {
val _ = classOf[sbt.internals.DslEntry] // this line exists to try to provide a compile-time error when the following line needs to be changed
"sbt.internals.DslEntry"
val _ = classOf[DslEntry] // this line exists to try to provide a compile-time error when the following line needs to be changed
"sbt.internal.DslEntry"
}
/**
@ -171,10 +172,10 @@ object EvaluateConfigurations {
* @param expression The scala expression we're compiling
* @param range The original position in source of the expression, for error messages.
*
* @return A method that given an sbt classloader, can return the actual [[internals.DslEntry]] defined by
* @return A method that given an sbt classloader, can return the actual [[sbt.internal.DslEntry]] defined by
* the expression, and the sequence of .class files generated.
*/
private[sbt] def evaluateDslEntry(eval: Eval, name: String, imports: Seq[(String, Int)], expression: String, range: LineRange): TrackedEvalResult[internals.DslEntry] = {
private[sbt] def evaluateDslEntry(eval: Eval, name: String, imports: Seq[(String, Int)], expression: String, range: LineRange): TrackedEvalResult[DslEntry] = {
// TODO - Should we try to namespace these between.sbt files? IF they hash to the same value, they may actually be
// exactly the same setting, so perhaps we don't care?
val result = try {
@ -186,7 +187,7 @@ object EvaluateConfigurations {
TrackedEvalResult(result.generated,
loader => {
val pos = RangePosition(name, range shift 1)
result.getValue(loader).asInstanceOf[internals.DslEntry].withPos(pos)
result.getValue(loader).asInstanceOf[DslEntry].withPos(pos)
})
}
@ -207,8 +208,8 @@ object EvaluateConfigurations {
def evaluateSetting(eval: Eval, name: String, imports: Seq[(String, Int)], expression: String, range: LineRange): LazyClassLoaded[Seq[Setting[_]]] =
{
evaluateDslEntry(eval, name, imports, expression, range).result andThen {
case internals.ProjectSettings(values) => values
case _ => Nil
case DslEntry.ProjectSettings(values) => values
case _ => Nil
}
}
private[this] def isSpace = (c: Char) => Character isWhitespace c

View File

@ -1,4 +1,5 @@
package sbt
package internal
import java.util.concurrent.atomic.AtomicLong
import scala.concurrent.duration._

View File

@ -1,9 +1,8 @@
package sbt
package internal
import sbt.librarymanagement.{ Configuration, Configurations, ModuleID, Resolver, SbtArtifacts, UpdateReport }
import sbt.internal.util.Attributed
import sbt.internal.{ Load, LoadBuildConfiguration }
import Def.{ ScopedKey, Setting }
import Scoped._
import Keys._

View File

@ -1,4 +1,5 @@
package sbt
package internal
import Def.Setting
import java.net.URI
@ -15,4 +16,4 @@ private[sbt] object GroupedAutoPlugins {
val all: Seq[AutoPlugin] = byBuild.values.toSeq.flatten.distinct
new GroupedAutoPlugins(all, byBuild)
}
}
}

View File

@ -1,4 +1,5 @@
package sbt
package internal
import sbt.internal.util.{ AttributeKey, complete, Types }

View File

@ -2,8 +2,8 @@
* Copyright 2011 Mark Harrah
*/
package sbt
package internal
import sbt.internal.Load
import sbt.internal.util.Attributed
import sbt.util.{ Level, Logger }

View File

@ -2,6 +2,7 @@
* Copyright 2011 Mark Harrah
*/
package sbt
package internal
import sbt.internal.util.Relation
@ -68,32 +69,32 @@ trait ExtendableKeyIndex extends KeyIndex {
def addAggregated(scoped: ScopedKey[_], extra: BuildUtil[_]): ExtendableKeyIndex
}
// task axis <-> key
private final class AKeyIndex(val data: Relation[Option[AttributeKey[_]], String]) {
private[sbt] final class AKeyIndex(val data: Relation[Option[AttributeKey[_]], String]) {
def add(task: Option[AttributeKey[_]], key: AttributeKey[_]): AKeyIndex = new AKeyIndex(data + (task, key.rawLabel) + (task, key.label))
def keys(task: Option[AttributeKey[_]]): Set[String] = data.forward(task)
def allKeys: Set[String] = data._2s.toSet
def tasks: Set[AttributeKey[_]] = data._1s.flatten.toSet
def tasks(key: String): Set[AttributeKey[_]] = data.reverse(key).flatten.toSet
}
private final class ConfigIndex(val data: Map[Option[String], AKeyIndex]) {
private[sbt] final class ConfigIndex(val data: Map[Option[String], AKeyIndex]) {
def add(config: Option[String], task: Option[AttributeKey[_]], key: AttributeKey[_]): ConfigIndex =
new ConfigIndex(data updated (config, keyIndex(config).add(task, key)))
def keyIndex(conf: Option[String]): AKeyIndex = getOr(data, conf, emptyAKeyIndex)
def configs: Set[String] = keySet(data)
}
private final class ProjectIndex(val data: Map[Option[String], ConfigIndex]) {
private[sbt] final class ProjectIndex(val data: Map[Option[String], ConfigIndex]) {
def add(id: Option[String], config: Option[String], task: Option[AttributeKey[_]], key: AttributeKey[_]): ProjectIndex =
new ProjectIndex(data updated (id, confIndex(id).add(config, task, key)))
def confIndex(id: Option[String]): ConfigIndex = getOr(data, id, emptyConfigIndex)
def projects: Set[String] = keySet(data)
}
private final class BuildIndex(val data: Map[Option[URI], ProjectIndex]) {
private[sbt] final class BuildIndex(val data: Map[Option[URI], ProjectIndex]) {
def add(build: Option[URI], project: Option[String], config: Option[String], task: Option[AttributeKey[_]], key: AttributeKey[_]): BuildIndex =
new BuildIndex(data updated (build, projectIndex(build).add(project, config, task, key)))
def projectIndex(build: Option[URI]): ProjectIndex = getOr(data, build, emptyProjectIndex)
def builds: Set[URI] = keySet(data)
}
private final class KeyIndex0(val data: BuildIndex) extends ExtendableKeyIndex {
private[sbt] final class KeyIndex0(val data: BuildIndex) extends ExtendableKeyIndex {
def buildURIs: Set[URI] = data.builds
def projects(uri: URI): Set[String] = data.projectIndex(Some(uri)).projects
def exists(proj: Option[ResolvedReference]): Boolean =

View File

@ -34,7 +34,7 @@ import xsbti.compile.Compilers
private[sbt] object Load {
// note that there is State passed in but not pulled out
def defaultLoad(state: State, baseDirectory: File, log: Logger, isPlugin: Boolean = false, topLevelExtras: List[URI] = Nil): (() => Eval, sbt.BuildStructure) =
def defaultLoad(state: State, baseDirectory: File, log: Logger, isPlugin: Boolean = false, topLevelExtras: List[URI] = Nil): (() => Eval, BuildStructure) =
{
val globalBase = getGlobalBase(state)
val base = baseDirectory.getCanonicalFile
@ -111,7 +111,7 @@ private[sbt] object Load {
} else
config
def defaultDelegates: sbt.LoadedBuild => Scope => Seq[Scope] = (lb: sbt.LoadedBuild) => {
def defaultDelegates: LoadedBuild => Scope => Seq[Scope] = (lb: LoadedBuild) => {
val rootProject = getRootProject(lb.units)
def resolveRef(project: Reference): ResolvedReference = Scope.resolveReference(lb.root, rootProject, project)
Scope.delegates(
@ -125,15 +125,15 @@ private[sbt] object Load {
(project, extra) => Nil
)
}
def configInherit(lb: sbt.LoadedBuild, ref: ResolvedReference, config: ConfigKey, rootProject: URI => String): Seq[ConfigKey] =
def configInherit(lb: LoadedBuild, ref: ResolvedReference, config: ConfigKey, rootProject: URI => String): Seq[ConfigKey] =
ref match {
case pr: ProjectRef => configInheritRef(lb, pr, config)
case BuildRef(uri) => configInheritRef(lb, ProjectRef(uri, rootProject(uri)), config)
}
def configInheritRef(lb: sbt.LoadedBuild, ref: ProjectRef, config: ConfigKey): Seq[ConfigKey] =
def configInheritRef(lb: LoadedBuild, ref: ProjectRef, config: ConfigKey): Seq[ConfigKey] =
configurationOpt(lb.units, ref.build, ref.project, config).toList.flatMap(_.extendsConfigs).map(c => ConfigKey(c.name))
def projectInherit(lb: sbt.LoadedBuild, ref: ProjectRef): Seq[ProjectRef] =
def projectInherit(lb: LoadedBuild, ref: ProjectRef): Seq[ProjectRef] =
getProject(lb.units, ref.build, ref.project).delegates
// build, load, and evaluate all units.
@ -145,7 +145,7 @@ private[sbt] object Load {
// 6) Load all configurations using build definitions and plugins (their classpaths and loaded instances).
// 7) Combine settings from projects, plugins, and configurations
// 8) Evaluate settings
def apply(rootBase: File, s: State, config: LoadBuildConfiguration): (() => Eval, sbt.BuildStructure) =
def apply(rootBase: File, s: State, config: LoadBuildConfiguration): (() => Eval, BuildStructure) =
{
// load, which includes some resolution, but can't fill in project IDs yet, so follow with full resolution
val loaded = resolveProjects(load(rootBase, s, config))
@ -157,7 +157,7 @@ private[sbt] object Load {
Project.checkTargets(data) foreach sys.error
val index = structureIndex(data, settings, loaded.extra(data), projects)
val streams = mkStreams(projects, loaded.root, data)
(rootEval, new sbt.BuildStructure(projects, loaded.root, settings, data, index, streams, delegates, config.scopeLocal))
(rootEval, new BuildStructure(projects, loaded.root, settings, data, index, streams, delegates, config.scopeLocal))
}
// map dependencies on the special tasks:
@ -190,7 +190,7 @@ private[sbt] object Load {
def setDefinitionKey[T](tk: Task[T], key: ScopedKey[_]): Task[T] =
if (isDummy(tk)) tk else Task(tk.info.set(Keys.taskDefinitionKey, key), tk.work)
def structureIndex(data: Settings[Scope], settings: Seq[Setting[_]], extra: KeyIndex => BuildUtil[_], projects: Map[URI, LoadedBuildUnit]): sbt.StructureIndex =
def structureIndex(data: Settings[Scope], settings: Seq[Setting[_]], extra: KeyIndex => BuildUtil[_], projects: Map[URI, LoadedBuildUnit]): StructureIndex =
{
val keys = Index.allKeys(settings)
val attributeKeys = Index.attributeKeys(data) ++ keys.map(_.key)
@ -198,21 +198,21 @@ private[sbt] object Load {
val projectsMap = projects.mapValues(_.defined.keySet)
val keyIndex = KeyIndex(scopedKeys, projectsMap)
val aggIndex = KeyIndex.aggregate(scopedKeys, extra(keyIndex), projectsMap)
new sbt.StructureIndex(Index.stringToKeyMap(attributeKeys), Index.taskToKeyMap(data), Index.triggers(data), keyIndex, aggIndex)
new StructureIndex(Index.stringToKeyMap(attributeKeys), Index.taskToKeyMap(data), Index.triggers(data), keyIndex, aggIndex)
}
// Reevaluates settings after modifying them. Does not recompile or reload any build components.
def reapply(newSettings: Seq[Setting[_]], structure: sbt.BuildStructure)(implicit display: Show[ScopedKey[_]]): sbt.BuildStructure =
def reapply(newSettings: Seq[Setting[_]], structure: BuildStructure)(implicit display: Show[ScopedKey[_]]): BuildStructure =
{
val transformed = finalTransforms(newSettings)
val newData = Def.make(transformed)(structure.delegates, structure.scopeLocal, display)
val newIndex = structureIndex(newData, transformed, index => BuildUtil(structure.root, structure.units, index, newData), structure.units)
val newStreams = mkStreams(structure.units, structure.root, newData)
new sbt.BuildStructure(units = structure.units, root = structure.root, settings = transformed, data = newData, index = newIndex, streams = newStreams, delegates = structure.delegates, scopeLocal = structure.scopeLocal)
new BuildStructure(units = structure.units, root = structure.root, settings = transformed, data = newData, index = newIndex, streams = newStreams, delegates = structure.delegates, scopeLocal = structure.scopeLocal)
}
def isProjectThis(s: Setting[_]) = s.key.scope.project match { case This | Select(ThisProject) => true; case _ => false }
def buildConfigurations(loaded: sbt.LoadedBuild, rootProject: URI => String, injectSettings: InjectSettings): Seq[Setting[_]] =
def buildConfigurations(loaded: LoadedBuild, rootProject: URI => String, injectSettings: InjectSettings): Seq[Setting[_]] =
{
((loadedBuild in GlobalScope :== loaded) +:
transformProjectOnly(loaded.root, rootProject, injectSettings.global)) ++
@ -237,7 +237,7 @@ private[sbt] object Load {
}
}
@deprecated("Does not account for AutoPlugins and will be made private.", "0.13.2")
def pluginGlobalSettings(loaded: sbt.LoadedBuild): Seq[Setting[_]] =
def pluginGlobalSettings(loaded: LoadedBuild): Seq[Setting[_]] =
loaded.units.toSeq flatMap {
case (_, build) =>
build.unit.plugins.detected.plugins.values flatMap { _.globalSettings }
@ -249,13 +249,13 @@ private[sbt] object Load {
Project.transform(Scope.resolveScope(thisScope, uri, rootProject), settings)
def projectScope(project: Reference): Scope = Scope(Select(project), Global, Global, Global)
def lazyEval(unit: sbt.BuildUnit): () => Eval =
def lazyEval(unit: BuildUnit): () => Eval =
{
lazy val eval = mkEval(unit)
() => eval
}
def mkEval(unit: sbt.BuildUnit): Eval = mkEval(unit.definitions, unit.plugins, unit.plugins.pluginData.scalacOptions)
def mkEval(defs: sbt.LoadedDefinitions, plugs: sbt.LoadedPlugins, options: Seq[String]): Eval =
def mkEval(unit: BuildUnit): Eval = mkEval(unit.definitions, unit.plugins, unit.plugins.pluginData.scalacOptions)
def mkEval(defs: LoadedDefinitions, plugs: LoadedPlugins, options: Seq[String]): Eval =
mkEval(defs.target ++ plugs.classpath, defs.base, options)
def mkEval(classpath: Seq[File], base: File, options: Seq[String]): Eval =
new Eval(options, classpath, s => new ConsoleReporter(s), Some(evalOutputDirectory(base)))
@ -288,7 +288,7 @@ private[sbt] object Load {
if (srcs.isEmpty) const(LoadedSbtFile.empty)
else EvaluateConfigurations(eval(), srcs, imports)
def load(file: File, s: State, config: LoadBuildConfiguration): sbt.PartBuild =
def load(file: File, s: State, config: LoadBuildConfiguration): PartBuild =
load(file, builtinLoader(s, config.copy(pluginManagement = config.pluginManagement.shift, extraBuilds = Nil)), config.extraBuilds.toList)
def builtinLoader(s: State, config: LoadBuildConfiguration): BuildLoader =
{
@ -298,19 +298,19 @@ private[sbt] object Load {
val components = BuildLoader.components(resolver, build, full = BuildLoader.componentLoader)
BuildLoader(components, fail, s, config)
}
def load(file: File, loaders: BuildLoader, extra: List[URI]): sbt.PartBuild = loadURI(IO.directoryURI(file), loaders, extra)
def loadURI(uri: URI, loaders: BuildLoader, extra: List[URI]): sbt.PartBuild =
def load(file: File, loaders: BuildLoader, extra: List[URI]): PartBuild = loadURI(IO.directoryURI(file), loaders, extra)
def loadURI(uri: URI, loaders: BuildLoader, extra: List[URI]): PartBuild =
{
IO.assertAbsolute(uri)
val (referenced, map, newLoaders) = loadAll(uri :: extra, Map.empty, loaders, Map.empty)
checkAll(referenced, map)
val build = new sbt.PartBuild(uri, map)
val build = new PartBuild(uri, map)
newLoaders transformAll build
}
def addOverrides(unit: sbt.BuildUnit, loaders: BuildLoader): BuildLoader =
def addOverrides(unit: BuildUnit, loaders: BuildLoader): BuildLoader =
loaders updatePluginManagement PluginManagement.extractOverrides(unit.plugins.fullClasspath)
def addResolvers(unit: sbt.BuildUnit, isRoot: Boolean, loaders: BuildLoader): BuildLoader =
def addResolvers(unit: BuildUnit, isRoot: Boolean, loaders: BuildLoader): BuildLoader =
unit.definitions.builds.flatMap(_.buildLoaders).toList match {
case Nil => loaders
case x :: xs =>
@ -319,7 +319,7 @@ private[sbt] object Load {
if (isRoot) loaders.setRoot(resolver) else loaders.addNonRoot(unit.uri, resolver)
}
def loaded(unit: sbt.BuildUnit): (sbt.PartBuildUnit, List[ProjectReference]) =
def loaded(unit: BuildUnit): (PartBuildUnit, List[ProjectReference]) =
{
val defined = projects(unit)
if (defined.isEmpty) sys.error("No projects defined in build unit " + unit)
@ -332,16 +332,16 @@ private[sbt] object Load {
val explicitRoots = unit.definitions.builds.flatMap(_.rootProject)
val projectsInRoot = if (explicitRoots.isEmpty) defined.filter(isRoot) else explicitRoots
val rootProjects = if (projectsInRoot.isEmpty) defined.head :: Nil else projectsInRoot
(new sbt.PartBuildUnit(unit, defined.map(d => (d.id, d)).toMap, rootProjects.map(_.id), buildSettings(unit)), externals)
(new PartBuildUnit(unit, defined.map(d => (d.id, d)).toMap, rootProjects.map(_.id), buildSettings(unit)), externals)
}
def buildSettings(unit: sbt.BuildUnit): Seq[Setting[_]] =
def buildSettings(unit: BuildUnit): Seq[Setting[_]] =
{
val buildScope = GlobalScope.copy(project = Select(BuildRef(unit.uri)))
val resolve = Scope.resolveBuildScope(buildScope, unit.uri)
Project.transform(resolve, unit.definitions.builds.flatMap(_.settings))
}
@tailrec def loadAll(bases: List[URI], references: Map[URI, List[ProjectReference]], loaders: BuildLoader, builds: Map[URI, sbt.PartBuildUnit]): (Map[URI, List[ProjectReference]], Map[URI, sbt.PartBuildUnit], BuildLoader) =
@tailrec def loadAll(bases: List[URI], references: Map[URI, List[ProjectReference]], loaders: BuildLoader, builds: Map[URI, PartBuildUnit]): (Map[URI, List[ProjectReference]], Map[URI, PartBuildUnit], BuildLoader) =
bases match {
case b :: bs =>
if (builds contains b)
@ -368,7 +368,7 @@ private[sbt] object Load {
else if (!base.exists)
IO createDirectory base
}
def resolveAll(builds: Map[URI, sbt.PartBuildUnit]): Map[URI, sbt.LoadedBuildUnit] =
def resolveAll(builds: Map[URI, PartBuildUnit]): Map[URI, LoadedBuildUnit] =
{
val rootProject = getRootProject(builds)
builds map {
@ -376,7 +376,7 @@ private[sbt] object Load {
(uri, unit.resolveRefs(ref => Scope.resolveProjectRef(uri, rootProject, ref)))
}
}
def checkAll(referenced: Map[URI, List[ProjectReference]], builds: Map[URI, sbt.PartBuildUnit]): Unit = {
def checkAll(referenced: Map[URI, List[ProjectReference]], builds: Map[URI, PartBuildUnit]): Unit = {
val rootProject = getRootProject(builds)
for ((uri, refs) <- referenced; ref <- refs) {
val ProjectRef(refURI, refID) = Scope.resolveProjectRef(uri, rootProject, ref)
@ -398,7 +398,7 @@ private[sbt] object Load {
}
p => p.copy(base = resolve(p.base))
}
def resolveProjects(loaded: sbt.PartBuild): sbt.LoadedBuild =
def resolveProjects(loaded: PartBuild): LoadedBuild =
{
val rootProject = getRootProject(loaded.units)
val units = loaded.units map {
@ -406,15 +406,15 @@ private[sbt] object Load {
IO.assertAbsolute(uri)
(uri, resolveProjects(uri, unit, rootProject))
}
new sbt.LoadedBuild(loaded.root, units)
new LoadedBuild(loaded.root, units)
}
def resolveProjects(uri: URI, unit: sbt.PartBuildUnit, rootProject: URI => String): sbt.LoadedBuildUnit =
def resolveProjects(uri: URI, unit: PartBuildUnit, rootProject: URI => String): LoadedBuildUnit =
{
IO.assertAbsolute(uri)
val resolve = (_: Project).resolve(ref => Scope.resolveProjectRef(uri, rootProject, ref))
new sbt.LoadedBuildUnit(unit.unit, unit.defined mapValues resolve, unit.rootProjects, unit.buildSettings)
new LoadedBuildUnit(unit.unit, unit.defined mapValues resolve, unit.rootProjects, unit.buildSettings)
}
def projects(unit: sbt.BuildUnit): Seq[Project] =
def projects(unit: BuildUnit): Seq[Project] =
{
// we don't have the complete build graph loaded, so we don't have the rootProject function yet.
// Therefore, we use resolveProjectBuild instead of resolveProjectRef. After all builds are loaded, we can fully resolve ProjectReferences.
@ -422,14 +422,14 @@ private[sbt] object Load {
// although the default loader will resolve the project base directory, other loaders may not, so run resolveBase here as well
unit.definitions.projects.map(resolveBuild compose resolveBase(unit.localBase))
}
def getRootProject(map: Map[URI, sbt.BuildUnitBase]): URI => String =
def getRootProject(map: Map[URI, BuildUnitBase]): URI => String =
uri => getBuild(map, uri).rootProjects.headOption getOrElse emptyBuild(uri)
def getConfiguration(map: Map[URI, sbt.LoadedBuildUnit], uri: URI, id: String, conf: ConfigKey): Configuration =
def getConfiguration(map: Map[URI, LoadedBuildUnit], uri: URI, id: String, conf: ConfigKey): Configuration =
configurationOpt(map, uri, id, conf) getOrElse noConfiguration(uri, id, conf.name)
def configurationOpt(map: Map[URI, sbt.LoadedBuildUnit], uri: URI, id: String, conf: ConfigKey): Option[Configuration] =
def configurationOpt(map: Map[URI, LoadedBuildUnit], uri: URI, id: String, conf: ConfigKey): Option[Configuration] =
getProject(map, uri, id).configurations.find(_.name == conf.name)
def getProject(map: Map[URI, sbt.LoadedBuildUnit], uri: URI, id: String): ResolvedProject =
def getProject(map: Map[URI, LoadedBuildUnit], uri: URI, id: String): ResolvedProject =
getBuild(map, uri).defined.getOrElse(id, noProject(uri, id))
def getBuild[T](map: Map[URI, T], uri: URI): T =
map.getOrElse(uri, noBuild(uri))
@ -439,7 +439,7 @@ private[sbt] object Load {
def noProject(uri: URI, id: String) = sys.error(s"No project '$id' defined in '$uri'.")
def noConfiguration(uri: URI, id: String, conf: String) = sys.error(s"No configuration '$conf' defined in project '$id' in '$uri'")
def loadUnit(uri: URI, localBase: File, s: State, config: LoadBuildConfiguration): sbt.BuildUnit =
def loadUnit(uri: URI, localBase: File, s: State, config: LoadBuildConfiguration): BuildUnit =
{
val normBase = localBase.getCanonicalFile
val defDir = projectStandard(normBase)
@ -485,8 +485,8 @@ private[sbt] object Load {
val valDefinitions = memoSettings.values.foldLeft(DefinedSbtValues.empty) { (prev, sbtFile) =>
prev.zip(sbtFile.definitions)
}
val loadedDefs = new sbt.LoadedDefinitions(defDir, Nil, plugs.loader, defs, loadedProjects, plugs.detected.builds.names, valDefinitions)
new sbt.BuildUnit(uri, normBase, loadedDefs, plugs)
val loadedDefs = new LoadedDefinitions(defDir, Nil, plugs.loader, defs, loadedProjects, plugs.detected.builds.names, valDefinitions)
new BuildUnit(uri, normBase, loadedDefs, plugs)
}
private[this] def autoID(localBase: File, context: PluginManagement.Context, existingIDs: Seq[String]): String =
@ -545,7 +545,7 @@ private[sbt] object Load {
private[this] def loadTransitive(
newProjects: Seq[Project],
buildBase: File,
plugins: sbt.LoadedPlugins,
plugins: LoadedPlugins,
eval: () => Eval,
injectSettings: InjectSettings,
acc: Seq[Project],
@ -651,7 +651,7 @@ private[sbt] object Load {
private[this] def resolveProject(
rawProject: Project,
configFiles: Seq[LoadedSbtFile],
loadedPlugins: sbt.LoadedPlugins,
loadedPlugins: LoadedPlugins,
globalUserSettings: InjectSettings,
memoSettings: mutable.Map[File, LoadedSbtFile],
log: Logger): Project = {
@ -714,7 +714,7 @@ private[sbt] object Load {
private[this] def discoverProjects(
auto: AddSettings,
projectBase: File,
loadedPlugins: sbt.LoadedPlugins,
loadedPlugins: LoadedPlugins,
eval: () => Eval,
memoSettings: mutable.Map[File, LoadedSbtFile]): DiscoveredProjects = {
@ -791,7 +791,7 @@ private[sbt] object Load {
case Some(gp) => config.copy(injectSettings = config.injectSettings.copy(project = gp.inject))
case None => config
}
def plugins(dir: File, s: State, config: LoadBuildConfiguration): sbt.LoadedPlugins =
def plugins(dir: File, s: State, config: LoadBuildConfiguration): LoadedPlugins =
if (hasDefinition(dir))
buildPlugins(dir, s, enableSbtPlugin(activateGlobalPlugin(config)))
else
@ -802,12 +802,12 @@ private[sbt] object Load {
import sbt.io.syntax._
(dir * -GlobFilter(DefaultTargetName)).get.nonEmpty
}
def noPlugins(dir: File, config: LoadBuildConfiguration): sbt.LoadedPlugins =
def noPlugins(dir: File, config: LoadBuildConfiguration): LoadedPlugins =
loadPluginDefinition(dir, config, PluginData(config.globalPluginClasspath, None, None))
def buildPlugins(dir: File, s: State, config: LoadBuildConfiguration): sbt.LoadedPlugins =
def buildPlugins(dir: File, s: State, config: LoadBuildConfiguration): LoadedPlugins =
loadPluginDefinition(dir, config, buildPluginDefinition(dir, s, config))
def loadPluginDefinition(dir: File, config: LoadBuildConfiguration, pluginData: PluginData): sbt.LoadedPlugins =
def loadPluginDefinition(dir: File, config: LoadBuildConfiguration, pluginData: PluginData): LoadedPlugins =
{
val (definitionClasspath, pluginLoader) = pluginDefinitionLoader(config, pluginData)
loadPlugins(dir, pluginData.copy(dependencyClasspath = definitionClasspath), pluginLoader)
@ -852,8 +852,8 @@ private[sbt] object Load {
def loadDefinition(loader: ClassLoader, definition: String): BuildDef =
ModuleUtilities.getObject(definition, loader).asInstanceOf[BuildDef]
def loadPlugins(dir: File, data: PluginData, loader: ClassLoader): sbt.LoadedPlugins =
new sbt.LoadedPlugins(dir, data, loader, PluginDiscovery.discoverAll(data, loader))
def loadPlugins(dir: File, data: PluginData, loader: ClassLoader): LoadedPlugins =
new LoadedPlugins(dir, data, loader, PluginDiscovery.discoverAll(data, loader))
@deprecated("Use PluginDiscovery.onClasspath", "0.13.2")
def onClasspath(classpath: Seq[File])(url: URL): Boolean =
@ -866,17 +866,17 @@ private[sbt] object Load {
def discover(analysis: Analysis, subclasses: String*): Seq[String] =
PluginDiscovery.sourceModuleNames(analysis, subclasses: _*)
def initialSession(structure: sbt.BuildStructure, rootEval: () => Eval, s: State): SessionSettings = {
def initialSession(structure: BuildStructure, rootEval: () => Eval, s: State): SessionSettings = {
val session = s get Keys.sessionSettings
val currentProject = session map (_.currentProject) getOrElse Map.empty
val currentBuild = session map (_.currentBuild) filter (uri => structure.units.keys exists (uri ==)) getOrElse structure.root
new SessionSettings(currentBuild, projectMap(structure, currentProject), structure.settings, Map.empty, Nil, rootEval)
}
def initialSession(structure: sbt.BuildStructure, rootEval: () => Eval): SessionSettings =
def initialSession(structure: BuildStructure, rootEval: () => Eval): SessionSettings =
new SessionSettings(structure.root, projectMap(structure, Map.empty), structure.settings, Map.empty, Nil, rootEval)
def projectMap(structure: sbt.BuildStructure, current: Map[URI, String]): Map[URI, String] =
def projectMap(structure: BuildStructure, current: Map[URI, String]): Map[URI, String] =
{
val units = structure.units
val getRoot = getRootProject(units)
@ -893,7 +893,7 @@ private[sbt] object Load {
@deprecated("Use BuildUtil.baseImports", "0.13.0")
def baseImports = BuildUtil.baseImports
@deprecated("Use BuildUtil.checkCycles", "0.13.0")
def checkCycles(units: Map[URI, sbt.LoadedBuildUnit]): Unit = BuildUtil.checkCycles(units)
def checkCycles(units: Map[URI, LoadedBuildUnit]): Unit = BuildUtil.checkCycles(units)
@deprecated("Use BuildUtil.importAll", "0.13.0")
def importAll(values: Seq[String]): Seq[String] = BuildUtil.importAll(values)
@deprecated("Use BuildUtil.importAllRoot", "0.13.0")
@ -901,7 +901,7 @@ private[sbt] object Load {
@deprecated("Use BuildUtil.rootedNames", "0.13.0")
def rootedName(s: String): String = BuildUtil.rootedName(s)
@deprecated("Use BuildUtil.getImports", "0.13.0")
def getImports(unit: sbt.BuildUnit): Seq[String] = BuildUtil.getImports(unit)
def getImports(unit: BuildUnit): Seq[String] = BuildUtil.getImports(unit)
def referenced[PR <: ProjectReference](definitions: Seq[ProjectDefinition[PR]]): Seq[PR] = definitions flatMap { _.referenced }
@ -909,7 +909,7 @@ private[sbt] object Load {
final case class InjectSettings(global: Seq[Setting[_]], project: Seq[Setting[_]], projectLoaded: ClassLoader => Seq[Setting[_]])
@deprecated("Use BuildUtil.apply", "0.13.0")
def buildUtil(root: URI, units: Map[URI, sbt.LoadedBuildUnit], keyIndex: KeyIndex, data: Settings[Scope]): BuildUtil[ResolvedProject] = BuildUtil(root, units, keyIndex, data)
def buildUtil(root: URI, units: Map[URI, LoadedBuildUnit], keyIndex: KeyIndex, data: Settings[Scope]): BuildUtil[ResolvedProject] = BuildUtil(root, units, keyIndex, data)
}
final case class LoadBuildConfiguration(
@ -917,9 +917,9 @@ final case class LoadBuildConfiguration(
classpath: Seq[Attributed[File]],
loader: ClassLoader,
compilers: Compilers,
evalPluginDef: (sbt.BuildStructure, State) => PluginData,
evalPluginDef: (BuildStructure, State) => PluginData,
definesClass: DefinesClass,
delegates: sbt.LoadedBuild => Scope => Seq[Scope],
delegates: LoadedBuild => Scope => Seq[Scope],
scopeLocal: ScopeLocal,
pluginManagement: PluginManagement,
injectSettings: Load.InjectSettings,

View File

@ -1,4 +1,5 @@
package sbt
package internal
import Def.Setting
import java.io.File

View File

@ -2,6 +2,7 @@
* Copyright 2011 Mark Harrah
*/
package sbt
package internal
import sbt.internal.util.{ Show, Types }

View File

@ -1,7 +1,8 @@
package sbt
package internal
import sbt.internal.util.Attributed
import sbt.internal.{ BuildDef, IncompatiblePluginsException, OldPlugin }
// import sbt.internal.{ BuildDef, IncompatiblePluginsException, OldPlugin }
import java.io.File
import java.net.URL
import Attributed.data

View File

@ -1,4 +1,5 @@
package sbt
package internal
import Keys.Classpath
import Def.Setting

View File

@ -1,4 +1,5 @@
package sbt
package internal
import sbt.internal.util.{ AttributeKey, Dag, Relation, Util }
import sbt.util.Logger

View File

@ -2,8 +2,8 @@
* Copyright 2008, 2009, 2010, 2011 Mark Harrah
*/
package sbt
package internal
import sbt.internal.Load
import sbt.internal.util.complete
import ProjectNavigation._

View File

@ -1,4 +1,5 @@
package sbt
package internal
import sbt.internal.util.AttributeKey

View File

@ -2,6 +2,7 @@
* Copyright 2011 Mark Harrah
*/
package sbt
package internal
import java.io.File
import java.net.URI

View File

@ -2,8 +2,8 @@
* Copyright 2011 Mark Harrah
*/
package sbt
package internal
import sbt.internal.Load
import sbt.librarymanagement.Configurations
import sbt.util.Level

View File

@ -2,6 +2,7 @@
* Copyright 2011 Mark Harrah
*/
package sbt
package internal
import sbt.internal.util.{ complete, LineRange, RangePosition, Types }
@ -12,7 +13,7 @@ import Types.Endo
import compiler.Eval
import SessionSettings._
import sbt.internals.parser.SbtRefactorings
import sbt.internal.parser.SbtRefactorings
import sbt.io.IO

View File

@ -1,6 +1,6 @@
package sbt
package internal
import sbt.internal.Load
import sbt.internal.util.{ AttributeKey, complete, Relation, Settings, Show, Types, Util }
import sbt.librarymanagement.Configuration

View File

@ -2,6 +2,7 @@
* Copyright 2011 Mark Harrah, Eugene Yokota
*/
package sbt
package internal
import sbt.internal.util.Show

View File

@ -1,4 +1,5 @@
package sbt
package internal
import Def.{ displayFull, ScopedKey }
import Keys.taskDefinitionKey

View File

@ -1,4 +1,5 @@
package sbt
package internal
import Def._

View File

@ -1,4 +1,5 @@
package sbt
package internal
import sbt.internal.util.RMap

View File

@ -1,12 +1,12 @@
package sbt
package internals
package internal
package parser
import sbt.internal.util.{ LineRange, MessageOnlyException }
import java.io.File
import sbt.internals.parser.SbtParser._
import sbt.internal.parser.SbtParser._
import scala.reflect.runtime.universe._
@ -60,7 +60,7 @@ private[sbt] case class SbtParser(file: File, lines: Seq[String]) extends Parsed
val (imports, settings, settingsTrees) = splitExpressions(file, lines)
private def splitExpressions(file: File, lines: Seq[String]): (Seq[(String, Int)], Seq[(String, LineRange)], Seq[(String, Tree)]) = {
import sbt.internals.parser.MissingBracketHandler._
import sbt.internal.parser.MissingBracketHandler._
import scala.compat.Platform.EOL
import scala.reflect.runtime._

View File

@ -1,16 +1,16 @@
package sbt
package internals
package internal
package parser
import scala.reflect.runtime.universe._
private[sbt] object SbtRefactorings {
import sbt.internals.parser.SbtParser.{ END_OF_LINE, FAKE_FILE }
import sbt.SessionSettings.{ SessionSetting, SbtConfigFile }
import sbt.internal.parser.SbtParser.{ END_OF_LINE, FAKE_FILE }
import sbt.internal.SessionSettings.{ SessionSetting, SbtConfigFile }
val EMPTY_STRING = ""
val REVERSE_ORDERING_INT = Ordering[Int].reverse
val emptyString = ""
val reverseOrderingInt = Ordering[Int].reverse
/**
* Refactoring a `.sbt` file so that the new settings are used instead of any existing settings.
@ -25,7 +25,7 @@ private[sbt] object SbtRefactorings {
val (file, lines) = configFile
val split = SbtParser(FAKE_FILE, lines)
val recordedCommands = recordCommands(commands, split)
val sortedRecordedCommands = recordedCommands.sortBy(_._1)(REVERSE_ORDERING_INT)
val sortedRecordedCommands = recordedCommands.sortBy(_._1)(reverseOrderingInt)
val newContent = replaceFromBottomToTop(lines.mkString(END_OF_LINE), sortedRecordedCommands)
(file, newContent.lines.toList)
@ -61,11 +61,9 @@ private[sbt] object SbtRefactorings {
case (acc, (st, tree)) =>
val treeName = extractSettingName(tree)
if (name == treeName) {
val replacement = if (acc.isEmpty) {
command.mkString(END_OF_LINE)
} else {
EMPTY_STRING
}
val replacement =
if (acc.isEmpty) command.mkString(END_OF_LINE)
else emptyString
(tree.pos.start, st, replacement) +: acc
} else {
acc

View File

@ -1,65 +0,0 @@
package sbt
package internals
import sbt.internal.util.RangePosition
import sbt.librarymanagement.Configuration
import Def._
/** This reprsents a `Setting` expression configured by the sbt DSL. */
sealed trait DslEntry {
/** Called by the parser. Sets the position where this entry was defined in the build.sbt file. */
def withPos(pos: RangePosition): DslEntry
}
object DslEntry {
implicit def fromSettingsDef(inc: SettingsDefinition): DslEntry =
DslSetting(inc)
implicit def fromSettingsDef(inc: Seq[Setting[_]]): DslEntry =
DslSetting(inc)
}
/** Represents a DSL entry which adds settings to the current project. */
sealed trait ProjectSettings extends DslEntry {
def toSettings: Seq[Setting[_]]
}
object ProjectSettings {
def unapply(e: DslEntry): Option[Seq[Setting[_]]] =
e match {
case e: ProjectSettings => Some(e.toSettings)
case _ => None
}
}
/** Represents a DSL entry which manipulates the current project. */
sealed trait ProjectManipulation extends DslEntry {
def toFunction: Project => Project
// TODO - Should we store this?
final def withPos(pos: RangePosition): DslEntry = this
}
object ProjectManipulation {
def unapply(e: DslEntry): Option[Project => Project] =
e match {
case e: ProjectManipulation => Some(e.toFunction)
case _ => None
}
}
/** this represents an actually Setting[_] or Seq[Setting[_]] configured by the sbt DSL. */
case class DslSetting(settings: SettingsDefinition) extends ProjectSettings {
def toSettings = settings.settings
final def withPos(pos: RangePosition): DslEntry = DslSetting(settings.settings.map(_.withPos(pos)))
}
/** this represents an `enablePlugins()` in the sbt DSL */
case class DslEnablePlugins(plugins: Seq[AutoPlugin]) extends ProjectManipulation {
override val toFunction: Project => Project = _.enablePlugins(plugins: _*)
}
/** this represents an `disablePlugins()` in the sbt DSL */
case class DslDisablePlugins(plugins: Seq[AutoPlugin]) extends ProjectManipulation {
override val toFunction: Project => Project = _.disablePlugins(plugins: _*)
}
/** Represents registering a set of configurations with the current project. */
case class DslConfigs(cs: Seq[Configuration]) extends ProjectManipulation {
override val toFunction: Project => Project = _.configs(cs: _*)
}

View File

@ -2,7 +2,7 @@ package sbt
import Project._
import sbt.internal.util.Types.{ idFun, some }
import TestBuild._
import sbt.internal.TestBuild._
import java.io.File
import java.net.URI

View File

@ -2,6 +2,7 @@ package sbt
import Def.{ displayFull, displayMasked, ScopedKey }
import java.net.URI
import sbt.internal.{ TestBuild, Resolve }
import TestBuild._
import sbt.internal.util.complete._

View File

@ -4,7 +4,7 @@ import java.io._
import org.specs2.mutable.Specification
import sbt.internal.{ Load, BuildDef, OldPlugin }
import sbt.internal._
import sbt.internal.util.{ AttributeEntry, AttributeMap, ConsoleOut, GlobalLogging, MainLogging, Settings }
object PluginCommandTestPlugin0 extends AutoPlugin

View File

@ -1,4 +1,5 @@
package sbt
package internal
import Def.{ ScopedKey, Setting }
import sbt.internal.util.{ AttributeKey, AttributeMap, Relation, Settings }

View File

@ -0,0 +1,5 @@
package sbt.internal.parser
import org.specs2.mutable._
trait AbstractSpec extends Specification with SplitExpression

View File

@ -1,6 +1,6 @@
package sbt.internals.parser
import sbt.EvaluateConfigurations
package sbt
package internal
package parser
abstract class CheckIfParsedSpec(implicit val splitter: SplitExpressions.SplitExpression = EvaluateConfigurations.splitExpressions) extends AbstractSpec {

View File

@ -1,4 +1,4 @@
package sbt.internals.parser
package sbt.internal.parser
class CommentedXmlSpec extends CheckIfParsedSpec {

Some files were not shown because too many files have changed in this diff Show More