mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-21 05:42:15 +00:00
Add option to dump the target class bytecode if mixin application fails
This commit is contained in:
1 parent
7dbc932597
commit
85330a8649
2 files changed
+24
-10
No files matched your search
@@ -130,6 +130,12 @@ public class MixinEnvironment {
|
||||
*/
|
||||
DEBUG_VERBOSE(Option.DEBUG_ALL, "verbose"),
|
||||
|
||||
/**
|
||||
* Dumps the bytecode for the target class to disk when mixin
|
||||
* application fails
|
||||
*/
|
||||
DUMP_TARGET_ON_FAILURE("dumpTargetOnFailure"),
|
||||
|
||||
/**
|
||||
* Enable all checks
|
||||
*/
|
||||
@@ -209,12 +215,12 @@ public class MixinEnvironment {
|
||||
if (this.getOption(Option.DEBUG_VERBOSE)) {
|
||||
PrettyPrinter printer = new PrettyPrinter(32);
|
||||
printer.add("SpongePowered MIXIN (Verbose debugging enabled)").centre().hr();
|
||||
printer.add("%24s : %s", "Code source", this.getClass().getProtectionDomain().getCodeSource().getLocation());
|
||||
printer.add("%24s : %s", "Internal Version", version).hr();
|
||||
printer.add("%25s : %s", "Code source", this.getClass().getProtectionDomain().getCodeSource().getLocation());
|
||||
printer.add("%25s : %s", "Internal Version", version).hr();
|
||||
for (Option option : Option.values()) {
|
||||
printer.add("%24s : %s%s", option.property, option.parent == null ? "" : " - ", this.getOption(option));
|
||||
printer.add("%25s : %s%s", option.property, option.parent == null ? "" : " - ", this.getOption(option));
|
||||
}
|
||||
printer.hr().add("%24s : %s", "Detected Side", this.getSide());
|
||||
printer.hr().add("%25s : %s", "Detected Side", this.getSide());
|
||||
printer.print(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,6 +292,10 @@ public class MixinTransformer extends TreeTransformer {
|
||||
try {
|
||||
basicClass = this.applyMixins(transformedName, basicClass, mixins);
|
||||
} catch (InvalidMixinException th) {
|
||||
if (MixinEnvironment.getCurrentEnvironment().getOption(Option.DUMP_TARGET_ON_FAILURE)) {
|
||||
this.dumpClass(transformedName.replace('.', '/') + ".target", basicClass);
|
||||
}
|
||||
|
||||
MixinConfig config = th.getMixin().getParent();
|
||||
this.logger.log(config.isRequired() ? Level.FATAL : Level.WARN, String.format("Mixin failed applying %s -> %s: %s %s",
|
||||
th.getMixin(), transformedName, th.getClass().getName(), th.getMessage()), th);
|
||||
@@ -434,16 +438,20 @@ public class MixinTransformer extends TreeTransformer {
|
||||
|
||||
// Export transformed class for debugging purposes
|
||||
if (MixinEnvironment.getCurrentEnvironment().getOption(Option.DEBUG_EXPORT)) {
|
||||
try {
|
||||
FileUtils.writeByteArrayToFile(new File(".mixin.out/" + transformedName.replace('.', '/') + ".class"), bytes);
|
||||
} catch (IOException ex) {
|
||||
// don't care
|
||||
}
|
||||
this.dumpClass(transformedName.replace('.', '/'), bytes);
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
||||
private void dumpClass(String fileName, byte[] bytes) {
|
||||
try {
|
||||
FileUtils.writeByteArrayToFile(new File(".mixin.out/" + fileName + ".class"), bytes);
|
||||
} catch (IOException ex) {
|
||||
// don't care
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process tasks before transform
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user