rework buildscript (part 1)

This commit is contained in:
Wagyourtail
2022-04-02 21:36:18 -07:00
parent f3c93855bb
commit 01c75db38a
16 changed files with 431 additions and 185 deletions

View File

@@ -18,6 +18,7 @@
package baritone.gradle.task;
import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.Input;
import java.io.File;
import java.io.IOException;
@@ -59,7 +60,7 @@ class BaritoneGradleTask extends DefaultTask {
proguardOut;
public BaritoneGradleTask() {
this.artifactName = getProject().getName();
this.artifactName = getProject().getProperties().get("archivesBaseName").toString();
this.artifactVersion = getProject().getVersion().toString();
this.artifactPath = this.getBuildFile(formatVersion(ARTIFACT_STANDARD));
@@ -102,6 +103,10 @@ class BaritoneGradleTask extends DefaultTask {
return Paths.get(new File(new File(getProject().getBuildDir(), "../"), file).getAbsolutePath());
}
protected Path getRootRelativeFile(String file) {
return Paths.get(new File(new File(getProject().getRootProject().getBuildDir(), "../"), file).getAbsolutePath());
}
protected Path getTemporaryFile(String file) {
return Paths.get(new File(getTemporaryDir(), file).getAbsolutePath());
}

View File

@@ -42,12 +42,12 @@ public class CreateDistTask extends BaritoneGradleTask {
super.verifyArtifacts();
// Define the distribution file paths
Path api = getRelativeFile("dist/" + getFileName(artifactApiPath));
Path standalone = getRelativeFile("dist/" + getFileName(artifactStandalonePath));
Path unoptimized = getRelativeFile("dist/" + getFileName(artifactUnoptimizedPath));
Path api = getRootRelativeFile("dist/" + getFileName(artifactApiPath));
Path standalone = getRootRelativeFile("dist/" + getFileName(artifactStandalonePath));
Path unoptimized = getRootRelativeFile("dist/" + getFileName(artifactUnoptimizedPath));
// NIO will not automatically create directories
Path dir = getRelativeFile("dist/");
Path dir = getRootRelativeFile("dist/");
if (!Files.exists(dir)) {
Files.createDirectory(dir);
}
@@ -67,7 +67,7 @@ public class CreateDistTask extends BaritoneGradleTask {
shasum.forEach(System.out::println);
// Write the checksums to a file
Files.write(getRelativeFile("dist/checksums.txt"), shasum);
Files.write(getRootRelativeFile("dist/checksums.txt"), shasum);
}
private static String getFileName(Path p) {
@@ -76,15 +76,15 @@ public class CreateDistTask extends BaritoneGradleTask {
private List<Path> getAllDistJars() {
return Arrays.asList(
getRelativeFile("dist/" + formatVersion(ARTIFACT_API)),
getRelativeFile("dist/" + formatVersion(ARTIFACT_FABRIC_API)),
getRelativeFile("dist/" + formatVersion(ARTIFACT_FORGE_API)),
getRelativeFile("dist/" + formatVersion(ARTIFACT_STANDALONE)),
getRelativeFile("dist/" + formatVersion(ARTIFACT_FABRIC_STANDALONE)),
getRelativeFile("dist/" + formatVersion(ARTIFACT_FORGE_STANDALONE)),
getRelativeFile("dist/" + formatVersion(ARTIFACT_UNOPTIMIZED)),
getRelativeFile("dist/" + formatVersion(ARTIFACT_FABRIC_UNOPTIMIZED)),
getRelativeFile("dist/" + formatVersion(ARTIFACT_FORGE_UNOPTIMIZED))
getRootRelativeFile("dist/" + formatVersion(ARTIFACT_API)),
getRootRelativeFile("dist/" + formatVersion(ARTIFACT_FABRIC_API)),
getRootRelativeFile("dist/" + formatVersion(ARTIFACT_FORGE_API)),
getRootRelativeFile("dist/" + formatVersion(ARTIFACT_STANDALONE)),
getRootRelativeFile("dist/" + formatVersion(ARTIFACT_FABRIC_STANDALONE)),
getRootRelativeFile("dist/" + formatVersion(ARTIFACT_FORGE_STANDALONE)),
getRootRelativeFile("dist/" + formatVersion(ARTIFACT_UNOPTIMIZED)),
getRootRelativeFile("dist/" + formatVersion(ARTIFACT_FABRIC_UNOPTIMIZED)),
getRootRelativeFile("dist/" + formatVersion(ARTIFACT_FORGE_UNOPTIMIZED))
);
}

View File

@@ -86,11 +86,11 @@ public class ProguardTask extends BaritoneGradleTask {
}
private boolean isMcJar(File f) {
return f.getName().startsWith(compType.equals("FORGE") ? "forge-" : "minecraft-") && f.getName().contains("minecraft-mapped");
return f.getName().startsWith(compType.equals("FORGE") ? "forge-" : "minecraft-") && f.getName().contains("minecraft-merged-named");
}
private void copyMcJar() throws IOException {
File mcClientJar = this.getProject().getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().findByName("launch").getRuntimeClasspath().getFiles()
File mcClientJar = this.getProject().getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().findByName("main").getRuntimeClasspath().getFiles()
.stream()
.filter(this::isMcJar)
.map(f -> {
@@ -98,9 +98,9 @@ public class ProguardTask extends BaritoneGradleTask {
case "OFFICIAL":
return new File(f.getParentFile().getParentFile(), "minecraft-merged.jar");
case "FABRIC":
return new File(f.getParentFile(), "minecraft-intermediary.jar");
return new File(f.getParentFile().getParentFile(), "minecraft-merged-intermediary.jar");
case "FORGE":
return new File(f.getParentFile(), "minecraft-srg.jar");
return new File(f.getParentFile().getParentFile(), f.getName().replace("-named.jar", "-srg.jar"));
}
return null;
})
@@ -233,7 +233,7 @@ public class ProguardTask extends BaritoneGradleTask {
}
private void generateConfigs() throws Exception {
Files.copy(getRelativeFile(PROGUARD_CONFIG_TEMPLATE), getTemporaryFile(PROGUARD_CONFIG_DEST), REPLACE_EXISTING);
Files.copy(getRootRelativeFile(PROGUARD_CONFIG_TEMPLATE), getTemporaryFile(PROGUARD_CONFIG_DEST), REPLACE_EXISTING);
// Setup the template that will be used to derive the API and Standalone configs
List<String> template = Files.readAllLines(getTemporaryFile(PROGUARD_CONFIG_DEST));
@@ -268,12 +268,8 @@ public class ProguardTask extends BaritoneGradleTask {
Files.write(getTemporaryFile(PROGUARD_STANDALONE_CONFIG), standalone);
}
private File getSrgMcJar() {
return getProject().getTasks().findByName("copyMcJar").getOutputs().getFiles().getSingleFile();
}
private Stream<File> acquireDependencies() {
return getProject().getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().findByName("launch").getRuntimeClasspath().getFiles()
return getProject().getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().findByName("main").getRuntimeClasspath().getFiles()
.stream()
.filter(File::isFile);
}