From 19ad4ae3a2c179ebd67a53724c3751e6b264a728 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 6 Jan 2016 16:16:48 -0800 Subject: [PATCH] VerifyKobaltZip. --- .../src/main/kotlin/com/beust/kobalt/Args.kt | 4 ++ src/main/kotlin/com/beust/kobalt/Main.kt | 9 ++-- .../com/beust/kobalt/app/VerifyKobaltZip.kt | 53 +++++++++++++++++++ 3 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 src/main/kotlin/com/beust/kobalt/app/VerifyKobaltZip.kt diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt index bf1b44e8..0e79db38 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt @@ -56,5 +56,9 @@ class Args { @Parameter(names = arrayOf("--update"), description = "Update to the latest version of Kobalt") var update: Boolean = false + + @Parameter(names = arrayOf("--verifyDistribution"), description = "Verify the distribution", + hidden = true) + var verifyDistribution: Boolean = false } diff --git a/src/main/kotlin/com/beust/kobalt/Main.kt b/src/main/kotlin/com/beust/kobalt/Main.kt index 82227eaa..f66c87f1 100644 --- a/src/main/kotlin/com/beust/kobalt/Main.kt +++ b/src/main/kotlin/com/beust/kobalt/Main.kt @@ -5,10 +5,7 @@ import com.beust.kobalt.api.IClasspathDependency import com.beust.kobalt.api.Kobalt import com.beust.kobalt.api.PluginTask import com.beust.kobalt.api.Project -import com.beust.kobalt.app.BuildFileCompiler -import com.beust.kobalt.app.MainModule -import com.beust.kobalt.app.ProjectGenerator -import com.beust.kobalt.app.UpdateKobalt +import com.beust.kobalt.app.* import com.beust.kobalt.app.remote.KobaltClient import com.beust.kobalt.app.remote.KobaltServer import com.beust.kobalt.internal.PluginInfo @@ -148,10 +145,12 @@ private class Main @Inject constructor( } else if (args.serverMode) { server.run() } else { - // Update doesn't require to parse the build file + // Options that don't need Build.kt to be parsed first if (args.update) { // --update updateKobalt.updateKobalt() + } else if (args.verifyDistribution) { + VerifyKobaltZip().run() } else { // // Everything below requires to parse the build file first diff --git a/src/main/kotlin/com/beust/kobalt/app/VerifyKobaltZip.kt b/src/main/kotlin/com/beust/kobalt/app/VerifyKobaltZip.kt new file mode 100644 index 00000000..22b74fcd --- /dev/null +++ b/src/main/kotlin/com/beust/kobalt/app/VerifyKobaltZip.kt @@ -0,0 +1,53 @@ +package com.beust.kobalt.app + +import com.beust.kobalt.KobaltException +import com.beust.kobalt.api.Kobalt +import com.beust.kobalt.misc.KFiles +import com.beust.kobalt.misc.log +import java.io.FileInputStream +import java.util.jar.JarFile +import java.util.jar.JarInputStream + +class VerifyKobaltZip { + fun run() { + var success = true + var foundKobaltw = false + var foundJar = false + var foundWrapperJar = false + + val jarFilePath = "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 == "kobaltw") { + foundKobaltw = true + } else if (entry.name.endsWith(jarFilePath)) { + val ins = zipFile.getInputStream(entry) + if (ins.available() < 20000000) { + throw KobaltException(jarFilePath + " is too small: " + jarFilePath) + } + foundJar = true + } else if (entry.name.endsWith("kobalt-wrapper.jar")) { + foundWrapperJar = true + } else { + success = false + } + entry = stream.nextEntry + } + if (! success) { + throw KobaltException("Found unexpected file in $zipFilePath") + } + 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") + } +}