mirror of https://github.com/sbt/sbt.git
move from TaskData to new system
This commit is contained in:
parent
5918c24722
commit
2a21a86f8c
|
|
@ -194,7 +194,7 @@ object Defaults extends BuildCommon
|
||||||
compileIncSetup <<= compileIncSetupTask,
|
compileIncSetup <<= compileIncSetupTask,
|
||||||
console <<= consoleTask,
|
console <<= consoleTask,
|
||||||
consoleQuick <<= consoleQuickTask,
|
consoleQuick <<= consoleQuickTask,
|
||||||
discoveredMainClasses <<= TaskData.write(compile map discoverMainClasses) triggeredBy compile,
|
discoveredMainClasses <<= compile map discoverMainClasses storeAs discoveredMainClasses triggeredBy compile,
|
||||||
definedSbtPlugins <<= discoverPlugins,
|
definedSbtPlugins <<= discoverPlugins,
|
||||||
inTask(run)(runnerTask :: Nil).head,
|
inTask(run)(runnerTask :: Nil).head,
|
||||||
selectMainClass <<= discoveredMainClasses map selectRunMain,
|
selectMainClass <<= discoveredMainClasses map selectRunMain,
|
||||||
|
|
@ -257,7 +257,8 @@ object Defaults extends BuildCommon
|
||||||
loadedTestFrameworks <<= (testFrameworks, streams, testLoader) map { (frameworks, s, loader) =>
|
loadedTestFrameworks <<= (testFrameworks, streams, testLoader) map { (frameworks, s, loader) =>
|
||||||
frameworks.flatMap(f => f.create(loader, s.log).map( x => (f,x)).toIterable).toMap
|
frameworks.flatMap(f => f.create(loader, s.log).map( x => (f,x)).toIterable).toMap
|
||||||
},
|
},
|
||||||
definedTests <<= TaskData.writeRelated(detectTests)(_.map(_.name).distinct) triggeredBy compile,
|
definedTests <<= detectTests,
|
||||||
|
definedTestNames <<= definedTests map ( _.map(_.name).distinct) storeAs definedTestNames triggeredBy compile,
|
||||||
testListeners in GlobalScope :== Nil,
|
testListeners in GlobalScope :== Nil,
|
||||||
testOptions in GlobalScope :== Nil,
|
testOptions in GlobalScope :== Nil,
|
||||||
executeTests <<= (streams in test, loadedTestFrameworks, parallelExecution in test, testOptions in test, testLoader, definedTests, resolvedScoped, state) flatMap {
|
executeTests <<= (streams in test, loadedTestFrameworks, parallelExecution in test, testOptions in test, testLoader, definedTests, resolvedScoped, state) flatMap {
|
||||||
|
|
@ -294,7 +295,7 @@ object Defaults extends BuildCommon
|
||||||
}
|
}
|
||||||
|
|
||||||
def testOnlyTask =
|
def testOnlyTask =
|
||||||
InputTask( TaskData(definedTests)(testOnlyParser)(Nil) ) { result =>
|
InputTask( loadForParser(definedTestNames)( (s, i) => testOnlyParser(s, i getOrElse Nil) ) ) { result =>
|
||||||
(streams, loadedTestFrameworks, parallelExecution in testOnly, testOptions in testOnly, testLoader, definedTests, resolvedScoped, result, state) flatMap {
|
(streams, loadedTestFrameworks, parallelExecution in testOnly, testOptions in testOnly, testLoader, definedTests, resolvedScoped, result, state) flatMap {
|
||||||
case (s, frameworks, par, opts, loader, discovered, scoped, (tests, frameworkOptions), st) =>
|
case (s, frameworks, par, opts, loader, discovered, scoped, (tests, frameworkOptions), st) =>
|
||||||
val filter = selectedFilter(tests)
|
val filter = selectedFilter(tests)
|
||||||
|
|
@ -405,7 +406,7 @@ object Defaults extends BuildCommon
|
||||||
def runMainTask(classpath: ScopedTask[Classpath], scalaRun: ScopedTask[ScalaRun]): Initialize[InputTask[Unit]] =
|
def runMainTask(classpath: ScopedTask[Classpath], scalaRun: ScopedTask[ScalaRun]): Initialize[InputTask[Unit]] =
|
||||||
{
|
{
|
||||||
import DefaultParsers._
|
import DefaultParsers._
|
||||||
InputTask( TaskData(discoveredMainClasses)(runMainParser)(Nil) ) { result =>
|
InputTask( loadForParser(discoveredMainClasses)( (s, names) => runMainParser(s, names getOrElse Nil) ) ) { result =>
|
||||||
(classpath, scalaRun, streams, result) map { case (cp, runner, s, (mainClass, args)) =>
|
(classpath, scalaRun, streams, result) map { case (cp, runner, s, (mainClass, args)) =>
|
||||||
toError(runner.run(mainClass, data(cp), args, s.log))
|
toError(runner.run(mainClass, data(cp), args, s.log))
|
||||||
}
|
}
|
||||||
|
|
@ -1133,7 +1134,18 @@ trait BuildCommon
|
||||||
def loadFromContext[T](task: ScopedTask[T], context: ScopedKey[_], s: State)(implicit f: sbinary.Format[T]): Option[T] =
|
def loadFromContext[T](task: ScopedTask[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)
|
||||||
|
|
||||||
// these are for use in tasks
|
// 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]] =
|
||||||
|
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]] =
|
||||||
|
(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]] =
|
||||||
|
getForParserI(task)(Project value init)
|
||||||
|
def getForParserI[P,T](task: ScopedTask[T])(init: Initialize[(State, Option[T]) => Parser[P]]): Initialize[State => Parser[P]] =
|
||||||
|
(resolvedScoped, init)( (ctx, f) => (s: State) => f(s, getFromContext(task, ctx, s)) )
|
||||||
|
|
||||||
|
// 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: ScopedTask[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) }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -181,6 +181,7 @@ object Keys
|
||||||
val testLoader = TaskKey[ClassLoader]("test-loader", "Provides the class loader used for testing.")
|
val testLoader = TaskKey[ClassLoader]("test-loader", "Provides the class loader used for testing.")
|
||||||
val loadedTestFrameworks = TaskKey[Map[TestFramework,Framework]]("loaded-test-frameworks", "Loads Framework definitions from the test loader.")
|
val loadedTestFrameworks = TaskKey[Map[TestFramework,Framework]]("loaded-test-frameworks", "Loads Framework definitions from the test loader.")
|
||||||
val definedTests = TaskKey[Seq[TestDefinition]]("defined-tests", "Provides the list of defined tests.")
|
val definedTests = TaskKey[Seq[TestDefinition]]("defined-tests", "Provides the list of defined tests.")
|
||||||
|
val definedTestNames = TaskKey[Seq[String]]("defined-test-names", "Provides the set of defined test names.")
|
||||||
val executeTests = TaskKey[Tests.Output]("execute-tests", "Executes all tests, producing a report.")
|
val executeTests = TaskKey[Tests.Output]("execute-tests", "Executes all tests, producing a report.")
|
||||||
val test = TaskKey[Unit]("test", "Executes all tests.")
|
val test = TaskKey[Unit]("test", "Executes all tests.")
|
||||||
val testOnly = InputKey[Unit]("test-only", "Executes the tests provided as arguments or all tests if no arguments are provided.")
|
val testOnly = InputKey[Unit]("test-only", "Executes the tests provided as arguments or all tests if no arguments are provided.")
|
||||||
|
|
|
||||||
|
|
@ -358,6 +358,8 @@ trait ProjectExtra
|
||||||
import sbinary.{Format, Operations}
|
import sbinary.{Format, Operations}
|
||||||
object SessionVar
|
object SessionVar
|
||||||
{
|
{
|
||||||
|
val DefaultDataID = "data"
|
||||||
|
|
||||||
// these are required because of inference+manifest limitations
|
// these are required because of inference+manifest limitations
|
||||||
final case class Key[T](key: ScopedKey[Task[T]])
|
final case class Key[T](key: ScopedKey[Task[T]])
|
||||||
final case class Map(map: IMap[Key, Id]) {
|
final case class Map(map: IMap[Key, Id]) {
|
||||||
|
|
@ -374,7 +376,7 @@ object SessionVar
|
||||||
|
|
||||||
def persist[T](key: ScopedKey[Task[T]], state: State, value: T)(implicit f: sbinary.Format[T]): Unit =
|
def persist[T](key: ScopedKey[Task[T]], state: State, value: T)(implicit f: sbinary.Format[T]): Unit =
|
||||||
Project.structure(state).streams.use(key)( s =>
|
Project.structure(state).streams.use(key)( s =>
|
||||||
Operations.write(s.binary(TaskData.DefaultDataID), value)(f)
|
Operations.write(s.binary(DefaultDataID), value)(f)
|
||||||
)
|
)
|
||||||
|
|
||||||
def get[T](key: ScopedKey[Task[T]], state: State): Option[T] = orEmpty(state get sessionVars) get key
|
def get[T](key: ScopedKey[Task[T]], state: State): Option[T] = orEmpty(state get sessionVars) get key
|
||||||
|
|
@ -398,7 +400,7 @@ object SessionVar
|
||||||
|
|
||||||
def read[T](key: ScopedKey[Task[T]], state: State)(implicit f: Format[T]): Option[T] =
|
def read[T](key: ScopedKey[Task[T]], state: State)(implicit f: Format[T]): Option[T] =
|
||||||
Project.structure(state).streams.use(key) { s =>
|
Project.structure(state).streams.use(key) { s =>
|
||||||
try { Some(Operations.read(s.readBinary(key, TaskData.DefaultDataID))) }
|
try { Some(Operations.read(s.readBinary(key, DefaultDataID))) }
|
||||||
catch { case e: Exception => None }
|
catch { case e: Exception => None }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ package sbt
|
||||||
|
|
||||||
import sbinary.{Format, Operations}
|
import sbinary.{Format, Operations}
|
||||||
|
|
||||||
|
@deprecated("Superseded by task state system.", "0.11.1")
|
||||||
object TaskData
|
object TaskData
|
||||||
{
|
{
|
||||||
val DefaultDataID = "data"
|
val DefaultDataID = "data"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue