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 { ...@@ -38,12 +38,12 @@ public class Utils {
if (!(Boolean) getConfigOrDefault("EXISTS", false)) if (!(Boolean) getConfigOrDefault("EXISTS", false))
System.err.println("Configurations could not be found, they must be downloaded from the repository. " + 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. " + "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) if (!CHECK_FOR_UPDATES || !Updater.checkForUpdates())
Updater.checkForUpdates(); System.out.println("Seed: " + SEED);
else
System.out.println("Seed: " + SEED); System.out.println("Updated tests, please re-run");
} }
/** /**
...@@ -203,16 +203,18 @@ public class Utils { ...@@ -203,16 +203,18 @@ public class Utils {
* </ul> * </ul>
* *
* Messages are printed in any case to let the user know what is happening * 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"); HttpResponse<String> response = getHttpResource(".test_version");
if (response == null || response.statusCode() != 200) { if (response == null || response.statusCode() != 200) {
System.err.println("Unable to fetch version from repository"); System.err.println("Unable to fetch version from repository");
return; return false;
} }
try (BufferedReader remoteReader = new BufferedReader(new StringReader(response.body()))) { try (BufferedReader remoteReader = new BufferedReader(new StringReader(response.body()))) {
boolean persistentChanges = false;
String[] versionLine = remoteReader.readLine().split(" -- ", 2); String[] versionLine = remoteReader.readLine().split(" -- ", 2);
Version localVersion = new Version(LOCAL_VERSION), Version localVersion = new Version(LOCAL_VERSION),
remoteVersion = new Version(versionLine[0]); remoteVersion = new Version(versionLine[0]);
...@@ -221,8 +223,7 @@ public class Utils { ...@@ -221,8 +223,7 @@ public class Utils {
System.out.println("Update available! Local version: " + localVersion + " -- Remote version: " + remoteVersion); System.out.println("Update available! Local version: " + localVersion + " -- Remote version: " + remoteVersion);
System.out.println("Changelog: " + REPOSITORY_URL + "blob/master/changelog.md"); System.out.println("Changelog: " + REPOSITORY_URL + "blob/master/changelog.md");
System.out.println(versionLine[1]); System.out.println(versionLine[1]);
} else }
System.out.println("Local tests are up to date");
for ( for (
String line = remoteReader.readLine(); String line = remoteReader.readLine();
...@@ -238,9 +239,11 @@ public class Utils { ...@@ -238,9 +239,11 @@ public class Utils {
File file = new File(fileName); File file = new File(fileName);
if (!file.exists()) { if (!file.exists()) {
if (AUTO_UPDATE) if (AUTO_UPDATE) {
updateLocal(fileName); updateLocal(fileName);
else
persistentChanges = true;
} else
System.err.println(fileName + " not found, can't compare hashes"); System.err.println(fileName + " not found, can't compare hashes");
continue; continue;
...@@ -254,15 +257,23 @@ public class Utils { ...@@ -254,15 +257,23 @@ public class Utils {
if (!actualHash.equals(expectedHash)) { if (!actualHash.equals(expectedHash)) {
System.out.println("Hash mismatch for file " + fileName); System.out.println("Hash mismatch for file " + fileName);
if (AUTO_UPDATE) if (AUTO_UPDATE) {
updateLocal(fileName); updateLocal(fileName);
persistentChanges = true;
}
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
System.out.println("Local tests are up to date");
return persistentChanges;
} catch (IOException | InterruptedException | NoSuchAlgorithmException e) { } catch (IOException | InterruptedException | NoSuchAlgorithmException e) {
e.printStackTrace(); 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