From 3a629b14917cbe3d1e5391e40f0720bacb09ad00 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 11 Oct 2015 09:31:59 -0700 Subject: [PATCH] Restore build file time stamps. --- .../com/beust/kobalt/kotlin/BuildFile.kt | 4 +-- .../beust/kobalt/kotlin/ScriptCompiler2.kt | 35 +++++++++++++------ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/kotlin/BuildFile.kt b/src/main/kotlin/com/beust/kobalt/kotlin/BuildFile.kt index 1a946b9b..e2311de4 100644 --- a/src/main/kotlin/com/beust/kobalt/kotlin/BuildFile.kt +++ b/src/main/kotlin/com/beust/kobalt/kotlin/BuildFile.kt @@ -11,8 +11,8 @@ import java.nio.file.attribute.BasicFileAttributes public class BuildFile(val path: Path, val name: String) { public fun exists() : Boolean = Files.exists(path) - public fun lastModified() : Long = Files.readAttributes(path, BasicFileAttributes::class.java).lastModifiedTime() - .toMillis() + public val lastModified : Long + get() = Files.readAttributes(path, BasicFileAttributes::class.java).lastModifiedTime().toMillis() public val directory : File get() = path.toFile().directory } diff --git a/src/main/kotlin/com/beust/kobalt/kotlin/ScriptCompiler2.kt b/src/main/kotlin/com/beust/kobalt/kotlin/ScriptCompiler2.kt index 0cb82765..da94c419 100644 --- a/src/main/kotlin/com/beust/kobalt/kotlin/ScriptCompiler2.kt +++ b/src/main/kotlin/com/beust/kobalt/kotlin/ScriptCompiler2.kt @@ -35,22 +35,37 @@ public class ScriptCompiler2 @Inject constructor(@Assisted("buildFiles") val bui val result = arrayListOf() buildFiles.forEach { buildFile -> val pluginUrls = findPlugInUrls(buildFile) - val script = File(KFiles.findBuildScriptLocation(buildFile, SCRIPT_JAR)) + val buildScriptJarFile = File(KFiles.findBuildScriptLocation(buildFile, SCRIPT_JAR)) - log(1, "Compiling main build file ${buildFile.path}") - kotlinCompilePrivate { - classpath(files.kobaltJar) - classpath(pluginUrls.map { it.file }) - sourceFiles(listOf(buildFile.path.toFile().absolutePath)) - output = script.absolutePath - }.compile() - - val output = parseBuildScriptJarFile(script, pluginUrls) + maybeCompileBuildFile(buildFile, buildScriptJarFile, pluginUrls) + val output = parseBuildScriptJarFile(buildScriptJarFile, pluginUrls) result.addAll(output.projects) } return result } + private fun maybeCompileBuildFile(buildFile: BuildFile, buildScriptJarFile: File, pluginUrls: List) { + log(2, "Running build file ${buildFile.name} jar: $buildScriptJarFile") + + if (buildFile.exists() && buildScriptJarFile.exists() + && buildFile.lastModified < buildScriptJarFile.lastModified()) { + log(2, "Build file is up to date") + } else { + log(2, "Need to recompile ${buildFile.name}") + + kotlinCompilePrivate { + classpath(files.kobaltJar) + classpath(pluginUrls.map { it.file }) + sourceFiles(listOf(buildFile.path.toFile().absolutePath)) + output = buildScriptJarFile.absolutePath + }.compile() + } + } + + /** + * Generate the script file with only the plugins()/repos() directives and run it. Then return + * the URL's of all the plug-ins that were found. + */ private fun findPlugInUrls(buildFile: BuildFile): List { val result = arrayListOf() val pluginCode = arrayListOf(