Skip to content

Commit

Permalink
move from TaskData to new system
Browse files Browse the repository at this point in the history
  • Loading branch information
harrah committed Sep 22, 2011
1 parent 5918c24 commit 2a21a86
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
22 changes: 17 additions & 5 deletions main/Defaults.scala
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ object Defaults extends BuildCommon
compileIncSetup <<= compileIncSetupTask,
console <<= consoleTask,
consoleQuick <<= consoleQuickTask,
discoveredMainClasses <<= TaskData.write(compile map discoverMainClasses) triggeredBy compile,
discoveredMainClasses <<= compile map discoverMainClasses storeAs discoveredMainClasses triggeredBy compile,
definedSbtPlugins <<= discoverPlugins,
inTask(run)(runnerTask :: Nil).head,
selectMainClass <<= discoveredMainClasses map selectRunMain,
Expand Down Expand Up @@ -257,7 +257,8 @@ object Defaults extends BuildCommon
loadedTestFrameworks <<= (testFrameworks, streams, testLoader) map { (frameworks, s, loader) =>
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,
testOptions in GlobalScope :== Nil,
executeTests <<= (streams in test, loadedTestFrameworks, parallelExecution in test, testOptions in test, testLoader, definedTests, resolvedScoped, state) flatMap {
Expand Down Expand Up @@ -294,7 +295,7 @@ object Defaults extends BuildCommon
}

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 {
case (s, frameworks, par, opts, loader, discovered, scoped, (tests, frameworkOptions), st) =>
val filter = selectedFilter(tests)
Expand Down Expand Up @@ -405,7 +406,7 @@ object Defaults extends BuildCommon
def runMainTask(classpath: ScopedTask[Classpath], scalaRun: ScopedTask[ScalaRun]): Initialize[InputTask[Unit]] =
{
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)) =>
toError(runner.run(mainClass, data(cp), args, s.log))
}
Expand Down Expand Up @@ -1133,7 +1134,18 @@ trait BuildCommon
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)

// 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]]] =
(state, resolvedScoped) map { (s, ctx) => loadFromContext(task, ctx, s)(f) }

Expand Down
1 change: 1 addition & 0 deletions main/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ object Keys
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 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 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.")
Expand Down
6 changes: 4 additions & 2 deletions main/Project.scala
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ trait ProjectExtra
import sbinary.{Format, Operations}
object SessionVar
{
val DefaultDataID = "data"

// these are required because of inference+manifest limitations
final case class Key[T](key: ScopedKey[Task[T]])
final case class Map(map: IMap[Key, Id]) {
Expand All @@ -374,7 +376,7 @@ object SessionVar

def persist[T](key: ScopedKey[Task[T]], state: State, value: T)(implicit f: sbinary.Format[T]): Unit =
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
Expand All @@ -398,7 +400,7 @@ object SessionVar

def read[T](key: ScopedKey[Task[T]], state: State)(implicit f: Format[T]): Option[T] =
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 }
}

Expand Down
1 change: 1 addition & 0 deletions main/TaskData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package sbt

import sbinary.{Format, Operations}

@deprecated("Superseded by task state system.", "0.11.1")
object TaskData
{
val DefaultDataID = "data"
Expand Down

0 comments on commit 2a21a86

Please sign in to comment.