From a15897221bb7c94d00ccc04637294f7a48e58b6d Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Thu, 19 Sep 2019 21:21:15 +0100 Subject: [PATCH] Minor tweaks to AP internals --- .../AnnotatedMixinElementHandler.java | 4 ---- .../tools/obfuscation/AnnotatedMixins.java | 6 ++++++ .../tools/obfuscation/ObfuscationType.java | 8 ++++---- .../obfuscation/fg3/ObfuscationServiceFG3.java | 2 -- .../obfuscation/interfaces/IOptionProvider.java | 10 ++++++++++ .../obfuscation/mcp/ObfuscationServiceMCP.java | 4 +--- .../obfuscation/service/ObfuscationServices.java | 16 ++++++++++++++++ .../mixin/transformer/MixinPostProcessor.java | 3 --- 8 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinElementHandler.java b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinElementHandler.java index b8b0a317..b32dc0f5 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinElementHandler.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinElementHandler.java @@ -498,10 +498,6 @@ abstract class AnnotatedMixinElementHandler { } } - private void printMessage(Kind kind, String msg, Element e, AnnotationHandle annotation) { - this.printMessage(kind, msg, e, annotation, null); - } - private void printMessage(Kind kind, String msg, Element e, AnnotationHandle annotation, String suppressedBy) { if (annotation == null) { this.ap.printMessage(kind, msg, e, suppressedBy); diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixins.java b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixins.java index 45da79de..fbe9bf62 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixins.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixins.java @@ -246,6 +246,12 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider return this.getProperties().getProperty(option); } + @Override + public String getOption(String option, String defaultValue) { + String value = this.getOption(option); + return value != null ? value : defaultValue; + } + @Override public boolean getOption(String option, boolean defaultValue) { String value = this.getOption(option); diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/ObfuscationType.java b/src/ap/java/org/spongepowered/tools/obfuscation/ObfuscationType.java index 41e407a0..5865fd56 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/ObfuscationType.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/ObfuscationType.java @@ -32,7 +32,6 @@ import java.util.Map; import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor; import org.spongepowered.tools.obfuscation.interfaces.IOptionProvider; -import org.spongepowered.tools.obfuscation.mcp.ObfuscationServiceMCP; import org.spongepowered.tools.obfuscation.service.ObfuscationTypeDescriptor; import com.google.common.collect.ImmutableList; @@ -43,6 +42,8 @@ import com.google.common.collect.ImmutableList.Builder; */ public final class ObfuscationType { + public static final String DEFAULT_TYPE = "searge"; + /** * Available obfuscation types indexed by key */ @@ -111,9 +112,8 @@ public final class ObfuscationType { * Get whether this is ithe default obfuscation environment */ public boolean isDefault() { - String defaultEnv = this.options.getOption(SupportedOptions.DEFAULT_OBFUSCATION_ENV); - return (defaultEnv == null && this.key.equals(ObfuscationServiceMCP.SEARGE)) - || (defaultEnv != null && this.key.equals(defaultEnv.toLowerCase(Locale.ROOT))); + String defaultEnv = this.options.getOption(SupportedOptions.DEFAULT_OBFUSCATION_ENV, ObfuscationType.DEFAULT_TYPE).toLowerCase(Locale.ROOT); + return (this.key.equals(defaultEnv)); } /** diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/fg3/ObfuscationServiceFG3.java b/src/ap/java/org/spongepowered/tools/obfuscation/fg3/ObfuscationServiceFG3.java index bf83a2fd..ad2654b9 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/fg3/ObfuscationServiceFG3.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/fg3/ObfuscationServiceFG3.java @@ -45,7 +45,6 @@ public class ObfuscationServiceFG3 implements IObfuscationService { public static final String REOBF_TSRG_FILE = "reobfTsrgFile"; public static final String OUT_TSRG_SRG_FILE = "outTsrgFile"; - public static final String OUT_REFMAP_FILE = "outRefMapFile"; public static final String TSRG_OUTPUT_BEHAVIOUR = "mergeBehaviour"; @Override @@ -53,7 +52,6 @@ public class ObfuscationServiceFG3 implements IObfuscationService { return ImmutableSet.of( ObfuscationServiceFG3.REOBF_TSRG_FILE, ObfuscationServiceFG3.OUT_TSRG_SRG_FILE, - ObfuscationServiceFG3.OUT_REFMAP_FILE, ObfuscationServiceFG3.TSRG_OUTPUT_BEHAVIOUR ); } diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/interfaces/IOptionProvider.java b/src/ap/java/org/spongepowered/tools/obfuscation/interfaces/IOptionProvider.java index 10d5eb8e..4680e488 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/interfaces/IOptionProvider.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/interfaces/IOptionProvider.java @@ -39,6 +39,16 @@ public interface IOptionProvider { */ public abstract String getOption(String option); + /** + * Fetch the value of the specified option, if available. If the option is + * not available, return the specified default value + * + * @param option Name of the option to fetch + * @param defaultValue Default value to return if the option is not present + * @return Option value or default if absent + */ + public abstract String getOption(String option, String defaultValue); + /** * Fetch the value of the specified option, if available. If the option is * not available, return the specified default value diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/mcp/ObfuscationServiceMCP.java b/src/ap/java/org/spongepowered/tools/obfuscation/mcp/ObfuscationServiceMCP.java index 9c8ccb63..e23dc0a1 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/mcp/ObfuscationServiceMCP.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/mcp/ObfuscationServiceMCP.java @@ -50,7 +50,6 @@ public class ObfuscationServiceMCP implements IObfuscationService { public static final String REOBF_EXTRA_NOTCH_FILES = "reobfNotchSrgFiles"; public static final String OUT_SRG_SRG_FILE = "outSrgFile"; public static final String OUT_NOTCH_SRG_FILE = "outNotchSrgFile"; - public static final String OUT_REFMAP_FILE = "outRefMapFile"; @Override public Set getSupportedOptions() { @@ -60,8 +59,7 @@ public class ObfuscationServiceMCP implements IObfuscationService { ObfuscationServiceMCP.REOBF_NOTCH_FILE, ObfuscationServiceMCP.REOBF_EXTRA_NOTCH_FILES, ObfuscationServiceMCP.OUT_SRG_SRG_FILE, - ObfuscationServiceMCP.OUT_NOTCH_SRG_FILE, - ObfuscationServiceMCP.OUT_REFMAP_FILE + ObfuscationServiceMCP.OUT_NOTCH_SRG_FILE ); } diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/service/ObfuscationServices.java b/src/ap/java/org/spongepowered/tools/obfuscation/service/ObfuscationServices.java index f65e9673..2ea96cb7 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/service/ObfuscationServices.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/service/ObfuscationServices.java @@ -26,6 +26,7 @@ package org.spongepowered.tools.obfuscation.service; import java.util.Collection; import java.util.HashSet; +import java.util.Locale; import java.util.ServiceConfigurationError; import java.util.ServiceLoader; import java.util.Set; @@ -33,6 +34,7 @@ import java.util.Set; import javax.tools.Diagnostic.Kind; import org.spongepowered.tools.obfuscation.ObfuscationType; +import org.spongepowered.tools.obfuscation.SupportedOptions; import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor; /** @@ -78,6 +80,8 @@ public final class ObfuscationServices { * @param ap annotation processor */ public void initProviders(IMixinAnnotationProcessor ap) { + boolean defaultIsPresent = false; + try { for (IObfuscationService service : this.serviceLoader) { if (!this.services.contains(service)) { @@ -91,6 +95,7 @@ public final class ObfuscationServices { try { ObfuscationType type = ObfuscationType.create(obfType, ap); ap.printMessage(Kind.NOTE, serviceName + " supports type: \"" + type + "\""); + defaultIsPresent |= type.isDefault(); } catch (Exception ex) { ex.printStackTrace(); } @@ -102,6 +107,17 @@ public final class ObfuscationServices { ap.printMessage(Kind.ERROR, serviceError.getClass().getSimpleName() + ": " + serviceError.getMessage()); serviceError.printStackTrace(); } + + if (!defaultIsPresent) { + String defaultEnv = ap.getOption(SupportedOptions.DEFAULT_OBFUSCATION_ENV); + if (defaultEnv == null) { + ap.printMessage(Kind.WARNING, "No default obfuscation environment was specified and \"" + ObfuscationType.DEFAULT_TYPE + + "\" is not available. Please ensure defaultObfuscationEnv is specified in your build configuration"); + } else { + ap.printMessage(Kind.WARNING, "Specified default obfuscation environment \"" + defaultEnv.toLowerCase(Locale.ROOT) + + "\" was not defined. This probably means your build configuration is out of date or a required service is missing"); + } + } } /** diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinPostProcessor.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinPostProcessor.java index 4e80f822..a0931ecf 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinPostProcessor.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinPostProcessor.java @@ -29,9 +29,6 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.FieldVisitor; -import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; import org.objectweb.asm.tree.AnnotationNode;