From f065037572c54e60942b1d0861095af0b1805404 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Fri, 5 Aug 2011 21:56:32 -0400 Subject: [PATCH] onComplete hook for cleanup after task execution --- main/Build.scala | 3 ++- main/Keys.scala | 4 ++++ tasks/Execute.scala | 6 +++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/main/Build.scala b/main/Build.scala index f3aa99b37..67c718e92 100644 --- a/main/Build.scala +++ b/main/Build.scala @@ -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 ) diff --git a/main/Keys.scala b/main/Keys.scala index a4bf865a6..d388c1700 100644 --- a/main/Keys.scala +++ b/main/Keys.scala @@ -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.") diff --git a/tasks/Execute.scala b/tasks/Execute.scala index c386e3828..9f4facb99 100644 --- a/tasks/Execute.scala +++ b/tasks/Execute.scala @@ -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)