merge Scoped{Setting,Task,Input} and {Setting,Task,Input}Key

This commit is contained in:
Mark Harrah 2011-10-16 17:27:36 -04:00
parent bb84e32291
commit 6ddeca12a2
4 changed files with 71 additions and 69 deletions

View File

@ -30,7 +30,7 @@ package sbt
object Defaults extends BuildCommon object Defaults extends BuildCommon
{ {
def configSrcSub(key: ScopedSetting[File]): Initialize[File] = (key in ThisScope.copy(config = Global), configuration) { (src, conf) => src / nameForSrc(conf.name) } def configSrcSub(key: SettingKey[File]): Initialize[File] = (key in ThisScope.copy(config = Global), configuration) { (src, conf) => src / nameForSrc(conf.name) }
def nameForSrc(config: String) = if(config == "compile") "main" else config def nameForSrc(config: String) = if(config == "compile") "main" else config
def prefix(config: String) = if(config == "compile") "" else config + "-" def prefix(config: String) = if(config == "compile") "" else config + "-"
@ -215,9 +215,9 @@ object Defaults extends BuildCommon
watch <<= watchSetting watch <<= watchSetting
) )
def generate(generators: ScopedSetting[Seq[Task[Seq[File]]]]): Initialize[Task[Seq[File]]] = generators {_.join.map(_.flatten) } def generate(generators: SettingKey[Seq[Task[Seq[File]]]]): Initialize[Task[Seq[File]]] = generators {_.join.map(_.flatten) }
def inAllConfigurations[T](key: ScopedTask[T]): Initialize[Task[Seq[T]]] = (state, thisProjectRef) flatMap { (state, ref) => def inAllConfigurations[T](key: TaskKey[T]): Initialize[Task[Seq[T]]] = (state, thisProjectRef) flatMap { (state, ref) =>
val structure = Project structure state val structure = Project structure state
val configurations = Project.getProject(ref, structure).toList.flatMap(_.configurations) val configurations = Project.getProject(ref, structure).toList.flatMap(_.configurations)
configurations.flatMap { conf => configurations.flatMap { conf =>
@ -353,7 +353,7 @@ object Defaults extends BuildCommon
def collectFiles(dirs: ScopedTaskable[Seq[File]], filter: ScopedTaskable[FileFilter], excludes: ScopedTaskable[FileFilter]): Initialize[Task[Seq[File]]] = def collectFiles(dirs: ScopedTaskable[Seq[File]], filter: ScopedTaskable[FileFilter], excludes: ScopedTaskable[FileFilter]): Initialize[Task[Seq[File]]] =
(dirs, filter, excludes) map { (d,f,excl) => d.descendentsExcept(f,excl).get } (dirs, filter, excludes) map { (d,f,excl) => d.descendentsExcept(f,excl).get }
def artifactPathSetting(art: ScopedSetting[Artifact]) = (crossTarget, projectID, art, scalaVersion in artifactName, artifactName) { (t, module, a, sv, toString) => t / toString(sv, module, a) asFile } def artifactPathSetting(art: SettingKey[Artifact]) = (crossTarget, projectID, art, scalaVersion in artifactName, artifactName) { (t, module, a, sv, toString) => t / toString(sv, module, a) asFile }
def artifactSetting = ((artifact, artifactClassifier).identity zipWith configuration.?) { case ((a,classifier),cOpt) => def artifactSetting = ((artifact, artifactClassifier).identity zipWith configuration.?) { case ((a,classifier),cOpt) =>
val cPart = cOpt flatMap { c => if(c == Compile) None else Some(c.name) } val cPart = cOpt flatMap { c => if(c == Compile) None else Some(c.name) }
val combined = cPart.toList ++ classifier.toList val combined = cPart.toList ++ classifier.toList
@ -404,7 +404,7 @@ object Defaults extends BuildCommon
IO.delete(clean) IO.delete(clean)
IO.move(mappings.map(_.swap)) IO.move(mappings.map(_.swap))
} }
def runMainTask(classpath: ScopedTask[Classpath], scalaRun: ScopedTask[ScalaRun]): Initialize[InputTask[Unit]] = def runMainTask(classpath: TaskKey[Classpath], scalaRun: TaskKey[ScalaRun]): Initialize[InputTask[Unit]] =
{ {
import DefaultParsers._ import DefaultParsers._
InputTask( loadForParser(discoveredMainClasses)( (s, names) => runMainParser(s, names getOrElse Nil) ) ) { result => InputTask( loadForParser(discoveredMainClasses)( (s, names) => runMainParser(s, names getOrElse Nil) ) ) { result =>
@ -414,7 +414,7 @@ object Defaults extends BuildCommon
} }
} }
def runTask(classpath: ScopedTask[Classpath], mainClassTask: ScopedTask[Option[String]], scalaRun: ScopedTask[ScalaRun]): Initialize[InputTask[Unit]] = def runTask(classpath: TaskKey[Classpath], mainClassTask: TaskKey[Option[String]], scalaRun: TaskKey[ScalaRun]): Initialize[InputTask[Unit]] =
inputTask { result => inputTask { result =>
(classpath, mainClassTask, scalaRun, streams, result) map { (cp, main, runner, s, args) => (classpath, mainClassTask, scalaRun, streams, result) map { (cp, main, runner, s, args) =>
val mainClass = main getOrElse error("No main class detected.") val mainClass = main getOrElse error("No main class detected.")
@ -432,7 +432,7 @@ object Defaults extends BuildCommon
new Run(si, trap, tmp) new Run(si, trap, tmp)
} }
def docSetting(key: ScopedTask[File]): Seq[Setting[_]] = inTask(key)(Seq( def docSetting(key: TaskKey[File]): Seq[Setting[_]] = inTask(key)(Seq(
cacheDirectory ~= (_ / key.key.label), cacheDirectory ~= (_ / key.key.label),
target <<= docDirectory, // deprecate docDirectory in favor of 'target in doc'; remove when docDirectory is removed target <<= docDirectory, // deprecate docDirectory in favor of 'target in doc'; remove when docDirectory is removed
scaladocOptions <<= scalacOptions, // deprecate scaladocOptions in favor of 'scalacOptions in doc'; remove when scaladocOptions is removed scaladocOptions <<= scalacOptions, // deprecate scaladocOptions in favor of 'scalacOptions in doc'; remove when scaladocOptions is removed
@ -460,7 +460,7 @@ object Defaults extends BuildCommon
def consoleProjectTask = (state, streams, initialCommands in consoleProject) map { (state, s, extra) => ConsoleProject(state, extra)(s.log); println() } def consoleProjectTask = (state, streams, initialCommands in consoleProject) map { (state, s, extra) => ConsoleProject(state, extra)(s.log); println() }
def consoleTask: Initialize[Task[Unit]] = consoleTask(fullClasspath, console) def consoleTask: Initialize[Task[Unit]] = consoleTask(fullClasspath, console)
def consoleQuickTask = consoleTask(externalDependencyClasspath, consoleQuick) def consoleQuickTask = consoleTask(externalDependencyClasspath, consoleQuick)
def consoleTask(classpath: ScopedTask[Classpath], task: TaskKey[_]): Initialize[Task[Unit]] = (compilers in task, classpath in task, scalacOptions in task, initialCommands in task, streams) map { def consoleTask(classpath: TaskKey[Classpath], task: TaskKey[_]): Initialize[Task[Unit]] = (compilers in task, classpath in task, scalacOptions in task, initialCommands in task, streams) map {
(cs, cp, options, initCommands, s) => (cs, cp, options, initCommands, s) =>
(new Console(cs.scalac))(data(cp), options, initCommands, s.log).foreach(msg => error(msg)) (new Console(cs.scalac))(data(cp), options, initCommands, s.log).foreach(msg => error(msg))
println() println()
@ -535,7 +535,7 @@ object Defaults extends BuildCommon
recurse ?? Nil recurse ?? Nil
} }
def inDependencies[T](key: ScopedSetting[T], default: ProjectRef => T, includeRoot: Boolean = true, classpath: Boolean = true, aggregate: Boolean = false): Initialize[Seq[T]] = def inDependencies[T](key: SettingKey[T], default: ProjectRef => T, includeRoot: Boolean = true, classpath: Boolean = true, aggregate: Boolean = false): Initialize[Seq[T]] =
Project.bind( (loadedBuild, thisProjectRef).identity ) { case (lb, base) => Project.bind( (loadedBuild, thisProjectRef).identity ) { case (lb, base) =>
transitiveDependencies(base, lb, includeRoot, classpath, aggregate) map ( ref => (key in ref) ?? default(ref) ) join ; transitiveDependencies(base, lb, includeRoot, classpath, aggregate) map ( ref => (key in ref) ?? default(ref) ) join ;
} }
@ -584,7 +584,7 @@ object Classpaths
def concatDistinct[T](a: ScopedTaskable[Seq[T]], b: ScopedTaskable[Seq[T]]): Initialize[Task[Seq[T]]] = (a,b) map { (x,y) => (x ++ y).distinct } def concatDistinct[T](a: ScopedTaskable[Seq[T]], b: ScopedTaskable[Seq[T]]): Initialize[Task[Seq[T]]] = (a,b) map { (x,y) => (x ++ y).distinct }
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 ( _ ++ _)
def concatSettings[T](a: ScopedSetting[Seq[T]], b: ScopedSetting[Seq[T]]): Initialize[Seq[T]] = (a,b)(_ ++ _) def concatSettings[T](a: SettingKey[Seq[T]], b: SettingKey[Seq[T]]): Initialize[Seq[T]] = (a,b)(_ ++ _)
lazy val configSettings: Seq[Setting[_]] = Seq( lazy val configSettings: Seq[Setting[_]] = Seq(
externalDependencyClasspath <<= concat(unmanagedClasspath, managedClasspath), externalDependencyClasspath <<= concat(unmanagedClasspath, managedClasspath),
@ -605,9 +605,9 @@ object Classpaths
} }
) )
def defaultPackageKeys = Seq(packageBin, packageSrc, packageDoc) def defaultPackageKeys = Seq(packageBin, packageSrc, packageDoc)
lazy val defaultPackages: Seq[ScopedTask[File]] = lazy val defaultPackages: Seq[TaskKey[File]] =
for(task <- defaultPackageKeys; conf <- Seq(Compile, Test)) yield (task in conf) for(task <- defaultPackageKeys; conf <- Seq(Compile, Test)) yield (task in conf)
lazy val defaultArtifactTasks: Seq[ScopedTask[File]] = makePom +: defaultPackages lazy val defaultArtifactTasks: Seq[TaskKey[File]] = makePom +: defaultPackages
def findClasspathConfig(map: Configuration => Configuration, thisConfig: Configuration, delegate: Task[Option[Configuration]], up: Task[UpdateReport]): Task[Configuration] = def findClasspathConfig(map: Configuration => Configuration, thisConfig: Configuration, delegate: Task[Option[Configuration]], up: Task[UpdateReport]): Task[Configuration] =
(delegate :^: up :^: KNil) map { case delegated :+: report :+: HNil => (delegate :^: up :^: KNil) map { case delegated :+: report :+: HNil =>
@ -617,14 +617,14 @@ object Classpaths
search find { defined contains _.name } getOrElse notFound search find { defined contains _.name } getOrElse notFound
} }
def packaged(pkgTasks: Seq[ScopedTask[File]]): Initialize[Task[Map[Artifact, File]]] = def packaged(pkgTasks: Seq[TaskKey[File]]): Initialize[Task[Map[Artifact, File]]] =
enabledOnly(packagedArtifact.task, pkgTasks) apply (_.join.map(_.toMap)) enabledOnly(packagedArtifact.task, pkgTasks) apply (_.join.map(_.toMap))
def artifactDefs(pkgTasks: Seq[ScopedTask[File]]): Initialize[Seq[Artifact]] = def artifactDefs(pkgTasks: Seq[TaskKey[File]]): Initialize[Seq[Artifact]] =
enabledOnly(artifact, pkgTasks) enabledOnly(artifact, pkgTasks)
def enabledOnly[T](key: ScopedSetting[T], pkgTasks: Seq[ScopedTask[File]]): Initialize[Seq[T]] = def enabledOnly[T](key: SettingKey[T], pkgTasks: Seq[TaskKey[File]]): Initialize[Seq[T]] =
( forallIn(key, pkgTasks) zipWith forallIn(publishArtifact, pkgTasks) ) ( _ zip _ collect { case (a, true) => a } ) ( forallIn(key, pkgTasks) zipWith forallIn(publishArtifact, pkgTasks) ) ( _ zip _ collect { case (a, true) => a } )
def forallIn[T](key: ScopedSetting[T], pkgTasks: Seq[ScopedTask[_]]): Initialize[Seq[T]] = def forallIn[T](key: SettingKey[T], pkgTasks: Seq[TaskKey[_]]): Initialize[Seq[T]] =
pkgTasks.map( pkg => key in pkg.scope in pkg ).join pkgTasks.map( pkg => key in pkg.scope in pkg ).join
val publishSettings: Seq[Setting[_]] = Seq( val publishSettings: Seq[Setting[_]] = Seq(
@ -1041,7 +1041,7 @@ trait BuildExtra extends BuildCommon
def addCompilerPlugin(dependency: ModuleID): Setting[Seq[ModuleID]] = def addCompilerPlugin(dependency: ModuleID): Setting[Seq[ModuleID]] =
libraryDependencies += compilerPlugin(dependency) libraryDependencies += compilerPlugin(dependency)
def addArtifact(a: Artifact, taskDef: ScopedTask[File]): SettingsDefinition = def addArtifact(a: Artifact, taskDef: TaskKey[File]): SettingsDefinition =
{ {
val pkgd = packagedArtifacts <<= (packagedArtifacts, taskDef) map ( (pas,file) => pas updated (a, file) ) val pkgd = packagedArtifacts <<= (packagedArtifacts, taskDef) map ( (pas,file) => pas updated (a, file) )
seq( artifacts += a, pkgd ) seq( artifacts += a, pkgd )
@ -1083,7 +1083,7 @@ trait BuildExtra extends BuildCommon
toError(r.run(mainClass, data(cp), arguments, s.log)) toError(r.run(mainClass, data(cp), arguments, s.log))
} }
def fullRunInputTask(scoped: ScopedInput[Unit], config: Configuration, mainClass: String, baseArguments: String*): Setting[InputTask[Unit]] = def fullRunInputTask(scoped: InputKey[Unit], config: Configuration, mainClass: String, baseArguments: String*): Setting[InputTask[Unit]] =
scoped <<= inputTask { result => scoped <<= inputTask { result =>
( initScoped(scoped.scopedKey, runnerInit) zipWith (fullClasspath in config, streams, result).identityMap) { (rTask, t) => ( initScoped(scoped.scopedKey, runnerInit) zipWith (fullClasspath in config, streams, result).identityMap) { (rTask, t) =>
(t :^: rTask :^: KNil) map { case (cp, s, args) :+: r :+: HNil => (t :^: rTask :^: KNil) map { case (cp, s, args) :+: r :+: HNil =>
@ -1091,7 +1091,7 @@ trait BuildExtra extends BuildCommon
} }
} }
} }
def fullRunTask(scoped: ScopedTask[Unit], config: Configuration, mainClass: String, arguments: String*): Setting[Task[Unit]] = def fullRunTask(scoped: TaskKey[Unit], config: Configuration, mainClass: String, arguments: String*): Setting[Task[Unit]] =
scoped <<= ( initScoped(scoped.scopedKey, runnerInit) zipWith (fullClasspath in config, streams).identityMap ) { case (rTask, t) => scoped <<= ( initScoped(scoped.scopedKey, runnerInit) zipWith (fullClasspath in config, streams).identityMap ) { case (rTask, t) =>
(t :^: rTask :^: KNil) map { case (cp, s) :+: r :+: HNil => (t :^: rTask :^: KNil) map { case (cp, s) :+: r :+: HNil =>
toError(r.run(mainClass, data(cp), arguments, s.log)) toError(r.run(mainClass, data(cp), arguments, s.log))
@ -1139,27 +1139,27 @@ trait BuildCommon
} }
// these are intended for use in input tasks for creating parsers // these are intended for use in input tasks for creating parsers
def getFromContext[T](task: ScopedTask[T], context: ScopedKey[_], s: State): Option[T] = def getFromContext[T](task: TaskKey[T], context: ScopedKey[_], s: State): Option[T] =
SessionVar.get(SessionVar.resolveContext(task.scopedKey, context.scope, s), s) SessionVar.get(SessionVar.resolveContext(task.scopedKey, context.scope, s), s)
def loadFromContext[T](task: ScopedTask[T], context: ScopedKey[_], s: State)(implicit f: sbinary.Format[T]): Option[T] = def loadFromContext[T](task: TaskKey[T], context: ScopedKey[_], s: State)(implicit f: sbinary.Format[T]): Option[T] =
SessionVar.load(SessionVar.resolveContext(task.scopedKey, context.scope, s), s) SessionVar.load(SessionVar.resolveContext(task.scopedKey, context.scope, s), s)
// intended for use in constructing InputTasks // intended for use in constructing InputTasks
def loadForParser[P,T](task: ScopedTask[T])(f: (State, Option[T]) => Parser[P])(implicit format: sbinary.Format[T]): Initialize[State => Parser[P]] = def loadForParser[P,T](task: TaskKey[T])(f: (State, Option[T]) => Parser[P])(implicit format: sbinary.Format[T]): Initialize[State => Parser[P]] =
loadForParserI(task)(Project value f)(format) loadForParserI(task)(Project value f)(format)
def loadForParserI[P,T](task: ScopedTask[T])(init: Initialize[(State, Option[T]) => Parser[P]])(implicit format: sbinary.Format[T]): Initialize[State => Parser[P]] = def loadForParserI[P,T](task: TaskKey[T])(init: Initialize[(State, Option[T]) => Parser[P]])(implicit format: sbinary.Format[T]): Initialize[State => Parser[P]] =
(resolvedScoped, init)( (ctx, f) => (s: State) => f( s, loadFromContext(task, ctx, s)(format)) ) (resolvedScoped, init)( (ctx, f) => (s: State) => f( s, loadFromContext(task, ctx, s)(format)) )
def getForParser[P,T](task: ScopedTask[T])(init: (State, Option[T]) => Parser[P]): Initialize[State => Parser[P]] = def getForParser[P,T](task: TaskKey[T])(init: (State, Option[T]) => Parser[P]): Initialize[State => Parser[P]] =
getForParserI(task)(Project value init) getForParserI(task)(Project value init)
def getForParserI[P,T](task: ScopedTask[T])(init: Initialize[(State, Option[T]) => Parser[P]]): Initialize[State => Parser[P]] = def getForParserI[P,T](task: TaskKey[T])(init: Initialize[(State, Option[T]) => Parser[P]]): Initialize[State => Parser[P]] =
(resolvedScoped, init)( (ctx, f) => (s: State) => f(s, getFromContext(task, ctx, s)) ) (resolvedScoped, init)( (ctx, f) => (s: State) => f(s, getFromContext(task, ctx, s)) )
// these are for use for constructing Tasks // these are for use for constructing Tasks
def loadPrevious[T](task: ScopedTask[T])(implicit f: sbinary.Format[T]): Initialize[Task[Option[T]]] = def loadPrevious[T](task: TaskKey[T])(implicit f: sbinary.Format[T]): Initialize[Task[Option[T]]] =
(state, resolvedScoped) map { (s, ctx) => loadFromContext(task, ctx, s)(f) } (state, resolvedScoped) map { (s, ctx) => loadFromContext(task, ctx, s)(f) }
def getPrevious[T](task: ScopedTask[T]): Initialize[Task[Option[T]]] = def getPrevious[T](task: TaskKey[T]): Initialize[Task[Option[T]]] =
(state, resolvedScoped) map { (s, ctx) => getFromContext(task, ctx, s) } (state, resolvedScoped) map { (s, ctx) => getFromContext(task, ctx, s) }
} }

View File

@ -67,13 +67,13 @@ final case class Extracted(structure: BuildStructure, session: SessionSettings,
lazy val currentUnit = structure units currentRef.build lazy val currentUnit = structure units currentRef.build
lazy val currentProject = currentUnit defined currentRef.project lazy val currentProject = currentUnit defined currentRef.project
lazy val currentLoader: ClassLoader = currentUnit.loader lazy val currentLoader: ClassLoader = currentUnit.loader
def get[T](key: ScopedTask[T]): Task[T] = get(key.task) def get[T](key: TaskKey[T]): Task[T] = get(key.task)
def get[T](key: ScopedSetting[T]) = getOrError(inCurrent(key), key.key) def get[T](key: SettingKey[T]) = getOrError(inCurrent(key), key.key)
def getOpt[T](key: ScopedSetting[T]): Option[T] = structure.data.get(inCurrent(key), key.key) def getOpt[T](key: SettingKey[T]): Option[T] = structure.data.get(inCurrent(key), key.key)
private[this] def inCurrent[T](key: ScopedSetting[T]): Scope = if(key.scope.project == This) key.scope.copy(project = Select(currentRef)) else key.scope private[this] def inCurrent[T](key: SettingKey[T]): Scope = if(key.scope.project == This) key.scope.copy(project = Select(currentRef)) else key.scope
@deprecated("This method does not apply state changes requested during task execution. Use 'runTask' instead, which does.", "0.11.1") @deprecated("This method does not apply state changes requested during task execution. Use 'runTask' instead, which does.", "0.11.1")
def evalTask[T](key: ScopedTask[T], state: State): T = runTask(key, state)._2 def evalTask[T](key: TaskKey[T], state: State): T = runTask(key, state)._2
def runTask[T](key: ScopedTask[T], state: State): (State, T) = def runTask[T](key: TaskKey[T], state: State): (State, T) =
{ {
import EvaluateTask._ import EvaluateTask._
val rkey = Project.mapScope(Scope.resolveScope(GlobalScope, currentRef.build, rootProject) )( key.scopedKey ) val rkey = Project.mapScope(Scope.resolveScope(GlobalScope, currentRef.build, rootProject) )( key.scopedKey )
@ -169,7 +169,7 @@ object Project extends Init[Scope] with ProjectExtra
onLoad(updateCurrent( newState )) onLoad(updateCurrent( newState ))
} }
def orIdentity[T](opt: Option[T => T]): T => T = opt getOrElse idFun def orIdentity[T](opt: Option[T => T]): T => T = opt getOrElse idFun
def getHook[T](key: ScopedSetting[T => T], data: Settings[Scope]): T => T = orIdentity(key in GlobalScope get data) def getHook[T](key: SettingKey[T => T], data: Settings[Scope]): T => T = orIdentity(key in GlobalScope get data)
def getHooks(data: Settings[Scope]): (State => State, State => State) = (getHook(Keys.onLoad, data), getHook(Keys.onUnload, data)) def getHooks(data: Settings[Scope]): (State => State, State => State) = (getHook(Keys.onLoad, data), getHook(Keys.onUnload, data))
def current(state: State): ProjectRef = session(state).current def current(state: State): ProjectRef = session(state).current

View File

@ -70,40 +70,35 @@ object InputTask
apply(Project.value(p))(action) apply(Project.value(p))(action)
} }
sealed trait Scoped { def scope: Scope; def key: AttributeKey[_] } sealed trait Scoped { def scope: Scope; val key: AttributeKey[_] }
sealed trait ScopedTaskable[T] extends Scoped sealed trait ScopedTaskable[T] extends Scoped
sealed trait ScopedSetting[T] extends ScopedTaskable[T] with KeyedInitialize[T] with Scoped.ScopingSetting[ScopedSetting[T]] with Scoped.DefinableSetting[T] with Scoped.ListSetting[T, Id] sealed trait SettingKey[T] extends ScopedTaskable[T] with KeyedInitialize[T] with Scoped.ScopingSetting[SettingKey[T]] with Scoped.DefinableSetting[T] with Scoped.ListSetting[T, Id]
{ {
def key: AttributeKey[T] val key: AttributeKey[T]
def scopedKey: ScopedKey[T] = ScopedKey(scope, key) def scopedKey: ScopedKey[T] = ScopedKey(scope, key)
def in(scope: Scope): ScopedSetting[T] = Scoped.scopedSetting(Scope.replaceThis(this.scope)(scope), this.key) def in(scope: Scope): SettingKey[T] = Scoped.scopedSetting(Scope.replaceThis(this.scope)(scope), this.key)
protected[this] def make[S](other: Initialize[S])(f: (T, S) => T): Setting[T] = this <<= (this, other)(f) protected[this] def make[S](other: Initialize[S])(f: (T, S) => T): Setting[T] = this <<= (this, other)(f)
} }
sealed trait ScopedTask[T] extends ScopedTaskable[T] with KeyedInitialize[Task[T]] with Scoped.ScopingSetting[ScopedTask[T]] with Scoped.ListSetting[T, Task] with Scoped.DefinableTask[T] sealed trait TaskKey[T] extends ScopedTaskable[T] with KeyedInitialize[Task[T]] with Scoped.ScopingSetting[TaskKey[T]] with Scoped.ListSetting[T, Task] with Scoped.DefinableTask[T]
{ {
def key: AttributeKey[Task[T]] val key: AttributeKey[Task[T]]
def scopedKey: ScopedKey[Task[T]] = ScopedKey(scope, key) def scopedKey: ScopedKey[Task[T]] = ScopedKey(scope, key)
def in(scope: Scope): ScopedTask[T] = Scoped.scopedTask(Scope.replaceThis(this.scope)(scope), this.key) def in(scope: Scope): TaskKey[T] = Scoped.scopedTask(Scope.replaceThis(this.scope)(scope), this.key)
protected[this] def make[S](other: Initialize[Task[S]])(f: (T, S) => T): Setting[Task[T]] = this <<= (this, other) { (a,b) => (a,b) map f } protected[this] def make[S](other: Initialize[Task[S]])(f: (T, S) => T): Setting[Task[T]] = this <<= (this, other) { (a,b) => (a,b) map f }
} }
sealed trait ScopedInput[T] extends Scoped with KeyedInitialize[InputTask[T]] with Scoped.ScopingSetting[ScopedInput[T]] with Scoped.DefinableSetting[InputTask[T]] sealed trait InputKey[T] extends Scoped with KeyedInitialize[InputTask[T]] with Scoped.ScopingSetting[InputKey[T]] with Scoped.DefinableSetting[InputTask[T]]
{ {
def key: AttributeKey[InputTask[T]] val key: AttributeKey[InputTask[T]]
def scopedKey: ScopedKey[InputTask[T]] = ScopedKey(scope, key) def scopedKey: ScopedKey[InputTask[T]] = ScopedKey(scope, key)
def in(scope: Scope): ScopedInput[T] = Scoped.scopedInput(Scope.replaceThis(this.scope)(scope), this.key) def in(scope: Scope): InputKey[T] = Scoped.scopedInput(Scope.replaceThis(this.scope)(scope), this.key)
} }
sealed trait Key[T] extends Scoped { final def scope: Scope = Scope.ThisScope }
final class SettingKey[T] private(val key: AttributeKey[T]) extends Key[T] with ScopedSetting[T]
final class TaskKey[T] private(val key: AttributeKey[Task[T]]) extends Key[T] with ScopedTask[T]
final class InputKey[T] private(val key: AttributeKey[InputTask[T]]) extends Key[InputTask[T]] with ScopedInput[T]
object Scoped object Scoped
{ {
implicit def taskScopedToKey[T](s: ScopedTask[T]): ScopedKey[Task[T]] = ScopedKey(s.scope, s.key) implicit def taskScopedToKey[T](s: TaskKey[T]): ScopedKey[Task[T]] = ScopedKey(s.scope, s.key)
implicit def inputScopedToKey[T](s: ScopedInput[T]): ScopedKey[InputTask[T]] = ScopedKey(s.scope, s.key) implicit def inputScopedToKey[T](s: InputKey[T]): ScopedKey[InputTask[T]] = ScopedKey(s.scope, s.key)
sealed trait ScopingSetting[Result] sealed trait ScopingSetting[Result]
{ {
@ -119,9 +114,9 @@ object Scoped
def in(p: ScopeAxis[Reference], c: ScopeAxis[ConfigKey], t: ScopeAxis[AttributeKey[_]]): Result = in( Scope(p, c, t, This) ) def in(p: ScopeAxis[Reference], c: ScopeAxis[ConfigKey], t: ScopeAxis[AttributeKey[_]]): Result = in( Scope(p, c, t, This) )
} }
def scopedSetting[T](s: Scope, k: AttributeKey[T]): ScopedSetting[T] = new ScopedSetting[T] { val scope = s; val key = k} def scopedSetting[T](s: Scope, k: AttributeKey[T]): SettingKey[T] = new SettingKey[T] { val scope = s; val key = k}
def scopedInput[T](s: Scope, k: AttributeKey[InputTask[T]]): ScopedInput[T] = new ScopedInput[T] { val scope = s; val key = k } def scopedInput[T](s: Scope, k: AttributeKey[InputTask[T]]): InputKey[T] = new InputKey[T] { val scope = s; val key = k }
def scopedTask[T](s: Scope, k: AttributeKey[Task[T]]): ScopedTask[T] = new ScopedTask[T] { val scope = s; val key = k } def scopedTask[T](s: Scope, k: AttributeKey[Task[T]]): TaskKey[T] = new TaskKey[T] { val scope = s; val key = k }
sealed trait ListSetting[S, M[_]] sealed trait ListSetting[S, M[_]]
{ {
@ -154,17 +149,17 @@ object Scoped
def flatMap[T](f: S => Task[T]): Initialize[Task[T]] = init(f) def flatMap[T](f: S => Task[T]): Initialize[Task[T]] = init(f)
} }
sealed trait DefinableTask[S] sealed trait DefinableTask[S]
{ self: ScopedTask[S] => { self: TaskKey[S] =>
private[sbt] def :==(value: S): Setting[Task[S]] = :=(value) private[sbt] def :==(value: S): Setting[Task[S]] = :=(value)
private[sbt] def ::=(value: Task[S]): Setting[Task[S]] = Project.setting(scopedKey, Project.value( value )) private[sbt] def ::=(value: Task[S]): Setting[Task[S]] = Project.setting(scopedKey, Project.value( value ))
def := (value: => S): Setting[Task[S]] = ::=(mktask(value)) def := (value: => S): Setting[Task[S]] = ::=(mktask(value))
private[sbt] def :== (v: ScopedSetting[S]): Setting[Task[S]] = <<=( v(constant)) private[sbt] def :== (v: SettingKey[S]): Setting[Task[S]] = <<=( v(constant))
def ~= (f: S => S): Setting[Task[S]] = Project.update(scopedKey)( _ map f ) def ~= (f: S => S): Setting[Task[S]] = Project.update(scopedKey)( _ map f )
def <<= (app: Initialize[Task[S]]): Setting[Task[S]] = Project.setting(scopedKey, app) def <<= (app: Initialize[Task[S]]): Setting[Task[S]] = Project.setting(scopedKey, app)
def task: ScopedSetting[Task[S]] = scopedSetting(scope, key) def task: SettingKey[Task[S]] = scopedSetting(scope, key)
def get(settings: Settings[Scope]): Option[Task[S]] = settings.get(scope, key) def get(settings: Settings[Scope]): Option[Task[S]] = settings.get(scope, key)
@deprecated("A call to 'identity' is no longer necessary and can be removed.") @deprecated("A call to 'identity' is no longer necessary and can be removed.")
@ -193,10 +188,10 @@ object Scoped
import SessionVar.{persistAndSet, resolveContext, set, transform} import SessionVar.{persistAndSet, resolveContext, set, transform}
def updateState(f: (State, S) => State): Initialize[Task[S]] = i(t => transform(t, f)) def updateState(f: (State, S) => State): Initialize[Task[S]] = i(t => transform(t, f))
def storeAs(key: ScopedTask[S])(implicit f: sbinary.Format[S]): Initialize[Task[S]] = (Keys.resolvedScoped, i) { (scoped, task) => def storeAs(key: TaskKey[S])(implicit f: sbinary.Format[S]): Initialize[Task[S]] = (Keys.resolvedScoped, i) { (scoped, task) =>
transform(task, (state, value) => persistAndSet( resolveContext(key, scoped.scope, state), state, value)(f)) transform(task, (state, value) => persistAndSet( resolveContext(key, scoped.scope, state), state, value)(f))
} }
def keepAs(key: ScopedTask[S]): Initialize[Task[S]] = def keepAs(key: TaskKey[S]): Initialize[Task[S]] =
(i, Keys.resolvedScoped)( (t,scoped) => transform(t, (state,value) => set(resolveContext(key, scoped.scope, state), state, value) ) ) (i, Keys.resolvedScoped)( (t,scoped) => transform(t, (state,value) => set(resolveContext(key, scoped.scope, state), state, value) ) )
def triggeredBy(tasks: AnyInitTask*): Initialize[Task[S]] = nonLocal(tasks, Keys.triggeredBy) def triggeredBy(tasks: AnyInitTask*): Initialize[Task[S]] = nonLocal(tasks, Keys.triggeredBy)
@ -219,15 +214,15 @@ object Scoped
} }
implicit def richFileSetting(s: ScopedSetting[File]): RichFileSetting = new RichFileSetting(s) implicit def richFileSetting(s: SettingKey[File]): RichFileSetting = new RichFileSetting(s)
implicit def richFilesSetting(s: ScopedSetting[Seq[File]]): RichFilesSetting = new RichFilesSetting(s) implicit def richFilesSetting(s: SettingKey[Seq[File]]): RichFilesSetting = new RichFilesSetting(s)
final class RichFileSetting(s: ScopedSetting[File]) extends RichFileBase final class RichFileSetting(s: SettingKey[File]) extends RichFileBase
{ {
def /(c: String): Initialize[File] = s { _ / c } def /(c: String): Initialize[File] = s { _ / c }
protected[this] def map0(f: PathFinder => PathFinder) = s(file => finder(f)(file :: Nil)) protected[this] def map0(f: PathFinder => PathFinder) = s(file => finder(f)(file :: Nil))
} }
final class RichFilesSetting(s: ScopedSetting[Seq[File]]) extends RichFileBase final class RichFilesSetting(s: SettingKey[Seq[File]]) extends RichFileBase
{ {
def /(s: String): Initialize[Seq[File]] = map0 { _ / s } def /(s: String): Initialize[Seq[File]] = map0 { _ / s }
protected[this] def map0(f: PathFinder => PathFinder) = s(finder(f)) protected[this] def map0(f: PathFinder => PathFinder) = s(finder(f))
@ -243,7 +238,7 @@ object Scoped
/* /*
* Reduced and combine provide support for mixed Setting/Task flatMap/map. * Reduced and combine provide support for mixed Setting/Task flatMap/map.
* The general idea is to take a KList of ScopedTaskables, which are either ScopedSettings or ScopedTasks, * The general idea is to take a KList of ScopedTaskables, which are either SettingKeys or TaskKeys,
* and uniformly provide multi-flatMap/map for constructing a new Task. * and uniformly provide multi-flatMap/map for constructing a new Task.
* For example: {{{ (SettingKeyA, TaskKeyB) flatMap { (a,b) => ... } }}} * For example: {{{ (SettingKeyA, TaskKeyB) flatMap { (a,b) => ... } }}}
*/ */
@ -272,8 +267,8 @@ object Scoped
def prependTaskable[H](key: ScopedTaskable[H]): Reduced[_,_,H :+: HLv] = def prependTaskable[H](key: ScopedTaskable[H]): Reduced[_,_,H :+: HLv] =
key match key match
{ {
case ss: ScopedSetting[H] => prependSetting(ss) case ss: SettingKey[H] => prependSetting(ss)
case st: ScopedTask[H] => prependTask(scopedSetting(st.scope, st.key)) case st: TaskKey[H] => prependTask(scopedSetting(st.scope, st.key))
} }
def combine[D[_],S](c: Combine[D], f: Results[HLv] => D[S]): Initialize[Task[S]] = def combine[D[_],S](c: Combine[D], f: Results[HLv] => D[S]): Initialize[Task[S]] =
@ -488,7 +483,7 @@ object InputKey
apply( AttributeKey[InputTask[T]](label, description, extendScoped(extend1, extendN)) ) apply( AttributeKey[InputTask[T]](label, description, extendScoped(extend1, extendN)) )
def apply[T](akey: AttributeKey[InputTask[T]]): InputKey[T] = def apply[T](akey: AttributeKey[InputTask[T]]): InputKey[T] =
new InputKey[T](akey) new InputKey[T] { val key = akey; def scope = Scope.ThisScope }
} }
object TaskKey object TaskKey
{ {
@ -499,7 +494,7 @@ object TaskKey
apply( AttributeKey[Task[T]](label, description, extendScoped(extend1, extendN)) ) apply( AttributeKey[Task[T]](label, description, extendScoped(extend1, extendN)) )
def apply[T](akey: AttributeKey[Task[T]]): TaskKey[T] = def apply[T](akey: AttributeKey[Task[T]]): TaskKey[T] =
new TaskKey[T](akey) new TaskKey[T] { val key = akey; def scope = Scope.ThisScope }
def local[T: Manifest]: TaskKey[T] = apply[T](AttributeKey.local[Task[T]]) def local[T: Manifest]: TaskKey[T] = apply[T](AttributeKey.local[Task[T]])
} }
@ -512,7 +507,7 @@ object SettingKey
apply( AttributeKey[T](label, description, extendScoped(extend1, extendN)) ) apply( AttributeKey[T](label, description, extendScoped(extend1, extendN)) )
def apply[T](akey: AttributeKey[T]): SettingKey[T] = def apply[T](akey: AttributeKey[T]): SettingKey[T] =
new SettingKey[T](akey) new SettingKey[T] { val key = akey; def scope = Scope.ThisScope }
def local[T: Manifest]: SettingKey[T] = apply[T](AttributeKey.local[T]) def local[T: Manifest]: SettingKey[T] = apply[T](AttributeKey.local[T])
} }

View File

@ -4,6 +4,13 @@
package object sbt extends sbt.std.TaskExtra with sbt.Types with sbt.ProcessExtra with sbt.impl.DependencyBuilders package object sbt extends sbt.std.TaskExtra with sbt.Types with sbt.ProcessExtra with sbt.impl.DependencyBuilders
with sbt.PathExtra with sbt.ProjectExtra with sbt.DependencyFilterExtra with sbt.BuildExtra with sbt.PathExtra with sbt.ProjectExtra with sbt.DependencyFilterExtra with sbt.BuildExtra
{ {
@deprecated("Use SettingKey, which is a drop-in replacement.", "0.11.1")
type ScopedSetting[T] = SettingKey[T]
@deprecated("Use TaskKey, which is a drop-in replacement.", "0.11.1")
type ScopedTask[T] = TaskKey[T]
@deprecated("Use InputKey, which is a drop-in replacement.", "0.11.1")
type ScopedInput[T] = InputKey[T]
type Setting[T] = Project.Setting[T] type Setting[T] = Project.Setting[T]
type ScopedKey[T] = Project.ScopedKey[T] type ScopedKey[T] = Project.ScopedKey[T]
type SettingsDefinition = Project.SettingsDefinition type SettingsDefinition = Project.SettingsDefinition