From 2af7250659cc8bb0e89f1dbe1ec639003319831d Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 10 Mar 2016 01:11:19 +0400 Subject: [PATCH] New zip structure. --- kobalt/src/Build.kt | 7 +-- .../java/com/beust/kobalt/wrapper/Main.java | 47 +++++++++++++------ 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index ee93daa4..1c52b263 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -135,10 +135,11 @@ val kobaltApp = project(kobaltPluginApi, wrapper) { } } zip { - include("kobaltw") - include(from("$buildDirectory/libs"), to("kobalt/wrapper"), + val dir = "kobalt-$version" + include(from("."), to("$dir/bin"), "kobaltw") + include(from("$buildDirectory/libs"), to("$dir/kobalt/wrapper"), "$projectName-$version.jar") - include(from("modules/wrapper/$buildDirectory/libs"), to("kobalt/wrapper"), + include(from("modules/wrapper/$buildDirectory/libs"), to("$dir/kobalt/wrapper"), "$projectName-wrapper.jar") } } diff --git a/modules/wrapper/src/main/java/com/beust/kobalt/wrapper/Main.java b/modules/wrapper/src/main/java/com/beust/kobalt/wrapper/Main.java index df148bf8..a93a6acb 100644 --- a/modules/wrapper/src/main/java/com/beust/kobalt/wrapper/Main.java +++ b/modules/wrapper/src/main/java/com/beust/kobalt/wrapper/Main.java @@ -16,6 +16,11 @@ public class Main { System.exit(exitCode); } + private static final boolean DEV = false; + private static final int DEV_VERSION_INT = 650; + private static final String DEV_VERSION = "0." + DEV_VERSION_INT; + private static final String DEV_ZIP = "/Users/beust/kotlin/kobalt/kobaltBuild/libs/kobalt-" + DEV_VERSION + ".zip"; + private static final String KOBALT_PROPERTIES = "kobalt.properties"; private static final String KOBALTW = "kobaltw"; private static final String KOBALT_WRAPPER_PROPERTIES = "kobalt-wrapper.properties"; @@ -123,19 +128,33 @@ public class Main { return System.getProperty("os.name").contains("Windows"); } - private Path installDistribution() throws IOException { - Properties properties = maybeCreateProperties(); + private static final String[] FILES = new String[] { KOBALTW, "kobalt/wrapper/" + FILE_NAME + "-wrapper.jar" }; - String version = properties.getProperty(PROPERTY_VERSION); - initWrapperFile(version); - String wrapperVersion = getWrapperVersion(); + private Path installDistribution() throws IOException { + String wrapperVersion; + String version; + Path localZipFile; + if (DEV) { + version = DEV_VERSION; + wrapperVersion = DEV_VERSION; + localZipFile = Paths.get(DEV_ZIP); + } else { + Properties properties = maybeCreateProperties(); + version = properties.getProperty(PROPERTY_VERSION); + initWrapperFile(version); + wrapperVersion = getWrapperVersion(); + String fileName = FILE_NAME + "-" + wrapperVersion + ".zip"; + Files.createDirectories(Paths.get(DISTRIBUTIONS_DIR)); + localZipFile = Paths.get(DISTRIBUTIONS_DIR, fileName); + } log(2, "Wrapper version: " + wrapperVersion); - String fileName = FILE_NAME + "-" + wrapperVersion + ".zip"; - Files.createDirectories(Paths.get(DISTRIBUTIONS_DIR)); - Path localZipFile = Paths.get(DISTRIBUTIONS_DIR, fileName); String zipOutputDir = DISTRIBUTIONS_DIR + "/" + wrapperVersion; + boolean isNew = Float.parseFloat(version) * 1000 >= 650; + if (isNew) { + zipOutputDir += File.separator + "kobalt-" + version; + } Path kobaltJarFile = Paths.get(zipOutputDir, getWrapperDir().getPath() + "/" + FILE_NAME + "-" + wrapperVersion + ".jar"); boolean downloadedZipFile = false; @@ -166,16 +185,18 @@ public class Main { // // Copy the wrapper files in the current kobalt/wrapper directory // + if (! noOverwrite) { log(2, "Copying the wrapper files"); for (String file : FILES) { - Path to = Paths.get(new File(".").getAbsolutePath(), file); + Path to = Paths.get(file); + to.toFile().getAbsoluteFile().getParentFile().mkdirs(); if (Files.exists(to)) { log(2, to + " already exists, not overwriting it"); continue; - } else if (file.equals(KOBALTW)) { - generateKobaltW(to); + } else if (file.endsWith(KOBALTW)) { + generateKobaltW(Paths.get(KOBALTW)); } else { Path from = Paths.get(zipOutputDir, file); try { @@ -211,7 +232,7 @@ public class Main { } log(2, "Generating " + KOBALTW + (envFile.exists() ? " with shebang" : "") + "."); - content += "java -jar $(dirname $0)/kobalt/wrapper/kobalt-wrapper.jar $*\n"; + content += "java -jar $(dirname $0)/../kobalt/wrapper/kobalt-wrapper.jar $*\n"; Files.write(filePath, content.getBytes()); @@ -248,8 +269,6 @@ public class Main { } } - private static final String[] FILES = new String[] { KOBALTW, "kobalt/wrapper/" + FILE_NAME + "-wrapper.jar" }; - private void download(File file, String version) throws IOException { for (int attempt = 0; attempt < 3; ++attempt) { try {