From 2032cd2724d49f4af36b29bf83054385db9900f6 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 1 Jan 2016 10:42:21 -0800 Subject: [PATCH] For a rerun if no files found in the directory being md5'ed. --- .../com/beust/kobalt/internal/IncrementalManager.kt | 3 ++- .../src/main/kotlin/com/beust/kobalt/maven/Md5.kt | 13 +++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/IncrementalManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/IncrementalManager.kt index f8609910..4b7a2c9b 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/IncrementalManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/IncrementalManager.kt @@ -104,7 +104,8 @@ class IncrementalManager(val fileName: String = IncrementalManager.BUILD_INFO_FI saveInputChecksum(taskName, it) logIncremental(1, " input checksum \"$it\" saved") } - taskOutputChecksum?.let { + // Important to rerun the checksum here since the output of the task might have changed it + iit.outputChecksum()?.let { saveOutputChecksum(taskName, it) logIncremental(1, " output checksum \"$it\" saved") } 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 850b2451..30b1ebd3 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 @@ -22,10 +22,12 @@ public class Md5 { val ds = directories.filter { it.exists() } if (ds.size > 0) { MessageDigest.getInstance("MD5").let { md5 -> + var fileCount = 0 directories.filter { it.exists() }.forEach { file -> if (file.isFile) { val bytes = file.readBytes() md5.update(bytes, 0, bytes.size) + fileCount++ } else { val files = KFiles.findRecursively(file) // , { f -> f.endsWith("java")}) log(2, " Calculating checksum of ${files.size} files in $file") @@ -34,13 +36,20 @@ public class Md5 { }.filter { it.isFile }.forEach { + fileCount++ val bytes = it.readBytes() md5.update(bytes, 0, bytes.size) } } } - val result = DatatypeConverter.printHexBinary(md5.digest()).toLowerCase() - return result + // The output directory might exist but with no files in it, in which case + // we must run the task + if (fileCount > 0) { + val result = DatatypeConverter.printHexBinary(md5.digest()).toLowerCase() + return result + } else { + return null + } } } else { return null