some improvements

This commit is contained in:
leijurv 2018-10-12 21:19:11 -07:00 committed by Leijurv
parent 6277c20e4c
commit b6a1608e73
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
3 changed files with 33 additions and 37 deletions

View File

@ -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");

View File

@ -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);
}
}

View File

@ -39,13 +39,15 @@ 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<JarEntry> entries = jarFile.stream()
.sorted(Comparator.comparing(JarEntry::getName))
@ -63,15 +65,13 @@ public class Determinizer {
jos.putNextEntry(clone);
if (entry.getName().endsWith(".refmap.json")) {
JsonObject object = new JsonParser().parse(new InputStreamReader(jarFile.getInputStream(entry))).getAsJsonObject();
copy(writeSorted(object), jos);
jos.write(writeSorted(object).getBytes());
} else {
copy(jarFile.getInputStream(entry), jos);
}
}
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);