diff --git a/build.gradle b/build.gradle index b139b8438..6076c5850 100755 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,6 @@ +import baritone.gradle.task.CreateDistTask +import baritone.gradle.task.ProguardTask + /* * This file is part of Baritone. * @@ -135,4 +138,45 @@ javadoc { options.encoding "UTF-8" // allow emoji in comments :^) source = sourceSets.api.allJava classpath += sourceSets.api.compileClasspath +} + + +task removeChecksum { + doLast { + delete "$rootDir/dist/checksums.txt" + } +} + +subprojects { + task proguard(type: ProguardTask, dependsOn: remapJar) { + url 'https://github.com/Guardsquare/proguard/releases/download/v7.2.1/proguard-7.2.1.zip' + extract 'proguard-7.2.1/lib/proguard.jar' + compType project.name + artifactPath = remapJar.archiveFile + } + + task createDist(type: CreateDistTask, dependsOn: proguard) { + compType project.name == "tweaker" ? null : project.name + artifactApiPath = proguard.artifactApiPath + artifactStandalonePath = proguard.artifactStandalonePath + artifactUnoptimizedPath = proguard.artifactUnoptimizedPath + } + + build.finalizedBy(createDist) + + publishing { + publications { + mavenFabric(MavenPublication) { + artifactId = rootProject.archives_base_name + "-" + project.name + from components.java + } + } + + // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. + repositories { + // Add repositories to publish to here. + } + } + + createDist.dependsOn(removeChecksum) } \ No newline at end of file diff --git a/buildSrc/src/main/java/baritone/gradle/task/BaritoneGradleTask.java b/buildSrc/src/main/java/baritone/gradle/task/BaritoneGradleTask.java index 2dad551f2..9c5a1d305 100644 --- a/buildSrc/src/main/java/baritone/gradle/task/BaritoneGradleTask.java +++ b/buildSrc/src/main/java/baritone/gradle/task/BaritoneGradleTask.java @@ -20,6 +20,7 @@ import org.gradle.api.DefaultTask; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.Optional; +import org.gradle.api.tasks.OutputFile; import org.gradle.api.tasks.TaskAction; import java.io.File; @@ -51,10 +52,6 @@ class BaritoneGradleTask extends DefaultTask { ARTIFACT_STANDALONE = "%s-standalone-%s.jar"; protected String artifactName, artifactVersion; - protected Path - artifactPath, - artifactUnoptimizedPath, artifactApiPath, artifactStandalonePath, // these are different for forge builds - proguardOut; @Input @@ -80,20 +77,6 @@ public void doFirst() { } else { this.artifactVersion = getProject().getVersion().toString(); } - - this.artifactPath = this.getBuildFile(formatVersion(ARTIFACT_STANDARD)); - - 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); - } - - protected void verifyArtifacts() throws IllegalStateException { - if (!Files.exists(this.artifactPath)) { - throw new IllegalStateException("Artifact not found! Run build first! Missing file: " + this.artifactPath); - } } protected void write(InputStream stream, Path file) throws IOException { diff --git a/buildSrc/src/main/java/baritone/gradle/task/CreateDistTask.java b/buildSrc/src/main/java/baritone/gradle/task/CreateDistTask.java index 48cd0a72a..50b2f812b 100644 --- a/buildSrc/src/main/java/baritone/gradle/task/CreateDistTask.java +++ b/buildSrc/src/main/java/baritone/gradle/task/CreateDistTask.java @@ -17,6 +17,9 @@ package baritone.gradle.task; +import baritone.gradle.util.Determinizer; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.tasks.InputFile; import org.gradle.api.tasks.TaskAction; import java.nio.charset.StandardCharsets; @@ -28,6 +31,7 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; +import java.util.stream.Stream; import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; @@ -35,19 +39,27 @@ * @author Brady * @since 10/12/2018 */ -public class CreateDistTask extends BaritoneGradleTask { +public abstract class CreateDistTask extends BaritoneGradleTask { private static MessageDigest SHA1_DIGEST; + @InputFile + abstract public RegularFileProperty getArtifactApiPath(); + + @InputFile + abstract public RegularFileProperty getArtifactStandalonePath(); + + @InputFile + abstract public RegularFileProperty getArtifactUnoptimizedPath(); + @TaskAction protected void exec() throws Exception { super.doFirst(); - super.verifyArtifacts(); // Define the distribution file paths - Path api = getRootRelativeFile("dist/" + getFileName(artifactApiPath)); - Path standalone = getRootRelativeFile("dist/" + getFileName(artifactStandalonePath)); - Path unoptimized = getRootRelativeFile("dist/" + getFileName(artifactUnoptimizedPath)); + Path api = getRootRelativeFile("dist/" + getFileName(getArtifactApiPath().get().getAsFile().toPath())); + Path standalone = getRootRelativeFile("dist/" + getFileName(getArtifactStandalonePath().get().getAsFile().toPath())); + Path unoptimized = getRootRelativeFile("dist/" + getFileName(getArtifactUnoptimizedPath().get().getAsFile().toPath())); // NIO will not automatically create directories Path dir = getRootRelativeFile("dist/"); @@ -57,12 +69,12 @@ protected void exec() throws Exception { // Copy build jars to dist/ // 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); + Files.copy(getArtifactApiPath().get().getAsFile().toPath(), api, REPLACE_EXISTING); + Files.copy(getArtifactStandalonePath().get().getAsFile().toPath(), standalone, REPLACE_EXISTING); + Files.copy(getArtifactUnoptimizedPath().get().getAsFile().toPath(), unoptimized, REPLACE_EXISTING); // Calculate all checksums and format them like "shasum" - List shasum = Files.list(getRootRelativeFile("dist/")) + List shasum = Stream.of(getArtifactApiPath().get().getAsFile().toPath(), getArtifactStandalonePath().get().getAsFile().toPath(), getArtifactUnoptimizedPath().get().getAsFile().toPath()) .filter(e -> e.getFileName().toString().endsWith(".jar")) .map(path -> sha1(path) + " " + path.getFileName().toString()) .collect(Collectors.toList()); @@ -70,7 +82,7 @@ protected void exec() throws Exception { shasum.forEach(System.out::println); // Write the checksums to a file - Files.write(getRootRelativeFile("dist/checksums.txt"), shasum); + Files.write(getRootRelativeFile("dist/checksums.txt"), shasum, StandardOpenOption.CREATE, StandardOpenOption.APPEND); } private static String getFileName(Path p) { diff --git a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java index 52d1d93dc..19c2fb7da 100644 --- a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java +++ b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java @@ -18,11 +18,12 @@ package baritone.gradle.task; import baritone.gradle.util.Determinizer; +import groovy.lang.Closure; import org.apache.commons.io.IOUtils; +import org.gradle.api.Task; +import org.gradle.api.file.RegularFileProperty; import org.gradle.api.plugins.JavaPluginConvention; -import org.gradle.api.tasks.Input; -import org.gradle.api.tasks.TaskAction; -import org.gradle.api.tasks.TaskCollection; +import org.gradle.api.tasks.*; import org.gradle.api.tasks.compile.ForkOptions; import org.gradle.api.tasks.compile.JavaCompile; import org.gradle.internal.jvm.Jvm; @@ -47,7 +48,7 @@ * @author Brady * @since 10/11/2018 */ -public class ProguardTask extends BaritoneGradleTask { +public abstract class ProguardTask extends BaritoneGradleTask { @Input private String url; @@ -63,11 +64,37 @@ public String getExtract() { return extract; } - @TaskAction - protected void exec() throws Exception { + @InputFile + abstract public RegularFileProperty getArtifactPath(); + + @OutputFile + @Optional + abstract public RegularFileProperty getArtifactUnoptimizedPath(); + + @OutputFile + @Optional + abstract public RegularFileProperty getArtifactApiPath(); + + @OutputFile + @Optional + abstract public RegularFileProperty getArtifactStandalonePath(); + + protected Path proguardOut; + + @Override + public Task configure(Closure closure) { super.doFirst(); - super.verifyArtifacts(); + getArtifactUnoptimizedPath().fileValue(this.getBuildFile(formatVersion(ARTIFACT_UNOPTIMIZED)).toFile()); + getArtifactApiPath().fileValue(this.getBuildFile(formatVersion(ARTIFACT_API)).toFile()); + getArtifactStandalonePath().fileValue(this.getBuildFile(formatVersion(ARTIFACT_STANDALONE)).toFile()); + + return super.configure(closure); + } + + @TaskAction + protected void exec() throws Exception { + this.proguardOut = this.getTemporaryFile(PROGUARD_EXPORT_PATH); // "Haha brady why don't you make separate tasks" processArtifact(); downloadProguard(); @@ -78,6 +105,14 @@ protected void exec() throws Exception { cleanup(); } + private void processArtifact() throws Exception { + if (Files.exists(getArtifactUnoptimizedPath().getAsFile().get().toPath())) { + Files.delete(getArtifactUnoptimizedPath().getAsFile().get().toPath()); + } + + Determinizer.determinize(this.getArtifactPath().get().toString(), getArtifactUnoptimizedPath().getAsFile().get().toString()); + } + MinecraftProvider provider = this.getProject().getExtensions().getByType(MinecraftProvider.class); private File getMcJar() { @@ -88,14 +123,6 @@ private boolean isMcJar(File f) { return this.getProject().getConfigurations().getByName(Constants.MINECRAFT_COMBINED_PROVIDER).getFiles().contains(f); } - private void processArtifact() throws Exception { - if (Files.exists(this.artifactUnoptimizedPath)) { - Files.delete(this.artifactUnoptimizedPath); - } - - Determinizer.determinize(this.artifactPath.toString(), this.artifactUnoptimizedPath.toString()); - } - private void downloadProguard() throws Exception { Path proguardZip = getTemporaryFile(PROGUARD_ZIP); if (!Files.exists(proguardZip)) { @@ -214,7 +241,7 @@ private void generateConfigs() throws Exception { // Setup the template that will be used to derive the API and Standalone configs List template = Files.readAllLines(getTemporaryFile(PROGUARD_CONFIG_DEST)); - template.add(0, "-injars '" + this.artifactPath.toString() + "'"); + template.add(0, "-injars '" + this.getArtifactPath().get().toString() + "'"); template.add(1, "-outjars '" + this.getTemporaryFile(PROGUARD_EXPORT_PATH) + "'"); template.add(2, "-libraryjars /jmods/java.base.jmod(!**.jar;!module-info.class)"); @@ -267,12 +294,12 @@ private Stream acquireDependencies() { private void proguardApi() throws Exception { runProguard(getTemporaryFile(compType+PROGUARD_API_CONFIG)); - Determinizer.determinize(this.proguardOut.toString(), this.artifactApiPath.toString()); + Determinizer.determinize(this.proguardOut.toString(), getArtifactApiPath().get().toString()); } private void proguardStandalone() throws Exception { runProguard(getTemporaryFile(compType+PROGUARD_STANDALONE_CONFIG)); - Determinizer.determinize(this.proguardOut.toString(), this.artifactStandalonePath.toString()); + Determinizer.determinize(this.proguardOut.toString(), getArtifactStandalonePath().get().toString()); } private void cleanup() { diff --git a/fabric/build.gradle b/fabric/build.gradle index 8adf7571b..1a8e58a82 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -74,30 +74,4 @@ components.java { withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) { skip() } -} - -task proguard(type: ProguardTask) { - url 'https://github.com/Guardsquare/proguard/releases/download/v7.2.1/proguard-7.2.1.zip' - extract 'proguard-7.2.1/lib/proguard.jar' - compType "fabric" -} - -task createDist(type: CreateDistTask, dependsOn: proguard) { - compType "fabric" -} - -build.finalizedBy(createDist) - -publishing { - publications { - mavenFabric(MavenPublication) { - artifactId = rootProject.archives_base_name + "-" + project.name - from components.java - } - } - - // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. - repositories { - // Add repositories to publish to here. - } } \ No newline at end of file diff --git a/forge/build.gradle b/forge/build.gradle index bac8ca54a..83fe38ddf 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -93,30 +93,4 @@ components.java { withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) { skip() } -} - -task proguard(type: ProguardTask) { - url 'https://github.com/Guardsquare/proguard/releases/download/v7.2.1/proguard-7.2.1.zip' - extract 'proguard-7.2.1/lib/proguard.jar' - compType "forge" -} - -task createDist(type: CreateDistTask, dependsOn: proguard) { - compType "forge" -} - -build.finalizedBy(createDist) - -publishing { - publications { - mavenFabric(MavenPublication) { - artifactId = rootProject.archives_base_name + "-" + project.name - from components.java - } - } - - // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. - repositories { - // Add repositories to publish to here. - } } \ No newline at end of file diff --git a/tweaker/build.gradle b/tweaker/build.gradle index 887d07cf2..a437e735a 100644 --- a/tweaker/build.gradle +++ b/tweaker/build.gradle @@ -91,27 +91,4 @@ jar { 'Implementation-Version': version, ) } -} - -task proguard(type: ProguardTask) { - url 'https://github.com/Guardsquare/proguard/releases/download/v7.2.1/proguard-7.2.1.zip' - extract 'proguard-7.2.1/lib/proguard.jar' -} - -task createDist(type: CreateDistTask, dependsOn: proguard) - -build.finalizedBy(createDist) - -publishing { - publications { - mavenCommon(MavenPublication) { - artifactId = rootProject.archives_base_name - from components.java - } - } - - // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. - repositories { - // Add repositories to publish to here. - } } \ No newline at end of file