Add option to disable target validation in AP, closes #48 for now

This commit is contained in:
Mumfrey committed 2015-06-04 16:07:42 +01:00
1 parent 333fec6f0b
commit ce9b186e44
6 files changed
+66 -10

No files matched your search

@@ -78,7 +78,7 @@ import net.minecraftforge.srg2source.rangeapplier.SrgContainer;
* Mixin info manager, stores all of the mixin info during processing and also
* manages access to the srgs
*/
class AnnotatedMixins implements Messager, ITokenProvider {
class AnnotatedMixins implements Messager, ITokenProvider, IOptionProvider {
static enum CompilerEnvironment {
/**
@@ -175,8 +175,8 @@ class AnnotatedMixins implements Messager, ITokenProvider {
this.outRefMapFileName = this.getOption("outRefMapFile");
this.validators = ImmutableList.<IMixinValidator>of(
new ParentValidator(processingEnv, this),
new TargetValidator(processingEnv, this)
new ParentValidator(processingEnv, this, this),
new TargetValidator(processingEnv, this, this)
);
this.initTokenCache(this.getOption("tokens"));
@@ -214,7 +214,8 @@ class AnnotatedMixins implements Messager, ITokenProvider {
return value;
}
private String getOption(String option) {
@Override
public String getOption(String option) {
String value = this.processingEnv.getOptions().get(option);
if (value != null) {
return value;
@@ -0,0 +1,40 @@
/*
* This file is part of Mixin, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.tools.obfuscation;
/**
* An object which can provide option values to consumers
*/
public interface IOptionProvider {
/**
* Fetch the value of the specified option, if available
*
* @param option Name of the option to fetch
* @return Option value or null if absent
*/
public abstract String getOption(String option);
}
@@ -51,6 +51,11 @@ public abstract class MixinValidator implements IMixinValidator {
*/
protected final Messager messager;
/**
* Option provider
*/
protected final IOptionProvider options;
/**
* Pass to run this validator in
*/
@@ -61,11 +66,13 @@ public abstract class MixinValidator implements IMixinValidator {
*
* @param processingEnv Processing environment
* @param messager Messager to use
* @param options Option provider
* @param pass Validation pass being performed
*/
public MixinValidator(ProcessingEnvironment processingEnv, Messager messager, ValidationPass pass) {
public MixinValidator(ProcessingEnvironment processingEnv, Messager messager, IOptionProvider options, ValidationPass pass) {
this.processingEnv = processingEnv;
this.messager = messager;
this.options = options;
this.pass = pass;
}
@@ -49,7 +49,7 @@ import org.spongepowered.tools.MirrorUtils;
*/
@SupportedSourceVersion(SourceVersion.RELEASE_6)
@SupportedAnnotationTypes({ "org.spongepowered.asm.mixin.Mixin", "org.spongepowered.asm.mixin.Shadow", "org.spongepowered.asm.mixin.Overwrite" })
@SupportedOptions({ "reobfSrgFile", "outSrgFile", "outRefMapFile" })
@SupportedOptions({ "reobfSrgFile", "outSrgFile", "outRefMapFile", "disableTargetValidator" })
public class TargetObfuscationProcessor extends MixinProcessor {
/* (non-Javadoc)
@@ -33,6 +33,7 @@ import javax.lang.model.element.ElementKind;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import org.spongepowered.tools.obfuscation.IOptionProvider;
import org.spongepowered.tools.obfuscation.MixinValidator;
import org.spongepowered.tools.obfuscation.TypeHandle;
@@ -47,9 +48,10 @@ public class ParentValidator extends MixinValidator {
*
* @param processingEnv Processing environment
* @param messager Messager
* @param options Option provider
*/
public ParentValidator(ProcessingEnvironment processingEnv, Messager messager) {
super(processingEnv, messager, ValidationPass.EARLY);
public ParentValidator(ProcessingEnvironment processingEnv, Messager messager, IOptionProvider options) {
super(processingEnv, messager, options, ValidationPass.EARLY);
}
/* (non-Javadoc)
@@ -34,6 +34,7 @@ import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import org.spongepowered.tools.obfuscation.IOptionProvider;
import org.spongepowered.tools.obfuscation.MixinValidator;
import org.spongepowered.tools.obfuscation.TypeHandle;
@@ -48,9 +49,10 @@ public class TargetValidator extends MixinValidator {
*
* @param processingEnv Processing environment
* @param messager Messager
* @param options Option provider
*/
public TargetValidator(ProcessingEnvironment processingEnv, Messager messager) {
super(processingEnv, messager, ValidationPass.LATE);
public TargetValidator(ProcessingEnvironment processingEnv, Messager messager, IOptionProvider options) {
super(processingEnv, messager, options, ValidationPass.LATE);
}
/* (non-Javadoc)
@@ -60,6 +62,10 @@ public class TargetValidator extends MixinValidator {
*/
@Override
public boolean validate(TypeElement mixin, AnnotationMirror annotation, Collection<TypeHandle> targets) {
if ("true".equalsIgnoreCase(this.options.getOption("disableTargetValidator"))) {
return true;
}
TypeMirror superClass = mixin.getSuperclass();
for (TypeHandle target : targets) {