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 be9d1760..396507ab 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 @@ -143,7 +143,9 @@ public class Main { return System.getProperty("os.name").contains("Windows"); } - private static final String[] FILES = new String[] { KOBALTW, "kobalt/wrapper/" + FILE_NAME + "-wrapper.jar" }; + private static final String OUT_DIR = "kobalt/wrapper/"; + private static final String[] FILES = new String[] { KOBALTW, OUT_DIR + FILE_NAME + "-wrapper.jar" }; + private static final String VERSION_TXT = "wrapper-version.txt"; private Path installDistribution() throws IOException { String wrapperVersion; @@ -195,13 +197,30 @@ public class Main { } } + // + // If the user didn't specify --noOverwrite, compare the installed wrapper to the one + // we're trying to install and if they are the same, no need to overwrite + if (! noOverwrite) { + try (FileReader fw = new FileReader(new File(OUT_DIR, VERSION_TXT))) { + try (BufferedReader bw = new BufferedReader(fw)) { + String installedVersion = bw.readLine(); + if (! wrapperVersion.equals(installedVersion)) { + log(2, " Trying to install a different version " + wrapperVersion + " != " + installedVersion + + ", overwriting the installed wrapper"); + } else { + log(2, " Trying to install the same version " + wrapperVersion + " == " + installedVersion + + ", not overwriting the installed wrapper"); + } + } + } + + } + // // Copy the wrapper files in the current kobalt/wrapper directory // - if (! noOverwrite) { - log(2, "Copying the wrapper files"); - for (String file : FILES) { + for (String file : FILES) { Path to = Paths.get(file); to.toFile().getAbsoluteFile().getParentFile().mkdirs(); @@ -213,6 +232,7 @@ public class Main { if (isWindows() && to.toFile().exists()) { log(2, " Windows detected, not overwriting " + to); } else { + log(2, " Writing " + to); Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING); } } catch (IOException ex) { @@ -220,6 +240,16 @@ public class Main { } } } + + // + // Save wrapper-version.txt + // + log(2, " Writing version.txt"); + try (FileWriter fw = new FileWriter(new File(OUT_DIR, VERSION_TXT))) { + try (BufferedWriter bw = new BufferedWriter(fw)) { + bw.write(wrapperVersion); + } + } } return kobaltJarFile; @@ -240,7 +270,7 @@ public class Main { if (envFile.exists()) { content = "#!" + envFile.getAbsolutePath() + " bash\n"; } - log(2, "Generating " + KOBALTW + (envFile.exists() ? " with shebang" : "") + "."); + log(2, " Generating " + KOBALTW + (envFile.exists() ? " with shebang" : "") + "."); content += "java -jar $(dirname $0)/kobalt/wrapper/kobalt-wrapper.jar $*\n";