This commit is contained in:
Leijurv 2018-12-01 10:45:58 -08:00
parent b9f7a05e2a
commit 07ce0a47f7
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A

View File

@ -20,8 +20,6 @@ package baritone.gradle.task;
import baritone.gradle.util.Determinizer; import baritone.gradle.util.Determinizer;
import baritone.gradle.util.MappingType; import baritone.gradle.util.MappingType;
import baritone.gradle.util.ReobfWrapper; import baritone.gradle.util.ReobfWrapper;
import java.lang.reflect.Field;
import java.util.stream.Collectors;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.gradle.api.NamedDomainObjectContainer; import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Configuration;
@ -32,12 +30,14 @@ import org.gradle.api.tasks.TaskAction;
import org.gradle.internal.Pair; import org.gradle.internal.Pair;
import java.io.*; import java.io.*;
import java.lang.reflect.Field;
import java.net.URL; import java.net.URL;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.*; import java.util.*;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
@ -151,8 +151,8 @@ public class ProguardTask extends BaritoneGradleTask {
for (String lib : this.requiredLibraries) { for (String lib : this.requiredLibraries) {
// copy from the forgegradle cache // copy from the forgegradle cache
if (lib.equals("minecraft")) { if (lib.equals("minecraft")) {
final Path cachedJar = getMinecraftJar(); Path cachedJar = getMinecraftJar();
final Path inTempDir = getTemporaryFile("tempLibraries/minecraft.jar"); Path inTempDir = getTemporaryFile("tempLibraries/minecraft.jar");
// TODO: maybe try not to copy every time // TODO: maybe try not to copy every time
Files.copy(cachedJar, inTempDir, REPLACE_EXISTING); Files.copy(cachedJar, inTempDir, REPLACE_EXISTING);
@ -204,25 +204,25 @@ public class ProguardTask extends BaritoneGradleTask {
} }
DefaultConvention convention = (DefaultConvention) this.getProject().getConvention(); DefaultConvention convention = (DefaultConvention) this.getProject().getConvention();
final Object extension = convention.getAsMap().get("minecraft"); Object extension = convention.getAsMap().get("minecraft");
Objects.requireNonNull(extension); Objects.requireNonNull(extension);
// for some reason cant use Class.forName // for some reason cant use Class.forName
Class<?> class_baseExtension = extension.getClass().getSuperclass().getSuperclass().getSuperclass(); Class<?> class_baseExtension = extension.getClass().getSuperclass().getSuperclass().getSuperclass();
Field f_replacer = class_baseExtension.getDeclaredField("replacer"); Field f_replacer = class_baseExtension.getDeclaredField("replacer");
f_replacer.setAccessible(true); f_replacer.setAccessible(true);
final Object replacer = f_replacer.get(extension); Object replacer = f_replacer.get(extension);
Class<?> class_replacementProvider = replacer.getClass(); Class<?> class_replacementProvider = replacer.getClass();
Field replacement_replaceMap = class_replacementProvider.getDeclaredField("replaceMap"); Field replacement_replaceMap = class_replacementProvider.getDeclaredField("replaceMap");
replacement_replaceMap.setAccessible(true); replacement_replaceMap.setAccessible(true);
final Map<String, Object> replacements = (Map) replacement_replaceMap.get(replacer); Map<String, Object> replacements = (Map) replacement_replaceMap.get(replacer);
final String cacheDir = replacements.get("CACHE_DIR").toString() + "/net/minecraft"; String cacheDir = replacements.get("CACHE_DIR").toString() + "/net/minecraft";
final String mcVersion = replacements.get("MC_VERSION").toString(); String mcVersion = replacements.get("MC_VERSION").toString();
final String mcpInsert = replacements.get("MAPPING_CHANNEL").toString() + "/" + replacements.get("MAPPING_VERSION").toString(); String mcpInsert = replacements.get("MAPPING_CHANNEL").toString() + "/" + replacements.get("MAPPING_VERSION").toString();
final String fullJarName = "minecraft-" + mcVersion + suffix + ".jar"; String fullJarName = "minecraft-" + mcVersion + suffix + ".jar";
final String baseDir = String.format("%s/minecraft/%s/", cacheDir, mcVersion); String baseDir = String.format("%s/minecraft/%s/", cacheDir, mcVersion);
String jarPath; String jarPath;
if (mappingType == MappingType.SEARGE) { if (mappingType == MappingType.SEARGE) {
@ -240,13 +240,14 @@ public class ProguardTask extends BaritoneGradleTask {
// throws IllegalStateException if mapping type is ambiguous or it fails to find it // throws IllegalStateException if mapping type is ambiguous or it fails to find it
private MappingType getMappingType() { private MappingType getMappingType() {
// if it fails to find this then its probably a forgegradle version problem // if it fails to find this then its probably a forgegradle version problem
final Set<Object> reobf = (NamedDomainObjectContainer<Object>) this.getProject().getExtensions().getByName("reobf"); Set<Object> reobf = (NamedDomainObjectContainer<Object>) this.getProject().getExtensions().getByName("reobf");
final List<MappingType> mappingTypes = getUsedMappingTypes(reobf); List<MappingType> mappingTypes = getUsedMappingTypes(reobf);
final long mappingTypesUsed = mappingTypes.size(); long mappingTypesUsed = mappingTypes.size();
if (mappingTypesUsed == 0) { if (mappingTypesUsed == 0) {
throw new IllegalStateException("Failed to find mapping type (no jar task?)"); throw new IllegalStateException("Failed to find mapping type (no jar task?)");
} if (mappingTypesUsed > 1) { }
if (mappingTypesUsed > 1) {
throw new IllegalStateException("Ambiguous mapping type (multiple jars with different mapping types?)"); throw new IllegalStateException("Ambiguous mapping type (multiple jars with different mapping types?)");
} }
@ -314,7 +315,7 @@ public class ProguardTask extends BaritoneGradleTask {
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
System.out.println(line); System.out.println(line);
} }
} catch (final Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
}).start(); }).start();