diff options
Diffstat (limited to 'stage2')
-rw-r--r-- | stage2/DefaultBuild.scala | 13 | ||||
-rw-r--r-- | stage2/Lib.scala | 41 | ||||
-rw-r--r-- | stage2/Stage2.scala | 43 | ||||
-rw-r--r-- | stage2/mixins.scala | 2 |
4 files changed, 43 insertions, 56 deletions
diff --git a/stage2/DefaultBuild.scala b/stage2/DefaultBuild.scala index c0072ff..c98aea0 100644 --- a/stage2/DefaultBuild.scala +++ b/stage2/DefaultBuild.scala @@ -85,7 +85,7 @@ class Build(val context: Context) extends Dependency with TriggerLoop{ final val logger = context.logger override final protected val lib: Lib = new Lib(logger) // ========== general stuff ========== - + def enableConcurrency = false final def projectDirectory: File = new File(context.cwd) assert( projectDirectory.exists, "projectDirectory does not exist: "+projectDirectory ) @@ -104,7 +104,7 @@ class Build(val context: Context) extends Dependency with TriggerLoop{ def dependencies: Seq[Dependency] = Seq( "org.scala-lang" % "scala-library" % scalaVersion ) - + // ========== paths ========== final private val defaultSourceDirectory = new File(projectDirectory+"/src/") @@ -122,7 +122,7 @@ class Build(val context: Context) extends Dependency with TriggerLoop{ /** Source directories and files. Defaults to .scala and .java files in src/ and top-level. */ def sources: Seq[File] = Seq(defaultSourceDirectory) ++ projectDirectory.listFiles.toVector.filter(sourceFileFilter) - /** Which file endings to consider being source files. */ + /** Which file endings to consider being source files. */ def sourceFileFilter(file: File): Boolean = file.toString.endsWith(".scala") || file.toString.endsWith(".java") /** Absolute path names for all individual files found in sources directly or contained in directories. */ @@ -130,7 +130,7 @@ class Build(val context: Context) extends Dependency with TriggerLoop{ base <- sources.filter(_.exists).map(lib.realpath) file <- lib.listFilesRecursive(base) if file.isFile && sourceFileFilter(file) } yield file - + protected def assertSourceDirectories(): Unit = { val nonExisting = sources @@ -215,15 +215,16 @@ class Build(val context: Context) extends Dependency with TriggerLoop{ } def runClass: String = "Main" - def run: Unit = lib.runMainIfFound( runClass, Seq(), classLoader ) + def run: ExitCode = lib.runMainIfFound( runClass, context.args, classLoader ) - def test: Unit = lib.test(context) + def test: ExitCode = lib.test(context) context.logger.composition(">"*80) context.logger.composition("class "+this.getClass) context.logger.composition("dir "+context.cwd) context.logger.composition("sources "+sources.toList.mkString(" ")) context.logger.composition("target "+target) + context.logger.composition("context "+context) context.logger.composition("dependencyTree\n"+dependencyTree) context.logger.composition("<"*80) diff --git a/stage2/Lib.scala b/stage2/Lib.scala index b92e0b3..9971b55 100644 --- a/stage2/Lib.scala +++ b/stage2/Lib.scala @@ -15,6 +15,7 @@ import scala.util._ import ammonite.ops.{cwd => _,_} +// pom model case class Developer(id: String, name: String, timezone: String, url: URL) case class License(name: String, url: URL) @@ -87,17 +88,6 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ version: String, compileArgs: Seq[String] ): File = { - class DisableSystemExit extends Exception - object DisableSystemExit{ - def apply(e: Throwable): Boolean = { - e match { - case i: InvocationTargetException => apply(i.getTargetException) - case _: DisableSystemExit => true - case _ => false - } - } - } - // FIXME: get this dynamically somehow, or is this even needed? val javacp = ClassPath( "/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/System/Library/Java/Extensions/MRJToolkit.jar".split(":").toVector.map(new File(_)) @@ -106,14 +96,7 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ mkdir(Path(apiTarget)) if(sourceFiles.nonEmpty){ System.err.println("creating docs") - try{ - System.setSecurityManager( - new SecurityManager{ - override def checkPermission( permission: java.security.Permission ) = { - if( permission.getName.startsWith("exitVM") ) throw new DisableSystemExit - } - } - ) + trapExitCode{ redirectOutToErr{ runMain( "scala.tools.nsc.ScalaDoc", @@ -128,10 +111,6 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ ) ) } - } catch { - case e:InvocationTargetException if DisableSystemExit(e) => - } finally { - System.setSecurityManager(null) } } val docJar = new File(jarTarget+"/"+artifactId+"-"+version+"-javadoc.jar") @@ -139,14 +118,19 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ docJar } - def test( context: Context ) = { + def test( context: Context ): ExitCode = { + val loggers = logger.enabledLoggers.mkString(",") + // FIXME: this is a hack to pass logger args on to the tests. + // should probably have a more structured way + val loggerArg = if(loggers != "") Some("-Dlog="+loggers) else None + logger.lib(s"invoke testDefault( $context )") - loadDynamic( - context.copy( cwd = context.cwd+"/test/" ), + val exitCode: ExitCode = loadDynamic( + context.copy( cwd = context.cwd+"/test/", args = loggerArg.toVector ++ context.args ), new Build(_) with mixins.Test ).run - logger.lib(s"return testDefault( $context )") - + logger.lib(s"return testDefault( $context )") + exitCode } // task reflection helpers @@ -203,6 +187,7 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ case e:NoSuchMethodException if e.getMessage contains "toConsole" => result match { case () => "" + case ExitCode(code) => System.exit(code) case other => println( other.toString ) // no method .toConsole, using to String } } diff --git a/stage2/Stage2.scala b/stage2/Stage2.scala index f3e833f..c6783d4 100644 --- a/stage2/Stage2.scala +++ b/stage2/Stage2.scala @@ -10,7 +10,7 @@ import cbt.paths._ object Stage2{ - def main(args: Array[String]) = { + def main(args: Array[String]): Unit = { val init = new Init(args) import init._ @@ -27,32 +27,33 @@ object Stage2{ } val task = argsV.lift( taskIndex ) - val context = Context( cwd, argsV.drop( taskIndex + 1 ), logger ) + val context = Context( argsV(0), argsV.drop( taskIndex + 1 ), logger ) val first = lib.loadRoot( context ) val build = first.finalBuild - val res = if (loop) { - // TODO: this should allow looping over task specific files, like test files as well - val triggerFiles = first.triggerLoopFiles.map(lib.realpath) - val triggerCbtFiles = Seq( nailgun, stage1, stage2 ).map(lib.realpath _) - val allTriggerFiles = triggerFiles ++ triggerCbtFiles - - logger.loop("Looping change detection over:\n - "+allTriggerFiles.mkString("\n - ")) - - lib.watch(allTriggerFiles) { - case file if triggerCbtFiles.exists(file.toString startsWith _.toString) => - logger.loop("Change is in CBT's own source code.") - logger.loop("Restarting CBT.") - scala.util.control.Breaks.break - - case file if triggerFiles.exists(file.toString startsWith _.toString) => - new lib.ReflectBuild( lib.loadDynamic(context) ).callNullary(task) + val res = lib.trapExitCode{ + if (loop) { + // TODO: this should allow looping over task specific files, like test files as well + val triggerFiles = first.triggerLoopFiles.map(lib.realpath) + val triggerCbtFiles = Seq( nailgun, stage1, stage2 ).map(lib.realpath _) + val allTriggerFiles = triggerFiles ++ triggerCbtFiles + + logger.loop("Looping change detection over:\n - "+allTriggerFiles.mkString("\n - ")) + + lib.watch(allTriggerFiles) { + case file if triggerCbtFiles.exists(file.toString startsWith _.toString) => + logger.loop("Change is in CBT's own source code.") + logger.loop("Restarting CBT.") + scala.util.control.Breaks.break + + case file if triggerFiles.exists(file.toString startsWith _.toString) => + new lib.ReflectBuild( lib.loadDynamic(context) ).callNullary(task) + } + } else { + new lib.ReflectBuild(build).callNullary(task) } - } else { - new lib.ReflectBuild(build).callNullary(task) } init.logger.stage2(s"[$now] Stage2 end") - res } } diff --git a/stage2/mixins.scala b/stage2/mixins.scala index 5ed26d8..4d72325 100644 --- a/stage2/mixins.scala +++ b/stage2/mixins.scala @@ -23,7 +23,7 @@ trait ScalaTest extends Build with Test{ // workaround probable ScalaTest bug throwing away the outer classloader. Not caching doesn't nest them. override def cacheDependencyClassLoader = false - override def run = { + override def run: ExitCode = { val discoveryPath = compile.toString+"/" context.logger.lib("discoveryPath: "+discoveryPath) lib.runMain( |