some improvements
This commit is contained in:
parent
6277c20e4c
commit
b6a1608e73
@ -67,7 +67,7 @@ public class CreateDistTask extends BaritoneGradleTask {
|
|||||||
Files.write(getRelativeFile("dist/checksums.txt"), shasum);
|
Files.write(getRelativeFile("dist/checksums.txt"), shasum);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String sha1(Path path) {
|
private static synchronized String sha1(Path path) {
|
||||||
try {
|
try {
|
||||||
if (SHA1_DIGEST == null) {
|
if (SHA1_DIGEST == null) {
|
||||||
SHA1_DIGEST = MessageDigest.getInstance("SHA-1");
|
SHA1_DIGEST = MessageDigest.getInstance("SHA-1");
|
||||||
|
@ -79,7 +79,7 @@ public class ProguardTask extends BaritoneGradleTask {
|
|||||||
Files.delete(this.artifactUnoptimizedPath);
|
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 {
|
private void downloadProguard() throws Exception {
|
||||||
@ -197,12 +197,12 @@ public class ProguardTask extends BaritoneGradleTask {
|
|||||||
|
|
||||||
private void proguardApi() throws Exception {
|
private void proguardApi() throws Exception {
|
||||||
runProguard(getTemporaryFile(PROGUARD_API_CONFIG));
|
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 {
|
private void proguardStandalone() throws Exception {
|
||||||
runProguard(getTemporaryFile(PROGUARD_STANDALONE_CONFIG));
|
runProguard(getTemporaryFile(PROGUARD_STANDALONE_CONFIG));
|
||||||
Determinizer.main(this.proguardOut.toString(), this.artifactStandalonePath.toString());
|
Determinizer.determinize(this.proguardOut.toString(), this.artifactStandalonePath.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cleanup() {
|
private void cleanup() {
|
||||||
@ -239,8 +239,8 @@ public class ProguardTask extends BaritoneGradleTask {
|
|||||||
this.printOutputLog(p.getErrorStream());
|
this.printOutputLog(p.getErrorStream());
|
||||||
|
|
||||||
// Halt the current thread until the process is complete, if the exit code isn't 0, throw an exception
|
// Halt the current thread until the process is complete, if the exit code isn't 0, throw an exception
|
||||||
int exitCode;
|
int exitCode = p.waitFor();
|
||||||
if ((exitCode = p.waitFor()) != 0) {
|
if (exitCode != 0) {
|
||||||
throw new Exception("Proguard exited with code " + exitCode);
|
throw new Exception("Proguard exited with code " + exitCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,39 +39,39 @@ import java.util.stream.Collectors;
|
|||||||
*/
|
*/
|
||||||
public class Determinizer {
|
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("Running Determinizer");
|
||||||
System.out.println(" Input path: " + args[0]);
|
System.out.println(" Input path: " + inputPath);
|
||||||
System.out.println(" Output path: " + args[1]);
|
System.out.println(" Output path: " + outputPath);
|
||||||
|
|
||||||
JarFile jarFile = new JarFile(new File(args[0]));
|
try (
|
||||||
JarOutputStream jos = new JarOutputStream(new FileOutputStream(new File(args[1])));
|
JarFile jarFile = new JarFile(new File(inputPath));
|
||||||
|
JarOutputStream jos = new JarOutputStream(new FileOutputStream(new File(outputPath)))
|
||||||
|
) {
|
||||||
|
|
||||||
List<JarEntry> entries = jarFile.stream()
|
List<JarEntry> entries = jarFile.stream()
|
||||||
.sorted(Comparator.comparing(JarEntry::getName))
|
.sorted(Comparator.comparing(JarEntry::getName))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
for (JarEntry entry : entries) {
|
for (JarEntry entry : entries) {
|
||||||
if (entry.getName().equals("META-INF/fml_cache_annotation.json")) {
|
if (entry.getName().equals("META-INF/fml_cache_annotation.json")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (entry.getName().equals("META-INF/fml_cache_class_versions.json")) {
|
if (entry.getName().equals("META-INF/fml_cache_class_versions.json")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
JarEntry clone = new JarEntry(entry.getName());
|
JarEntry clone = new JarEntry(entry.getName());
|
||||||
clone.setTime(42069);
|
clone.setTime(42069);
|
||||||
jos.putNextEntry(clone);
|
jos.putNextEntry(clone);
|
||||||
if (entry.getName().endsWith(".refmap.json")) {
|
if (entry.getName().endsWith(".refmap.json")) {
|
||||||
JsonObject object = new JsonParser().parse(new InputStreamReader(jarFile.getInputStream(entry))).getAsJsonObject();
|
JsonObject object = new JsonParser().parse(new InputStreamReader(jarFile.getInputStream(entry))).getAsJsonObject();
|
||||||
copy(writeSorted(object), jos);
|
jos.write(writeSorted(object).getBytes());
|
||||||
} else {
|
} else {
|
||||||
copy(jarFile.getInputStream(entry), jos);
|
copy(jarFile.getInputStream(entry), jos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
jos.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
jos.finish();
|
|
||||||
jos.close();
|
|
||||||
jarFile.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void copy(InputStream is, OutputStream os) throws IOException {
|
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 {
|
private static String writeSorted(JsonObject in) throws IOException {
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
JsonWriter jw = new JsonWriter(writer);
|
JsonWriter jw = new JsonWriter(writer);
|
||||||
|
Loading…
Reference in New Issue
Block a user