mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-22 03:52:11 +00:00
Continue applying mixins if an optional mixin is invalid, fixes #313
This commit is contained in:
1 parent
4120c80a8a
commit
7567dec1d8
7 files changed
+92
-24
No files matched your search
@@ -271,9 +271,18 @@ class MixinApplicatorStandard {
|
||||
final void apply(SortedSet<MixinInfo> mixins) {
|
||||
List<MixinTargetContext> mixinContexts = new ArrayList<MixinTargetContext>();
|
||||
|
||||
for (MixinInfo mixin : mixins) {
|
||||
this.logger.log(mixin.getLoggingLevel(), "Mixing {} from {} into {}", mixin.getName(), mixin.getParent(), this.targetName);
|
||||
mixinContexts.add(mixin.createContextFor(this.context));
|
||||
for (Iterator<MixinInfo> iter = mixins.iterator(); iter.hasNext();) {
|
||||
MixinInfo mixin = iter.next();
|
||||
try {
|
||||
this.logger.log(mixin.getLoggingLevel(), "Mixing {} from {} into {}", mixin.getName(), mixin.getParent(), this.targetName);
|
||||
mixinContexts.add(mixin.createContextFor(this.context));
|
||||
} catch (InvalidMixinException ex) {
|
||||
if (mixin.isRequired()) {
|
||||
throw ex;
|
||||
}
|
||||
this.context.addSuppressed(ex);
|
||||
iter.remove(); // Do not process this mixin further
|
||||
}
|
||||
}
|
||||
|
||||
MixinTargetContext current = null;
|
||||
@@ -292,9 +301,18 @@ class MixinApplicatorStandard {
|
||||
activity.next("%s Applicator Phase", pass);
|
||||
Section timer = this.profiler.begin("pass", pass.name().toLowerCase(Locale.ROOT));
|
||||
Activity applyActivity = this.activities.begin("Mixin");
|
||||
for (MixinTargetContext context : mixinContexts) {
|
||||
applyActivity.next(context.toString());
|
||||
this.applyMixin(current = context, pass);
|
||||
for (Iterator<MixinTargetContext> iter = mixinContexts.iterator(); iter.hasNext();) {
|
||||
current = iter.next();
|
||||
applyActivity.next(current.toString());
|
||||
try {
|
||||
this.applyMixin(current, pass);
|
||||
} catch (InvalidMixinException ex) {
|
||||
if (current.isRequired()) {
|
||||
throw ex;
|
||||
}
|
||||
this.context.addSuppressed(ex);
|
||||
iter.remove(); // Do not process this mixin further
|
||||
}
|
||||
}
|
||||
applyActivity.end();
|
||||
timer.end();
|
||||
@@ -302,9 +320,18 @@ class MixinApplicatorStandard {
|
||||
|
||||
activity.next("PostApply Phase");
|
||||
Activity postApplyActivity = this.activities.begin("Mixin");
|
||||
for (MixinTargetContext context : mixinContexts) {
|
||||
postApplyActivity.next(context.toString());
|
||||
(current = context).postApply(this.targetName, this.targetClass);
|
||||
for (Iterator<MixinTargetContext> iter = mixinContexts.iterator(); iter.hasNext();) {
|
||||
current = iter.next();
|
||||
postApplyActivity.next(current.toString());
|
||||
try {
|
||||
current.postApply(this.targetName, this.targetClass);
|
||||
} catch (InvalidMixinException ex) {
|
||||
if (current.isRequired()) {
|
||||
throw ex;
|
||||
}
|
||||
this.context.addSuppressed(ex);
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
activity.end();
|
||||
} catch (InvalidMixinException ex) {
|
||||
|
||||
@@ -1071,6 +1071,13 @@ class MixinInfo implements Comparable<MixinInfo>, IMixinInfo {
|
||||
return this.type.isLoadable();
|
||||
}
|
||||
|
||||
/**
|
||||
* True if the parent mixin config is marked as required
|
||||
*/
|
||||
public boolean isRequired() {
|
||||
return this.parent.isRequired();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the logging level for this mixin
|
||||
*/
|
||||
|
||||
+1
-1
@@ -603,7 +603,7 @@ class MixinPreProcessorStandard {
|
||||
target = context.findRemappedField(mixinField);
|
||||
if (target == null) {
|
||||
// If this field is a shadow field but is NOT found in the target class, that's bad, mmkay
|
||||
throw new InvalidMixinException(this.mixin, String.format("Shadow field %s was not located in the target class %s. %s%s",
|
||||
throw new InvalidMixinException(this.mixin, String.format("@Shadow field %s was not located in the target class %s. %s%s",
|
||||
mixinField.name, context.getTarget(), context.getReferenceMapper().getStatus(),
|
||||
MixinPreProcessorStandard.getDynamicInfo(mixinField)));
|
||||
}
|
||||
|
||||
@@ -539,7 +539,7 @@ public class MixinProcessor {
|
||||
Section timer = this.profiler.begin("preapply");
|
||||
this.extensions.preApply(context);
|
||||
timer = timer.next("apply");
|
||||
this.apply(context);
|
||||
context.applyMixins();
|
||||
timer = timer.next("postapply");
|
||||
boolean export = false;
|
||||
try {
|
||||
@@ -554,15 +554,9 @@ public class MixinProcessor {
|
||||
if (export) {
|
||||
this.extensions.export(this.currentEnvironment, context.getClassName(), context.isExportForced(), context.getClassNode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the mixins to the target class
|
||||
*
|
||||
* @param context Target class context
|
||||
*/
|
||||
private void apply(TargetClassContext context) {
|
||||
context.applyMixins();
|
||||
for (InvalidMixinException suppressed : context.getSuppressedExceptions()) {
|
||||
this.handleMixinApplyError(context.getClassName(), suppressed, environment);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleMixinPrepareError(MixinConfig config, InvalidMixinException ex, MixinEnvironment environment) throws MixinPrepareError {
|
||||
@@ -589,6 +583,7 @@ public class MixinProcessor {
|
||||
|
||||
if (environment.getOption(Option.DEBUG_VERBOSE)) {
|
||||
new PrettyPrinter()
|
||||
.wrapTo(160)
|
||||
.add("Invalid Mixin").centre()
|
||||
.hr('-')
|
||||
.kvWidth(10)
|
||||
@@ -602,7 +597,7 @@ public class MixinProcessor {
|
||||
.addWrapped(" %s", ex.getMessage())
|
||||
.hr('-')
|
||||
.add(ex, 8)
|
||||
.trace(action.logLevel);
|
||||
.log(action.logLevel);
|
||||
}
|
||||
|
||||
for (IMixinErrorHandler handler : this.getErrorHandlers(mixin.getPhase())) {
|
||||
|
||||
@@ -1048,6 +1048,13 @@ public class MixinTargetContext extends ClassContext implements IMixinContext {
|
||||
MixinInfo getInfo() {
|
||||
return this.mixin;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if the parent mixin config is marked as required
|
||||
*/
|
||||
boolean isRequired() {
|
||||
return this.mixin.isRequired();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mixin priority
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.transformer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Deque;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -45,6 +46,7 @@ import org.spongepowered.asm.mixin.injection.struct.Target;
|
||||
import org.spongepowered.asm.mixin.struct.SourceMap;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.Extensions;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.ITargetClassContext;
|
||||
import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException;
|
||||
import org.spongepowered.asm.util.Annotations;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
import org.spongepowered.asm.util.ClassSignature;
|
||||
@@ -116,6 +118,12 @@ final class TargetClassContext extends ClassContext implements ITargetClassConte
|
||||
* target class.
|
||||
*/
|
||||
private final Set<MethodNode> mixinMethods = new HashSet<MethodNode>();
|
||||
|
||||
/**
|
||||
* Exceptions which were suppressed during mixin application because they
|
||||
* were raised by an optional mixin
|
||||
*/
|
||||
private final List<InvalidMixinException> suppressedExceptions = new ArrayList<InvalidMixinException>();
|
||||
|
||||
/**
|
||||
* True once mixins have been applied to this class
|
||||
@@ -383,4 +391,12 @@ final class TargetClassContext extends ClassContext implements ITargetClassConte
|
||||
}
|
||||
}
|
||||
|
||||
void addSuppressed(InvalidMixinException ex) {
|
||||
this.suppressedExceptions.add(ex);
|
||||
}
|
||||
|
||||
List<InvalidMixinException> getSuppressedExceptions() {
|
||||
return this.suppressedExceptions;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -378,6 +378,11 @@ public class PrettyPrinter {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Minimum allowed width
|
||||
*/
|
||||
private static final int MIN_WIDTH = 40;
|
||||
|
||||
/**
|
||||
* Horizontal rule
|
||||
*/
|
||||
@@ -421,7 +426,8 @@ public class PrettyPrinter {
|
||||
}
|
||||
|
||||
public PrettyPrinter(int width) {
|
||||
this.width = width;
|
||||
this.width = Math.max(PrettyPrinter.MIN_WIDTH, width);
|
||||
this.wrapWidth = this.width - 20;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -684,7 +690,7 @@ public class PrettyPrinter {
|
||||
*/
|
||||
public PrettyPrinter add(Throwable th, int indent) {
|
||||
while (th != null) {
|
||||
this.add("%s: %s", th.getClass().getName(), th.getMessage());
|
||||
this.addWrapped(" %s: %s", th.getClass().getName(), th.getMessage());
|
||||
this.add(th.getStackTrace(), indent);
|
||||
th = th.getCause();
|
||||
}
|
||||
@@ -783,7 +789,7 @@ public class PrettyPrinter {
|
||||
|
||||
try {
|
||||
for (String wrappedLine : this.getWrapped(width, line, indent)) {
|
||||
this.addLine(wrappedLine);
|
||||
this.add(wrappedLine);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
this.add(line);
|
||||
@@ -1099,6 +1105,16 @@ public class PrettyPrinter {
|
||||
return this.log(logger, Level.INFO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write this printer to the specified logger at {@link Level#INFO}
|
||||
*
|
||||
* @param level log level
|
||||
* @return fluent interface
|
||||
*/
|
||||
public PrettyPrinter log(Level level) {
|
||||
return this.log(LogManager.getLogger(PrettyPrinter.getDefaultLoggerName()), level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write this printer to the specified logger
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user