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

--noOverwrite

This commit is contained in:
Cedric Beust 2015-11-17 01:16:44 -08:00
parent d93975d426
commit b31da8fa49
2 changed files with 30 additions and 16 deletions

View file

@ -27,23 +27,34 @@ public class Main {
private final Properties wrapperProperties = new Properties();
private static int logLevel = 1;
private boolean noOverwrite = false;
private void installAndLaunchMain(String[] argv) throws IOException, InterruptedException {
List<String> kobaltArgv = new ArrayList<>();
boolean noLaunch = false;
for (int i = 0; i < argv.length; i++) {
boolean passToKobalt = true;
switch(argv[i]) {
case "--no-launch":
case "--noOverwrite":
noOverwrite = true;
passToKobalt = false;
break;
case "--noLaunch":
noLaunch = true;
break;
case "--log":
logLevel = Integer.parseInt(argv[i + 1]);
kobaltArgv.add(argv[i]);
i++;
break;
}
if (passToKobalt) {
kobaltArgv.add(argv[i]);
}
}
Path kobaltJarFile = installJarFile();
if (! noLaunch) {
launchMain(kobaltJarFile, argv);
launchMain(kobaltJarFile, kobaltArgv.toArray(new String[kobaltArgv.size()]));
}
}
@ -131,24 +142,26 @@ public class Main {
//
// Extract all the zip files
//
int retries = 0;
while (retries < 2) {
try {
extractZipFile(localZipFile, zipOutputDir);
break;
} catch (ZipException e) {
retries++;
error("Couldn't open zip file " + localZipFile + ": " + e.getMessage());
error("The file is probably corrupt, downloading it again");
Files.delete(localZipFile);
download(localZipFile.toFile(), wrapperVersion);
if (! noOverwrite) {
int retries = 0;
while (retries < 2) {
try {
extractZipFile(localZipFile, zipOutputDir);
break;
} catch (ZipException e) {
retries++;
error("Couldn't open zip file " + localZipFile + ": " + e.getMessage());
error("The file is probably corrupt, downloading it again");
Files.delete(localZipFile);
download(localZipFile.toFile(), wrapperVersion);
}
}
}
//
// Copy the wrapper files in the current kobalt/wrapper directory
//
if (! wrapperVersion.equals(version)) {
if (! noOverwrite && ! wrapperVersion.equals(version)) {
log(2, "Copying the wrapper files");
for (String file : FILES) {
Path from = Paths.get(zipOutputDir, file);
@ -175,6 +188,7 @@ public class Main {
}
private void extractZipFile(Path localZipFile, String zipOutputDir) throws IOException {
log(2, "Extracting " + localZipFile);
try (ZipFile zipFile = new ZipFile(localZipFile.toFile())) {
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {

View file

@ -134,9 +134,9 @@ private class Main @Inject constructor(
if (args.init) {
//
// --init: create a new build project and install the wrapper
// Make sure the wrapper won't call us back with --no-launch
// Make sure the wrapper won't call us back with --noLaunch
//
com.beust.kobalt.wrapper.Main.main(arrayOf("--no-launch") + argv)
com.beust.kobalt.wrapper.Main.main(arrayOf("--noLaunch") + argv)
projectGenerator.run(args)
} else if (args.usage) {
jc.usage()