From 17fad01b01e988ab00c709e6b102737b83c07cd9 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Sun, 3 Jul 2011 15:44:52 -0400 Subject: [PATCH] convenience on State for global locking --- main/State.scala | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main/State.scala b/main/State.scala index 0fee59e4a..5b60fb52f 100644 --- a/main/State.scala +++ b/main/State.scala @@ -4,6 +4,7 @@ package sbt import java.io.File + import java.util.concurrent.Callable import CommandSupport.FailureWall final case class State( @@ -40,6 +41,7 @@ trait StateOps { def put[T](key: AttributeKey[T], value: T): State def remove(key: AttributeKey[_]): State def baseDir: File + def locked[T](file: File)(t: => T): T def runExitHooks(): State def addExitHook(f: => Unit): State } @@ -92,5 +94,7 @@ object State ExitHooks.runExitHooks(s.exitHooks.toSeq) s.copy(exitHooks = Set.empty) } + def locked[T](file: File)(t: => T): T = + s.configuration.provider.scalaProvider.launcher.globalLock.apply(file, new Callable[T] { def call = t }) } } \ No newline at end of file