From c2c4d8e254d0b951a101e7cdb1eaa86c5c66bd48 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 16 Mar 2017 14:44:12 -0700 Subject: [PATCH] Clarify and document. --- .../plugin/packaging/PackagingPlugin.kt | 57 +++++++++++-------- 1 file changed, 32 insertions(+), 25 deletions(-) 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 ea541efa..2e81d778 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt @@ -62,21 +62,28 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana runTask = { taskInstall(project) }) } - val zipToFiles = hashMapOf>() - override fun assemble(project: Project, context: KobaltContext) : IncrementalTaskInfo { val allConfigs = packages.filter { it.project.name == project.name } + val zipToFiles = hashMapOf>() val benchmark = benchmarkMillis { if (true) { + // + // This loop prepares the data so we can calculate input and output checksums for the + // assemble task: + // - Input: Calculate the list of all the included files for every archive (jar/war/zip) and + // store them in the `zipToFiles` map. + // - Output: Calculate all the output archive files into `allFiles` + // + // `zipToFiles` is used again so we can pass that list of included files to the actual execution + // of the task, so we don't have to look for them a second time + // val allIncludedFiles = arrayListOf() val outputArchives = arrayListOf() allConfigs.forEach { packageConfig -> listOf(packageConfig.jars, packageConfig.wars, packageConfig.zips).forEach { archives -> archives.forEach { val files = jarGenerator.findIncludedFiles(packageConfig.project, context, it) - val suffixIndex = it.name.lastIndexOf(".") - val suffix = it.name.substring(suffixIndex) val outputFile = jarGenerator.fullArchiveName(project, context, it.name) outputArchives.add(outputFile) allIncludedFiles.addAll(files) @@ -84,7 +91,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana } } } - val allFiles = allIncludedFiles.fold(arrayListOf()) { files, includedFile: IncludedFile -> + val inputFiles = allIncludedFiles.fold(arrayListOf()) { files, includedFile: IncludedFile -> val foundFiles = includedFile.allFromFiles(project.directory) val absFiles = foundFiles.map { File(KFiles.joinDir(project.directory, includedFile.from, it.path)) @@ -93,7 +100,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana files } - val inMd5 = Md5.toMd5Directories(allFiles) + val inMd5 = Md5.toMd5Directories(inputFiles) val outMd5 = Md5.toMd5Directories(outputArchives) Pair(inMd5, outMd5) } else { @@ -150,7 +157,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana context.pluginInfo.incrementalAssemblyContributors.forEach { val taskInfo = it.assemble(project, context) val closure = incrementalManagerFactory.create().toIncrementalTaskClosure(TASK_ASSEMBLE, { - p: Project -> taskInfo }, context.variant) + _: Project -> taskInfo }, context.variant) val thisResult = closure.invoke(project) if (! thisResult.success) { // Abort at the first failure @@ -174,24 +181,24 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana } // @Task(name = "generateOsgiManifest", alwaysRunAfter = arrayOf(TASK_ASSEMBLE)) - fun generateManifest(project: Project): TaskResult { - val analyzer = Analyzer().apply { - jar = aQute.bnd.osgi.Jar(project.projectProperties.get(Archives.JAR_NAME) as String) - val dependencies = project.compileDependencies + project.compileRuntimeDependencies - dependencyManager.calculateDependencies(project, context, passedDependencies = dependencies).forEach { - addClasspath(it.jarFile.get()) - } - setProperty(Analyzer.BUNDLE_VERSION, project.version) - setProperty(Analyzer.BUNDLE_NAME, project.group) - setProperty(Analyzer.BUNDLE_DESCRIPTION, project.description) - setProperty(Analyzer.IMPORT_PACKAGE, "*") - setProperty(Analyzer.EXPORT_PACKAGE, "*;-noimport:=false;version=" + project.version) - } - - val manifest = analyzer.calcManifest() - manifest.write(System.out) - return TaskResult() - } +// fun generateManifest(project: Project): TaskResult { +// val analyzer = Analyzer().apply { +// jar = aQute.bnd.osgi.Jar(project.projectProperties.get(Archives.JAR_NAME) as String) +// val dependencies = project.compileDependencies + project.compileRuntimeDependencies +// dependencyManager.calculateDependencies(project, context, passedDependencies = dependencies).forEach { +// addClasspath(it.jarFile.get()) +// } +// setProperty(Analyzer.BUNDLE_VERSION, project.version) +// setProperty(Analyzer.BUNDLE_NAME, project.group) +// setProperty(Analyzer.BUNDLE_DESCRIPTION, project.description) +// setProperty(Analyzer.IMPORT_PACKAGE, "*") +// setProperty(Analyzer.EXPORT_PACKAGE, "*;-noimport:=false;version=" + project.version) +// } +// +// val manifest = analyzer.calcManifest() +// manifest.write(System.out) +// return TaskResult() +// } @Task(name = PackagingPlugin.TASK_INSTALL, description = "Install the artifacts",