Skip to content

Commit

Permalink
Add refmapper debugging/runtime flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Mumfrey committed Jan 7, 2016
1 parent 30e2530 commit fb2360c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
33 changes: 32 additions & 1 deletion src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,27 @@ boolean getBooleanValue() {
/**
* Enables the hot-swap agent
*/
HOT_SWAP("hotSwap");
HOT_SWAP("hotSwap"),

/**
* Parent for environment settings
*/
ENVIRONMENT("env") {
@Override
boolean getBooleanValue() {
return false;
}
},

/**
* Force refmap obf type when required
*/
OBFUSCATION_TYPE(Option.ENVIRONMENT, "obf"),

/**
* Disable refmap when required
*/
DISABLE_REFMAP(Option.ENVIRONMENT, "disableRefMap");

/**
* Prefix for mixin options
Expand Down Expand Up @@ -925,6 +945,17 @@ public String getObfuscationContext() {
return this.obfuscationContext;
}

/**
* Get the current obfuscation context
*/
public String getRefmapObfuscationContext() {
String overrideObfuscationType = Option.OBFUSCATION_TYPE.getStringValue();
if (overrideObfuscationType != null) {
return overrideObfuscationType;
}
return this.obfuscationContext;
}

/**
* Get the remapper chain for this environment
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,27 @@
import com.google.gson.GsonBuilder;

public final class ReferenceMapper implements Serializable {

private static final long serialVersionUID = 2L;

public static final String DEFAULT_RESOURCE = "mixin.refmap.json";

public static final ReferenceMapper DEFAULT_MAPPER = new ReferenceMapper(true);

private final Map<String, Map<String, String>> mappings = Maps.newHashMap();

private final Map<String, Map<String, Map<String, String>>> data = Maps.newHashMap();

private final transient boolean readOnly;

private transient String context = null;

public ReferenceMapper() {
this(false);
}

private ReferenceMapper(boolean readOnly) {
this.readOnly = readOnly;
}

public String getContext() {
Expand Down Expand Up @@ -93,6 +102,9 @@ private String remap(Map<String, Map<String, String>> mappings, String className
}

public void addMapping(String context, String className, String reference, String newReference) {
if (this.readOnly) {
return;
}
Map<String, Map<String, String>> mappings = this.mappings;
if (context != null) {
mappings = this.data.get(context);
Expand All @@ -119,7 +131,7 @@ public static ReferenceMapper read(String resource) {
reader = new InputStreamReader(Launch.classLoader.getResourceAsStream(resource));
return ReferenceMapper.read(reader);
} catch (Exception ex) {
return new ReferenceMapper();
return ReferenceMapper.DEFAULT_MAPPER;
} finally {
if (reader != null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,10 @@ public boolean shouldSetSourceFile() {
* Get the reference remapper for injectors
*/
public ReferenceMapper getReferenceMapper() {
this.refMapper.setContext(this.env.getObfuscationContext());
if (this.env.getOption(Option.DISABLE_REFMAP)) {
return ReferenceMapper.DEFAULT_MAPPER;
}
this.refMapper.setContext(this.env.getRefmapObfuscationContext());
return this.refMapper;
}

Expand Down

0 comments on commit fb2360c

Please sign in to comment.