From ec1ab4fe8b25fdc6462dcf07727233b80563285a Mon Sep 17 00:00:00 2001 From: Christopher Vogt Date: Fri, 17 Mar 2017 03:36:49 -0400 Subject: Add string quoting helpers --- stage1/cbt.scala | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'stage1') diff --git a/stage1/cbt.scala b/stage1/cbt.scala index cb6cb10..5f8f2b5 100644 --- a/stage1/cbt.scala +++ b/stage1/cbt.scala @@ -20,6 +20,10 @@ object `package`{ private val lib = new BaseLib + implicit class CbtStringExtensions(string: String){ + def escape = string.replace("\\","\\\\").replace("\"","\\\"") + def quote = s""""$escape"""" + } implicit class PathExtensionMethods( path: Path ){ def /(s: String): Path = path.resolve(s) def ++( s: String ): Path = { @@ -64,6 +68,7 @@ object `package`{ def lastModifiedRecursive = listRecursive.map(_.lastModified).max def readAsString = new String( readAllBytes( file.toPath ) ) + def quote = s"new _root_.java.io.File(${string.quote})" } implicit class URLExtensionMethods( url: URL ){ def ++( s: String ): URL = new URL( url.toString ++ s ) -- cgit v1.2.3 From 57e3ead5801ef3a88a3b40830b93657217b5a955 Mon Sep 17 00:00:00 2001 From: Christopher Vogt Date: Fri, 17 Mar 2017 03:37:32 -0400 Subject: fix bug in identifying main classes --- stage1/Stage1Lib.scala | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'stage1') diff --git a/stage1/Stage1Lib.scala b/stage1/Stage1Lib.scala index 1cda9fd..7f7fa37 100644 --- a/stage1/Stage1Lib.scala +++ b/stage1/Stage1Lib.scala @@ -184,8 +184,9 @@ class Stage1Lib( logger: Logger ) extends BaseLib{ val arrayClass = classOf[Array[String]] val unitClass = classOf[Unit] - iterateClasses( classesRootDirectory, classLoader, true ).filter( - _.getDeclaredMethods().exists( m => + iterateClasses( classesRootDirectory, classLoader, true ).filter( c => + !c.isInterface && + c.getDeclaredMethods().exists( m => m.getName == "main" && m.getParameterTypes.toList == List(arrayClass) && m.getReturnType == unitClass -- cgit v1.2.3 From 9dbe839f074a8ed69f1e2853f7d40c21a9db407f Mon Sep 17 00:00:00 2001 From: Christopher Vogt Date: Fri, 17 Mar 2017 03:39:38 -0400 Subject: add boolean to option helper --- stage1/cbt.scala | 3 +++ 1 file changed, 3 insertions(+) (limited to 'stage1') diff --git a/stage1/cbt.scala b/stage1/cbt.scala index 5f8f2b5..b97ad44 100644 --- a/stage1/cbt.scala +++ b/stage1/cbt.scala @@ -20,6 +20,9 @@ object `package`{ private val lib = new BaseLib + implicit class CbtBooleanExtensions(condition: Boolean){ + def option[T](value: =>T): Option[T] = if(condition) Some(value) else None + } implicit class CbtStringExtensions(string: String){ def escape = string.replace("\\","\\\\").replace("\"","\\\"") def quote = s""""$escape"""" -- cgit v1.2.3 From ac2e2c0e7800ebbd6ca8087e546fb9d3480cb57e Mon Sep 17 00:00:00 2001 From: Christopher Vogt Date: Fri, 17 Mar 2017 03:39:54 -0400 Subject: add helper for caching based on a status file --- stage1/Stage1Lib.scala | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'stage1') diff --git a/stage1/Stage1Lib.scala b/stage1/Stage1Lib.scala index 7f7fa37..f66eff4 100644 --- a/stage1/Stage1Lib.scala +++ b/stage1/Stage1Lib.scala @@ -482,6 +482,21 @@ ${sourceFiles.sorted.mkString(" \\\n")} StandardOpenOption.APPEND ) } + def cached[T]( targetDirectory: File, inputLastModified: Long )( action: () => T ): (Option[T],Long) = { + val t = targetDirectory + val start = System.currentTimeMillis + def lastSucceeded = t.lastModified + def outputLastModified = t.listRecursive.diff(t :: Nil).map(_.lastModified).maxOption.getOrElse(0l) + def updateSucceeded(time: Long) = Files.setLastModifiedTime( t.toPath, FileTime.fromMillis(time) ) + ( + ( inputLastModified >= lastSucceeded ).option{ + val result: T = action() + updateSucceeded( start ) + result + }, + outputLastModified + ) + } } import scala.reflect._ -- cgit v1.2.3 From fa34babe1167623fba7b4b84d1df170e5461b232 Mon Sep 17 00:00:00 2001 From: Christopher Vogt Date: Fri, 17 Mar 2017 03:41:05 -0400 Subject: better show for PostBuildDependency --- stage1/resolver.scala | 1 + 1 file changed, 1 insertion(+) (limited to 'stage1') diff --git a/stage1/resolver.scala b/stage1/resolver.scala index 1d539a2..318ea59 100644 --- a/stage1/resolver.scala +++ b/stage1/resolver.scala @@ -172,6 +172,7 @@ case class Dependencies( dependencies: Seq[Dependency] )(implicit val logger: Lo case class PostBuildDependency(target: File, _dependencies: Seq[DependencyImplementation])(implicit val logger: Logger, val transientCache: java.util.Map[AnyRef,AnyRef], val classLoaderCache: ClassLoaderCache) extends DependencyImplementation{ override final lazy val lastModified = (target++".last-success").lastModified def moduleKey = target.string + override def show = s"PostBuildDependency($target)" override def targetClasspath = exportedClasspath override def exportedClasspath = ClassPath( Seq(target) ) override def dependencies = _dependencies -- cgit v1.2.3