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

Don't overwrite the wrapper files if the version is the same.

This commit is contained in:
Cedric Beust 2016-04-09 08:08:25 -07:00
parent 9351c9f8ce
commit 111343cdeb

View file

@ -166,7 +166,6 @@ public class Main {
boolean isNew = Float.parseFloat(version) * 1000 >= 650; boolean isNew = Float.parseFloat(version) * 1000 >= 650;
String fromZipOutputDir = DISTRIBUTIONS_DIR + File.separator + "kobalt-" + version;
String toZipOutputDir = DISTRIBUTIONS_DIR; String toZipOutputDir = DISTRIBUTIONS_DIR;
Path kobaltJarFile = Paths.get(toZipOutputDir, Path kobaltJarFile = Paths.get(toZipOutputDir,
isNew ? "kobalt-" + wrapperVersion : "", isNew ? "kobalt-" + wrapperVersion : "",
@ -205,8 +204,10 @@ public class Main {
try (BufferedReader bw = new BufferedReader(fw)) { try (BufferedReader bw = new BufferedReader(fw)) {
String installedVersion = bw.readLine(); String installedVersion = bw.readLine();
if (!wrapperVersion.equals(installedVersion)) { if (!wrapperVersion.equals(installedVersion)) {
log(2, " Trying to install a different version " + wrapperVersion + " != " + installedVersion log(2, " Trying to install a different version "
+ wrapperVersion + " != " + installedVersion
+ ", overwriting the installed wrapper"); + ", overwriting the installed wrapper");
installWrapperFiles(version, wrapperVersion);
} else { } else {
log(2, " Trying to install the same version " + wrapperVersion + " == " + installedVersion log(2, " Trying to install the same version " + wrapperVersion + " == " + installedVersion
+ ", not overwriting the installed wrapper"); + ", not overwriting the installed wrapper");
@ -216,43 +217,42 @@ public class Main {
} }
} }
// return kobaltJarFile;
// Copy the wrapper files in the current kobalt/wrapper directory }
//
if (! noOverwrite) {
for (String file : FILES) {
Path to = Paths.get(file);
to.toFile().getAbsoluteFile().getParentFile().mkdirs();
if (file.endsWith(KOBALTW)) { private void installWrapperFiles(String version, String wrapperVersion) throws IOException {
generateKobaltW(Paths.get(KOBALTW)); String fromZipOutputDir = DISTRIBUTIONS_DIR + File.separator + "kobalt-" + version;
} else {
Path from = Paths.get(fromZipOutputDir, file); for (String file : FILES) {
try { Path to = Paths.get(file);
if (isWindows() && to.toFile().exists()) { to.toFile().getAbsoluteFile().getParentFile().mkdirs();
log(2, " Windows detected, not overwriting " + to);
} else { if (file.endsWith(KOBALTW)) {
log(2, " Writing " + to); generateKobaltW(Paths.get(KOBALTW));
Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING); } else {
} Path from = Paths.get(fromZipOutputDir, file);
} catch (IOException ex) { try {
log(1, " Couldn't copy " + from + " to " + to + ": " + ex.getMessage()); 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) {
} log(1, " Couldn't copy " + from + " to " + to + ": " + ex.getMessage());
//
// Save wrapper-version.txt
//
log(2, " Writing " + VERSION_TXT);
try (FileWriter fw = new FileWriter(VERSION_TXT)) {
try (BufferedWriter bw = new BufferedWriter(fw)) {
bw.write(wrapperVersion);
} }
} }
} }
return kobaltJarFile; //
// Save wrapper-version.txt
//
log(2, " Writing " + VERSION_TXT);
try (FileWriter fw = new FileWriter(VERSION_TXT)) {
try (BufferedWriter bw = new BufferedWriter(fw)) {
bw.write(wrapperVersion);
}
}
} }
private void generateKobaltW(Path filePath) throws IOException { private void generateKobaltW(Path filePath) throws IOException {