make ComponentManager honor value of Ivy home provided by the launcher

This commit is contained in:
Mark Harrah 2011-09-16 23:08:01 -04:00
parent 63931234d4
commit 31f492f4bc
3 changed files with 10 additions and 9 deletions

View File

@ -15,8 +15,9 @@ import java.util.concurrent.Callable
* This is used for compiled source jars so that the compilation need not be repeated for other projects on the same * This is used for compiled source jars so that the compilation need not be repeated for other projects on the same
* machine. * machine.
*/ */
class ComponentManager(globalLock: xsbti.GlobalLock, provider: xsbti.ComponentProvider, val log: Logger) extends NotNull class ComponentManager(globalLock: xsbti.GlobalLock, provider: xsbti.ComponentProvider, ivyHome: Option[File], val log: Logger)
{ {
private[this] val ivyCache = new IvyCache(ivyHome)
/** Get all of the files for component 'id', throwing an exception if no files exist for the component. */ /** Get all of the files for component 'id', throwing an exception if no files exist for the component. */
def files(id: String)(ifMissing: IfMissing): Iterable[File] = def files(id: String)(ifMissing: IfMissing): Iterable[File] =
{ {
@ -45,7 +46,7 @@ class ComponentManager(globalLock: xsbti.GlobalLock, provider: xsbti.ComponentPr
/** This is used to lock the local cache in project/boot/. By checking the local cache first, we can avoid grabbing a global lock. */ /** This is used to lock the local cache in project/boot/. By checking the local cache first, we can avoid grabbing a global lock. */
private def lockLocalCache[T](action: => T): T = lock(provider.lockFile)( action ) private def lockLocalCache[T](action: => T): T = lock(provider.lockFile)( action )
/** This is used to ensure atomic access to components in the global Ivy cache.*/ /** This is used to ensure atomic access to components in the global Ivy cache.*/
private def lockGlobalCache[T](action: => T): T = lock(IvyCache.lockFile)( action ) private def lockGlobalCache[T](action: => T): T = lock(ivyCache.lockFile)( action )
private def lock[T](file: File)(action: => T): T = globalLock(file, new Callable[T] { def call = action }) private def lock[T](file: File)(action: => T): T = globalLock(file, new Callable[T] { def call = action })
/** Get the file for component 'id', throwing an exception if no files or multiple files exist for the component. */ /** Get the file for component 'id', throwing an exception if no files or multiple files exist for the component. */
def file(id: String)(ifMissing: IfMissing): File = def file(id: String)(ifMissing: IfMissing): File =
@ -58,12 +59,12 @@ class ComponentManager(globalLock: xsbti.GlobalLock, provider: xsbti.ComponentPr
def define(id: String, files: Iterable[File]) = lockLocalCache { provider.defineComponent(id, files.toSeq.toArray) } def define(id: String, files: Iterable[File]) = lockLocalCache { provider.defineComponent(id, files.toSeq.toArray) }
/** Retrieve the file for component 'id' from the local repository. */ /** Retrieve the file for component 'id' from the local repository. */
private def update(id: String): Unit = IvyCache.withCachedJar(sbtModuleID(id), Some(globalLock), log)(jar => define(id, Seq(jar)) ) private def update(id: String): Unit = ivyCache.withCachedJar(sbtModuleID(id), Some(globalLock), log)(jar => define(id, Seq(jar)) )
private def sbtModuleID(id: String) = ModuleID("org.scala-tools.sbt", id, ComponentManager.stampedVersion) private def sbtModuleID(id: String) = ModuleID("org.scala-tools.sbt", id, ComponentManager.stampedVersion)
/** Install the files for component 'id' to the local repository. This is usually used after writing files to the directory returned by 'location'. */ /** Install the files for component 'id' to the local repository. This is usually used after writing files to the directory returned by 'location'. */
def cache(id: String): Unit = IvyCache.cacheJar(sbtModuleID(id), file(id)(IfMissing.Fail), Some(globalLock), log) def cache(id: String): Unit = ivyCache.cacheJar(sbtModuleID(id), file(id)(IfMissing.Fail), Some(globalLock), log)
def clearCache(id: String): Unit = lockGlobalCache { IvyCache.clearCachedJar(sbtModuleID(id), Some(globalLock), log) } def clearCache(id: String): Unit = lockGlobalCache { ivyCache.clearCachedJar(sbtModuleID(id), Some(globalLock), log) }
} }
class InvalidComponent(msg: String, cause: Throwable) extends RuntimeException(msg, cause) class InvalidComponent(msg: String, cause: Throwable) extends RuntimeException(msg, cause)
{ {

View File

@ -28,9 +28,9 @@ private object NotInCache
} }
} }
/** Provides methods for working at the level of a single jar file with the default Ivy cache.*/ /** Provides methods for working at the level of a single jar file with the default Ivy cache.*/
object IvyCache class IvyCache(val ivyHome: Option[File])
{ {
def lockFile = new File(System.getProperty("user.home"), ".sbt.cache.lock") def lockFile = new File(ivyHome getOrElse Path.userHome, ".sbt.cache.lock")
/** Caches the given 'file' with the given ID. It may be retrieved or cleared using this ID.*/ /** Caches the given 'file' with the given ID. It may be retrieved or cleared using this ID.*/
def cacheJar(moduleID: ModuleID, file: File, lock: Option[xsbti.GlobalLock], log: Logger) def cacheJar(moduleID: ModuleID, file: File, lock: Option[xsbti.GlobalLock], log: Logger)
{ {
@ -85,7 +85,7 @@ object IvyCache
private def basicLocalIvy(lock: Option[xsbti.GlobalLock], log: Logger) = private def basicLocalIvy(lock: Option[xsbti.GlobalLock], log: Logger) =
{ {
val local = Resolver.defaultLocal val local = Resolver.defaultLocal
val paths = new IvyPaths(new File("."), None) val paths = new IvyPaths(new File("."), ivyHome)
val conf = new InlineIvyConfiguration(paths, Seq(local), Nil, Nil, false, lock, IvySbt.DefaultChecksums, log) val conf = new InlineIvyConfiguration(paths, Seq(local), Nil, Nil, false, lock, IvySbt.DefaultChecksums, log)
(new IvySbt(conf), local) (new IvySbt(conf), local)
} }

View File

@ -77,5 +77,5 @@ object ComponentManagerTest extends Specification
private def writeRandomContent(file: File) = IO.write(file, randomString) private def writeRandomContent(file: File) = IO.write(file, randomString)
private def randomString = "asdf" private def randomString = "asdf"
private def withManager[T](f: ComponentManager => T): T = private def withManager[T](f: ComponentManager => T): T =
TestLogger( logger => withTemporaryDirectory { temp => f(new ComponentManager(xsbt.boot.Locks, new xsbt.boot.ComponentProvider(temp, true), logger)) } ) TestLogger( logger => withTemporaryDirectory { temp => f(new ComponentManager(xsbt.boot.Locks, new xsbt.boot.ComponentProvider(temp, true), None, logger)) } )
} }