Store multiple obf types in a refmap

This commit is contained in:
Mumfrey committed 2015-12-04 13:25:58 +00:00
1 parent 03744c86a0
commit b56a535005
10 files changed
+202 -107

No files matched your search

@@ -585,6 +585,11 @@ public class MixinEnvironment implements ITokenProvider {
*/
private IClassNameTransformer nameTransformer;
/**
* Obfuscation context (refmap key to use in this environment)
*/
private String obfuscationContext = null;
MixinEnvironment(Phase phase) {
this.phase = phase;
this.configsKey = MixinEnvironment.CONFIGS_KEY + "." + this.phase.name.toLowerCase();
@@ -847,6 +852,19 @@ public class MixinEnvironment implements ITokenProvider {
return option.getStringValue();
}
/**
* Set the obfuscation context
*
* @param context
*/
public void setObfuscationContext(String context) {
this.obfuscationContext = context;
}
public String getObfuscationContext() {
return this.obfuscationContext;
}
/**
* Invoke a mixin environment audit process
*/
@@ -26,6 +26,8 @@ package org.spongepowered.asm.mixin.extensibility;
import java.util.Set;
import org.spongepowered.asm.mixin.MixinEnvironment;
/**
* Interface for loaded mixin configurations
*/
@@ -35,6 +37,13 @@ public interface IMixinConfig {
* Default priority for mixin configs and mixins
*/
public static final int DEFAULT_PRIORITY = 1000;
/**
* Get the parent environment of this config
*
* @return the parent environment
*/
public abstract MixinEnvironment getEnvironment();
/**
* Get the name of the file from which this configuration object was
@@ -433,7 +433,7 @@ public class MemberInfo {
* @param mixinClass Mixin class to use for remapping
* @return parsed MemberInfo
*/
public static MemberInfo parse(String name, ReferenceMapper refMapper, String mixinClass) {
private static MemberInfo parse(String name, ReferenceMapper refMapper, String mixinClass) {
String desc = null;
String owner = null;
@@ -33,35 +33,58 @@ import java.util.Map;
import net.minecraft.launchwrapper.Launch;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public final class ReferenceMapper implements Serializable {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 2L;
public static final String DEFAULT_RESOURCE = "mixin.refmap.json";
private final Map<String, Map<String, String>> mappings;
private final Map<String, Map<String, String>> mappings = Maps.newHashMap();
private final Map<String, Map<String, Map<String, String>>> data = Maps.newHashMap();
private transient String context = null;
public ReferenceMapper() {
this(new HashMap<String, Map<String, String>>());
}
public ReferenceMapper(Map<String, Map<String, String>> mappings) {
this.mappings = mappings;
public String getContext() {
return this.context;
}
public void setContext(String context) {
this.context = context;
}
public String remap(String className, String reference) {
return this.remapWithContext(this.context, className, reference);
}
public String remapWithContext(String context, String className, String reference) {
Map<String, Map<String, String>> mappings = this.mappings;
if (context != null) {
mappings = this.data.get(context);
if (mappings == null) {
mappings = this.mappings;
}
}
return this.remap(mappings, className, reference);
}
private String remap(Map<String, Map<String, String>> mappings, String className, String reference) {
if (className == null) {
for (Map<String, String> mappings : this.mappings.values()) {
if (mappings.containsKey(reference)) {
return mappings.get(reference);
for (Map<String, String> mapping : mappings.values()) {
if (mapping.containsKey(reference)) {
return mapping.get(reference);
}
}
}
Map<String, String> classMappings = this.mappings.get(className);
Map<String, String> classMappings = mappings.get(className);
if (classMappings == null) {
return reference;
}
@@ -69,11 +92,19 @@ public final class ReferenceMapper implements Serializable {
return remappedReference != null ? remappedReference : reference;
}
public void addMapping(String className, String reference, String newReference) {
Map<String, String> classMappings = this.mappings.get(className);
public void addMapping(String context, String className, String reference, String newReference) {
Map<String, Map<String, String>> mappings = this.mappings;
if (context != null) {
mappings = this.data.get(context);
if (mappings == null) {
mappings = Maps.newHashMap();
this.data.put(context, mappings);
}
}
Map<String, String> classMappings = mappings.get(className);
if (classMappings == null) {
classMappings = new HashMap<String, String>();
this.mappings.put(className, classMappings);
mappings.put(className, classMappings);
}
classMappings.put(reference, newReference);
}
@@ -173,6 +173,11 @@ class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
*/
private final transient int order = MixinConfig.configOrder++;
/**
* Parent environment
*/
private transient MixinEnvironment env;
/**
* Name of the file this config was initialised from
*/
@@ -198,7 +203,7 @@ class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
* Keep track of initialisation state
*/
private transient boolean initialised = false;
/**
* Spawn via GSON, no public ctor for you
*/
@@ -207,16 +212,18 @@ class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
/**
* Called immediately after deserialisation
*
* @param env Parent environment
* @param name Mixin config name
* @return true if the config was successfully initialised and should be
* returned, or false if initialisation failed and the config should
* be discarded
*/
private boolean onLoad(String name) {
private boolean onLoad(MixinEnvironment env, String name) {
this.env = env;
this.name = name;
VersionNumber minVersion = VersionNumber.parse(this.version);
VersionNumber curVersion = VersionNumber.parse(MixinEnvironment.getCurrentEnvironment().getVersion());
VersionNumber curVersion = VersionNumber.parse(env.getVersion());
if (minVersion.compareTo(curVersion) > 0) {
this.logger.warn("Mixin config {} requires mixin subsystem version {} but {} was found. The mixin config will not be applied.",
this.name, minVersion, curVersion);
@@ -257,7 +264,7 @@ class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
}
this.refMapper = ReferenceMapper.read(this.refMapperConfig);
this.verboseLogging |= MixinEnvironment.getCurrentEnvironment().getOption(Option.DEBUG_VERBOSE);
this.verboseLogging |= env.getOption(Option.DEBUG_VERBOSE);
return true;
}
@@ -283,7 +290,7 @@ class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
this.initialiseMixins(this.mixinClasses, false, hotSwapper);
switch (MixinEnvironment.getCurrentEnvironment().getSide()) {
switch (this.env.getSide()) {
case CLIENT:
this.initialiseMixins(this.mixinClassesClient, false, hotSwapper);
break;
@@ -372,7 +379,16 @@ class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
public boolean isRequired() {
return this.required;
}
/* (non-Javadoc)
* @see org.spongepowered.asm.mixin.extensibility.IMixinConfig
* #getEnvironment()
*/
@Override
public MixinEnvironment getEnvironment() {
return this.env;
}
/* (non-Javadoc)
* @see org.spongepowered.asm.mixin.transformer.IMixinConfig#getName()
*/
@@ -424,6 +440,7 @@ class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
* Get the reference remapper for injectors
*/
public ReferenceMapper getReferenceMapper() {
this.refMapper.setContext(this.env.getObfuscationContext());
return this.refMapper;
}
@@ -551,12 +568,13 @@ class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
* specified configFile, which must be accessible on the classpath
*
* @param configFile
* @param env parent environment
* @return
*/
static MixinConfig create(String configFile) {
static MixinConfig create(String configFile, MixinEnvironment env) {
try {
MixinConfig config = new Gson().fromJson(new InputStreamReader(Launch.classLoader.getResourceAsStream(configFile)), MixinConfig.class);
if (config.onLoad(configFile)) {
if (config.onLoad(env, configFile)) {
return config;
}
return null;
@@ -492,7 +492,7 @@ public class MixinTransformer extends TreeTransformer {
if (configs != null) {
for (String configFile : configs) {
try {
MixinConfig config = MixinConfig.create(configFile);
MixinConfig config = MixinConfig.create(configFile, environment);
if (config != null) {
this.logger.log(this.verboseLoggingLevel, "Adding mixin config {}", config);
this.pendingConfigs.add(config);