From 005f835ef9773e6de8d07d12de01690f95cef20c Mon Sep 17 00:00:00 2001 From: Matt Farmer Date: Sat, 5 Mar 2016 18:08:07 -0500 Subject: Some style cleanups in Stage1. --- stage1/Stage1.scala | 83 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 36 deletions(-) (limited to 'stage1/Stage1.scala') diff --git a/stage1/Stage1.scala b/stage1/Stage1.scala index 13c097e..6c05f00 100644 --- a/stage1/Stage1.scala +++ b/stage1/Stage1.scala @@ -1,70 +1,81 @@ package cbt + import java.io._ -import paths._ +import java.time.LocalTime.now + import scala.collection.immutable.Seq +import scala.collection.JavaConverters._ + +import paths._ object CheckAlive{ def main(args: Array[String]): Unit = { System.exit(33) } } + +class Init(args: Array[String]) { + /** + * Raw parameters including their `-D` flag. + **/ + val propsRaw: Seq[String] = args.toVector.filter(_.startsWith("-D")) + + /** + * All arguments that weren't `-D` property declarations. + **/ + val argsV: Seq[String] = args.toVector diff propsRaw + + /** + * Parsed properties, as a map of keys to values. + **/ + lazy val props = propsRaw + .map(_.drop(2).split("=")).map({ + case Array(key, value) => + key -> value + }).toMap ++ System.getProperties.asScala + + val logger = new Logger(props.get("log")) + + val cwd = argsV(0) +} + object Stage1 extends Stage1Base{ def mainClass = ("cbt.Stage2") } + object AdminStage1 extends Stage1Base{ def mainClass = ("cbt.AdminStage2") } -abstract class Stage1Base{ - class Init(args: Array[String]){ - import scala.collection.JavaConverters._ - val propsRaw: Seq[String] = args.toVector.filter(_.startsWith("-D")) - val argsV: Seq[String] = args.toVector diff propsRaw - lazy val props = propsRaw.map(_.drop(2)).map(_.split("=")).map{ - case Array(key, value) => key -> value - }.toMap ++ System.getProperties.asScala - val logger = new Logger(props.get("log")) +abstract class Stage1Base{ + def mainClass: String - val cwd = argsV(0) + protected def newerThan( a: File, b: File ) ={ + a.lastModified > b.lastModified } - def mainClass: String + def main(args: Array[String]): Unit = { - import java.time.LocalTime.now val init = new Init(args) val lib = new Stage1Lib(init.logger) + lib.logger.stage1(s"[$now] Stage1 start") lib.logger.stage1("Stage1: after creating lib") - import lib._ + val cwd = args(0) - val src = stage2.listFiles.toVector.filter(_.isFile).filter(_.toString.endsWith(".scala")) + val src = stage2.listFiles.toVector.filter(_.isFile).filter(_.toString.endsWith(".scala")) val changeIndicator = new File(stage2Target+"/cbt/Build.class") - def newerThan( a: File, b: File ) ={ - val res = a.lastModified > b.lastModified - if(res) { - /* - println(a) - println(a.lastModified) - println(b) - println(b.lastModified) - */ - } - res - } - - logger.stage1("before conditionally running zinc to recompile CBT") - if( src.exists(newerThan(_, changeIndicator)) ){ + lib.logger.stage1("before conditionally running zinc to recompile CBT") + if( src.exists(newerThan(_, changeIndicator)) ) { val stage1Classpath = CbtDependency(init.logger).dependencyClasspath - logger.stage1("cbt.lib has changed. Recompiling with cp: "+stage1Classpath) + lib.logger.stage1("cbt.lib has changed. Recompiling with cp: "+stage1Classpath) lib.zinc( true, src, stage2Target, stage1Classpath )( zincVersion = "0.3.9", scalaVersion = constants.scalaVersion ) } - logger.stage1(s"[$now] calling CbtDependency.classLoader") + lib.logger.stage1(s"[$now] calling CbtDependency.classLoader") - logger.stage1(s"[$now] Run Stage2") + lib.logger.stage1(s"[$now] Run Stage2") lib.runMain( mainClass, cwd +: args.drop(1).toVector, CbtDependency(init.logger).classLoader ) lib.logger.stage1(s"[$now] Stage1 end") - - - } + } } -- cgit v1.2.3