This commit is contained in:
Babbaj 2020-03-25 19:00:26 -04:00
parent db718a1781
commit 592a01f3e4
No known key found for this signature in database
GPG Key ID: 48FD0BEFD63C8E3F
3 changed files with 34 additions and 40 deletions

View File

@ -45,31 +45,30 @@ class BaritoneGradleTask extends DefaultTask {
ARTIFACT_UNOPTIMIZED = "%s-unoptimized-%s.jar",
ARTIFACT_API = "%s-api-%s.jar",
ARTIFACT_STANDALONE = "%s-standalone-%s.jar",
ARTIFACT_FORGE_API = "%s-api-forge-%s.jar";
// TODO: forge standalone
ARTIFACT_FORGE_UNOPTIMIZED = "%s-unoptimized-forge-%s.jar",
ARTIFACT_FORGE_API = "%s-api-forge-%s.jar",
ARTIFACT_FORGE_STANDALONE = "%s-standalone-forge-%s.jar";
protected String artifactName, artifactVersion;
protected final Path
artifactPath, artifactUnoptimizedPath,
// processed by proguard
artifactApiPath, artifactStandalonePath,
artifactPath,
artifactUnoptimizedPath, artifactApiPath, artifactStandalonePath, // these are different for forge builds
proguardOut;
protected final Path artifactForgeApiPath;
{
public BaritoneGradleTask() {
this.artifactName = getProject().getName();
this.artifactVersion = getProject().getVersion().toString();
this.artifactPath = this.getBuildFile(formatVersion(ARTIFACT_STANDARD));
this.artifactUnoptimizedPath = this.getBuildFile(formatVersion(ARTIFACT_UNOPTIMIZED));
// just make it null if its not used lol
if (getProject().hasProperty("baritone.forge_build")) {
this.artifactForgeApiPath = this.getBuildFile(formatVersion(ARTIFACT_FORGE_API));
this.artifactApiPath = null;
this.artifactStandalonePath = null;
this.artifactUnoptimizedPath = this.getBuildFile(formatVersion(ARTIFACT_FORGE_UNOPTIMIZED));
this.artifactApiPath = this.getBuildFile(formatVersion(ARTIFACT_FORGE_API));
this.artifactStandalonePath = this.getBuildFile(formatVersion(ARTIFACT_FORGE_STANDALONE));
} else {
this.artifactForgeApiPath = null;
this.artifactApiPath = this.getBuildFile(formatVersion(ARTIFACT_API));
this.artifactStandalonePath = this.getBuildFile(formatVersion(ARTIFACT_STANDALONE));
this.artifactUnoptimizedPath = this.getBuildFile(formatVersion(ARTIFACT_UNOPTIMIZED));
this.artifactApiPath = this.getBuildFile(formatVersion(ARTIFACT_API));
this.artifactStandalonePath = this.getBuildFile(formatVersion(ARTIFACT_STANDALONE));
}
this.proguardOut = this.getTemporaryFile(PROGUARD_EXPORT_PATH);

View File

@ -42,10 +42,9 @@ public class CreateDistTask extends BaritoneGradleTask {
super.verifyArtifacts();
// Define the distribution file paths
Path api = getRelativeFile("dist/" + formatVersion(ARTIFACT_API));
Path standalone = getRelativeFile("dist/" + formatVersion(ARTIFACT_STANDALONE));
Path unoptimized = getRelativeFile("dist/" + formatVersion(ARTIFACT_UNOPTIMIZED));
Path forgeApi = getRelativeFile("dist/" + formatVersion(ARTIFACT_FORGE_API));
Path api = getRelativeFile("dist/" + getFileName(artifactApiPath));
Path standalone = getRelativeFile("dist/" + getFileName(artifactStandalonePath));
Path unoptimized = getRelativeFile("dist/" + getFileName(artifactUnoptimizedPath));
// NIO will not automatically create directories
Path dir = getRelativeFile("dist/");
@ -54,18 +53,15 @@ public class CreateDistTask extends BaritoneGradleTask {
}
// Copy build jars to dist/
if (getProject().hasProperty("baritone.forge_build")) {
Files.copy(this.artifactForgeApiPath, forgeApi, REPLACE_EXISTING);
} else {
Files.copy(this.artifactApiPath, api, REPLACE_EXISTING);
Files.copy(this.artifactStandalonePath, standalone, REPLACE_EXISTING);
Files.copy(this.artifactUnoptimizedPath, unoptimized, REPLACE_EXISTING);
}
// TODO: dont copy files that dont exist
Files.copy(this.artifactApiPath, api, REPLACE_EXISTING);
Files.copy(this.artifactStandalonePath, standalone, REPLACE_EXISTING);
Files.copy(this.artifactUnoptimizedPath, unoptimized, REPLACE_EXISTING);
// Calculate all checksums and format them like "shasum"
List<String> shasum = Stream.of(forgeApi, api, standalone, unoptimized)
.filter(f -> false) // TODO: dont sha nonexistant artifacts
// TODO: get the hash for both forge and non forge jars
List<String> shasum = Stream.of(api, standalone, unoptimized)
.filter(Files::exists)
.map(path -> sha1(path) + " " + path.getFileName().toString())
.collect(Collectors.toList());
@ -75,6 +71,10 @@ public class CreateDistTask extends BaritoneGradleTask {
Files.write(getRelativeFile("dist/checksums.txt"), shasum);
}
private static String getFileName(Path p) {
return p.getFileName().toString();
}
private static synchronized String sha1(Path path) {
try {
if (SHA1_DIGEST == null) {

View File

@ -56,12 +56,8 @@ public class ProguardTask extends BaritoneGradleTask {
downloadProguard();
extractProguard();
generateConfigs();
if (getProject().hasProperty("baritone.forge_build")) {
proguardApi(this.artifactForgeApiPath.toString());
} else {
proguardApi(this.artifactApiPath.toString());
proguardStandalone(this.artifactStandalonePath.toString());
}
proguardApi();
proguardStandalone();
cleanup();
}
@ -142,17 +138,16 @@ public class ProguardTask extends BaritoneGradleTask {
return getProject().getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().findByName("launch").getRuntimeClasspath().getFiles()
.stream()
.filter(File::isFile);
//.peek(f -> System.out.println("xd: " + f));
}
private void proguardApi(String artifact) throws Exception {
private void proguardApi() throws Exception {
runProguard(getTemporaryFile(PROGUARD_API_CONFIG));
Determinizer.determinize(this.proguardOut.toString(), artifact);
Determinizer.determinize(this.proguardOut.toString(), this.artifactApiPath.toString());
}
private void proguardStandalone(String artifact) throws Exception {
private void proguardStandalone() throws Exception {
runProguard(getTemporaryFile(PROGUARD_STANDALONE_CONFIG));
Determinizer.determinize(this.proguardOut.toString(), artifact);
Determinizer.determinize(this.proguardOut.toString(), this.artifactStandalonePath.toString());
}
private void cleanup() {