From a9b8594a8395e56fb07cce58ac7d4794fa64fb1d Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 7 Jun 2016 21:09:11 -0800 Subject: [PATCH] Change md5 implementation to checksum timestamps instead of files. --- .../src/main/kotlin/com/beust/kobalt/maven/Md5.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 339efaa1..6cfb4832 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 @@ -18,7 +18,13 @@ public class Md5 { // return DatatypeConverter.printHexBinary(md5.digest()).toLowerCase() // } - fun toMd5Directories(directories: List) : String? { + /** + * Calculate a checksum for all the files under the passed directories. The conversion from File to + * bytes can be customized by the @param{toBytes} parameter. The default implementation calculates + * a checksum of the last modified timestamp. + */ + fun toMd5Directories(directories: List, + toBytes: (File) -> ByteArray = { it.lastModified().toString().toByteArray() } ): String? { val ds = directories.filter { it.exists() } if (ds.size > 0) { MessageDigest.getInstance("MD5").let { md5 -> @@ -37,7 +43,7 @@ public class Md5 { it.isFile }.forEach { fileCount++ - val bytes = it.readBytes() + val bytes = toBytes(it) md5.update(bytes, 0, bytes.size) } }