mirror of https://github.com/sbt/sbt.git
onComplete hook for cleanup after task execution
This commit is contained in:
parent
7f64e84393
commit
f065037572
|
|
@ -190,7 +190,8 @@ object Index
|
|||
update(runBefore, value, as get Keys.runBefore)
|
||||
update(triggeredBy, value, as get Keys.triggeredBy)
|
||||
}
|
||||
new Triggers[Task](runBefore, triggeredBy)
|
||||
val onComplete = Keys.onComplete in GlobalScope get ss getOrElse { () => () }
|
||||
new Triggers[Task](runBefore, triggeredBy, map => { onComplete(); map } )
|
||||
}
|
||||
private[this] def update(map: TriggerMap, base: Task[_], tasksOpt: Option[Seq[Task[_]]]): Unit =
|
||||
for( tasks <- tasksOpt; task <- tasks )
|
||||
|
|
|
|||
|
|
@ -46,6 +46,10 @@ object Keys
|
|||
val onLoad = SettingKey[State => State]("on-load", "Transformation to apply to the build state when the build is loaded.")
|
||||
val onUnload = SettingKey[State => State]("on-unload", "Transformation to apply to the build state when the build is unloaded.")
|
||||
|
||||
val onComplete = SettingKey[() => Unit]("on-complete", "Hook to run when task evaluation completes. The type of this setting is subject to change, pending the resolution of SI-2915.")
|
||||
// https://issues.scala-lang.org/browse/SI-2915
|
||||
// val onComplete = SettingKey[RMap[Task,Result] => RMap[Task,Result]]("on-complete", "Transformation to apply to the final task result map. This may also be used to register hooks to run when task evaluation completes.")
|
||||
|
||||
// Command keys
|
||||
val globalLogging = SettingKey[GlobalLogging]("global-logging", "Provides a global Logger, including command logging.")
|
||||
val historyPath = SettingKey[Option[File]]("history", "The location where command line history is persisted.")
|
||||
|
|
|
|||
|
|
@ -22,12 +22,12 @@ object Execute
|
|||
private[sbt] def completed(p: => Unit): Completed = new Completed {
|
||||
def process() { p }
|
||||
}
|
||||
def noTriggers[A[_]] = new Triggers[A](Map.empty, Map.empty)
|
||||
def noTriggers[A[_]] = new Triggers[A](Map.empty, Map.empty, idFun)
|
||||
}
|
||||
sealed trait Completed {
|
||||
def process(): Unit
|
||||
}
|
||||
final class Triggers[A[_]](val runBefore: collection.Map[A[_], Seq[A[_]]], val injectFor: collection.Map[A[_], Seq[A[_]]])
|
||||
final class Triggers[A[_]](val runBefore: collection.Map[A[_], Seq[A[_]]], val injectFor: collection.Map[A[_], Seq[A[_]]], val onComplete: RMap[A,Result] => RMap[A,Result])
|
||||
|
||||
final class Execute[A[_] <: AnyRef](checkCycles: Boolean, triggers: Triggers[A])(implicit view: NodeView[A])
|
||||
{
|
||||
|
|
@ -56,7 +56,7 @@ final class Execute[A[_] <: AnyRef](checkCycles: Boolean, triggers: Triggers[A])
|
|||
addNew(root)
|
||||
processAll()
|
||||
assert( results contains root, "No result for root node." )
|
||||
results
|
||||
triggers.onComplete(results)
|
||||
}
|
||||
|
||||
def processAll()(implicit strategy: Strategy)
|
||||
|
|
|
|||
Loading…
Reference in New Issue