From f7912f40e76016545a7ff28267200942e7c80999 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Mon, 18 Apr 2016 18:53:57 -0700 Subject: [PATCH] Fix local tests. --- .../com/beust/kobalt/VerifyKobaltZipTest.kt | 61 +++++++++++-------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt index 515b6067..861a8ea3 100644 --- a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt +++ b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt @@ -39,34 +39,38 @@ class VerifyKobaltZipTest : KobaltTest() { val mainJarFilePath = "kobalt-$KOBALT_VERSION.jar" val zipFilePath = KFiles.joinDir("kobaltBuild", "libs", "kobalt-$KOBALT_VERSION.zip") - val zipFile = JarFile(zipFilePath) - val stream = JarInputStream(FileInputStream(zipFilePath)) - var entry = stream.nextEntry - while (entry != null) { - if (entry.name.endsWith("kobaltw")) { - foundKobaltw = true - } else if (entry.name.endsWith(mainJarFilePath)) { - val ins = zipFile.getInputStream(entry) - if (ins.available() < 20000000) { - throw KobaltException(mainJarFilePath + " is too small: " + mainJarFilePath) + if (File(zipFilePath).exists()) { + val zipFile = JarFile(zipFilePath) + val stream = JarInputStream(FileInputStream(zipFilePath)) + var entry = stream.nextEntry + while (entry != null) { + if (entry.name.endsWith("kobaltw")) { + foundKobaltw = true + } else if (entry.name.endsWith(mainJarFilePath)) { + val ins = zipFile.getInputStream(entry) + if (ins.available() < 20000000) { + throw KobaltException(mainJarFilePath + " is too small: " + mainJarFilePath) + } + verifyMainJarFile(ins) + foundJar = true + } else if (entry.name.endsWith("kobalt-wrapper.jar")) { + foundWrapperJar = true } - verifyMainJarFile(ins) - foundJar = true - } else if (entry.name.endsWith("kobalt-wrapper.jar")) { - foundWrapperJar = true + entry = stream.nextEntry } - entry = stream.nextEntry + if (!foundKobaltw) { + throw KobaltException("Couldn't find kobaltw in $zipFilePath") + } + if (!foundJar) { + throw KobaltException("Couldn't find jar in $zipFilePath") + } + if (!foundWrapperJar) { + throw KobaltException("Couldn't find wrapper jar in $zipFilePath") + } + log(1, "$zipFilePath looks correct") + } else { + log(1, "Couldn't find $zipFilePath, skipping test") } - if (! foundKobaltw) { - throw KobaltException("Couldn't find kobaltw in $zipFilePath") - } - if (! foundJar) { - throw KobaltException("Couldn't find jar in $zipFilePath") - } - if (! foundWrapperJar) { - throw KobaltException("Couldn't find wrapper jar in $zipFilePath") - } - log(1, "$zipFilePath looks correct") } private fun assertExistsInJarInputStream(ins: JarInputStream, vararg fileNames: String) { @@ -79,7 +83,12 @@ class VerifyKobaltZipTest : KobaltTest() { private fun assertExistsInJar(jarName: String, vararg fileNames: String) { val sourceJarPath = KFiles.joinDir("kobaltBuild", "libs", jarName) - assertExistsInJarInputStream(JarInputStream(FileInputStream(File(sourceJarPath))), *fileNames) + val file = File(sourceJarPath) + if (file.exists()) { + assertExistsInJarInputStream(JarInputStream(FileInputStream(file)), *fileNames) + } else { + log(1, "Couldn't find $file, skipping test") + } } private fun jarContents(stream: JarInputStream) : Set {