From b6a1608e739e9ff10f6cee313cf3f81ec5b11d60 Mon Sep 17 00:00:00 2001 From: leijurv Date: Fri, 12 Oct 2018 21:19:11 -0700 Subject: [PATCH] some improvements --- .../baritone/gradle/task/CreateDistTask.java | 2 +- .../baritone/gradle/task/ProguardTask.java | 10 ++-- .../baritone/gradle/util/Determinizer.java | 58 +++++++++---------- 3 files changed, 33 insertions(+), 37 deletions(-) diff --git a/buildSrc/src/main/java/baritone/gradle/task/CreateDistTask.java b/buildSrc/src/main/java/baritone/gradle/task/CreateDistTask.java index f0d3e547..1b8f1aa5 100644 --- a/buildSrc/src/main/java/baritone/gradle/task/CreateDistTask.java +++ b/buildSrc/src/main/java/baritone/gradle/task/CreateDistTask.java @@ -67,7 +67,7 @@ public class CreateDistTask extends BaritoneGradleTask { Files.write(getRelativeFile("dist/checksums.txt"), shasum); } - private static String sha1(Path path) { + private static synchronized String sha1(Path path) { try { if (SHA1_DIGEST == null) { SHA1_DIGEST = MessageDigest.getInstance("SHA-1"); diff --git a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java index ad0db8cc..06af0011 100644 --- a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java +++ b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java @@ -79,7 +79,7 @@ public class ProguardTask extends BaritoneGradleTask { Files.delete(this.artifactUnoptimizedPath); } - Determinizer.main(this.artifactPath.toString(), this.artifactUnoptimizedPath.toString()); + Determinizer.determinize(this.artifactPath.toString(), this.artifactUnoptimizedPath.toString()); } private void downloadProguard() throws Exception { @@ -197,12 +197,12 @@ public class ProguardTask extends BaritoneGradleTask { private void proguardApi() throws Exception { runProguard(getTemporaryFile(PROGUARD_API_CONFIG)); - Determinizer.main(this.proguardOut.toString(), this.artifactApiPath.toString()); + Determinizer.determinize(this.proguardOut.toString(), this.artifactApiPath.toString()); } private void proguardStandalone() throws Exception { runProguard(getTemporaryFile(PROGUARD_STANDALONE_CONFIG)); - Determinizer.main(this.proguardOut.toString(), this.artifactStandalonePath.toString()); + Determinizer.determinize(this.proguardOut.toString(), this.artifactStandalonePath.toString()); } private void cleanup() { @@ -239,8 +239,8 @@ public class ProguardTask extends BaritoneGradleTask { this.printOutputLog(p.getErrorStream()); // Halt the current thread until the process is complete, if the exit code isn't 0, throw an exception - int exitCode; - if ((exitCode = p.waitFor()) != 0) { + int exitCode = p.waitFor(); + if (exitCode != 0) { throw new Exception("Proguard exited with code " + exitCode); } } diff --git a/buildSrc/src/main/java/baritone/gradle/util/Determinizer.java b/buildSrc/src/main/java/baritone/gradle/util/Determinizer.java index f08649d2..d50c1e54 100644 --- a/buildSrc/src/main/java/baritone/gradle/util/Determinizer.java +++ b/buildSrc/src/main/java/baritone/gradle/util/Determinizer.java @@ -39,39 +39,39 @@ import java.util.stream.Collectors; */ public class Determinizer { - public static void main(String... args) throws IOException { + public static void determinize(String inputPath, String outputPath) throws IOException { System.out.println("Running Determinizer"); - System.out.println(" Input path: " + args[0]); - System.out.println(" Output path: " + args[1]); + System.out.println(" Input path: " + inputPath); + System.out.println(" Output path: " + outputPath); - JarFile jarFile = new JarFile(new File(args[0])); - JarOutputStream jos = new JarOutputStream(new FileOutputStream(new File(args[1]))); + try ( + JarFile jarFile = new JarFile(new File(inputPath)); + JarOutputStream jos = new JarOutputStream(new FileOutputStream(new File(outputPath))) + ) { - List entries = jarFile.stream() - .sorted(Comparator.comparing(JarEntry::getName)) - .collect(Collectors.toList()); + List entries = jarFile.stream() + .sorted(Comparator.comparing(JarEntry::getName)) + .collect(Collectors.toList()); - for (JarEntry entry : entries) { - if (entry.getName().equals("META-INF/fml_cache_annotation.json")) { - continue; - } - if (entry.getName().equals("META-INF/fml_cache_class_versions.json")) { - continue; - } - JarEntry clone = new JarEntry(entry.getName()); - clone.setTime(42069); - jos.putNextEntry(clone); - if (entry.getName().endsWith(".refmap.json")) { - JsonObject object = new JsonParser().parse(new InputStreamReader(jarFile.getInputStream(entry))).getAsJsonObject(); - copy(writeSorted(object), jos); - } else { - copy(jarFile.getInputStream(entry), jos); + for (JarEntry entry : entries) { + if (entry.getName().equals("META-INF/fml_cache_annotation.json")) { + continue; + } + if (entry.getName().equals("META-INF/fml_cache_class_versions.json")) { + continue; + } + JarEntry clone = new JarEntry(entry.getName()); + clone.setTime(42069); + jos.putNextEntry(clone); + if (entry.getName().endsWith(".refmap.json")) { + JsonObject object = new JsonParser().parse(new InputStreamReader(jarFile.getInputStream(entry))).getAsJsonObject(); + jos.write(writeSorted(object).getBytes()); + } else { + copy(jarFile.getInputStream(entry), jos); + } } + jos.finish(); } - - jos.finish(); - jos.close(); - jarFile.close(); } private static void copy(InputStream is, OutputStream os) throws IOException { @@ -82,10 +82,6 @@ public class Determinizer { } } - private static void copy(String s, OutputStream os) throws IOException { - os.write(s.getBytes()); - } - private static String writeSorted(JsonObject in) throws IOException { StringWriter writer = new StringWriter(); JsonWriter jw = new JsonWriter(writer);