Make sure of EvaluateTask in Extracted obvious

This commit is contained in:
Dale Wijnand 2017-10-12 15:03:05 +01:00
parent fa33b6e422
commit 10397926aa
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
3 changed files with 15 additions and 14 deletions

View File

@ -552,7 +552,7 @@ object Defaults extends BuildCommon {
val trigMsg = triggeredMessage.value
new Watched {
val scoped = watchTransitiveSources in base
val key = ScopedKey(scoped.scope, scoped.key)
val key = scoped.scopedKey
override def pollInterval = interval
override def watchingMessage(s: WatchState) = msg(s)
override def triggeredMessage(s: WatchState) = trigMsg(s)

View File

@ -460,6 +460,7 @@ object EvaluateTask {
onResult(result, log) { v =>
if (show) println("Result: " + v); v
}
def onResult[T, S](result: Result[T], log: Logger)(f: T => S): S =
result match {
case Value(v) => f(v)

View File

@ -15,6 +15,7 @@ import sbt.internal.util.complete.Parser
import sbt.internal.util.AttributeKey
import sbt.util.Show
import std.Transform.DummyTaskMap
import sbt.EvaluateTask.extractedTaskConfig
final case class Extracted(structure: BuildStructure,
session: SessionSettings,
@ -49,16 +50,16 @@ final case class Extracted(structure: BuildStructure,
* If the project axis is not defined for the key, it is resolved to be the current project.
* Other axes are resolved to `Zero` if unspecified.
*
* This method requests execution of only the given task and does not aggregate execution. See `runAggregated` for that.
* This method requests execution of only the given task and does not aggregate execution.
* See `runAggregated` for that.
*/
def runTask[T](key: TaskKey[T], state: State): (State, T) = {
import EvaluateTask._
val rkey = resolve(key.scopedKey)
val config = extractedTaskConfig(this, structure, state)
val value: Option[(State, Result[T])] =
apply(structure, key.scopedKey, state, currentRef, config)
EvaluateTask(structure, key.scopedKey, state, currentRef, config)
val (newS, result) = getOrError(rkey.scope, rkey.key, value)
(newS, processResult(result, newS.log))
(newS, EvaluateTask.processResult(result, newS.log))
}
/**
@ -71,25 +72,22 @@ final case class Extracted(structure: BuildStructure,
* This method requests execution of only the given task and does not aggregate execution.
*/
def runInputTask[T](key: InputKey[T], input: String, state: State): (State, T) = {
import EvaluateTask._
val scopedKey = Scoped.scopedSetting(
Scope.resolveScope(Load.projectScope(currentRef), currentRef.build, structure.rootProject)(
key.scope),
val scopedKey = ScopedKey(
Scope.resolveScope(Load.projectScope(currentRef), currentRef.build, rootProject)(key.scope),
key.key
)
val rkey = resolve(scopedKey.scopedKey)
val rkey = resolve(scopedKey)
val inputTask = get(Scoped.scopedSetting(rkey.scope, rkey.key))
val task = Parser.parse(input, inputTask.parser(state)) match {
case Right(t) => t
case Left(msg) => sys.error(s"Invalid programmatic input:\n$msg")
}
val config = extractedTaskConfig(this, structure, state)
withStreams(structure, state) { str =>
val nv = nodeView(state, str, rkey :: Nil)
EvaluateTask.withStreams(structure, state) { str =>
val nv = EvaluateTask.nodeView(state, str, rkey :: Nil)
val (newS, result) =
EvaluateTask.runTask(task, state, str, structure.index.triggers, config)(nv)
(newS, processResult(result, newS.log))
(newS, EvaluateTask.processResult(result, newS.log))
}
}
@ -112,9 +110,11 @@ final case class Extracted(structure: BuildStructure,
private[this] def resolve[T](key: ScopedKey[T]): ScopedKey[T] =
Project.mapScope(Scope.resolveScope(GlobalScope, currentRef.build, rootProject))(key.scopedKey)
private def getOrError[T](scope: Scope, key: AttributeKey[_], value: Option[T])(
implicit display: Show[ScopedKey[_]]): T =
value getOrElse sys.error(display.show(ScopedKey(scope, key)) + " is undefined.")
private def getOrError[T](scope: Scope, key: AttributeKey[T])(
implicit display: Show[ScopedKey[_]]): T =
structure.data.get(scope, key) getOrElse sys.error(