Verified Commit e277b3ed authored by Daniel Mangold's avatar Daniel Mangold
Browse files

Minor changes to Utils.java

parent e6b0d026
......@@ -38,12 +38,12 @@ public class Utils {
if (!(Boolean) getConfigOrDefault("EXISTS", false))
System.err.println("Configurations could not be found, they must be downloaded from the repository. " +
"They will be automatically downloaded when using the installer or when CHECK_FOR_UPDATES and AUTO_UPDATE are true. " +
"Please re-run the tests.");
"Please re-run the tests afterwards.");
if (CHECK_FOR_UPDATES)
Updater.checkForUpdates();
System.out.println("Seed: " + SEED);
if (!CHECK_FOR_UPDATES || !Updater.checkForUpdates())
System.out.println("Seed: " + SEED);
else
System.out.println("Updated tests, please re-run");
}
/**
......@@ -203,16 +203,18 @@ public class Utils {
* </ul>
*
* Messages are printed in any case to let the user know what is happening
* @return whether any changes have been written
*/
private static void checkForUpdates() {
private static boolean checkForUpdates() {
HttpResponse<String> response = getHttpResource(".test_version");
if (response == null || response.statusCode() != 200) {
System.err.println("Unable to fetch version from repository");
return;
return false;
}
try (BufferedReader remoteReader = new BufferedReader(new StringReader(response.body()))) {
boolean persistentChanges = false;
String[] versionLine = remoteReader.readLine().split(" -- ", 2);
Version localVersion = new Version(LOCAL_VERSION),
remoteVersion = new Version(versionLine[0]);
......@@ -221,8 +223,7 @@ public class Utils {
System.out.println("Update available! Local version: " + localVersion + " -- Remote version: " + remoteVersion);
System.out.println("Changelog: " + REPOSITORY_URL + "blob/master/changelog.md");
System.out.println(versionLine[1]);
} else
System.out.println("Local tests are up to date");
}
for (
String line = remoteReader.readLine();
......@@ -238,9 +239,11 @@ public class Utils {
File file = new File(fileName);
if (!file.exists()) {
if (AUTO_UPDATE)
if (AUTO_UPDATE) {
updateLocal(fileName);
else
persistentChanges = true;
} else
System.err.println(fileName + " not found, can't compare hashes");
continue;
......@@ -254,15 +257,23 @@ public class Utils {
if (!actualHash.equals(expectedHash)) {
System.out.println("Hash mismatch for file " + fileName);
if (AUTO_UPDATE)
if (AUTO_UPDATE) {
updateLocal(fileName);
persistentChanges = true;
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
System.out.println("Local tests are up to date");
return persistentChanges;
} catch (IOException | InterruptedException | NoSuchAlgorithmException e) {
e.printStackTrace();
return true;
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment