Skip to content

Commit

Permalink
Add option to disable target validation in AP, closes SpongePowered#48
Browse files Browse the repository at this point in the history
…for now
  • Loading branch information
Mumfrey committed Jun 4, 2015
1 parent 333fec6 commit ce9b186
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
* 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 {
/**
Expand Down Expand Up @@ -175,8 +175,8 @@ private AnnotatedMixins(ProcessingEnvironment processingEnv) {
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"));
Expand Down Expand Up @@ -214,7 +214,8 @@ public Integer getToken(String token) {
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
*/
@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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
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;

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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;

Expand All @@ -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)
Expand All @@ -60,6 +62,10 @@ public TargetValidator(ProcessingEnvironment processingEnv, Messager messager) {
*/
@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) {
Expand Down

0 comments on commit ce9b186

Please sign in to comment.