diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2016-09-12 14:10:10 +0100 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-09-12 14:10:10 +0100 |
commit | f886b385aea32b6387384bd4c72edea275ac691a (patch) | |
tree | 7db39a1af2945bd9a5a59b6e88493559847e3d6b /stage2 | |
parent | b9622662f76cd6a1c738224aea04e94b55190e58 (diff) | |
download | cbt-f886b385aea32b6387384bd4c72edea275ac691a.tar.gz cbt-f886b385aea32b6387384bd4c72edea275ac691a.tar.bz2 cbt-f886b385aea32b6387384bd4c72edea275ac691a.zip |
better error message when you forget to extend BaseBuild
Diffstat (limited to 'stage2')
-rw-r--r-- | stage2/BuildBuild.scala | 79 |
1 files changed, 40 insertions, 39 deletions
diff --git a/stage2/BuildBuild.scala b/stage2/BuildBuild.scala index c57ce1b..5392217 100644 --- a/stage2/BuildBuild.scala +++ b/stage2/BuildBuild.scala @@ -21,50 +21,51 @@ trait BuildBuild extends BaseBuild{ def managedBuildDirectory: java.io.File = lib.realpath( projectDirectory.parent ) private object managedBuildCache extends Cache[BuildInterface] def managedBuild = managedBuildCache{ - try{ - val managedBuildFile = projectDirectory++"/build.scala" - logger.composition("Loading build at "++managedContext.projectDirectory.toString) - ( - if(managedBuildFile.exists){ - val contents = new String(Files.readAllBytes(managedBuildFile.toPath)) - val cbtUrl = ("cbt:"++GitDependency.GitUrl.regex++"#[a-z0-9A-Z]+").r - cbtUrl - .findFirstIn(contents) - .flatMap{ - url => - val Array(base,hash) = url.drop(4).split("#") - if(context.cbtHome.string.contains(hash)) - None - else Some{ - // Note: cbt can't use an old version of itself for building, - // otherwise we'd have to recursively build all versions since - // the beginning. Instead CBT always needs to build the pure Java - // Launcher in the checkout with itself and then run it via reflection. - val dep = new GitDependency(base, hash, Some("nailgun_launcher")) - val ctx = managedContext.copy( cbtHome = dep.checkout ) - dep.classLoader(classLoaderCache) - .loadClass( "cbt.NailgunLauncher" ) - .getMethod( "getBuild", classOf[AnyRef] ) - .invoke( null, ctx ) - } - }.getOrElse{ - //new BasicBuild(managedContext) - ///* + val managedBuildFile = projectDirectory++"/build.scala" + logger.composition("Loading build at "++managedContext.projectDirectory.toString) + val build = ( + if(managedBuildFile.exists){ + val contents = new String(Files.readAllBytes(managedBuildFile.toPath)) + val cbtUrl = ("cbt:"++GitDependency.GitUrl.regex++"#[a-z0-9A-Z]+").r + cbtUrl + .findFirstIn(contents) + .flatMap{ + url => + val Array(base,hash) = url.drop(4).split("#") + if(context.cbtHome.string.contains(hash)) + None + else Some{ + // Note: cbt can't use an old version of itself for building, + // otherwise we'd have to recursively build all versions since + // the beginning. Instead CBT always needs to build the pure Java + // Launcher in the checkout with itself and then run it via reflection. + val dep = new GitDependency(base, hash, Some("nailgun_launcher")) + val ctx = managedContext.copy( cbtHome = dep.checkout ) + dep.classLoader(classLoaderCache) + .loadClass( "cbt.NailgunLauncher" ) + .getMethod( "getBuild", classOf[AnyRef] ) + .invoke( null, ctx ) + } + }.getOrElse{ + try{ classLoader(context.classLoaderCache) .loadClass(lib.buildClassName) .getConstructors.head .newInstance(managedContext) - //*/ - } - } else { - new BasicBuild(managedContext) - } - ).asInstanceOf[BuildInterface] + } catch { + case e: ClassNotFoundException if e.getMessage == lib.buildClassName => + throw new Exception("You need to remove the directory or define a class Build in: "+context.projectDirectory) + } + } + } else { + new BasicBuild(managedContext) + } + ) + try{ + build.asInstanceOf[BuildInterface] } catch { - case e: ClassNotFoundException if e.getMessage == lib.buildClassName => - throw new Exception("You need to remove the directory or define a class Build in: "+context.projectDirectory) - case e: Exception => - throw new Exception("during build: "+context.projectDirectory, e) + case e: ClassCastException if e.getMessage.contains("Build cannot be cast to cbt.BuildInterface") => + throw new Exception("Your Build class needs to extend BaseBuild in: "+context.projectDirectory, e) } } override def triggerLoopFiles = super.triggerLoopFiles ++ managedBuild.triggerLoopFiles |