1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 16:28:12 -07:00

Incremental packaging.

This commit is contained in:
Cedric Beust 2017-03-14 18:40:28 -07:00
parent c974330612
commit b2390f34f8

View file

@ -61,52 +61,52 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
runTask = { taskInstall(project) }) runTask = { taskInstall(project) })
} }
/**
* "assemble" is an incremental task but with a twist. Because it can be costly to determine if any
* of the class files generated in the previous phase is new or not, we just don't do that and always
* return "null" for both input and output checksums, which would cause that task to always be rerun.
* However, we are depending on Kobalt's cascading incremental management to skip us whenever appropriate:
* whenever a previous incremental task was a success, all following incremental tasks are automatically
* skipped.
*/
override fun assemble(project: Project, context: KobaltContext) : IncrementalTaskInfo { override fun assemble(project: Project, context: KobaltContext) : IncrementalTaskInfo {
val allConfigs = packages.filter { it.project.name == project.name } val allConfigs = packages.filter { it.project.name == project.name }
if (false) { val start = System.currentTimeMillis()
// Work in progress val checksums =
val allIncludedFiles = arrayListOf<IncludedFile>() if (true) {
val zipToFiles = hashMapOf<String, List<IncludedFile>>() val allIncludedFiles = arrayListOf<IncludedFile>()
val outputArchives = arrayListOf<File>() val zipToFiles = hashMapOf<String, List<IncludedFile>>()
allConfigs.forEach { packageConfig -> val outputArchives = arrayListOf<File>()
listOf(packageConfig.jars, packageConfig.wars, packageConfig.zips).forEach { archives -> allConfigs.forEach { packageConfig ->
archives.forEach { listOf(packageConfig.jars, packageConfig.wars, packageConfig.zips).forEach { archives ->
val files = jarGenerator.findIncludedFiles(packageConfig.project, context, it) archives.forEach {
val suffixIndex = it.name.lastIndexOf(".") val files = jarGenerator.findIncludedFiles(packageConfig.project, context, it)
val suffix = it.name.substring(suffixIndex) val suffixIndex = it.name.lastIndexOf(".")
val outputFile = jarGenerator.fullArchiveName(project, context, it.name, suffix) val suffix = it.name.substring(suffixIndex)
outputArchives.add(outputFile) val outputFile = jarGenerator.fullArchiveName(project, context, it.name, suffix)
allIncludedFiles.addAll(files) outputArchives.add(outputFile)
zipToFiles[it.name] = files allIncludedFiles.addAll(files)
zipToFiles[it.name] = files
}
} }
} }
} val allFiles = allIncludedFiles.fold(arrayListOf<File>()) { files, includedFile: IncludedFile ->
val allFiles = allIncludedFiles.fold(arrayListOf<File>()) { files, includedFile: IncludedFile -> val foundFiles = includedFile.allFromFiles(project.directory)
val foundFiles = includedFile.allFromFiles(project.directory) val absFiles = foundFiles.map {
val absFiles = foundFiles.map { File(KFiles.joinDir(project.directory, includedFile.from, it.path))
File(KFiles.joinDir(project.directory, includedFile.from, it.path)) }
files.addAll(absFiles)
files
} }
files.addAll(absFiles)
files val inMd5 = Md5.toMd5Directories(allFiles)
val outMd5 = Md5.toMd5Directories(outputArchives)
Pair(inMd5, outMd5)
} else {
Pair(null, null)
} }
val md5 = Md5.toMd5Directories(allFiles) val inMd5 = checksums.first
val outMd5 = Md5.toMd5Directories(outputArchives) val outMd5 = checksums.second
println("Input MD5: $md5 output MD5: $outMd5") context.logger.log(project.name, 2,
} " Time to calculate packaging checksum: " + (System.currentTimeMillis() - start) + " ms")
return IncrementalTaskInfo( return IncrementalTaskInfo(
{ null }, { -> inMd5 },
{ null }, { -> outMd5 },
{ project -> { project ->
try { try {
project.projectProperties.put(Archives.JAR_NAME, project.projectProperties.put(Archives.JAR_NAME,