Skip to content

Commit

Permalink
Minor improvements, documentation, code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
piegamesde committed Aug 7, 2020
1 parent 69e4a41 commit 75cb5ea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public static void checkMinecraftVersions() throws IOException {
.map(Optional::get)
.collect(Collectors.toList());
log.debug("Latest known Minecraft versions: " + latestReleases.stream().map(v -> v.id).collect(Collectors.toList()));

for (MinecraftVersion version : MinecraftVersion.values()) {
log.info("Checking " + version);
Semver minecraftVersion = new Semver(version.versionName, SemverType.LOOSE);
Expand All @@ -68,6 +69,7 @@ public static void checkMinecraftVersions() throws IOException {
log.error("Specified URL does not match, should be " + latestMatching.url);
}
}

Semver latestRelease = latestReleases.stream()
.map(v -> new Semver(v.id, SemverType.LOOSE))
.max(Comparator.naturalOrder())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,23 @@ public void generateData() throws Exception {

{ /* Call the Minecraft data report tool */
Path serverFile = OUTPUT_INTERNAL_CACHE.resolve("server-" + version.fileSuffix + ".jar");
String serverHash = null, cachedServerHash = null;

/* The hash of the current existing server.jar file */
String serverHash;
try {
serverHash = Downloader.getHashSHA256(serverFile);
} finally {
}

/* The hash of the server.jar at the time the data was generated. */
String cachedServerHash = null;
try {
cachedServerHash = Files.readString(extractedDataDirectory.resolve("server-sha256"));
} catch (RuntimeException | IOException e) {
}
if (serverHash == null || cachedServerHash == null || !serverHash.equals(cachedServerHash)) {

/* If the cached hash does not exist or does not match the current one, re-generate the data. */
if (cachedServerHash == null || !serverHash.equals(cachedServerHash)) {
log.info("Extracting Minecraft data for version " + version);

FileUtils.deleteDirectory(extractedDataDirectory.toFile());
Expand All @@ -98,6 +107,7 @@ public void generateData() throws Exception {
main.invoke(null, new Object[] { new String[] { "--reports", "--output=" + extractedDataDirectory } });
}

/* Write the hash last. Thus the presence of this file implies the existence of the data. */
Files.writeString(extractedDataDirectory.resolve("server-sha256"), serverHash);
} else {
log.info("Extracted Minecraft data for version " + version + " is up to date");
Expand Down

0 comments on commit 75cb5ea

Please sign in to comment.