mirror of https://github.com/sbt/sbt.git
keys cleanup part 2
This commit is contained in:
parent
5ea24a460b
commit
19698e308e
|
|
@ -3,7 +3,8 @@
|
||||||
*/
|
*/
|
||||||
package sbt
|
package sbt
|
||||||
|
|
||||||
import Project.{ScopedKey, ThisProject}
|
import Project.ScopedKey
|
||||||
|
import Keys.ThisProject
|
||||||
import CommandSupport.logger
|
import CommandSupport.logger
|
||||||
import Load.BuildStructure
|
import Load.BuildStructure
|
||||||
import complete.{DefaultParsers, Parser}
|
import complete.{DefaultParsers, Parser}
|
||||||
|
|
@ -83,5 +84,5 @@ object Act
|
||||||
|
|
||||||
|
|
||||||
def requireSession[T](s: State, p: => Parser[T]): Parser[T] =
|
def requireSession[T](s: State, p: => Parser[T]): Parser[T] =
|
||||||
if(s get Project.SessionKey isEmpty) failure("No project loaded") else p
|
if(s get Keys.SessionKey isEmpty) failure("No project loaded") else p
|
||||||
}
|
}
|
||||||
|
|
@ -7,11 +7,11 @@ package sbt
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
import compile.{Discovered,Discovery,Eval,EvalImports}
|
import compile.{Discovered,Discovery,Eval,EvalImports}
|
||||||
import classpath.ClasspathUtilities
|
import classpath.ClasspathUtilities
|
||||||
import inc.Analysis
|
|
||||||
import scala.annotation.tailrec
|
import scala.annotation.tailrec
|
||||||
import collection.mutable
|
import collection.mutable
|
||||||
import Compile.{Compilers,Inputs}
|
import Compile.{Compilers,Inputs}
|
||||||
import Project.{AppConfig, Config, ScopedKey, ScopeLocal, Setting, ThisProject, ThisProjectRef}
|
import Project.{ScopedKey, ScopeLocal, Setting}
|
||||||
|
import Keys.{AppConfig, Config, ThisProject, ThisProjectRef}
|
||||||
import TypeFunctions.{Endo,Id}
|
import TypeFunctions.{Endo,Id}
|
||||||
import tools.nsc.reporters.ConsoleReporter
|
import tools.nsc.reporters.ConsoleReporter
|
||||||
import Build.{analyzed, data}
|
import Build.{analyzed, data}
|
||||||
|
|
@ -32,7 +32,7 @@ object Build
|
||||||
def defaultProject(id: String, base: File): Project = Project(id, base)
|
def defaultProject(id: String, base: File): Project = Project(id, base)
|
||||||
|
|
||||||
def data[T](in: Seq[Attributed[T]]): Seq[T] = in.map(_.data)
|
def data[T](in: Seq[Attributed[T]]): Seq[T] = in.map(_.data)
|
||||||
def analyzed(in: Seq[Attributed[_]]): Seq[Analysis] = in.flatMap{ _.metadata.get(Command.Analysis) }
|
def analyzed(in: Seq[Attributed[_]]): Seq[inc.Analysis] = in.flatMap{ _.metadata.get(Keys.Analysis) }
|
||||||
}
|
}
|
||||||
object RetrieveUnit
|
object RetrieveUnit
|
||||||
{
|
{
|
||||||
|
|
@ -497,14 +497,14 @@ object Load
|
||||||
def loadDefinition(loader: ClassLoader, definition: String): Build =
|
def loadDefinition(loader: ClassLoader, definition: String): Build =
|
||||||
ModuleUtilities.getObject(definition, loader).asInstanceOf[Build]
|
ModuleUtilities.getObject(definition, loader).asInstanceOf[Build]
|
||||||
|
|
||||||
def build(classpath: Seq[File], sources: Seq[File], target: File, compilers: Compilers, log: Logger): (Inputs, Analysis) =
|
def build(classpath: Seq[File], sources: Seq[File], target: File, compilers: Compilers, log: Logger): (Inputs, inc.Analysis) =
|
||||||
{
|
{
|
||||||
val inputs = Compile.inputs(classpath, sources, target, Nil, Nil, Nil, Compile.DefaultMaxErrors)(compilers, log)
|
val inputs = Compile.inputs(classpath, sources, target, Nil, Nil, Nil, Compile.DefaultMaxErrors)(compilers, log)
|
||||||
val analysis = Compile(inputs, log)
|
val analysis = Compile(inputs, log)
|
||||||
(inputs, analysis)
|
(inputs, analysis)
|
||||||
}
|
}
|
||||||
|
|
||||||
def loadPlugins(classpath: Seq[File], loader: ClassLoader, analysis: Seq[Analysis]): LoadedPlugins =
|
def loadPlugins(classpath: Seq[File], loader: ClassLoader, analysis: Seq[inc.Analysis]): LoadedPlugins =
|
||||||
{
|
{
|
||||||
val (pluginNames, plugins) = if(classpath.isEmpty) (Nil, Nil) else {
|
val (pluginNames, plugins) = if(classpath.isEmpty) (Nil, Nil) else {
|
||||||
val names = analysis flatMap findPlugins
|
val names = analysis flatMap findPlugins
|
||||||
|
|
@ -521,9 +521,9 @@ object Load
|
||||||
|
|
||||||
def importAll(values: Seq[String]) = if(values.isEmpty) Nil else values.map( _ + "._" ).mkString("import ", ", ", "") :: Nil
|
def importAll(values: Seq[String]) = if(values.isEmpty) Nil else values.map( _ + "._" ).mkString("import ", ", ", "") :: Nil
|
||||||
|
|
||||||
def findPlugins(analysis: Analysis): Seq[String] = discover(analysis, "sbt.Plugin")
|
def findPlugins(analysis: inc.Analysis): Seq[String] = discover(analysis, "sbt.Plugin")
|
||||||
def findDefinitions(analysis: Analysis): Seq[String] = discover(analysis, "sbt.Build")
|
def findDefinitions(analysis: inc.Analysis): Seq[String] = discover(analysis, "sbt.Build")
|
||||||
def discover(analysis: Analysis, subclasses: String*): Seq[String] =
|
def discover(analysis: inc.Analysis, subclasses: String*): Seq[String] =
|
||||||
{
|
{
|
||||||
val subclassSet = subclasses.toSet
|
val subclassSet = subclasses.toSet
|
||||||
val ds = Discovery(subclassSet, Set.empty)(Test.allDefs(analysis))
|
val ds = Discovery(subclassSet, Set.empty)(Test.allDefs(analysis))
|
||||||
|
|
|
||||||
|
|
@ -28,12 +28,6 @@ object Command
|
||||||
|
|
||||||
import DefaultParsers._
|
import DefaultParsers._
|
||||||
|
|
||||||
val Logged = AttributeKey[Logger]("log")
|
|
||||||
val HistoryPath = SettingKey[Option[File]]("history")
|
|
||||||
val ShellPrompt = SettingKey[State => String]("shell-prompt")
|
|
||||||
val Analysis = AttributeKey[inc.Analysis]("analysis")
|
|
||||||
val Watch = SettingKey[Watched]("continuous-watch")
|
|
||||||
|
|
||||||
def command(name: String)(f: State => State): Command = command(name, Nil)(f)
|
def command(name: String)(f: State => State): Command = command(name, Nil)(f)
|
||||||
def command(name: String, briefHelp: String, detail: String)(f: State => State): Command = command(name, Help(name, (name, briefHelp), detail) :: Nil)(f)
|
def command(name: String, briefHelp: String, detail: String)(f: State => State): Command = command(name, Help(name, (name, briefHelp), detail) :: Nil)(f)
|
||||||
def command(name: String, help: Seq[Help])(f: State => State): Command = make(name, help : _*)(state => success(() => f(state)))
|
def command(name: String, help: Seq[Help])(f: State => State): Command = make(name, help : _*)(state => success(() => f(state)))
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import Path._
|
||||||
|
|
||||||
object CommandSupport
|
object CommandSupport
|
||||||
{
|
{
|
||||||
def logger(s: State) = s get Command.Logged getOrElse ConsoleLogger()
|
def logger(s: State) = s get Keys.Logged getOrElse ConsoleLogger()
|
||||||
|
|
||||||
private def canRead = (_: File).canRead
|
private def canRead = (_: File).canRead
|
||||||
def notReadable(files: Seq[File]): Seq[File] = files filterNot canRead
|
def notReadable(files: Seq[File]): Seq[File] = files filterNot canRead
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,10 @@ package sbt
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import Build.data
|
import Build.data
|
||||||
import Scope.{GlobalScope,ThisScope}
|
import Scope.{GlobalScope,ThisScope}
|
||||||
import Project.{AppConfig, Config, Initialize, ScopedKey, Setting, ThisProject, ThisProjectRef}
|
import Project.{Initialize, ScopedKey, Setting}
|
||||||
import Configurations.{Compile => CompileConf, Test => TestConf}
|
import Configurations.{Compile => CompileConf, Test => TestConf}
|
||||||
import Command.{HistoryPath, ShellPrompt}
|
|
||||||
import EvaluateTask.{resolvedScoped, streams}
|
import EvaluateTask.{resolvedScoped, streams}
|
||||||
import complete._
|
import complete._
|
||||||
import inc.Analysis
|
|
||||||
import std.TaskExtra._
|
import std.TaskExtra._
|
||||||
import scala.xml.{Node => XNode,NodeSeq}
|
import scala.xml.{Node => XNode,NodeSeq}
|
||||||
import org.apache.ivy.core.module.{descriptor, id}
|
import org.apache.ivy.core.module.{descriptor, id}
|
||||||
|
|
@ -49,10 +47,10 @@ object Default
|
||||||
def prefix(config: String) = if(config == "compile") "" else config + "-"
|
def prefix(config: String) = if(config == "compile") "" else config + "-"
|
||||||
def toSeq[T](key: ScopedSetting[T]): Initialize[Seq[T]] = key( _ :: Nil)
|
def toSeq[T](key: ScopedSetting[T]): Initialize[Seq[T]] = key( _ :: Nil)
|
||||||
|
|
||||||
def extractAnalysis[T](a: Attributed[T]): (T, Analysis) =
|
def extractAnalysis[T](a: Attributed[T]): (T, inc.Analysis) =
|
||||||
(a.data, a.metadata get Command.Analysis getOrElse Analysis.Empty)
|
(a.data, a.metadata get Keys.Analysis getOrElse inc.Analysis.Empty)
|
||||||
|
|
||||||
def analysisMap[T](cp: Seq[Attributed[T]]): Map[T, Analysis] =
|
def analysisMap[T](cp: Seq[Attributed[T]]): Map[T, inc.Analysis] =
|
||||||
(cp map extractAnalysis).toMap
|
(cp map extractAnalysis).toMap
|
||||||
|
|
||||||
def core: Seq[Setting[_]] = Seq(
|
def core: Seq[Setting[_]] = Seq(
|
||||||
|
|
@ -66,7 +64,7 @@ object Default
|
||||||
Name <<= ThisProject(_.id),
|
Name <<= ThisProject(_.id),
|
||||||
Version :== "0.1",
|
Version :== "0.1",
|
||||||
MaxErrors in GlobalScope :== 100,
|
MaxErrors in GlobalScope :== 100,
|
||||||
Project.Commands :== Nil,
|
Commands :== Nil,
|
||||||
Data <<= EvaluateTask.state map { state => Project.structure(state).data }
|
Data <<= EvaluateTask.state map { state => Project.structure(state).data }
|
||||||
)
|
)
|
||||||
def paths = Seq(
|
def paths = Seq(
|
||||||
|
|
@ -251,7 +249,7 @@ object Default
|
||||||
|
|
||||||
def mainRunTask = RunTask <<= runTask(FullClasspath in Configurations.Runtime, MainClass in RunTask, Runner in RunTask)
|
def mainRunTask = RunTask <<= runTask(FullClasspath in Configurations.Runtime, MainClass in RunTask, Runner in RunTask)
|
||||||
|
|
||||||
def discoverMainClasses(analysis: Analysis): Seq[String] =
|
def discoverMainClasses(analysis: inc.Analysis): Seq[String] =
|
||||||
compile.Discovery.applications(Test.allDefs(analysis)) collect { case (definition, discovered) if(discovered.hasMain) => definition.name }
|
compile.Discovery.applications(Test.allDefs(analysis)) collect { case (definition, discovered) if(discovered.hasMain) => definition.name }
|
||||||
|
|
||||||
def consoleProject = (EvaluateTask.state, streams, InitialCommands in ConsoleProject) map { (state, s, extra) => Console.sbt(state, extra)(s.log) }
|
def consoleProject = (EvaluateTask.state, streams, InitialCommands in ConsoleProject) map { (state, s, extra) => Console.sbt(state, extra)(s.log) }
|
||||||
|
|
@ -346,7 +344,7 @@ object Classpaths
|
||||||
|
|
||||||
def concat[T](a: ScopedTaskable[Seq[T]], b: ScopedTaskable[Seq[T]]): Initialize[Task[Seq[T]]] = (a,b) map (_ ++ _)
|
def concat[T](a: ScopedTaskable[Seq[T]], b: ScopedTaskable[Seq[T]]): Initialize[Task[Seq[T]]] = (a,b) map (_ ++ _)
|
||||||
|
|
||||||
lazy val configSettings: Seq[Project.Setting[_]] = Seq(
|
lazy val configSettings: Seq[Setting[_]] = Seq(
|
||||||
ExternalDependencyClasspath <<= concat(UnmanagedClasspath, ManagedClasspath),
|
ExternalDependencyClasspath <<= concat(UnmanagedClasspath, ManagedClasspath),
|
||||||
DependencyClasspath <<= concat(InternalDependencyClasspath, ExternalDependencyClasspath),
|
DependencyClasspath <<= concat(InternalDependencyClasspath, ExternalDependencyClasspath),
|
||||||
FullClasspath <<= concat(Products, DependencyClasspath),
|
FullClasspath <<= concat(Products, DependencyClasspath),
|
||||||
|
|
@ -361,7 +359,7 @@ object Classpaths
|
||||||
def defaultPackageTasks: Seq[ScopedTask[_]] =
|
def defaultPackageTasks: Seq[ScopedTask[_]] =
|
||||||
for(task <- Seq(Package, PackageSrc, PackageDoc); conf <- Seq(CompileConf, TestConf)) yield (task in conf)
|
for(task <- Seq(Package, PackageSrc, PackageDoc); conf <- Seq(CompileConf, TestConf)) yield (task in conf)
|
||||||
|
|
||||||
val publishSettings: Seq[Project.Setting[_]] = Seq(
|
val publishSettings: Seq[Setting[_]] = Seq(
|
||||||
PublishMavenStyle in GlobalScope :== true,
|
PublishMavenStyle in GlobalScope :== true,
|
||||||
PackageToPublish <<= defaultPackageTasks.dependOn,
|
PackageToPublish <<= defaultPackageTasks.dependOn,
|
||||||
DeliverDepends <<= (PublishMavenStyle, MakePom.setting, PackageToPublish.setting) { (mavenStyle, makePom, ptp) =>
|
DeliverDepends <<= (PublishMavenStyle, MakePom.setting, PackageToPublish.setting) { (mavenStyle, makePom, ptp) =>
|
||||||
|
|
@ -373,7 +371,7 @@ object Classpaths
|
||||||
Publish <<= publish(PublishConfig, Deliver),
|
Publish <<= publish(PublishConfig, Deliver),
|
||||||
PublishLocal <<= publish(PublishLocalConfig, DeliverLocal)
|
PublishLocal <<= publish(PublishLocalConfig, DeliverLocal)
|
||||||
)
|
)
|
||||||
val baseSettings: Seq[Project.Setting[_]] = Seq(
|
val baseSettings: Seq[Setting[_]] = Seq(
|
||||||
UnmanagedBase <<= Base / "lib",
|
UnmanagedBase <<= Base / "lib",
|
||||||
NormalizedName <<= Name(StringUtilities.normalize),
|
NormalizedName <<= Name(StringUtilities.normalize),
|
||||||
Organization :== NormalizedName,
|
Organization :== NormalizedName,
|
||||||
|
|
@ -502,7 +500,7 @@ object Classpaths
|
||||||
new RawRepository(new ProjectResolver("inter-project", m))
|
new RawRepository(new ProjectResolver("inter-project", m))
|
||||||
}
|
}
|
||||||
|
|
||||||
def analyzed[T](data: T, analysis: Analysis) = Attributed.blank(data).put(Command.Analysis, analysis)
|
def analyzed[T](data: T, analysis: inc.Analysis) = Attributed.blank(data).put(Keys.Analysis, analysis)
|
||||||
def makeProducts: Initialize[Task[Classpath]] =
|
def makeProducts: Initialize[Task[Classpath]] =
|
||||||
(CompileTask, CompileInputs, CopyResources) map { (analysis, i, _) => analyzed(i.config.classesDirectory, analysis) :: Nil }
|
(CompileTask, CompileInputs, CopyResources) map { (analysis, i, _) => analyzed(i.config.classesDirectory, analysis) :: Nil }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,23 @@ package sbt
|
||||||
|
|
||||||
object Keys
|
object Keys
|
||||||
{
|
{
|
||||||
|
// Project keys
|
||||||
|
val ProjectCommand = AttributeKey[Boolean]("project-command")
|
||||||
|
val SessionKey = AttributeKey[SessionSettings]("session-settings")
|
||||||
|
val StructureKey = AttributeKey[Load.BuildStructure]("build-structure")
|
||||||
|
val AppConfig = SettingKey[xsbti.AppConfiguration]("app-configuration")
|
||||||
|
val ThisProject = SettingKey[Project]("project")
|
||||||
|
val ThisProjectRef = SettingKey[ProjectRef]("project-ref")
|
||||||
|
val Config = SettingKey[Configuration]("configuration")
|
||||||
|
val Commands = SettingKey[Seq[Command]]("commands")
|
||||||
|
|
||||||
|
// Command keys
|
||||||
|
val Logged = AttributeKey[Logger]("log")
|
||||||
|
val HistoryPath = SettingKey[Option[File]]("history")
|
||||||
|
val ShellPrompt = SettingKey[State => String]("shell-prompt")
|
||||||
|
val Analysis = AttributeKey[inc.Analysis]("analysis")
|
||||||
|
val Watch = SettingKey[Watched]("continuous-watch")
|
||||||
|
|
||||||
// Path Keys
|
// Path Keys
|
||||||
val Base = SettingKey[File]("base-directory")
|
val Base = SettingKey[File]("base-directory")
|
||||||
val Target = SettingKey[File]("target")
|
val Target = SettingKey[File]("target")
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,8 @@ package sbt
|
||||||
import compile.EvalImports
|
import compile.EvalImports
|
||||||
import sbt.complete.{DefaultParsers, Parser}
|
import sbt.complete.{DefaultParsers, Parser}
|
||||||
|
|
||||||
import Command.{applyEffect,Analysis,HistoryPath,Logged,ShellPrompt,Watch}
|
import Command.applyEffect
|
||||||
|
import Keys.{Analysis,HistoryPath,Logged,ShellPrompt,Watch}
|
||||||
import scala.annotation.tailrec
|
import scala.annotation.tailrec
|
||||||
import scala.collection.JavaConversions._
|
import scala.collection.JavaConversions._
|
||||||
import Function.tupled
|
import Function.tupled
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ package sbt
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
import Project._
|
import Project._
|
||||||
import Types.Endo
|
import Types.Endo
|
||||||
import Command.{HistoryPath,ShellPrompt,Watch}
|
import Keys.{AppConfig, Commands, Config, HistoryPath, ProjectCommand, SessionKey, ShellPrompt, StructureKey, ThisProject, ThisProjectRef, Watch}
|
||||||
import CommandSupport.logger
|
import CommandSupport.logger
|
||||||
import compile.Eval
|
import compile.Eval
|
||||||
|
|
||||||
|
|
@ -153,15 +153,6 @@ object Project extends Init[Scope]
|
||||||
}
|
}
|
||||||
def reverseDependencies(cMap: CompiledMap, scoped: ScopedKey[_]): Iterable[ScopedKey[_]] =
|
def reverseDependencies(cMap: CompiledMap, scoped: ScopedKey[_]): Iterable[ScopedKey[_]] =
|
||||||
for( (key,compiled) <- cMap; dep <- compiled.dependencies if dep == scoped) yield key
|
for( (key,compiled) <- cMap; dep <- compiled.dependencies if dep == scoped) yield key
|
||||||
|
|
||||||
val ProjectCommand = AttributeKey[Boolean]("project-command")
|
|
||||||
val SessionKey = AttributeKey[SessionSettings]("session-settings")
|
|
||||||
val StructureKey = AttributeKey[Load.BuildStructure]("build-structure")
|
|
||||||
val AppConfig = SettingKey[xsbti.AppConfiguration]("app-configuration")
|
|
||||||
val ThisProject = SettingKey[Project]("project")
|
|
||||||
val ThisProjectRef = SettingKey[ProjectRef]("project-ref")
|
|
||||||
val Config = SettingKey[Configuration]("configuration")
|
|
||||||
val Commands = SettingKey[Seq[Command]]("commands")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
import SessionSettings._
|
import SessionSettings._
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@
|
||||||
package sbt
|
package sbt
|
||||||
|
|
||||||
import ProjectNavigation._
|
import ProjectNavigation._
|
||||||
import Project.{SessionKey, updateCurrent}
|
import Project.updateCurrent
|
||||||
|
import Keys.SessionKey
|
||||||
import CommandSupport.logger
|
import CommandSupport.logger
|
||||||
import complete.{DefaultParsers, Parser}
|
import complete.{DefaultParsers, Parser}
|
||||||
import DefaultParsers._
|
import DefaultParsers._
|
||||||
|
|
@ -19,7 +20,7 @@ object ProjectNavigation
|
||||||
final class ChangeProject(val id: String) extends Navigate
|
final class ChangeProject(val id: String) extends Navigate
|
||||||
|
|
||||||
def command(s: State): Parser[() => State] =
|
def command(s: State): Parser[() => State] =
|
||||||
if(s get Project.SessionKey isEmpty) failure("No project loaded") else (new ProjectNavigation(s)).command
|
if(s get SessionKey isEmpty) failure("No project loaded") else (new ProjectNavigation(s)).command
|
||||||
}
|
}
|
||||||
final class ProjectNavigation(s: State)
|
final class ProjectNavigation(s: State)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
*/
|
*/
|
||||||
package object sbt extends sbt.std.TaskExtra with sbt.Types with sbt.ProcessExtra with sbt.impl.DependencyBuilders with sbt.PathExtra with sbt.ProjectConstructors
|
package object sbt extends sbt.std.TaskExtra with sbt.Types with sbt.ProcessExtra with sbt.impl.DependencyBuilders with sbt.PathExtra with sbt.ProjectConstructors
|
||||||
{
|
{
|
||||||
|
type Setting[T] = Project.Setting[T]
|
||||||
|
type ScopedKey[T] = Project.ScopedKey[T]
|
||||||
type File = java.io.File
|
type File = java.io.File
|
||||||
type URI = java.net.URI
|
type URI = java.net.URI
|
||||||
implicit def maybeToOption[S](m: xsbti.Maybe[S]): Option[S] =
|
implicit def maybeToOption[S](m: xsbti.Maybe[S]): Option[S] =
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue