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

Changed test metadata format to JSON

parent e277b3ed
package h05; package h05;
import org.json.JSONObject;
import org.opentest4j.TestAbortedException; import org.opentest4j.TestAbortedException;
import java.io.*; import java.io.*;
...@@ -213,24 +214,24 @@ public class Utils { ...@@ -213,24 +214,24 @@ public class Utils {
return false; return false;
} }
try (BufferedReader remoteReader = new BufferedReader(new StringReader(response.body()))) { try {
JSONObject remoteData = new JSONObject(response.body());
boolean persistentChanges = false; boolean persistentChanges = false;
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(remoteData.getString("version"));
if (remoteVersion.compareTo(localVersion) > 0) { if (remoteVersion.compareTo(localVersion) > 0) {
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(remoteData.getString("updateMessage"));
} } else
System.out.println("Local tests are up to date");
for ( if (!(CHECK_HASHES || (AUTO_UPDATE && remoteVersion.compareTo(localVersion) > 0)))
String line = remoteReader.readLine(); return false;
(CHECK_HASHES || (AUTO_UPDATE && remoteVersion.compareTo(localVersion) > 0)) && line != null && line.length() != 0;
line = remoteReader.readLine() for (Map.Entry<String, Object> fileMap : remoteData.getJSONObject("hashes").toMap().entrySet()) {
) { String fileName = fileMap.getKey(), expectedHash = (String) fileMap.getValue();
String fileName = line.split(" +")[0], expectedHash = line.split(" +")[1];
if (((List<?>) getConfigOrDefault("EXCLUDED_FILES", List.of())).contains(fileName)) if (((List<?>) getConfigOrDefault("EXCLUDED_FILES", List.of())).contains(fileName))
continue; continue;
...@@ -268,8 +269,6 @@ public class Utils { ...@@ -268,8 +269,6 @@ public class Utils {
} }
} }
System.out.println("Local tests are up to date");
return persistentChanges; return persistentChanges;
} catch (IOException | InterruptedException | NoSuchAlgorithmException e) { } catch (IOException | InterruptedException | NoSuchAlgorithmException e) {
e.printStackTrace(); e.printStackTrace();
......
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