Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some modifications to buildsrc #3987

Open
wants to merge 1 commit into
base: 1.20.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import baritone.gradle.task.CreateDistTask
import baritone.gradle.task.ProguardTask

/*
* This file is part of Baritone.
*
Expand Down Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
32 changes: 22 additions & 10 deletions buildSrc/src/main/java/baritone/gradle/task/CreateDistTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,26 +31,35 @@
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;

/**
* @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/");
Expand All @@ -57,20 +69,20 @@ 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<String> shasum = Files.list(getRootRelativeFile("dist/"))
List<String> 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());

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) {
Expand Down
63 changes: 45 additions & 18 deletions buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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() {
Expand All @@ -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)) {
Expand Down Expand Up @@ -214,7 +241,7 @@ private void generateConfigs() throws Exception {

// Setup the template that will be used to derive the API and Standalone configs
List<String> 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 <java.home>/jmods/java.base.jmod(!**.jar;!module-info.class)");
Expand Down Expand Up @@ -267,12 +294,12 @@ private Stream<File> 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() {
Expand Down
26 changes: 0 additions & 26 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
}
26 changes: 0 additions & 26 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
}
23 changes: 0 additions & 23 deletions tweaker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
}