diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Features.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Features.kt index 867b2394..83e01827 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Features.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Features.kt @@ -3,6 +3,6 @@ package com.beust.kobalt class Features { companion object { /** If true, uses timestamps to speed up the tasks */ - const val USE_TIMESTAMPS = false + const val USE_TIMESTAMPS = true } } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompiler.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompiler.kt index a770ffc5..89b4abab 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompiler.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompiler.kt @@ -40,7 +40,7 @@ class JvmCompiler @Inject constructor(val dependencyManager: DependencyManager) val addedFlags = contributorFlags + ArrayList(info.compilerArgs) validateClasspath(allDependencies.map { it.jarFile.get().absolutePath }) - return action.compile(info.copy(dependencies = allDependencies, compilerArgs = addedFlags)) + return action.compile(project?.name, info.copy(dependencies = allDependencies, compilerArgs = addedFlags)) } private fun validateClasspath(cp: List) { @@ -53,5 +53,5 @@ class JvmCompiler @Inject constructor(val dependencyManager: DependencyManager) } interface ICompilerAction { - fun compile(info: CompilerActionInfo): TaskResult + fun compile(projectName: String?, info: CompilerActionInfo): TaskResult } \ No newline at end of file diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt index 15f1c797..6820ec81 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt @@ -1,6 +1,5 @@ package com.beust.kobalt.internal -import com.beust.kobalt.Features import com.beust.kobalt.IncrementalTaskInfo import com.beust.kobalt.KobaltException import com.beust.kobalt.TaskResult @@ -188,16 +187,11 @@ abstract class JvmCompilerPlugin @Inject constructor( sourceDirectories.add(sourceDirectory) } val info = createCompilerActionInfo(project, context, isTest = false) - if (! Features.USE_TIMESTAMPS || isOutdated(project, context, info)) { - val compiler = ActorUtils.selectAffinityActor(project, context, context.pluginInfo.compilerContributors) - if (compiler != null) { - return compiler.compile(project, context, info) - } else { - throw KobaltException("Couldn't find any compiler for project ${project.name}") - } + val compiler = ActorUtils.selectAffinityActor(project, context, context.pluginInfo.compilerContributors) + if (compiler != null) { + return compiler.compile(project, context, info) } else { - log(2, " Source files are up to date, not compiling") - return TaskResult() + throw KobaltException("Couldn't find any compiler for project ${project.name}") } } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt index 4dc353b4..243ab169 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt @@ -109,7 +109,7 @@ public class TaskManager @Inject constructor(val args: Args, val incrementalMana graph.addEdge(pluginTask, to) } } else { - log(2, "Couldn't find node $it: not applicable to project ${project.name}") + log(1, "Couldn't find node $it: not applicable to project ${project.name}") } } } @@ -206,7 +206,7 @@ public class TaskManager @Inject constructor(val args: Args, val incrementalMana newToProcess.add(TaskInfo(project.name, it)) } } else { - log(2, "Couldn't find task ${currentTask.taskName}: not applicable to project ${project.name}") + log(1, "Couldn't find task ${currentTask.taskName}: not applicable to project ${project.name}") } } done = newToProcess.isEmpty() @@ -256,34 +256,37 @@ public class TaskManager @Inject constructor(val args: Args, val incrementalMana if (outputChecksum == iit.outputChecksum) { upToDate = true } else { - log(2, " INC- Incremental task ${ta.name} output is out of date, running it") + logIncremental(1, "Incremental task ${ta.name} output is out of date, running it") } } } else { - log(2, " INC- Incremental task ${ta.name} input is out of date, running it") + logIncremental(1, "Incremental task ${ta.name} input is out of date, running it" + + " old: $inputChecksum new: ${iit.inputChecksum}") } } if (! upToDate) { val result = iit.task(project) if (result.success) { - log(2, " INC- Incremental task ${ta.name} done running, saving checksums") + logIncremental(1, "Incremental task ${ta.name} done running, saving checksums") iit.inputChecksum?.let { incrementalManager.saveInputChecksum(taskName, it) - log(2, " INC- input checksum \"$it\" saved") + logIncremental(1, " input checksum \"$it\" saved") } iit.outputChecksum?.let { incrementalManager.saveOutputChecksum(taskName, it) - log(2, " INC- output checksum \"$it\" saved") + logIncremental(1, " output checksum \"$it\" saved") } } result } else { - log(2, " INC- Incremental task ${ta.name} is up to date, not running it") + logIncremental(2, "Incremental task \"${ta.name}\" is up to date, not running it") TaskResult() } }) + private fun logIncremental(level: Int, s: String) = log(level, " INC - $s") + class PluginDynamicTask(val plugin: IPlugin, val task: DynamicTask) /** Tasks annotated with @Task or @IncrementalTask */ diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Md5.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Md5.kt index 4654eb00..1dfceec6 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Md5.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Md5.kt @@ -11,15 +11,20 @@ public class Md5 { fun toMd5Directories(directories: List) : String { MessageDigest.getInstance("MD5").let { md5 -> directories.forEach { file -> - val files = KFiles.findRecursively(file) // , { f -> f.endsWith("java")}) - log(2, " Calculating checksum of ${files.size} files") - files.map { - File(file, it) - }.filter { - it.isFile - }.forEach { - val bytes = it.readBytes() + if (file.isFile) { + val bytes = file.readBytes() md5.update(bytes, 0, bytes.size) + } else { + val files = KFiles.findRecursively(file) // , { f -> f.endsWith("java")}) + log(2, " Calculating checksum of ${files.size} files in $file") + files.map { + File(file, it) + }.filter { + it.isFile + }.forEach { + val bytes = it.readBytes() + md5.update(bytes, 0, bytes.size) + } } } val result = DatatypeConverter.printHexBinary(md5.digest()).toLowerCase() diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt index ffca6332..b13dffc7 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt @@ -157,10 +157,10 @@ class IncludedFile(val fromOriginal: From, val toOriginal: To, val specs: List { + fun allFromFiles(directory: String? = null): List { val result = arrayListOf() specs.forEach { spec -> - val fullDir = KFiles.joinDir(directory, from) + val fullDir = if (directory == null) from else KFiles.joinDir(directory, from) spec.toFiles(fullDir).forEach { source -> result.add(if (source.isAbsolute) source else File(source.path)) } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/java/JavaCompiler.kt b/src/main/kotlin/com/beust/kobalt/plugin/java/JavaCompiler.kt index 988bc1d0..ce5b9710 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/java/JavaCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/java/JavaCompiler.kt @@ -22,7 +22,7 @@ import javax.tools.ToolProvider @Singleton class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler) { fun compilerAction(executable: File) = object : ICompilerAction { - override fun compile(info: CompilerActionInfo): TaskResult { + override fun compile(projectName: String?, info: CompilerActionInfo): TaskResult { if (info.sourceFiles.isEmpty()) { warn("No source files to compile") return TaskResult() diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt index de965ccc..c6a373f9 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt @@ -26,7 +26,7 @@ import kotlin.properties.Delegates * @since 08 03, 2015 */ @Singleton -class KotlinCompiler @Inject constructor(val localRepo : LocalRepo, +class KotlinCompiler @Inject constructor( val files: KFiles, val dependencyManager: DependencyManager, val depFactory: DepFactory, @@ -37,7 +37,7 @@ class KotlinCompiler @Inject constructor(val localRepo : LocalRepo, } val compilerAction = object: ICompilerAction { - override fun compile(info: CompilerActionInfo): TaskResult { + override fun compile(projectName: String?, info: CompilerActionInfo): TaskResult { if (info.sourceFiles.size > 1) { log(1, " Compiling ${info.sourceFiles.size} files") } @@ -58,7 +58,7 @@ class KotlinCompiler @Inject constructor(val localRepo : LocalRepo, *(info.compilerArgs.toTypedArray()), *(info.sourceFiles.toTypedArray()) ) - val success = invokeCompiler(cp, allArgs) + val success = invokeCompiler(projectName ?: "kobalt-" + Random().nextInt(), cp, allArgs) return TaskResult(success) } @@ -72,8 +72,8 @@ class KotlinCompiler @Inject constructor(val localRepo : LocalRepo, * There are plenty of ways in which this method can break but this will be immediately * apparent if it happens. */ - private fun invokeCompiler(cp: List, args: Array): Boolean { - val allArgs = listOf("-module-name", "module" + Random().nextInt()) + args + private fun invokeCompiler(projectName: String, cp: List, args: Array): Boolean { + val allArgs = listOf("-module-name", "project-" + projectName) + args log(2, "Calling kotlinc " + allArgs.joinToString(" ")) val result : Boolean = if (true) { diff --git a/src/main/kotlin/com/beust/kobalt/plugin/packaging/JarGenerator.kt b/src/main/kotlin/com/beust/kobalt/plugin/packaging/JarGenerator.kt index 9cf79468..b3c5d77f 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/JarGenerator.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/JarGenerator.kt @@ -14,7 +14,7 @@ import java.nio.file.Paths import java.util.jar.JarOutputStream class JarGenerator @Inject constructor(val dependencyManager: DependencyManager){ - fun includedFilesForJarFile(project: Project, context: KobaltContext, jar: Jar) : List { + fun findIncludedFiles(project: Project, context: KobaltContext, jar: Jar) : List { // // Add all the applicable files for the current project // @@ -73,7 +73,7 @@ class JarGenerator @Inject constructor(val dependencyManager: DependencyManager) } fun generateJar(project: Project, context: KobaltContext, jar: Jar) : File { - val allFiles = includedFilesForJarFile(project, context, jar) + val allFiles = findIncludedFiles(project, context, jar) // // Generate the manifest diff --git a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt index a3128bea..f90f8073 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt @@ -116,7 +116,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana val file = File(KFiles.joinDir(directory, root.from, relFile.path)) if (file.isFile) { if (file.lastModified() > lastModified) { - log(2, " Outdated $file and $output " + log(2, " TS - Outdated $file and $output " + Date(file.lastModified()) + " " + Date(output.lastModified())) return true } @@ -139,12 +139,43 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana super.apply(project, context) project.projectProperties.put(LIBS_DIR, libsDir(project)) taskContributor.addVariantTasks(this, project, context, "assemble", runAfter = listOf("compile"), - runTask = { taskAssemble(project) }) + runTask = { doTaskAssemble(project) }) } + private fun findIncludedFiles(project: Project) : List { + val inf = arrayListOf() + packages.filter { it.project.name == project.name }.forEach { pkg -> + pkg.jars.forEach { inf.addAll(jarGenerator.findIncludedFiles(pkg.project, context, it)) } + pkg.wars.forEach { inf.addAll(warGenerator.findIncludedFiles(pkg.project, context, it, projects)) } + pkg.zips.forEach { inf.addAll(zipGenerator.findIncludedFiles(pkg.project, context, it)) } + } + + val result = arrayListOf() + inf.map { includedFile -> + result.addAll(includedFile.allFromFiles().map { + if (it.isAbsolute) it else File(KFiles.joinDir(project.directory, includedFile.from, it.path)) + }) + } + result.forEach { if (! it.exists()) + throw RuntimeException("Should exist $it") + } + return result + } + +// @IncrementalTask(name = TASK_ASSEMBLE, description = "Package the artifacts", +// runAfter = arrayOf(JvmCompilerPlugin.TASK_COMPILE)) +// fun taskAssemble(project: Project) : IncrementalTaskInfo { +// val i = findIncludedFiles(project) +// val inputChecksum = Md5.toMd5Directories(i) +// return IncrementalTaskInfo( +// inputChecksum = inputChecksum, +// outputChecksum = "1", +// task = { project -> doTaskAssemble(project) }) +// } + @Task(name = TASK_ASSEMBLE, description = "Package the artifacts", runAfter = arrayOf(JvmCompilerPlugin.TASK_COMPILE)) - fun taskAssemble(project: Project) : TaskResult { + fun doTaskAssemble(project: Project) : TaskResult { project.projectProperties.put(PACKAGES, packages) packages.filter { it.project.name == project.name }.forEach { pkg -> pkg.jars.forEach { jarGenerator.generateJar(pkg.project, context, it) } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/packaging/WarGenerator.kt b/src/main/kotlin/com/beust/kobalt/plugin/packaging/WarGenerator.kt index 1b9a7860..a4bfc761 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/WarGenerator.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/WarGenerator.kt @@ -18,7 +18,7 @@ import java.util.jar.JarOutputStream class WarGenerator @Inject constructor(val dependencyManager: DependencyManager){ - fun includedFilesForJarFile(project: Project, context: KobaltContext, war: War, + fun findIncludedFiles(project: Project, context: KobaltContext, war: War, projects: List) : List { // // src/main/web app and classes @@ -67,7 +67,7 @@ class WarGenerator @Inject constructor(val dependencyManager: DependencyManager) manifest.mainAttributes.putValue(attribute.first, attribute.second) } - val allFiles = includedFilesForJarFile(project, context, war, projects) + val allFiles = findIncludedFiles(project, context, war, projects) val jarFactory = { os: OutputStream -> JarOutputStream(os, manifest) } return PackagingPlugin.generateArchive(project, context, war.name, ".war", allFiles, false /* don't expand jar files */, jarFactory) diff --git a/src/test/kotlin/com/beust/kobalt/misc/IncludedFileTest.kt b/src/test/kotlin/com/beust/kobalt/misc/IncludedFileTest.kt new file mode 100644 index 00000000..a988b2cb --- /dev/null +++ b/src/test/kotlin/com/beust/kobalt/misc/IncludedFileTest.kt @@ -0,0 +1,17 @@ +package com.beust.kobalt.misc + +import com.beust.kobalt.IFileSpec +import org.testng.Assert +import org.testng.annotations.Test +import java.io.File + +@Test +class IncludedFileTest { + fun simple() { + val from = "src/main/kotlin/" + val inf = IncludedFile(From(from), To(""), listOf(IFileSpec.Glob("**.kt"))) + inf.allFromFiles().map { File(from, it.path) }.forEach { + Assert.assertTrue(it.exists(), "Should exist: $it") + } + } +}