From a005a14db55263c0f8019f51a6e29be9e572ebc0 Mon Sep 17 00:00:00 2001 From: DevCharly Date: Tue, 7 Jun 2016 14:05:30 +0200 Subject: [PATCH 1/3] avoid adding empty "classes" directory entry to Jar file (this did add the empty "classes" directory to kobalt-0.xxx.jar) --- .../main/kotlin/com/beust/kobalt/misc/JarUtils.kt | 13 ------------- 1 file changed, 13 deletions(-) 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 70a8bbb4..dfd8cc70 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 @@ -51,19 +51,6 @@ public class JarUtils { log(2, "Writing contents of directory $foundFile") // Directory - var name = foundFile.name - if (!name.isEmpty()) { - if (!name.endsWith("/")) name += "/" - val entry = JarEntry(name) - entry.time = localFile.lastModified() - try { - outputStream.putNextEntry(entry) - } catch(ex: ZipException) { - log(2, "Can't add $name: ${ex.message}") - } finally { - outputStream.closeEntry() - } - } val includedFile = IncludedFile(From(foundFile.path), To(""), listOf(IFileSpec.GlobSpec("**"))) addSingleFile(".", includedFile, outputStream, expandJarFiles) } else { From cbbe9cbeb72f3e129b21209bdef9288a8b423b21 Mon Sep 17 00:00:00 2001 From: DevCharly Date: Tue, 7 Jun 2016 16:58:18 +0200 Subject: [PATCH 2/3] fixed fatJar for projects in subdirectories that depend on other projects E.g. building p2 (see below) failed with `java.lang.AssertionError: File should exist: p2\p1\kobaltBuild\classes` because `p2.directory is != "."` ``` val p1 = project { name = "p1" directory = name } val p2 = project(p1) { name = "p2" directory = name assemble { jar { fatJar = true } } } ``` --- .../src/main/kotlin/com/beust/kobalt/JarGenerator.kt | 2 +- .../src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JarGenerator.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JarGenerator.kt index 39c4c2e1..59f51deb 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JarGenerator.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JarGenerator.kt @@ -107,7 +107,7 @@ class JarGenerator @Inject constructor(val dependencyManager: DependencyManager) if (! seen.contains(file.path)) { seen.add(file.path) if (! KFiles.Companion.isExcluded(file, jar.excludes)) { - result.add(IncludedFile(specs = arrayListOf(IFileSpec.FileSpec(file.path)), + result.add(IncludedFile(specs = arrayListOf(IFileSpec.FileSpec(file.absolutePath)), expandJarFiles = true)) } } 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 dfd8cc70..fedac00f 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 @@ -47,12 +47,12 @@ public class JarUtils { throw AssertionError("File should exist: $localFile") } - if (foundFile.isDirectory) { + if (localFile.isDirectory) { log(2, "Writing contents of directory $foundFile") // Directory - val includedFile = IncludedFile(From(foundFile.path), To(""), listOf(IFileSpec.GlobSpec("**"))) - addSingleFile(".", includedFile, outputStream, expandJarFiles) + val includedFile = IncludedFile(From(""), To(""), listOf(IFileSpec.GlobSpec("**"))) + addSingleFile(localFile.path, includedFile, outputStream, expandJarFiles) } else { if (file.expandJarFiles && foundFile.name.endsWith(".jar") && ! file.from.contains("resources")) { log(2, "Writing contents of jar file $foundFile") From d3a70a25a82e0f5dae19cf22865afc6430d76a04 Mon Sep 17 00:00:00 2001 From: DevCharly Date: Tue, 7 Jun 2016 17:28:20 +0200 Subject: [PATCH 3/3] delete jar if exception occurs while creating it (otherwise incremental build does not work on next run) --- .../com/beust/kobalt/archive/Archives.kt | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Archives.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Archives.kt index ca808318..66fe50e1 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Archives.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Archives.kt @@ -33,12 +33,19 @@ class Archives { val result = File(archiveDir.path, fullArchiveName) log(3, "Creating $result") if (! Features.USE_TIMESTAMPS || isOutdated(project.directory, includedFiles, result)) { - val outStream = outputStreamFactory(FileOutputStream(result)) - JarUtils.addFiles(project.directory, includedFiles, outStream, expandJarFiles) - log(2, text = "Added ${includedFiles.size} files to $result") - outStream.flush() - outStream.close() - log(1, " Created $result") + try { + outputStreamFactory(FileOutputStream(result)).use { + JarUtils.addFiles(project.directory, includedFiles, it, expandJarFiles) + log(2, text = "Added ${includedFiles.size} files to $result") + log(1, " Created $result") + } + } catch (e: Throwable) { + // make sure that incomplete archive is deleted + // otherwise incremental build does not work on next run + result.delete() + throw e + } + } else { log(3, " $result is up to date") }