1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 00:17:11 -07:00

Initial steps to be less aggressive overwriting kobalt-wrapper.jar.

This commit is contained in:
Cedric Beust 2016-04-02 08:02:28 -07:00
parent 1d39b74001
commit 83dfe4f5e4

View file

@ -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,12 +197,29 @@ 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) {
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";