2010-07-15 01:24:50 +02:00
|
|
|
/* sbt -- Simple Build Tool
|
|
|
|
|
* Copyright 2009, 2010 Mark Harrah
|
|
|
|
|
*/
|
|
|
|
|
package sbt
|
|
|
|
|
|
|
|
|
|
/** Defines a function to call as sbt exits.*/
|
2011-03-22 01:26:04 +01:00
|
|
|
trait ExitHook
|
2010-07-15 01:24:50 +02:00
|
|
|
{
|
|
|
|
|
/** Subclasses should implement this method, which is called when this hook is executed. */
|
|
|
|
|
def runBeforeExiting(): Unit
|
|
|
|
|
}
|
2011-03-22 01:26:04 +01:00
|
|
|
object ExitHook
|
|
|
|
|
{
|
|
|
|
|
def apply(f: => Unit): ExitHook = new ExitHook { def runBeforeExiting() = f }
|
|
|
|
|
}
|
2010-07-15 01:24:50 +02:00
|
|
|
|
2010-07-17 18:07:41 +02:00
|
|
|
object ExitHooks
|
2010-07-15 01:24:50 +02:00
|
|
|
{
|
|
|
|
|
/** Calls each registered exit hook, trapping any exceptions so that each hook is given a chance to run. */
|
2010-07-17 18:07:41 +02:00
|
|
|
def runExitHooks(exitHooks: Seq[ExitHook]): Seq[Throwable] =
|
|
|
|
|
exitHooks.flatMap( hook =>
|
2010-07-15 01:24:50 +02:00
|
|
|
ErrorHandling.wideConvert( hook.runBeforeExiting() ).left.toOption
|
|
|
|
|
)
|
|
|
|
|
}
|