diff options
author | Jan Christopher Vogt <oss.nsp@cvogt.org> | 2017-03-17 10:04:32 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-17 10:04:32 -0400 |
commit | 0f30e3d611c24123206aa1ba270905ce1d099a61 (patch) | |
tree | 3f7e37a00c293683631163949db3111b37debdd5 /stage1 | |
parent | f69efe343f9b77479e5744ec248d801cb4b2abac (diff) | |
parent | fa34babe1167623fba7b4b84d1df170e5461b232 (diff) | |
download | cbt-0f30e3d611c24123206aa1ba270905ce1d099a61.tar.gz cbt-0f30e3d611c24123206aa1ba270905ce1d099a61.tar.bz2 cbt-0f30e3d611c24123206aa1ba270905ce1d099a61.zip |
Merge pull request #441 from cvogt/various-changes
Various changes
Diffstat (limited to 'stage1')
-rw-r--r-- | stage1/Stage1Lib.scala | 20 | ||||
-rw-r--r-- | stage1/cbt.scala | 8 | ||||
-rw-r--r-- | stage1/resolver.scala | 1 |
3 files changed, 27 insertions, 2 deletions
diff --git a/stage1/Stage1Lib.scala b/stage1/Stage1Lib.scala index 83febe8..565a06c 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 @@ -481,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._ diff --git a/stage1/cbt.scala b/stage1/cbt.scala index cb6cb10..b97ad44 100644 --- a/stage1/cbt.scala +++ b/stage1/cbt.scala @@ -20,6 +20,13 @@ 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"""" + } implicit class PathExtensionMethods( path: Path ){ def /(s: String): Path = path.resolve(s) def ++( s: String ): Path = { @@ -64,6 +71,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 ) diff --git a/stage1/resolver.scala b/stage1/resolver.scala index 105177e..47d4460 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 |