From d3a70a25a82e0f5dae19cf22865afc6430d76a04 Mon Sep 17 00:00:00 2001 From: DevCharly Date: Tue, 7 Jun 2016 17:28:20 +0200 Subject: [PATCH] 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") }