This commit is contained in:
Leijurv 2019-02-04 19:34:44 -08:00
parent b55e449398
commit dfe171a5c2
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
4 changed files with 39 additions and 12 deletions

View File

@ -52,10 +52,11 @@ class BaritoneGradleTask extends DefaultTask {
ARTIFACT_STANDARD = "%s-%s.jar", ARTIFACT_STANDARD = "%s-%s.jar",
ARTIFACT_UNOPTIMIZED = "%s-unoptimized-%s.jar", ARTIFACT_UNOPTIMIZED = "%s-unoptimized-%s.jar",
ARTIFACT_API = "%s-api-%s.jar", ARTIFACT_API = "%s-api-%s.jar",
ARTIFACT_STANDALONE = "%s-standalone-%s.jar"; ARTIFACT_STANDALONE = "%s-standalone-%s.jar",
ARTIFACT_FORGE = "%s-forge-%s.jar";
protected String artifactName, artifactVersion; protected String artifactName, artifactVersion;
protected Path artifactPath, artifactUnoptimizedPath, artifactApiPath, artifactStandalonePath, proguardOut; protected Path artifactPath, artifactUnoptimizedPath, artifactApiPath, artifactStandalonePath, artifactForgePath, proguardOut;
protected void verifyArtifacts() throws IllegalStateException { protected void verifyArtifacts() throws IllegalStateException {
this.artifactName = getProject().getName(); this.artifactName = getProject().getName();
@ -65,6 +66,7 @@ class BaritoneGradleTask extends DefaultTask {
this.artifactUnoptimizedPath = this.getBuildFile(formatVersion(ARTIFACT_UNOPTIMIZED)); this.artifactUnoptimizedPath = this.getBuildFile(formatVersion(ARTIFACT_UNOPTIMIZED));
this.artifactApiPath = this.getBuildFile(formatVersion(ARTIFACT_API)); this.artifactApiPath = this.getBuildFile(formatVersion(ARTIFACT_API));
this.artifactStandalonePath = this.getBuildFile(formatVersion(ARTIFACT_STANDALONE)); this.artifactStandalonePath = this.getBuildFile(formatVersion(ARTIFACT_STANDALONE));
this.artifactForgePath = this.getBuildFile(formatVersion(ARTIFACT_FORGE));
this.proguardOut = this.getTemporaryFile(PROGUARD_EXPORT_PATH); this.proguardOut = this.getTemporaryFile(PROGUARD_EXPORT_PATH);

View File

@ -45,6 +45,7 @@ public class CreateDistTask extends BaritoneGradleTask {
Path api = getRelativeFile("dist/" + formatVersion(ARTIFACT_API)); Path api = getRelativeFile("dist/" + formatVersion(ARTIFACT_API));
Path standalone = getRelativeFile("dist/" + formatVersion(ARTIFACT_STANDALONE)); Path standalone = getRelativeFile("dist/" + formatVersion(ARTIFACT_STANDALONE));
Path unoptimized = getRelativeFile("dist/" + formatVersion(ARTIFACT_UNOPTIMIZED)); Path unoptimized = getRelativeFile("dist/" + formatVersion(ARTIFACT_UNOPTIMIZED));
Path forge = getRelativeFile("dist/" + formatVersion(ARTIFACT_FORGE));
// NIO will not automatically create directories // NIO will not automatically create directories
Path dir = getRelativeFile("dist/"); Path dir = getRelativeFile("dist/");
@ -56,9 +57,10 @@ public class CreateDistTask extends BaritoneGradleTask {
Files.copy(this.artifactApiPath, api, REPLACE_EXISTING); Files.copy(this.artifactApiPath, api, REPLACE_EXISTING);
Files.copy(this.artifactStandalonePath, standalone, REPLACE_EXISTING); Files.copy(this.artifactStandalonePath, standalone, REPLACE_EXISTING);
Files.copy(this.artifactUnoptimizedPath, unoptimized, REPLACE_EXISTING); Files.copy(this.artifactUnoptimizedPath, unoptimized, REPLACE_EXISTING);
Files.copy(this.artifactForgePath, forge, REPLACE_EXISTING);
// Calculate all checksums and format them like "shasum" // Calculate all checksums and format them like "shasum"
List<String> shasum = Stream.of(api, standalone, unoptimized) List<String> shasum = Stream.of(api, standalone, unoptimized, forge)
.map(path -> sha1(path) + " " + path.getFileName().toString()) .map(path -> sha1(path) + " " + path.getFileName().toString())
.collect(Collectors.toList()); .collect(Collectors.toList());

View File

@ -59,6 +59,8 @@ public class ProguardTask extends BaritoneGradleTask {
private List<String> requiredLibraries; private List<String> requiredLibraries;
private File mixin;
@TaskAction @TaskAction
protected void exec() throws Exception { protected void exec() throws Exception {
super.verifyArtifacts(); super.verifyArtifacts();
@ -71,6 +73,7 @@ public class ProguardTask extends BaritoneGradleTask {
acquireDependencies(); acquireDependencies();
proguardApi(); proguardApi();
proguardStandalone(); proguardStandalone();
createForge();
cleanup(); cleanup();
} }
@ -79,7 +82,7 @@ public class ProguardTask extends BaritoneGradleTask {
Files.delete(this.artifactUnoptimizedPath); Files.delete(this.artifactUnoptimizedPath);
} }
Determinizer.determinize(this.artifactPath.toString(), this.artifactUnoptimizedPath.toString()); Determinizer.determinize(this.artifactPath.toString(), this.artifactUnoptimizedPath.toString(), Optional.empty());
} }
private void downloadProguard() throws Exception { private void downloadProguard() throws Exception {
@ -173,10 +176,18 @@ public class ProguardTask extends BaritoneGradleTask {
// Find the library jar file, and copy it to tempLibraries // Find the library jar file, and copy it to tempLibraries
for (File file : pair.getLeft().files(pair.getRight())) { for (File file : pair.getLeft().files(pair.getRight())) {
if (file.getName().startsWith(lib)) { if (file.getName().startsWith(lib)) {
System.out.println(lib);
if (lib.contains("mixin")) {
mixin = file;
}
Files.copy(file.toPath(), getTemporaryFile("tempLibraries/" + lib + ".jar"), REPLACE_EXISTING); Files.copy(file.toPath(), getTemporaryFile("tempLibraries/" + lib + ".jar"), REPLACE_EXISTING);
} }
} }
} }
if (mixin == null) {
throw new IllegalStateException("Unable to find mixin jar");
}
} }
// a bunch of epic stuff to get the path to the cached jar // a bunch of epic stuff to get the path to the cached jar
@ -264,12 +275,16 @@ 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.determinize(this.proguardOut.toString(), this.artifactApiPath.toString()); Determinizer.determinize(this.proguardOut.toString(), this.artifactApiPath.toString(), Optional.empty());
} }
private void proguardStandalone() throws Exception { private void proguardStandalone() throws Exception {
runProguard(getTemporaryFile(PROGUARD_STANDALONE_CONFIG)); runProguard(getTemporaryFile(PROGUARD_STANDALONE_CONFIG));
Determinizer.determinize(this.proguardOut.toString(), this.artifactStandalonePath.toString()); Determinizer.determinize(this.proguardOut.toString(), this.artifactStandalonePath.toString(), Optional.empty());
}
private void createForge() throws Exception {
Determinizer.determinize(this.proguardOut.toString(), this.artifactForgePath.toString(), Optional.of(mixin));
} }
private void cleanup() { private void cleanup() {

View File

@ -22,10 +22,7 @@ import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter; import com.google.gson.stream.JsonWriter;
import java.io.*; import java.io.*;
import java.util.ArrayList; import java.util.*;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import java.util.jar.JarOutputStream; import java.util.jar.JarOutputStream;
@ -39,7 +36,7 @@ import java.util.stream.Collectors;
*/ */
public class Determinizer { public class Determinizer {
public static void determinize(String inputPath, String outputPath) throws IOException { public static void determinize(String inputPath, String outputPath, Optional<File> toInclude) throws IOException {
System.out.println("Running Determinizer"); System.out.println("Running Determinizer");
System.out.println(" Input path: " + inputPath); System.out.println(" Input path: " + inputPath);
System.out.println(" Output path: " + outputPath); System.out.println(" Output path: " + outputPath);
@ -66,7 +63,7 @@ public class Determinizer {
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();
jos.write(writeSorted(object).getBytes()); jos.write(writeSorted(object).getBytes());
} else if (entry.getName().equals("META-INF/MANIFEST.MF")) { } else if (entry.getName().equals("META-INF/MANIFEST.MF") && toInclude.isPresent()) { // only replace for forge jar
ByteArrayOutputStream cancer = new ByteArrayOutputStream(); ByteArrayOutputStream cancer = new ByteArrayOutputStream();
copy(jarFile.getInputStream(entry), cancer); copy(jarFile.getInputStream(entry), cancer);
String manifest = new String(cancer.toByteArray()); String manifest = new String(cancer.toByteArray());
@ -79,6 +76,17 @@ public class Determinizer {
copy(jarFile.getInputStream(entry), jos); copy(jarFile.getInputStream(entry), jos);
} }
} }
if (toInclude.isPresent()) {
try (JarFile mixin = new JarFile(toInclude.get())) {
for (JarEntry entry : mixin.stream().sorted(Comparator.comparing(JarEntry::getName)).collect(Collectors.toList())) {
if (entry.getName().startsWith("META-INF") && !entry.getName().startsWith("META-INF/services")) {
continue;
}
jos.putNextEntry(entry);
copy(mixin.getInputStream(entry), jos);
}
}
}
jos.finish(); jos.finish();
} }
} }