aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2016-11-10 01:43:04 -0500
committerChristopher Vogt <oss.nsp@cvogt.org>2016-11-10 01:44:46 -0500
commitfcd003b384ccbe49c7f1f2d3a19e7627149e7e07 (patch)
treea64774dfd729677ec23eab4807d022e9ff154d1a
parente6568ab2b821891acfeb5ded1e0555ebc5f9fe81 (diff)
downloadcbt-fcd003b384ccbe49c7f1f2d3a19e7627149e7e07.tar.gz
cbt-fcd003b384ccbe49c7f1f2d3a19e7627149e7e07.tar.bz2
cbt-fcd003b384ccbe49c7f1f2d3a19e7627149e7e07.zip
more sanity checks for cbt's classloaders
-rw-r--r--nailgun_launcher/NailgunLauncher.java25
-rw-r--r--stage1/Stage1.scala39
2 files changed, 37 insertions, 27 deletions
diff --git a/nailgun_launcher/NailgunLauncher.java b/nailgun_launcher/NailgunLauncher.java
index 6639218..dede00b 100644
--- a/nailgun_launcher/NailgunLauncher.java
+++ b/nailgun_launcher/NailgunLauncher.java
@@ -44,8 +44,8 @@ public class NailgunLauncher{
res
.classLoader
.loadClass("cbt.Stage1")
- .getMethod( "getBuild", Object.class, Boolean.class )
- .invoke(null, context, res.changed);
+ .getMethod( "getBuild", Object.class, BuildStage1Result.class )
+ .invoke(null, context, res);
}
public static void main( String[] args ) throws Throwable {
@@ -92,13 +92,13 @@ public class NailgunLauncher{
.loadClass("cbt.Stage1")
.getMethod(
"run",
- String[].class, File.class, File.class, Boolean.class,
- File.class, Long.class, ConcurrentHashMap.class, ConcurrentHashMap.class
+ String[].class, File.class, File.class, BuildStage1Result.class,
+ Long.class, ConcurrentHashMap.class, ConcurrentHashMap.class
)
.invoke(
null,
- (Object) args, new File(cache), new File(CBT_HOME), res.changed,
- new File(compatibilityTarget), start, classLoaderCache.keys, classLoaderCache.values
+ (Object) args, new File(cache), new File(CBT_HOME), res,
+ start, classLoaderCache.keys, classLoaderCache.values
)
);
} catch (java.lang.reflect.InvocationTargetException e) {
@@ -186,15 +186,10 @@ public class NailgunLauncher{
return new BuildStage1Result(
changed,
- stage1classLoader
+ stage1classLoader,
+ stage1Classpath,
+ nailgunClasspath,
+ compatibilityTarget
);
}
}
-class BuildStage1Result{
- Boolean changed;
- ClassLoader classLoader;
- BuildStage1Result( Boolean changed, ClassLoader classLoader ){
- this.changed = changed;
- this.classLoader = classLoader;
- }
-}
diff --git a/stage1/Stage1.scala b/stage1/Stage1.scala
index 79bf1d5..81b008f 100644
--- a/stage1/Stage1.scala
+++ b/stage1/Stage1.scala
@@ -56,17 +56,16 @@ object Stage1{
a.lastModified > b.lastModified
}
- def getBuild( _context: java.lang.Object, _cbtChanged: java.lang.Boolean ) = {
+ def getBuild( _context: java.lang.Object, buildStage1: BuildStage1Result ) = {
val context = _context.asInstanceOf[Context]
val logger = new Logger( context.enabledLoggers, context.start )
val (changed, classLoader) = buildStage2(
- context.compatibilityTarget,
+ buildStage1,
ClassLoaderCache(
logger,
context.permanentKeys,
context.permanentClassLoaders
),
- _cbtChanged,
context.cbtHome,
context.cache
)
@@ -74,11 +73,11 @@ object Stage1{
classLoader
.loadClass("cbt.Stage2")
.getMethod( "getBuild", classOf[java.lang.Object], classOf[java.lang.Boolean] )
- .invoke(null, context, (_cbtChanged || changed): java.lang.Boolean)
+ .invoke(null, context, (buildStage1.changed || changed): java.lang.Boolean)
}
def buildStage2(
- compatibilityTarget: File, classLoaderCache: ClassLoaderCache, _cbtChanged: Boolean, cbtHome: File, cache: File
+ buildStage1: BuildStage1Result, classLoaderCache: ClassLoaderCache, cbtHome: File, cache: File
): (Boolean, ClassLoader) = {
import classLoaderCache.logger
@@ -91,11 +90,11 @@ object Stage1{
stage2.listFiles ++ (stage2 ++ "/plugins").listFiles
).toVector.filter(_.isFile).filter(_.toString.endsWith(".scala"))
- val cbtHasChanged = _cbtChanged || lib.needsUpdate(stage2sourceFiles, stage2StatusFile)
+ val cbtHasChanged = buildStage1.changed || lib.needsUpdate(stage2sourceFiles, stage2StatusFile)
val cls = this.getClass.getClassLoader.loadClass("cbt.NailgunLauncher")
- val cbtDependency = CbtDependency(cbtHasChanged, mavenCache, nailgunTarget, stage1Target, stage2Target, compatibilityTarget)
+ val cbtDependency = CbtDependency(cbtHasChanged, mavenCache, nailgunTarget, stage1Target, stage2Target, new File(buildStage1.compatibilityClasspath))
logger.stage1("Compiling stage2 if necessary")
compile(
@@ -111,6 +110,23 @@ object Stage1{
logger.stage1(s"calling CbtDependency.classLoader")
if( cbtHasChanged && classLoaderCache.persistent.containsKey( cbtDependency.classpath.string ) ) {
classLoaderCache.persistent.remove( cbtDependency.classpath.string )
+ } else {
+ assert(
+ buildStage1.compatibilityClasspath === cbtDependency.stage1Dependency.compatibilityDependency.classpath.string,
+ "compatibility classpath different from NailgunLauncher"
+ )
+ assert(
+ buildStage1.stage1Classpath === cbtDependency.stage1Dependency.classpath.string,
+ "stage1 classpath different from NailgunLauncher"
+ )
+ assert(
+ classLoaderCache.persistent.containsKey( cbtDependency.stage1Dependency.compatibilityDependency.classpath.string ),
+ "cbt unchanged, expected compatibility classloader to be cached"
+ )
+ assert(
+ classLoaderCache.persistent.containsKey( cbtDependency.stage1Dependency.classpath.string ),
+ "cbt unchanged, expected stage1/nailgun classloader to be cached"
+ )
}
val stage2ClassLoader = cbtDependency.classLoader(classLoaderCache)
@@ -144,8 +160,7 @@ object Stage1{
_args: Array[String],
cache: File,
cbtHome: File,
- _cbtChanged: java.lang.Boolean,
- compatibilityTarget: File,
+ buildStage1: BuildStage1Result,
start: java.lang.Long,
classLoaderCacheKeys: ConcurrentHashMap[String,AnyRef],
classLoaderCacheValues: ConcurrentHashMap[AnyRef,ClassLoader]
@@ -159,9 +174,9 @@ object Stage1{
classLoaderCacheKeys,
classLoaderCacheValues
)
-
- val (cbtHasChanged, classLoader) = buildStage2( compatibilityTarget, classLoaderCache, _cbtChanged, cbtHome, cache )
+
+ val (cbtHasChanged, classLoader) = buildStage2( buildStage1, classLoaderCache, cbtHome, cache )
val stage2Args = Stage2Args(
new File( args.args(0) ),
@@ -171,7 +186,7 @@ object Stage1{
classLoaderCache = classLoaderCache,
cache,
cbtHome,
- compatibilityTarget
+ new File(buildStage1.compatibilityClasspath)
)
logger.stage1(s"Run Stage2")