Allow initial compatibility level to be defined via system property

This commit is contained in:
Mumfrey committed 2016-01-28 16:07:56 +00:00
1 parent 529c8ad202
commit 6ad5bc8f76
3 files changed
+47 -7

No files matched your search

@@ -336,7 +336,12 @@ public class MixinEnvironment implements ITokenProvider {
/**
* Disable refmap when required
*/
DISABLE_REFMAP(Option.ENVIRONMENT, "disableRefMap");
DISABLE_REFMAP(Option.ENVIRONMENT, "disableRefMap"),
/**
* Default compatibility level to operate at
*/
DEFAULT_COMPATIBILITY_LEVEL(Option.ENVIRONMENT, "compatLevel");
/**
* Prefix for mixin options
@@ -408,6 +413,16 @@ public class MixinEnvironment implements ITokenProvider {
String getStringValue() {
return (this.parent == null || this.parent.getBooleanValue()) ? System.getProperty(this.property) : null;
}
@SuppressWarnings("unchecked")
<E extends Enum<E>> E getEnumValue(E defaultValue) {
String value = System.getProperty(this.property, defaultValue.name());
try {
return (E) Enum.valueOf(defaultValue.getClass(), value);
} catch (IllegalArgumentException ex) {
return defaultValue;
}
}
}
/**
@@ -583,7 +598,7 @@ public class MixinEnvironment implements ITokenProvider {
/**
* Current compatibility level
*/
private static CompatibilityLevel compatibility = CompatibilityLevel.JAVA_6;
private static CompatibilityLevel compatibility = Option.DEFAULT_COMPATIBILITY_LEVEL.<CompatibilityLevel>getEnumValue(CompatibilityLevel.JAVA_6);
/**
* Show debug header info on first environment construction
@@ -338,6 +338,10 @@ class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
for (String innerClass : mixin.getSyntheticInnerClasses()) {
this.syntheticInnerClasses.add(innerClass.replace('/', '.'));
}
} catch (InvalidMixinException ex) {
this.logger.error(ex.getMixin() + ": " + ex.getMessage(), ex);
this.removeMixin(mixin);
iter.remove();
} catch (Exception ex) {
this.logger.error(ex.getMessage(), ex);
this.removeMixin(mixin);
@@ -46,6 +46,7 @@ import org.spongepowered.asm.lib.tree.MethodNode;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.MixinEnvironment.CompatibilityLevel;
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
@@ -437,19 +438,39 @@ class MixinInfo extends TreeInfo implements Comparable<MixinInfo>, IMixinInfo {
* @param state State to validate
*/
private void validateMixin(ValidationState state) {
this.validateType();
this.validateInner(state);
this.validateClassVersion(state);
this.validateRemappables(state);
}
private void validateType() {
if (this.isInterfaceMixin && !MixinEnvironment.getCompatibilityLevel().supportsMethodsInInterfaces()) {
throw new InvalidMixinException(this, "Interface mixin not supported in current enviromnment");
}
}
private void validateInner(ValidationState state) {
// isInner (shouldn't) return true for static inner classes
if (!state.classInfo.isProbablyStatic()) {
throw new InvalidMixinException(this, "Inner class mixin must be declared static");
}
if (state.classNode.version > MixinEnvironment.getCompatibilityLevel().classVersion()) {
throw new InvalidMixinException(this, "Unsupported mixin class version " + state.classNode.version);
}
}
private void validateClassVersion(ValidationState state) {
if (state.classNode.version > MixinEnvironment.getCompatibilityLevel().classVersion()) {
String helpText = ".";
for (CompatibilityLevel level : CompatibilityLevel.values()) {
if (level.classVersion() >= state.classNode.version) {
helpText = String.format(". Mixin requires compatibility level %s or above.", level.name());
}
}
throw new InvalidMixinException(this, "Unsupported mixin class version " + state.classNode.version + helpText);
}
}
private void validateRemappables(ValidationState state) {
// Can't have remappable fields or methods on a multi-target mixin, because after obfuscation the fields will remap to conflicting names
if (this.targetClasses.size() > 1) {
for (FieldNode field : state.classNode.fields) {