diff --git a/.gitignore b/.gitignore
index d4c25ad90..8f43e8055 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@
run/
autotest/
dist/
+mapping/
# Gradle
build/
diff --git a/build.gradle b/build.gradle
index 0ce05058c..4d76c9e16 100755
--- a/build.gradle
+++ b/build.gradle
@@ -15,97 +15,140 @@
* along with Baritone. If not, see .
*/
-group 'baritone'
-version '1.2.17'
+allprojects {
+ apply plugin: 'java'
+ apply plugin: "xyz.wagyourtail.unimined"
+ apply plugin: "maven-publish"
+
+ archivesBaseName = rootProject.archives_base_name
+ def vers;
+ try {
+ vers = 'git describe --always --tags --match=v* --dirty'.execute().text.trim()
+ } catch (IOException ignored) {
+ vers = ""
+ println "git doesn't appear to be installed!"
+ }
+ if (vers.equals("")) {
+ println "Couldn't find version tag!"
+ println "Using fallback version number: " + rootProject.mod_version
+ version = rootProject.mod_version
+ } else if (!vers.startsWith("v")) {
+ println "Couldn't find version tag!"
+ println "Using fallback version number: " + rootProject.mod_version
+ version = rootProject.mod_version + "-g" + vers
+ } else {
+ version = vers.substring(1)
+ }
+ group = rootProject.maven_group
+
+ sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
+
+ minecraft {
+ mcRemapper.tinyRemapperConf = {
+ ignoreFieldDesc(true)
+ ignoreConflicts(true)
+ }
+ }
-buildscript {
repositories {
maven {
- name = 'forge'
- url = 'http://files.minecraftforge.net/maven'
+ name = 'spongepowered-repo'
+ url = 'https://repo.spongepowered.org/repository/maven-public/'
}
maven {
- name = 'SpongePowered'
- url = 'https://repo.spongepowered.org/repository/maven-public/'
+ name = 'fabric-maven'
+ url = 'https://maven.fabricmc.net/'
+ }
+ maven {
+ name = 'forge-maven'
+ url = 'https://maven.minecraftforge.net/'
+ metadataSources {
+ artifact()
+ }
+ }
+ maven {
+ name = 'impactdevelopment-repo'
+ url = 'https://impactdevelopment.github.io/maven/'
+ }
+ maven {
+ name = "ldtteam"
+ url = "https://maven.parchmentmc.net/"
+ }
+ // for the newer version of launchwrapper
+ maven {
+ name = "multimc-maven"
+ url = "https://files.multimc.org/maven/"
+ metadataSources {
+ artifact()
+ }
}
- jcenter()
+ mavenCentral()
}
dependencies {
- classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
- classpath 'org.spongepowered:mixingradle:0.6-SNAPSHOT'
- }
-}
+ minecraft "net.minecraft:minecraft:${rootProject.minecraft_version}"
+ mappings "de.oceanlabs.mcp:mcp_config:${rootProject.minecraft_version}@zip"
+ mappings "de.oceanlabs.mcp:mcp_${rootProject.mcp_channel}:${rootProject.mcp_version}@zip"
+ }
-import baritone.gradle.task.CreateDistTask
-import baritone.gradle.task.ProguardTask
+ tasks.withType(JavaCompile).configureEach {
+ it.options.encoding = "UTF-8"
-apply plugin: 'java'
-apply plugin: 'maven'
-apply plugin: 'net.minecraftforge.gradle.tweaker-client'
-apply plugin: 'org.spongepowered.mixin'
+ def targetVersion = 8
+ if (JavaVersion.current().isJava9Compatible()) {
+ it.options.release = targetVersion
+ }
+ }
+}
-sourceCompatibility = targetCompatibility = '1.8'
-compileJava {
- sourceCompatibility = targetCompatibility = '1.8'
- options.encoding = "UTF-8" // allow emoji in comments :^)
+minecraft {
+ runs.off = true
}
+archivesBaseName = archivesBaseName + "-common"
+
sourceSets {
+ api {
+ compileClasspath += main.compileClasspath
+ runtimeClasspath += main.runtimeClasspath
+ }
+ main {
+ compileClasspath += api.output
+ runtimeClasspath += api.output
+ }
+ test {
+ compileClasspath += main.compileClasspath + main.runtimeClasspath + main.output
+ runtimeClasspath += main.compileClasspath + main.runtimeClasspath + main.output
+ }
launch {
compileClasspath += main.compileClasspath + main.runtimeClasspath + main.output
+ runtimeClasspath += main.compileClasspath + main.runtimeClasspath + main.output
}
-
schematica_api {
compileClasspath += main.compileClasspath
+ runtimeClasspath += main.runtimeClasspath
}
-
main {
compileClasspath += schematica_api.output
+ runtimeClasspath += schematica_api.output
}
}
-minecraft {
- version = '1.12.2'
- mappings = 'stable_39'
- tweakClass = 'baritone.launch.BaritoneTweaker'
- runDir = 'run'
-
- // The sources jar should use SRG names not MCP to ensure compatibility with all mappings
- makeObfSourceJar = true
-}
-
-repositories {
- mavenCentral()
-
- maven {
- name = 'spongepowered-repo'
- url = 'https://repo.spongepowered.org/repository/maven-public/'
- }
+dependencies {
+ testImplementation 'junit:junit:4.13.2'
- maven {
- name = 'impactdevelopment-repo'
- url = 'https://impactdevelopment.github.io/maven/'
+ implementation "org.spongepowered:mixin:0.7.11-SNAPSHOT", {
+ transitive = false
}
}
-dependencies {
- runtime launchCompile('com.github.ImpactDevelopment:SimpleTweaker:1.2')
- runtime launchCompile('org.spongepowered:mixin:0.7.11-SNAPSHOT') {
- // Mixin includes a lot of dependencies that are too up-to-date
- exclude module: 'launchwrapper'
- exclude module: 'guava'
- exclude module: 'gson'
- exclude module: 'commons-io'
- exclude module: 'log4j-core'
- }
- testImplementation 'junit:junit:4.12'
+jar {
+ from sourceSets.main.output, sourceSets.launch.output, sourceSets.api.output
}
-mixin {
- defaultObfuscationEnv searge
- add sourceSets.launch, 'mixins.baritone.refmap.json'
+remapJar {
+ target = "mcp"
}
javadoc {
@@ -114,56 +157,4 @@ javadoc {
options.encoding "UTF-8" // allow emoji in comments :^)
source = sourceSets.api.allJava
classpath += sourceSets.api.compileClasspath
-}
-
-jar {
- from sourceSets.launch.output, sourceSets.api.output
-
- if (!getProject().hasProperty("baritone.forge_build")) {
- exclude "**/BaritoneForgeModXD.class"
- exclude "**/mods.toml"
- }
-
- preserveFileTimestamps = false
- reproducibleFileOrder = true
-
- manifest {
- attributes(
- 'MixinConfigs': 'mixins.baritone.json',
-
- 'Implementation-Title': 'Baritone',
- 'Implementation-Version': version
- )
- }
-}
-
-task proguard(type: ProguardTask) {
- url 'https://downloads.sourceforge.net/project/proguard/proguard/6.0/proguard6.0.3.zip'
- extract 'proguard6.0.3/lib/proguard.jar'
-}
-
-task createDist(type: CreateDistTask, dependsOn: proguard)
-
-build.finalizedBy(createDist)
-
-install {
- def jarApiName = String.format("%s-api-%s", rootProject.name, version.toString())
- def jarApiForgeName = String.format("%s-api-forge-%s", rootProject.name, version.toString())
- def jarSAName = String.format("%s-standalone-%s", rootProject.name, version.toString())
- def jarSAForgeName = String.format("%s-standalone-forge-%s", rootProject.name, version.toString())
-
- artifacts {
- archives file("$buildDir/libs/"+jarApiName+".jar")
- archives file("$buildDir/libs/"+jarApiForgeName+".jar")
- archives file("$buildDir/libs/"+jarSAName+".jar")
- archives file("$buildDir/libs/"+jarSAForgeName+".jar")
- }
- repositories.mavenInstaller {
- addFilter('api') { artifact, file -> artifact.name == "baritone-api" }
- addFilter('api-forge') { artifact, file -> artifact.name == "baritone-api-forge" }
- addFilter('standalone') { artifact, file -> artifact.name == "baritone-standalone" }
- addFilter('standalone-forge') { artifact, file -> artifact.name == "baritone-standalone-forge" }
- }
-}
-
-install.dependsOn(build)
+}
\ No newline at end of file
diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle
index 2ac49af0f..4ac65b03d 100644
--- a/buildSrc/build.gradle
+++ b/buildSrc/build.gradle
@@ -16,10 +16,24 @@
*/
repositories {
+ maven {
+ name = 'WagYourMaven'
+ url = 'https://maven.wagyourtail.xyz/releases'
+ }
+ maven {
+ name = 'ForgeMaven'
+ url = 'https://maven.minecraftforge.net/'
+ }
+ maven {
+ name = 'FabricMaven'
+ url = 'https://maven.fabricmc.net/'
+ }
mavenCentral()
}
dependencies {
- compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
- compile group: 'commons-io', name: 'commons-io', version: '2.6'
+ implementation group: 'com.google.code.gson', name: 'gson', version: '2.9.0'
+ implementation group: 'commons-io', name: 'commons-io', version: '2.6'
+
+ implementation group: 'xyz.wagyourtail.unimined', name: 'xyz.wagyourtail.unimined.gradle.plugin', version: '0.4.9'
}
\ 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 7e26dac11..2dad551f2 100644
--- a/buildSrc/src/main/java/baritone/gradle/task/BaritoneGradleTask.java
+++ b/buildSrc/src/main/java/baritone/gradle/task/BaritoneGradleTask.java
@@ -18,8 +18,12 @@
package baritone.gradle.task;
import org.gradle.api.DefaultTask;
+import org.gradle.api.tasks.Input;
+import org.gradle.api.tasks.Optional;
+import org.gradle.api.tasks.TaskAction;
import java.io.File;
+import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -39,38 +43,60 @@ class BaritoneGradleTask extends DefaultTask {
PROGUARD_API_CONFIG = "api.pro",
PROGUARD_STANDALONE_CONFIG = "standalone.pro",
PROGUARD_EXPORT_PATH = "proguard_out.jar",
+ PROGUARD_MAPPING_DIR = "mapping",
- TEMP_LIBRARY_DIR = "tempLibraries/",
-
- ARTIFACT_STANDARD = "%s-%s.jar",
- 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",
- ARTIFACT_FORGE_STANDALONE = "%s-standalone-forge-%s.jar";
+ ARTIFACT_STANDARD = "%s-%s.jar",
+ ARTIFACT_UNOPTIMIZED = "%s-unoptimized-%s.jar",
+ ARTIFACT_API = "%s-api-%s.jar",
+ ARTIFACT_STANDALONE = "%s-standalone-%s.jar";
protected String artifactName, artifactVersion;
- protected Path artifactPath, artifactUnoptimizedPath, artifactApiPath, artifactStandalonePath, artifactForgeApiPath, artifactForgeStandalonePath, proguardOut;
+ protected Path
+ artifactPath,
+ artifactUnoptimizedPath, artifactApiPath, artifactStandalonePath, // these are different for forge builds
+ proguardOut;
- protected void verifyArtifacts() throws IllegalStateException {
- this.artifactName = getProject().getName();
- 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.artifactForgeApiPath = this.getBuildFile(formatVersion(ARTIFACT_FORGE_API));
- this.artifactForgeStandalonePath = this.getBuildFile(formatVersion(ARTIFACT_FORGE_STANDALONE));
+ @Input
+ @Optional
+ protected String compType = null;
+
+ public String getCompType() {
+ return compType;
+ }
+
+ public void setCompType(String compType) {
+ this.compType = compType;
+ }
+
+
+ public BaritoneGradleTask() {
+ this.artifactName = getProject().getRootProject().getProperties().get("archives_base_name").toString();
+ }
+
+ public void doFirst() {
+ if (compType != null) {
+ this.artifactVersion = compType + "-" + getProject().getVersion();
+ } 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!");
+ throw new IllegalStateException("Artifact not found! Run build first! Missing file: " + this.artifactPath);
}
}
- protected void write(InputStream stream, Path file) throws Exception {
+ protected void write(InputStream stream, Path file) throws IOException {
if (Files.exists(file)) {
Files.delete(file);
}
@@ -82,7 +108,11 @@ protected String formatVersion(String string) {
}
protected Path getRelativeFile(String file) {
- return Paths.get(new File(file).getAbsolutePath());
+ return Paths.get(new File(getProject().getBuildDir(), file).getAbsolutePath());
+ }
+
+ protected Path getRootRelativeFile(String file) {
+ return Paths.get(new File(getProject().getRootDir(), file).getAbsolutePath());
}
protected Path getTemporaryFile(String file) {
@@ -90,6 +120,10 @@ protected Path getTemporaryFile(String file) {
}
protected Path getBuildFile(String file) {
- return getRelativeFile("build/libs/" + file);
+ return getRelativeFile("libs/" + file);
+ }
+
+ protected String addCompTypeFirst(String string) {
+ return compType == null ? string : compType + "-" + string;
}
}
diff --git a/buildSrc/src/main/java/baritone/gradle/task/CreateDistTask.java b/buildSrc/src/main/java/baritone/gradle/task/CreateDistTask.java
index 3ca935d16..48cd0a72a 100644
--- a/buildSrc/src/main/java/baritone/gradle/task/CreateDistTask.java
+++ b/buildSrc/src/main/java/baritone/gradle/task/CreateDistTask.java
@@ -19,13 +19,15 @@
import org.gradle.api.tasks.TaskAction;
-import javax.xml.bind.DatatypeConverter;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
+import java.nio.file.OpenOption;
import java.nio.file.Path;
+import java.nio.file.StandardOpenOption;
import java.security.MessageDigest;
+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;
@@ -39,37 +41,40 @@ public class CreateDistTask extends BaritoneGradleTask {
@TaskAction
protected void exec() throws Exception {
+ super.doFirst();
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 forgeStandalone = getRelativeFile("dist/" + formatVersion(ARTIFACT_FORGE_STANDALONE));
+ 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);
}
// Copy build jars to dist/
- Files.copy(this.artifactApiPath, api, REPLACE_EXISTING);
- Files.copy(this.artifactStandalonePath, standalone, REPLACE_EXISTING);
- Files.copy(this.artifactUnoptimizedPath, unoptimized, REPLACE_EXISTING);
- Files.copy(this.artifactForgeApiPath, forgeApi, REPLACE_EXISTING);
- Files.copy(this.artifactForgeStandalonePath, forgeStandalone, 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 shasum = Stream.of(api, forgeApi, standalone, forgeStandalone, unoptimized)
+ List shasum = Files.list(getRootRelativeFile("dist/"))
+ .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(getRelativeFile("dist/checksums.txt"), shasum);
+ Files.write(getRootRelativeFile("dist/checksums.txt"), shasum);
+ }
+
+ private static String getFileName(Path p) {
+ return p.getFileName().toString();
}
private static synchronized String sha1(Path path) {
@@ -77,10 +82,22 @@ private static synchronized String sha1(Path path) {
if (SHA1_DIGEST == null) {
SHA1_DIGEST = MessageDigest.getInstance("SHA-1");
}
- return DatatypeConverter.printHexBinary(SHA1_DIGEST.digest(Files.readAllBytes(path))).toLowerCase();
+ return bytesToHex(SHA1_DIGEST.digest(Files.readAllBytes(path))).toLowerCase();
} catch (Exception e) {
// haha no thanks
throw new IllegalStateException(e);
}
}
+
+ private static final byte[] HEX_ARRAY = "0123456789ABCDEF".getBytes(StandardCharsets.US_ASCII);
+
+ public static String bytesToHex(byte[] bytes) {
+ byte[] hexChars = new byte[bytes.length * 2];
+ for (int j = 0; j < bytes.length; j++) {
+ int v = bytes[j] & 0xFF;
+ hexChars[j * 2] = HEX_ARRAY[v >>> 4];
+ hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
+ }
+ return new String(hexChars, StandardCharsets.UTF_8);
+ }
}
diff --git a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java
index 1789435f7..30941d025 100644
--- a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java
+++ b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java
@@ -18,34 +18,27 @@
package baritone.gradle.task;
import baritone.gradle.util.Determinizer;
-import baritone.gradle.util.MappingType;
-import baritone.gradle.util.ReobfWrapper;
import org.apache.commons.io.IOUtils;
import org.gradle.api.JavaVersion;
-import org.gradle.api.NamedDomainObjectContainer;
-import org.gradle.api.artifacts.Configuration;
-import org.gradle.api.artifacts.Dependency;
-import org.gradle.api.internal.file.IdentityFileResolver;
-import org.gradle.api.internal.plugins.DefaultConvention;
+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.compile.ForkOptions;
import org.gradle.api.tasks.compile.JavaCompile;
-import org.gradle.internal.Pair;
import org.gradle.internal.jvm.Jvm;
-import org.gradle.internal.jvm.inspection.DefaultJvmVersionDetector;
-import org.gradle.process.internal.DefaultExecActionFactory;
+import xyz.wagyourtail.unimined.api.Constants;
+import xyz.wagyourtail.unimined.api.minecraft.EnvType;
+import xyz.wagyourtail.unimined.api.minecraft.MinecraftProvider;
import java.io.*;
-import java.lang.reflect.Field;
+import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.util.*;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@@ -57,20 +50,23 @@
*/
public class ProguardTask extends BaritoneGradleTask {
- private static final Pattern TEMP_LIBRARY_PATTERN = Pattern.compile("-libraryjars 'tempLibraries\\/([a-zA-Z0-9/_\\-\\.]+)\\.jar'");
-
@Input
private String url;
+ public String getUrl() {
+ return url;
+ }
+
@Input
private String extract;
- private List requiredLibraries;
-
- private File mixin;
+ public String getExtract() {
+ return extract;
+ }
@TaskAction
protected void exec() throws Exception {
+ super.doFirst();
super.verifyArtifacts();
// "Haha brady why don't you make separate tasks"
@@ -78,18 +74,27 @@ protected void exec() throws Exception {
downloadProguard();
extractProguard();
generateConfigs();
- acquireDependencies();
proguardApi();
proguardStandalone();
cleanup();
}
+ MinecraftProvider, ?> provider = this.getProject().getExtensions().getByType(MinecraftProvider.class);
+
+ private File getMcJar() {
+ return provider.getMinecraftWithMapping(EnvType.COMBINED, provider.getMcPatcher().getProdNamespace(), provider.getMcPatcher().getProdNamespace()).toFile();
+ }
+
+ 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(), Optional.empty());
+ Determinizer.determinize(this.artifactPath.toString(), this.artifactUnoptimizedPath.toString());
}
private void downloadProguard() throws Exception {
@@ -192,197 +197,88 @@ public boolean accept(File dir, String name) {
}
private boolean validateJavaVersion(String java) {
- final JavaVersion javaVersion = new DefaultJvmVersionDetector(new DefaultExecActionFactory(new IdentityFileResolver())).getJavaVersion(java);
-
- if (!javaVersion.getMajorVersion().equals("8")) {
- System.out.println("Failed to validate Java version " + javaVersion.toString() + " [" + java + "] for ProGuard libraryjars");
- // throw new RuntimeException("Java version incorrect: " + javaVersion.getMajorVersion() + " for " + java);
- return false;
- }
-
- System.out.println("Validated Java version " + javaVersion.toString() + " [" + java + "] for ProGuard libraryjars");
+ //TODO: fix for j16
+// final JavaVersion javaVersion = new DefaultJvmVersionDetector(new DefaultExecActionFactory(new IdentityFileResolver())).getJavaVersion(java);
+//
+// if (!javaVersion.getMajorVersion().equals("8")) {
+// System.out.println("Failed to validate Java version " + javaVersion.toString() + " [" + java + "] for ProGuard libraryjars");
+// // throw new RuntimeException("Java version incorrect: " + javaVersion.getMajorVersion() + " for " + java);
+// return false;
+// }
+//
+// System.out.println("Validated Java version " + javaVersion.toString() + " [" + java + "] for ProGuard libraryjars");
return true;
}
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 template = Files.readAllLines(getTemporaryFile(PROGUARD_CONFIG_DEST));
template.add(0, "-injars '" + this.artifactPath.toString() + "'");
template.add(1, "-outjars '" + this.getTemporaryFile(PROGUARD_EXPORT_PATH) + "'");
- // Acquire the RT jar using "java -verbose". This doesn't work on Java 9+
- Process p = new ProcessBuilder(this.getJavaBinPathForProguard(), "-verbose").start();
- String out = IOUtils.toString(p.getInputStream(), "UTF-8").split("\n")[0].split("Opened ")[1].replace("]", "");
- template.add(2, "-libraryjars '" + out + "'");
-
- // API config doesn't require any changes from the changes that we made to the template
- Files.write(getTemporaryFile(PROGUARD_API_CONFIG), template);
-
- // For the Standalone config, don't keep the API package
- List standalone = new ArrayList<>(template);
- standalone.removeIf(s -> s.contains("# this is the keep api"));
- Files.write(getTemporaryFile(PROGUARD_STANDALONE_CONFIG), standalone);
-
- // Discover all of the libraries that we will need to acquire from gradle
- this.requiredLibraries = new ArrayList<>();
- template.forEach(line -> {
- if (!line.startsWith("#")) {
- Matcher m = TEMP_LIBRARY_PATTERN.matcher(line);
- if (m.find()) {
- this.requiredLibraries.add(m.group(1));
- }
- }
- });
- }
-
- private void acquireDependencies() throws Exception {
-
- // Create a map of all of the dependencies that we are able to access in this project
- // Likely a better way to do this, I just pair the dependency with the first valid configuration
- Map> dependencyLookupMap = new HashMap<>();
- getProject().getConfigurations().stream().filter(Configuration::isCanBeResolved).forEach(config ->
- config.getAllDependencies().forEach(dependency ->
- dependencyLookupMap.putIfAbsent(dependency.getName() + "-" + dependency.getVersion(), Pair.of(config, dependency))));
-
- // Create the directory if it doesn't already exist
- Path tempLibraries = getTemporaryFile(TEMP_LIBRARY_DIR);
- if (!Files.exists(tempLibraries)) {
- Files.createDirectory(tempLibraries);
+ if (JavaVersion.current().isJava9Compatible()) {
+ template.add(2, "-libraryjars /jmods/java.base.jmod(!**.jar;!module-info.class)");
+ template.add(3, "-libraryjars /jmods/java.desktop.jmod(!**.jar;!module-info.class)");
+ template.add(4, "-libraryjars /jmods/jdk.unsupported.jmod(!**.jar;!module-info.class)");
+ template.add(5, "-libraryjars /jmods/java.compiler.jmod(!**.jar;!module-info.class)");
+ } else {
+ template.add(2, "-libraryjars /lib/rt.jar");
}
- // Iterate the required libraries to copy them to tempLibraries
- for (String lib : this.requiredLibraries) {
- // copy from the forgegradle cache
- if (lib.equals("minecraft")) {
- Path cachedJar = getMinecraftJar();
- Path inTempDir = getTemporaryFile("tempLibraries/minecraft.jar");
- // TODO: maybe try not to copy every time
- Files.copy(cachedJar, inTempDir, REPLACE_EXISTING);
-
- continue;
- }
-
- // Find a configuration/dependency pair that matches the desired library
- Pair pair = null;
- for (Map.Entry> entry : dependencyLookupMap.entrySet()) {
- if (entry.getKey().startsWith(lib)) {
- pair = entry.getValue();
- }
+ {
+ final Stream libraries;
+ File mcJar;
+ try {
+ mcJar = getMcJar();
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to find Minecraft jar", e);
}
- // The pair must be non-null
- Objects.requireNonNull(pair);
+ {
+ // Discover all of the libraries that we will need to acquire from gradle
+ final Stream dependencies = acquireDependencies()
+ // remove MCP mapped jar, and nashorn
+ .filter(f -> !f.toString().endsWith("-recomp.jar") && !f.getName().startsWith("nashorn") && !f.getName().startsWith("coremods"));
- // Find the library jar file, and copy it to tempLibraries
- for (File file : pair.getLeft().files(pair.getRight())) {
- if (file.getName().startsWith(lib)) {
- if (lib.contains("mixin")) {
- mixin = file;
- }
- Files.copy(file.toPath(), getTemporaryFile("tempLibraries/" + lib + ".jar"), REPLACE_EXISTING);
- }
+ libraries = dependencies
+ .map(f -> isMcJar(f) ? mcJar : f);
}
- }
- if (mixin == null) {
- throw new IllegalStateException("Unable to find mixin jar");
- }
- }
-
- // a bunch of epic stuff to get the path to the cached jar
- private Path getMinecraftJar() throws Exception {
- MappingType mappingType;
- try {
- mappingType = getMappingType();
- } catch (Exception e) {
- System.err.println("Failed to get mapping type, assuming NOTCH.");
- mappingType = MappingType.NOTCH;
- }
-
- String suffix;
- switch (mappingType) {
- case NOTCH:
- suffix = "";
- break;
- case SEARGE:
- suffix = "-srgBin";
- break;
- case CUSTOM:
- throw new IllegalStateException("Custom mappings not supported!");
- default:
- throw new IllegalStateException("Unknown mapping type: " + mappingType);
+ libraries.forEach(f -> {
+ template.add(2, "-libraryjars '" + f + "'");
+ });
}
- DefaultConvention convention = (DefaultConvention) this.getProject().getConvention();
- Object extension = convention.getAsMap().get("minecraft");
- Objects.requireNonNull(extension);
-
- // for some reason cant use Class.forName
- Class> class_baseExtension = extension.getClass().getSuperclass().getSuperclass().getSuperclass(); // <-- cursed
- Field f_replacer = class_baseExtension.getDeclaredField("replacer");
- f_replacer.setAccessible(true);
- Object replacer = f_replacer.get(extension);
- Class> class_replacementProvider = replacer.getClass();
- Field replacement_replaceMap = class_replacementProvider.getDeclaredField("replaceMap");
- replacement_replaceMap.setAccessible(true);
-
- Map replacements = (Map) replacement_replaceMap.get(replacer);
- String cacheDir = replacements.get("CACHE_DIR").toString() + "/net/minecraft";
- String mcVersion = replacements.get("MC_VERSION").toString();
- String mcpInsert = replacements.get("MAPPING_CHANNEL").toString() + "/" + replacements.get("MAPPING_VERSION").toString();
- String fullJarName = "minecraft-" + mcVersion + suffix + ".jar";
-
- String baseDir = String.format("%s/minecraft/%s/", cacheDir, mcVersion);
-
- String jarPath;
- if (mappingType == MappingType.SEARGE) {
- jarPath = String.format("%s/%s/%s", baseDir, mcpInsert, fullJarName);
- } else {
- jarPath = baseDir + fullJarName;
- }
- jarPath = jarPath
- .replace("/", File.separator)
- .replace("\\", File.separator); // hecking regex
+ Files.createDirectories(this.getRootRelativeFile(PROGUARD_MAPPING_DIR));
- return new File(jarPath).toPath();
- }
+ List api = new ArrayList<>(template);
+ api.add(2, "-printmapping " + new File(this.getRootRelativeFile(PROGUARD_MAPPING_DIR).toFile(), "mappings-" + addCompTypeFirst("api.txt")));
- // throws IllegalStateException if mapping type is ambiguous or it fails to find it
- private MappingType getMappingType() {
- // if it fails to find this then its probably a forgegradle version problem
- Set