, 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.
+ *
+ * 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, 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, 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, IMixinConfig {
String wrapperName = this.mixinPackage + this.refMapperWrapper;
try {
@SuppressWarnings("unchecked")
- Class wrapperCls = (Class) Class.forName(wrapperName);
+ Class wrapperCls = (Class) this.service.getClassProvider().findClass(wrapperName, true);
Constructor 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, 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, IMixinConfig {
void postInitialise() {
if (this.plugin != null) {
List pluginMixins = this.plugin.getMixins();
- this.prepareMixins(pluginMixins, true);
+ this.prepareMixins("companion plugin", pluginMixins, true);
}
for (Iterator iter = this.mixins.iterator(); iter.hasNext();) {
@@ -756,11 +815,19 @@ final class MixinConfig implements Comparable, IMixinConfig {
}
}
- private void prepareMixins(List mixinClasses, boolean ignorePlugin) {
+ private void prepareMixins(String collectionName, List 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, IMixinConfig {
*/
@Override
public String getMixinPackage() {
- return this.mixinPackage;
+ return Strings.nullToEmpty(this.mixinPackage);
}
/**
@@ -969,6 +1036,10 @@ final class MixinConfig implements Comparable, IMixinConfig {
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public List getClasses() {
+ if (Strings.isNullOrEmpty(this.mixinPackage)) {
+ return Collections.emptyList();
+ }
+
Builder list = ImmutableList.builder();
for (List classes : new List[] { this.mixinClasses, this.mixinClassesClient, this.mixinClassesServer} ) {
if (classes != null) {
@@ -1065,7 +1136,7 @@ final class MixinConfig implements Comparable, IMixinConfig {
* package
*/
public boolean packageMatch(String className) {
- return className.startsWith(this.mixinPackage);
+ return !Strings.isNullOrEmpty(this.mixinPackage) && className.startsWith(this.mixinPackage);
}
/**
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java
index 51f2077d..96767c46 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java
@@ -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)
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/ext/extensions/ExtensionClassExporter.java b/src/main/java/org/spongepowered/asm/mixin/transformer/ext/extensions/ExtensionClassExporter.java
index 2c40ee97..c362ac03 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/ext/extensions/ExtensionClassExporter.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/ext/extensions/ExtensionClassExporter.java
@@ -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. {}: {}",