Merge remote-tracking branch 'SpongePowered/0.8.3'

# Conflicts:
#	gradle.properties
#	src/fernflower/java/org/spongepowered/asm/mixin/transformer/debug/RuntimeDecompiler.java
This commit is contained in:
modmuss50 committed 2021-07-01 19:08:42 +01:00
commit cf0d6242cd
7 files changed
+173 -43

No files matched your search

+1 -1
View File
@@ -234,7 +234,7 @@ checkstyle {
"year" : project.inceptionYear
]
configFile = file("checkstyle.xml")
toolVersion = '8.36.1'
toolVersion = '8.43'
}
// Source compiler configuration
+2 -3
View File
@@ -90,7 +90,7 @@
</module>
<module name="JavadocMethod">
<metadata name="net.sf.eclipsecs.core.comment" value="Package members"/>
<property name="scope" value="package"/>
<property name="accessModifiers" value="package"/>
<property name="allowMissingParamTags" value="true"/>
<property name="allowMissingReturnTag" value="true"/>
<property name="tokens" value="METHOD_DEF"/>
@@ -100,8 +100,7 @@
</module>
<module name="JavadocMethod">
<metadata name="net.sf.eclipsecs.core.comment" value="Public members"/>
<property name="scope" value="public"/>
<property name="excludeScope" value="package"/>
<property name="accessModifiers" value="public"/>
<property name="allowMissingReturnTag" value="true"/>
<property name="tokens" value="METHOD_DEF"/>
</module>
@@ -26,6 +26,8 @@ package org.spongepowered.asm.mixin.transformer.debug;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.Map;
import java.util.jar.Manifest;
@@ -35,6 +37,7 @@ import org.apache.logging.log4j.Logger;
import org.jetbrains.java.decompiler.main.Fernflower;
import org.jetbrains.java.decompiler.main.extern.IBytecodeProvider;
import org.jetbrains.java.decompiler.main.extern.IFernflowerLogger;
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences;
import org.jetbrains.java.decompiler.main.extern.IResultSaver;
import org.jetbrains.java.decompiler.util.InterpreterUtil;
import org.spongepowered.asm.mixin.transformer.ext.IDecompiler;
@@ -53,8 +56,14 @@ public class RuntimeDecompiler extends IFernflowerLogger implements IDecompiler,
private static final Level[] SEVERITY_LEVELS = { Level.TRACE, Level.INFO, Level.WARN, Level.ERROR };
private final Map<String, Object> options = ImmutableMap.<String, Object>builder()
.put("din", "0").put("rbr", "0").put("dgs", "1").put("asc", "1")
.put("den", "1").put("hdc", "1").put("ind", " ").build();
.put(IFernflowerPreferences.DECOMPILE_INNER, "0")
.put(IFernflowerPreferences.REMOVE_BRIDGE, "0")
.put(IFernflowerPreferences.DECOMPILE_GENERIC_SIGNATURES, "1")
.put(IFernflowerPreferences.ASCII_STRING_CHARACTERS, "1")
.put(IFernflowerPreferences.DECOMPILE_ENUM, "1")
.put(IFernflowerPreferences.HIDE_DEFAULT_CONSTRUCTOR, "1")
.put(IFernflowerPreferences.INDENT_STRING, " ")
.build();
private final File outputPath;
@@ -71,6 +80,17 @@ public class RuntimeDecompiler extends IFernflowerLogger implements IDecompiler,
}
}
@Override
public String toString() {
try {
URL codeSource = Fernflower.class.getProtectionDomain().getCodeSource().getLocation();
File file = new File(codeSource.toURI());
return file.getName();
} catch (Exception ex) {
return "unknown source (classpath)";
}
}
@Override
public void decompile(final File file) {
try {
@@ -88,7 +108,15 @@ public class RuntimeDecompiler extends IFernflowerLogger implements IDecompiler,
}, this, this.options, this);
fernflower.addSource(file);
try {
// New fernflower (including forgeflower)
Method mdAddSource = fernflower.getClass().getDeclaredMethod("addSource", File.class);
mdAddSource.invoke(fernflower, file);
} catch (ReflectiveOperationException ex) {
// Old fernflower
fernflower.addSource(file);
}
fernflower.decompileContext();
} catch (Throwable ex) {
this.logger.warn("Decompilation error while processing {}", file.getName());
@@ -128,7 +156,7 @@ public class RuntimeDecompiler extends IFernflowerLogger implements IDecompiler,
@Override
public void writeMessage(String message, Severity severity, Throwable t) {
this.logger.log(RuntimeDecompiler.SEVERITY_LEVELS[severity.ordinal()], message, t);
this.logger.log(RuntimeDecompiler.SEVERITY_LEVELS[severity.ordinal()], message, severity == Severity.ERROR ? t : null);
}
@Override
@@ -742,6 +742,28 @@ public final class MixinEnvironment implements ITokenProvider {
*/
public static CompatibilityLevel DEFAULT = CompatibilityLevel.JAVA_6;
/**
* Maximum compatibility level actually supported. Other compatibility
* levels might exist but we don't actually have any internal code in
* place which supports those features. This is mainly used to indicate
* that mixin classes compiled with newer JDKs might have bytecode-level
* class features that this version of mixin doesn't understand, even
* when the current ASM or JRE do.
*
* <p>This is particularly important for the case where a config
* declares a higher version (eg. JAVA_14) which has been added to the
* enum but no code actually exists within Mixin as a library to handle
* language features from that version. In other words adding values to
* this enum doesn't magically add support for language features, and
* this field should point to the highest <em>known <b>supported</b>
* </em> version regardless of other <em>known</em> versions.</p>
*
* <p>This comment mainly added to avoid stuff in the future like
* PR #500 which demonstrates that the nature of compatibility levels
* in mixin are not understood that well.</p>
*/
public static CompatibilityLevel MAX_SUPPORTED = CompatibilityLevel.JAVA_11;
private final int ver;
private final int classVersion;
@@ -887,13 +909,28 @@ public final class MixinEnvironment implements ITokenProvider {
static String getSupportedVersions() {
StringBuilder sb = new StringBuilder();
boolean comma = false;
int rangeStart = 0, rangeEnd = 0;
for (CompatibilityLevel level : CompatibilityLevel.values()) {
if (level.isSupported()) {
if (comma) {
sb.append(", ");
if (level.ver == rangeEnd + 1) {
rangeEnd = level.ver;
} else {
if (rangeStart > 0) {
sb.append(comma ? "," : "").append(rangeStart);
if (rangeEnd > rangeStart) {
sb.append(rangeEnd > rangeStart + 1 ? '-' : ',').append(rangeEnd);
}
comma = true;
rangeStart = rangeEnd = level.ver;
}
rangeStart = rangeEnd = level.ver;
}
sb.append(level.ver);
comma = true;
}
}
if (rangeStart > 0) {
sb.append(comma ? "," : "").append(rangeStart);
if (rangeEnd > rangeStart) {
sb.append(rangeEnd > rangeStart + 1 ? '-' : ',').append(rangeEnd);
}
}
return sb.toString();
@@ -1075,8 +1112,8 @@ public final class MixinEnvironment implements ITokenProvider {
printer.add("SpongePowered MIXIN%s", verbose ? " (Verbose debugging enabled)" : "").centre().hr();
printer.kv("Code source", codeSource);
printer.kv("Internal Version", version);
printer.kv("Java Versions Supported", CompatibilityLevel.getSupportedVersions());
printer.kv("Current Compatibility Level", MixinEnvironment.getCompatibilityLevel());
printer.kv("Java Version", "%s (supports compatibility %s)", JavaVersion.current(), CompatibilityLevel.getSupportedVersions());
printer.kv("Default Compatibility Level", MixinEnvironment.getCompatibilityLevel());
printer.kv("Detected ASM API Version", ASM.getApiVersionString());
printer.kv("Detected ASM Supports Java", ASM.getClassVersionString()).hr();
printer.kv("Service Name", serviceName);
@@ -372,6 +372,17 @@ final class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
* Track whether this mixin has been evaluated for selection yet
*/
private transient boolean visited = false;
/**
* Compatibility level read from the config (or default if none specified)
*/
private transient CompatibilityLevel compatibilityLevel = CompatibilityLevel.DEFAULT;
/**
* Only emit the compatibility level warning for any increase in the class
* version, track warned level here
*/
private transient int warnedClassVersion = 0;
/**
* Spawn via GSON, no public ctor for you
@@ -399,6 +410,7 @@ final class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
// If no parent, initialise config options
this.env = this.parseSelector(this.selector, fallbackEnvironment);
this.verboseLogging |= this.env.getOption(Option.DEBUG_VERBOSE);
this.required = this.requiredValue != null && this.requiredValue.booleanValue() && !this.env.getOption(Option.IGNORE_REQUIRED);
this.initPriority(IMixinConfig.DEFAULT_PRIORITY, IMixinConfig.DEFAULT_PRIORITY);
@@ -442,6 +454,7 @@ final class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
}
this.env = this.parseSelector(this.selector, this.parent.env);
this.verboseLogging |= this.env.getOption(Option.DEBUG_VERBOSE);
this.required = this.requiredValue == null ? this.parent.required
: this.requiredValue.booleanValue() && !this.env.getOption(Option.IGNORE_REQUIRED);
@@ -488,31 +501,74 @@ final class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
@SuppressWarnings("deprecation")
private void initCompatibilityLevel() {
this.compatibilityLevel = MixinEnvironment.getCompatibilityLevel();
if (this.compatibility == null) {
return;
}
CompatibilityLevel level = CompatibilityLevel.valueOf(this.compatibility.trim().toUpperCase(Locale.ROOT));
CompatibilityLevel current = MixinEnvironment.getCompatibilityLevel();
String strCompatibility = this.compatibility.trim().toUpperCase(Locale.ROOT);
try {
this.compatibilityLevel = CompatibilityLevel.valueOf(strCompatibility);
} catch (IllegalArgumentException ex) {
throw new MixinInitialisationError(String.format("Mixin config %s specifies compatibility level %s which is not recognised",
this.name, strCompatibility));
}
if (level == current) {
CompatibilityLevel currentLevel = MixinEnvironment.getCompatibilityLevel();
if (this.compatibilityLevel == currentLevel) {
return;
}
// Current level is higher than required but too new to support it
if (current.isAtLeast(level)) {
if (!current.canSupport(level)) {
throw new MixinInitialisationError("Mixin config " + this.name + " requires compatibility level " + level + " which is too old");
}
if (currentLevel.isAtLeast(this.compatibilityLevel) && !currentLevel.canSupport(this.compatibilityLevel)) {
throw new MixinInitialisationError(String.format("Mixin config %s requires compatibility level %s which is too old",
this.name, this.compatibilityLevel));
}
// Current level is lower than required but current level prohibits elevation
if (!current.canElevateTo(level)) {
throw new MixinInitialisationError("Mixin config " + this.name + " requires compatibility level " + level + " which is prohibited by "
+ current);
if (!currentLevel.canElevateTo(this.compatibilityLevel)) {
throw new MixinInitialisationError(String.format("Mixin config %s requires compatibility level %s which is prohibited by %s",
this.name, this.compatibilityLevel, currentLevel));
}
MixinEnvironment.setCompatibilityLevel(level);
// Required level is higher than highest version we support, this possibly
// means that a shaded mixin dependency has been usurped by an old version,
// or the mixin author is trying to elevate the compatibility level beyond
// the versions currently supported
if (CompatibilityLevel.MAX_SUPPORTED.isLessThan(this.compatibilityLevel)) {
Level logLevel = this.verboseLogging ? Level.WARN : Level.DEBUG;
this.logger.log(logLevel,
"Compatibility level {} specified by {} is higher than the maximum level supported by this version of mixin ({}).",
this.compatibilityLevel, this, CompatibilityLevel.MAX_SUPPORTED);
}
MixinEnvironment.setCompatibilityLevel(this.compatibilityLevel);
}
/**
* Called by MixinTargetContext when class version is elevated, allows us to
* warn devs (or end-users with verbose turned on, for whatever reason) that
* the current compatibility level is too low for the classes being
* processed. The warning is only emitted at WARN for each new class version
* and at DEBUG thereafter.
*
* <p>The logic here is that we only really care about supported class
* features, but a version of mixin which doesn't actually support newer
* features may well be able to operate with classes *compiled* with a newer
* JDK, but we don't actually know that for sure).
*/
void checkCompatibilityLevel(MixinInfo mixin, int majorVersion, int minorVersion) {
if (majorVersion <= this.compatibilityLevel.getClassMajorVersion()) {
return;
}
Level logLevel = this.verboseLogging && majorVersion > this.warnedClassVersion ? Level.WARN : Level.DEBUG;
String message = majorVersion > CompatibilityLevel.MAX_SUPPORTED.getClassMajorVersion()
? "the current version of Mixin" : "the declared compatibility level";
this.warnedClassVersion = majorVersion;
this.logger.log(logLevel, "{}: Class version {} required is higher than the class version supported by {} ({} supports class version {})",
mixin, majorVersion, message, this.compatibilityLevel, this.compatibilityLevel.getClassMajorVersion());
}
// AMS - temp
@@ -639,7 +695,11 @@ final class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
*/
void onSelect() {
this.plugin = new PluginHandle(this, this.service, this.pluginClassName);
this.plugin.onLoad(this.mixinPackage);
this.plugin.onLoad(Strings.nullToEmpty(this.mixinPackage));
if (Strings.isNullOrEmpty(this.mixinPackage)) {
return;
}
if (!this.mixinPackage.endsWith(".")) {
this.mixinPackage += ".";
@@ -657,7 +717,6 @@ final class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
}
this.refMapper = ReferenceMapper.read(this.refMapperConfig);
this.verboseLogging |= this.env.getOption(Option.DEBUG_VERBOSE);
if (!suppressRefMapWarning && this.refMapper.isDefault() && !this.env.getOption(Option.DISABLE_REFMAP)) {
this.logger.warn("Reference map '{}' for {} could not be read. If this is a development environment you can ignore this message",
@@ -672,7 +731,7 @@ final class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
String wrapperName = this.mixinPackage + this.refMapperWrapper;
try {
@SuppressWarnings("unchecked")
Class<IReferenceMapper> wrapperCls = (Class<IReferenceMapper>) Class.forName(wrapperName);
Class<IReferenceMapper> wrapperCls = (Class<IReferenceMapper>) this.service.getClassProvider().findClass(wrapperName, true);
Constructor<IReferenceMapper> ctr = wrapperCls.getConstructor(MixinEnvironment.class, IReferenceMapper.class);
this.refMapper = ctr.newInstance(this.env, this.refMapper);
} catch (ClassNotFoundException e) {
@@ -704,14 +763,14 @@ final class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
}
this.prepared = true;
this.prepareMixins(this.mixinClasses, false);
this.prepareMixins("mixins", this.mixinClasses, false);
switch (this.env.getSide()) {
case CLIENT:
this.prepareMixins(this.mixinClassesClient, false);
this.prepareMixins("client", this.mixinClassesClient, false);
break;
case SERVER:
this.prepareMixins(this.mixinClassesServer, false);
this.prepareMixins("server", this.mixinClassesServer, false);
break;
case UNKNOWN:
//$FALL-THROUGH$
@@ -724,7 +783,7 @@ final class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
void postInitialise() {
if (this.plugin != null) {
List<String> pluginMixins = this.plugin.getMixins();
this.prepareMixins(pluginMixins, true);
this.prepareMixins("companion plugin", pluginMixins, true);
}
for (Iterator<MixinInfo> iter = this.mixins.iterator(); iter.hasNext();) {
@@ -756,11 +815,19 @@ final class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
}
}
private void prepareMixins(List<String> mixinClasses, boolean ignorePlugin) {
private void prepareMixins(String collectionName, List<String> mixinClasses, boolean ignorePlugin) {
if (mixinClasses == null) {
return;
}
if (Strings.isNullOrEmpty(this.mixinPackage)) {
if (mixinClasses.size() > 0) {
this.logger.error("{} declares mixin classes in {} but does not specify a package, {} orphaned mixins will not be loaded: {}",
this, collectionName, mixinClasses.size(), mixinClasses);
}
return;
}
for (String mixinClass : mixinClasses) {
String fqMixinClass = this.mixinPackage + mixinClass;
@@ -864,7 +931,7 @@ final class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
*/
@Override
public String getMixinPackage() {
return this.mixinPackage;
return Strings.nullToEmpty(this.mixinPackage);
}
/**
@@ -969,6 +1036,10 @@ final class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public List<String> getClasses() {
if (Strings.isNullOrEmpty(this.mixinPackage)) {
return Collections.<String>emptyList();
}
Builder<String> list = ImmutableList.<String>builder();
for (List<String> classes : new List[] { this.mixinClasses, this.mixinClassesClient, this.mixinClassesServer} ) {
if (classes != null) {
@@ -1065,7 +1136,7 @@ final class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
* package
*/
public boolean packageMatch(String className) {
return className.startsWith(this.mixinPackage);
return !Strings.isNullOrEmpty(this.mixinPackage) && className.startsWith(this.mixinPackage);
}
/**
@@ -1088,12 +1088,7 @@ public class MixinTargetContext extends ClassContext implements IMixinContext {
majorVersion, minorVersion, ASM.getClassVersionString()));
}
CompatibilityLevel compatibilityLevel = MixinEnvironment.getCompatibilityLevel();
if (majorVersion > compatibilityLevel.getClassMajorVersion()) {
MixinTargetContext.logger.warn(
"{}: Class version {}.{} required is higher than the class version supported by the current compatibility level {} ",
this, majorVersion, minorVersion, compatibilityLevel);
}
this.mixin.getParent().checkCompatibilityLevel(this.mixin, majorVersion, minorVersion);
}
/* (non-Javadoc)
@@ -98,8 +98,8 @@ public class ExtensionClassExporter implements IExtension {
Class<? extends IDecompiler> clazz = (Class<? extends IDecompiler>)Class.forName(className);
Constructor<? extends IDecompiler> ctor = clazz.getDeclaredConstructor(File.class);
IDecompiler decompiler = ctor.newInstance(outputPath);
ExtensionClassExporter.logger.info("Fernflower decompiler was successfully initialised, exported classes will be decompiled{}",
as ? " in a separate thread" : "");
ExtensionClassExporter.logger.info("Fernflower decompiler was successfully initialised from {}, exported classes will be decompiled{}",
decompiler, as ? " in a separate thread" : "");
return decompiler;
} catch (Throwable th) {
ExtensionClassExporter.logger.info("Fernflower could not be loaded, exported classes will not be decompiled. {}: {}",