diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2016-02-06 13:03:36 -0500 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-03-04 15:06:30 -0500 |
commit | 974942db43ff2d1fa7ba71ad60f9bb9eae2d8631 (patch) | |
tree | d7235df9d4d6a67753dc2a20ab6bfcb7a24dc74c /stage2/Stage2.scala | |
download | cbt-974942db43ff2d1fa7ba71ad60f9bb9eae2d8631.tar.gz cbt-974942db43ff2d1fa7ba71ad60f9bb9eae2d8631.tar.bz2 cbt-974942db43ff2d1fa7ba71ad60f9bb9eae2d8631.zip |
CBT Version 1.0-BETA
Diffstat (limited to 'stage2/Stage2.scala')
-rw-r--r-- | stage2/Stage2.scala | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/stage2/Stage2.scala b/stage2/Stage2.scala new file mode 100644 index 0000000..05b7c58 --- /dev/null +++ b/stage2/Stage2.scala @@ -0,0 +1,47 @@ +package cbt +import cbt.paths._ +import java.io._ +import scala.collection.immutable.Seq + +object Stage2{ + def main(args: Array[String]) = { + import java.time.LocalTime.now + val init = new Stage1.Init(args) + import java.time._ + val start = LocalTime.now() + def timeTaken = Duration.between(start, LocalTime.now()).toMillis + init.logger.stage2(s"[$now] Stage2 start") + + import init._ + val loop = argsV.lift(1) == Some("loop") + val direct = argsV.lift(1) == Some("direct") + val taskIndex = if(loop || direct) 2 else 1 + val task = argsV.lift( taskIndex ) + + val lib = new Lib(new Stage1.Init(args).logger) + + val context = Context( cwd, 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' 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) + init.logger.stage2(s"[$now] Stage2 end") + res + } +} |