diff --git a/gradle.properties b/gradle.properties index e0b0a086..e65224d9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,5 +4,5 @@ packaging=jar description=Mixin url=https://www.spongepowered.org organization=SpongePowered -buildVersion=0.5.1 +buildVersion=0.5.2 buildType=SNAPSHOT diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixins.java b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixins.java index 443b20e9..c07715aa 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixins.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixins.java @@ -24,6 +24,8 @@ */ package org.spongepowered.tools.obfuscation; +import java.io.File; +import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; @@ -161,6 +163,14 @@ class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider, ITyp protected TargetMap initTargetMap() { TargetMap targets = TargetMap.create(System.getProperty(AnnotatedMixins.MAPID_SYSTEM_PROPERTY)); System.setProperty(AnnotatedMixins.MAPID_SYSTEM_PROPERTY, targets.getSessionId()); + String targetsFileName = this.getOption(SupportedOptions.DEPENDENCY_TARGETS_FILE); + if (targetsFileName != null) { + try { + targets.readImports(new File(targetsFileName)); + } catch (IOException ex) { + this.printMessage(Kind.WARNING, "Could not read from specified imports file: " + targetsFileName); + } + } return targets; } diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/SupportedOptions.java b/src/ap/java/org/spongepowered/tools/obfuscation/SupportedOptions.java index e278faf7..ac1252d0 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/SupportedOptions.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/SupportedOptions.java @@ -47,6 +47,7 @@ public final class SupportedOptions { public static final String DISABLE_OVERWRITE_CHECKER = "disableOverwriteChecker"; public static final String OVERWRITE_ERROR_LEVEL = "overwriteErrorLevel"; public static final String DEFAULT_OBFUSCATION_ENV = "defaultObfuscationEnv"; + public static final String DEPENDENCY_TARGETS_FILE = "dependencyTargetsFile"; public static final Set all = ImmutableSet.of( SupportedOptions.TOKENS, @@ -61,7 +62,8 @@ public final class SupportedOptions { SupportedOptions.DISABLE_TARGET_EXPORT, SupportedOptions.DISABLE_OVERWRITE_CHECKER, SupportedOptions.OVERWRITE_ERROR_LEVEL, - SupportedOptions.DEFAULT_OBFUSCATION_ENV + SupportedOptions.DEFAULT_OBFUSCATION_ENV, + SupportedOptions.DEPENDENCY_TARGETS_FILE ); private SupportedOptions() {} diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/TargetMap.java b/src/ap/java/org/spongepowered/tools/obfuscation/TargetMap.java index 0e5c472a..aa7d9773 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/TargetMap.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/TargetMap.java @@ -30,6 +30,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.nio.charset.Charset; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -39,6 +40,8 @@ import java.util.Set; import javax.lang.model.element.TypeElement; +import com.google.common.io.Files; + /** * Serialisable map of classes to their associated mixins, used so that we can * pass target information for supermixins from one compiler session to another @@ -106,6 +109,16 @@ public class TargetMap extends HashMap> { this.addMixin(target.getReference(), mixin.getReference()); } + /** + * Register the specified mixin against the specified target + * + * @param target Target class + * @param mixin Mixin class + */ + public void addMixin(String target, String mixin) { + this.addMixin(new TypeReference(target), new TypeReference(mixin)); + } + /** * Register the specified mixin against the specified target * @@ -161,6 +174,25 @@ public class TargetMap extends HashMap> { } return mixins; } + + /** + * Read upstream library mixins from a file + * + * @param file File to read from + * @throws IOException if an error occurs whilst reading the file + */ + public void readImports(File file) throws IOException { + if (!file.isFile()) { + return; + } + + for (String line : Files.readLines(file, Charset.defaultCharset())) { + String[] parts = line.split("\t"); + if (parts.length == 2) { + this.addMixin(parts[1], parts[0]); + } + } + } /** * Write this target map to temporary session file @@ -246,4 +278,5 @@ public class TargetMap extends HashMap> { File tempDir = new File(System.getProperty("java.io.tmpdir")); return new File(tempDir, String.format("mixin-targetdb-%s.tmp", sessionId)); } + } diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/TypeReference.java b/src/ap/java/org/spongepowered/tools/obfuscation/TypeReference.java index 9e14f807..40e28c9a 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/TypeReference.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/TypeReference.java @@ -56,6 +56,15 @@ public class TypeReference implements Serializable, Comparable { this.handle = handle; } + /** + * Create a type reference with no handle + * + * @param name Name of the type + */ + TypeReference(String name) { + this.name = name; + } + /** * Get the class name (internal format) */ diff --git a/src/main/java/org/spongepowered/asm/launch/MixinBootstrap.java b/src/main/java/org/spongepowered/asm/launch/MixinBootstrap.java index 9498cb1e..2f8be596 100644 --- a/src/main/java/org/spongepowered/asm/launch/MixinBootstrap.java +++ b/src/main/java/org/spongepowered/asm/launch/MixinBootstrap.java @@ -60,7 +60,7 @@ public abstract class MixinBootstrap { /** * Subsystem version */ - public static final String VERSION = "0.5.1"; + public static final String VERSION = "0.5.2"; /** * Blackboard key where the subsystem version will be stored to indicate