From c9e61e49a9276f2069d27ec1fa2c6a389af8da74 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 8 Apr 2017 11:08:17 -0700 Subject: [PATCH 1/2] Any nonexistent version will cause Kobalt to use local build directories. Relaxes the restriction for that version to be +1. --- .../kotlin/com/beust/kobalt/misc/KFiles.kt | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt index 15c2a15d..065e5ab1 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt @@ -10,7 +10,9 @@ import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths import java.nio.file.StandardCopyOption +import java.util.* import java.util.jar.JarInputStream +import java.util.regex.Pattern class KFiles { @@ -20,6 +22,20 @@ class KFiles { */ val kobaltJar : List get() { + val PATTERN = Pattern.compile("kobalt-([-.0-9]+)") + + fun latestInstalledVersion() : StringVersion { + val versions = File(distributionsDir).listFiles().map { it.name }.map { + val matcher = PATTERN.matcher(it) + val result = + if (matcher.matches()) matcher.group(1) + else null + result + }.filterNotNull().map(::StringVersion) + Collections.sort(versions, reverseOrder()) + return versions[0] + } + val envJar = System.getenv("KOBALT_JAR") if (envJar != null) { debug("Using kobalt jar $envJar") @@ -31,16 +47,15 @@ class KFiles { if (jarFile.exists()) { return listOf(jarFile.absolutePath) } else { - // In development mode, keep your kobalt.properties version one above kobalt-wrapper.properties: + // In development mode, keep your kobalt.properties version to a nonexistent version // kobalt.properties: kobalt.version=0.828 // kobalt-wrapper.properties: kobalt.version=0.827 // When Kobalt can't find the newest jar file, it will instead use the classes produced by IDEA // in the directories specified here: - val leftSuffix = Kobalt.version.substring(0, Kobalt.version.lastIndexOf(".") + 1) - val previousVersion = leftSuffix + - (Kobalt.version.split(".").let { it[it.size - 1] }.toInt() - 1).toString() + val previousVersion = latestInstalledVersion().version val previousJar = joinDir(distributionsDir, "kobalt-" + previousVersion, "kobalt/wrapper/kobalt-$previousVersion.jar") + val v = latestInstalledVersion() val result = listOf("", "modules/kobalt-plugin-api", "modules/wrapper").map { File(homeDir(KFiles.joinDir("kotlin", "kobalt", it, "kobaltBuild", "classes"))) .absolutePath From 6a08d3caa8cda8f5804314dd970f5a0856b02500 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 22 Apr 2017 13:23:11 -0700 Subject: [PATCH 2/2] Fix slashes in the zip file. --- .../src/main/kotlin/com/beust/kobalt/archive/MetaArchive.kt | 2 +- src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/MetaArchive.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/MetaArchive.kt index 69918dd4..539ce238 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/MetaArchive.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/MetaArchive.kt @@ -25,7 +25,7 @@ class MetaArchive(outputFile: File, val manifest: Manifest?) : Closeable { fun addFile(f: File, entryFile: File, path: String?) { val file = f.normalize() FileInputStream(file).use { inputStream -> - val actualPath = if (path != null) path + entryFile.path else entryFile.path + val actualPath = KFiles.fixSlashes(if (path != null) path + entryFile.path else entryFile.path) ZipArchiveEntry(actualPath).let { entry -> maybeAddEntry(entry) { addEntry(entry, inputStream) diff --git a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt index c15e95d2..7966c8b5 100644 --- a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt +++ b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt @@ -3,6 +3,7 @@ package com.beust.kobalt import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.kobaltLog import com.beust.kobalt.misc.warn +import org.assertj.core.api.Assertions.assertThat import org.testng.annotations.Test import java.io.File import java.io.FileInputStream @@ -38,6 +39,7 @@ class VerifyKobaltZipTest : KobaltTest() { val stream = JarInputStream(FileInputStream(zipFilePath)) var entry = stream.nextEntry while (entry != null) { + assertThat(entry.name).doesNotContain("\\") if (! entry.name.startsWith(root)) { throw AssertionError("Entries in the zip file should be under the directory $root") }