diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2016-04-06 23:40:17 -0400 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-04-06 23:40:17 -0400 |
commit | 1e2063c934028bd765f761038c607b1c78e6d161 (patch) | |
tree | 5c4528b93c86bbb8e79849c104747a6b05e92a77 /stage1 | |
parent | f4068604a65f61a739c9f5b6be16c76bc93ecc65 (diff) | |
download | cbt-1e2063c934028bd765f761038c607b1c78e6d161.tar.gz cbt-1e2063c934028bd765f761038c607b1c78e6d161.tar.bz2 cbt-1e2063c934028bd765f761038c607b1c78e6d161.zip |
Temporarily cache classloaders for potentially changing files
to avoid creating classloaders for the same files more than once, which leads to conflicts.
Diffstat (limited to 'stage1')
-rw-r--r-- | stage1/Stage1.scala | 4 | ||||
-rw-r--r-- | stage1/resolver.scala | 46 |
2 files changed, 26 insertions, 24 deletions
diff --git a/stage1/Stage1.scala b/stage1/Stage1.scala index 91f8ca7..b68387f 100644 --- a/stage1/Stage1.scala +++ b/stage1/Stage1.scala @@ -76,8 +76,10 @@ object Stage1{ } logger.stage1(s"Run Stage2") + val cl = NailgunLauncher.stage2classLoader val exitCode = ( - NailgunLauncher.stage2classLoader.loadClass( + cl + .loadClass( if(args.admin) "cbt.AdminStage2" else "cbt.Stage2" ) .getMethod( "run", classOf[Stage2Args] ) diff --git a/stage1/resolver.scala b/stage1/resolver.scala index 8eaf107..e4af8a9 100644 --- a/stage1/resolver.scala +++ b/stage1/resolver.scala @@ -85,7 +85,7 @@ abstract class Dependency{ ) } - private def actual(current: Dependency, latest: Map[(String,String),Dependency]) = current match { + protected def actual(current: Dependency, latest: Map[(String,String),Dependency]) = current match { case d: ArtifactInfo => latest((d.groupId,d.artifactId)) case d => d } @@ -103,31 +103,26 @@ abstract class Dependency{ ) ) } else { - val (cachable, nonCachable) = dependencies.partition(_.canBeCached) - new URLClassLoader( - ClassPath.flatten( nonCachable.map(actual(_,latest)).map(_.exportedClasspath) ), - cache.persistent.get( - ClassPath.flatten( cachable.map(actual(_,latest)).map(_.exportedClasspath) ).string, - new MultiClassLoader( - cachable.map( _.classLoaderRecursion(latest, cache) ) - ) + cache.transient.get( + dependencyClasspath.string, + new MultiClassLoader( + dependencies.map( _.classLoaderRecursion(latest, cache) ) ) ) - new MultiClassLoader( - dependencies.map( _.classLoaderRecursion(latest, cache) ) - ) } } protected def classLoaderRecursion( latest: Map[(String,String),Dependency], cache: ClassLoaderCache ): ClassLoader = { - if( canBeCached ){ - val a = actual( this, latest ) - cache.persistent.get( - a.classpath.string, - new cbt.URLClassLoader( a.exportedClasspath, dependencyClassLoader(latest, cache) ) - ) - } else { - new cbt.URLClassLoader( exportedClasspath, dependencyClassLoader(latest, cache) ) - } + val a = actual( this, latest ) + ( + if( canBeCached ){ + cache.persistent + } else { + cache.transient + } + ).get( + a.classpath.string, + new cbt.URLClassLoader( a.exportedClasspath, dependencyClassLoader(latest, cache) ) + ) } def classLoader( cache: ClassLoaderCache ): ClassLoader = { if( concurrencyEnabled ){ @@ -231,8 +226,13 @@ case class Stage1Dependency()(implicit val logger: Logger) extends Dependency{ ) ) // FIXME: implement sanity check to prevent using incompatible scala-library and xml version on cp - override def classLoaderRecursion( latest: Map[(String,String),Dependency], cache: ClassLoaderCache ) - = getClass.getClassLoader + override def classLoaderRecursion( latest: Map[(String,String),Dependency], cache: ClassLoaderCache ) = { + val a = actual( this, latest ) + cache.transient.get( + a.classpath.string, + getClass.getClassLoader + ) + } } case class CbtDependency()(implicit val logger: Logger) extends Dependency{ override def needsUpdate = false // FIXME: think this through, might allow simplifications and/or optimizations |