Verified Commit 0c423af4 authored by Daniel Mangold's avatar Daniel Mangold
Browse files

Optimized Utils.java and added installer for tests

parent 485a296c
......@@ -43,6 +43,11 @@ public class Utils {
System.out.println("Seed: " + SEED);
}
/**
* main method stub, test installer
*/
public static void main(String[] args) {}
/**
* Returns the class object for a given name or throws an {@link TestAbortedException} if it is not found
* @param className the fully qualified name of the class
......@@ -132,7 +137,7 @@ public class Utils {
METHOD_CORRECT.put(method, false);
throw new TestAbortedException(Thread.currentThread().getStackTrace()[2].getMethodName() + " requires that " +
method.getName() + " executes without any exceptions", e.getCause());
method.getName() + " executes without any exceptions", e.getCause());
}
}
......@@ -245,7 +250,7 @@ public class Utils {
private static class Updater {
private static final String REPOSITORY_URL = "https://git.rwth-aachen.de/aud-tests/AuD-2021-H05-Student/-/raw/master/";
private static final String REPOSITORY_URL = "https://git.rwth-aachen.de/aud-tests/AuD-2021-H05-Student/-/raw/development/";
/**
* Checks if the repository is newer than the local copy and does the following actions
......@@ -283,16 +288,15 @@ public class Utils {
line = remoteReader.readLine()
) {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
String fileName = line.split(" ")[0], expectedHash = line.split(" ")[1];
StringJoiner systemSpecificFileName = new StringJoiner(System.getProperty("file.separator"));
Arrays.stream(fileName.split("/")).forEach(systemSpecificFileName::add);
messageDigest.reset();
File file = new File(systemSpecificFileName.toString());
String fileName = line.split(" +")[0], expectedHash = line.split(" +")[1];
File file = new File(fileName);
if (!file.exists()) {
System.err.println(systemSpecificFileName + " not found, can't compare hashes");
if (AUTO_UPDATE)
updateLocal(fileName);
else
System.err.println(fileName + " not found, can't compare hashes");
continue;
}
......@@ -302,10 +306,10 @@ public class Utils {
actualHash = "0".repeat(32 - actualHash.length()) + actualHash;
if (!actualHash.equals(expectedHash)) {
System.out.println("Hash mismatch for file " + systemSpecificFileName);
System.out.println("Hash mismatch for file " + fileName);
if (AUTO_UPDATE)
updateLocal(systemSpecificFileName.toString(), fileName);
updateLocal(fileName);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
......@@ -339,19 +343,20 @@ public class Utils {
}
/**
* Updates (overwrites) the specified file (first parameter) with the contents of the
* file at the repository (second parameter)
* @param fileName the relative path to the local file
* @param remoteFileName the relative path to the remote file
* Updates (overwrites) the specified file with the contents of the file at the repository
* @param fileName the relative path to the file
*/
private static void updateLocal(String fileName, String remoteFileName) throws IOException, InterruptedException {
System.out.print("Updating " + fileName + "... ");
private static void updateLocal(String fileName) throws IOException, InterruptedException {
System.out.print("Downloading " + fileName + "... ");
File file = new File(fileName);
HttpResponse<String> response = getHttpResource(fileName);
File localFile = new File(fileName);
HttpResponse<String> response = getHttpResource(remoteFileName);
//noinspection ResultOfMethodCallIgnored
file.getParentFile().mkdirs();
if (response != null && response.statusCode() == 200) {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(localFile))) {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
writer.write(response.body());
} catch (IOException e) {
e.printStackTrace();
......
Markdown is supported
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