mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-22 08:38:24 +00:00
0.7.3 - Refactoring some packages and unify transformer extensions
This commit is contained in:
1 parent
5a1a51a2f0
commit
a05e7347a5
52 files changed
+721
-313
No files matched your search
@@ -62,7 +62,7 @@ public abstract class MixinBootstrap {
|
||||
/**
|
||||
* Subsystem version
|
||||
*/
|
||||
public static final String VERSION = "0.7.2";
|
||||
public static final String VERSION = "0.7.3";
|
||||
|
||||
// Consts
|
||||
private static final String LAUNCH_PACKAGE = "org.spongepowered.asm.launch.";
|
||||
|
||||
@@ -33,8 +33,6 @@ import java.util.jar.Attributes;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
/**
|
||||
* "Main" attribute cache for a URI container, mainly to avoid constantly
|
||||
* opening jar files just to read odd values out of the manifest.
|
||||
|
||||
@@ -1260,7 +1260,7 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
Object activeTransformer = this.getActiveTransformer();
|
||||
if (activeTransformer instanceof MixinTransformer) {
|
||||
MixinTransformer transformer = (MixinTransformer)activeTransformer;
|
||||
transformer.audit();
|
||||
transformer.audit(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1275,7 +1275,7 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
this.buildTransformerDelegationList();
|
||||
}
|
||||
|
||||
return Collections.unmodifiableList(this.transformers);
|
||||
return Collections.<IClassTransformer>unmodifiableList(this.transformers);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1465,7 +1465,7 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
throw new IllegalArgumentException("Cannot go to the specified phase, phase is null or invalid");
|
||||
}
|
||||
|
||||
if (phase.ordinal > getCurrentPhase().ordinal) {
|
||||
if (phase.ordinal > MixinEnvironment.getCurrentPhase().ordinal) {
|
||||
MixinBootstrap.addProxy();
|
||||
}
|
||||
|
||||
|
||||
@@ -34,13 +34,13 @@ import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.tree.*;
|
||||
import org.spongepowered.asm.mixin.injection.Coerce;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionNodes.InjectionNode;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.Surrogate;
|
||||
import org.spongepowered.asm.mixin.injection.code.Injector;
|
||||
import org.spongepowered.asm.mixin.injection.points.BeforeReturn;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
|
||||
import org.spongepowered.asm.mixin.injection.struct.Target;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InjectionError;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
|
||||
import org.spongepowered.asm.util.Annotations;
|
||||
|
||||
@@ -46,10 +46,10 @@ import org.spongepowered.asm.lib.tree.MethodInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.spongepowered.asm.lib.tree.TypeInsnNode;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionNodes.InjectionNode;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
|
||||
import org.spongepowered.asm.mixin.injection.struct.Target;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
|
||||
@@ -32,11 +32,11 @@ import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.MethodInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.VarInsnNode;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionNodes.InjectionNode;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.code.Injector;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
|
||||
import org.spongepowered.asm.mixin.injection.struct.Target;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,10 +30,10 @@ import java.util.List;
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.MethodInsnNode;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionNodes.InjectionNode;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
|
||||
import org.spongepowered.asm.mixin.injection.struct.Target;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
|
||||
|
||||
@@ -30,10 +30,10 @@ import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.InsnNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.VarInsnNode;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionNodes.InjectionNode;
|
||||
import org.spongepowered.asm.mixin.injection.invoke.arg.ArgsClassGenerator;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
|
||||
import org.spongepowered.asm.mixin.injection.struct.Target;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
|
||||
@@ -43,11 +43,15 @@ import org.spongepowered.asm.util.Bytecode;
|
||||
*/
|
||||
public class ModifyArgsInjector extends InvokeInjector {
|
||||
|
||||
private final ArgsClassGenerator argsClassGenerator;
|
||||
|
||||
/**
|
||||
* @param info Injection info
|
||||
*/
|
||||
public ModifyArgsInjector(InjectionInfo info) {
|
||||
super(info, "@ModifyArgs");
|
||||
|
||||
this.argsClassGenerator = info.getContext().getExtensions().<ArgsClassGenerator>getGenerator(ArgsClassGenerator.class);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -78,7 +82,7 @@ public class ModifyArgsInjector extends InvokeInjector {
|
||||
+ targetMethod.name + targetMethod.desc + " with no arguments!");
|
||||
}
|
||||
|
||||
String clArgs = ArgsClassGenerator.getInstance().getClassRef(targetMethod.desc);
|
||||
String clArgs = this.argsClassGenerator.getClassRef(targetMethod.desc);
|
||||
boolean withArgs = this.verifyTarget(target);
|
||||
|
||||
InsnList insns = new InsnList();
|
||||
|
||||
+1
-1
@@ -31,9 +31,9 @@ import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.InsnNode;
|
||||
import org.spongepowered.asm.lib.tree.JumpInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.VarInsnNode;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionNodes.InjectionNode;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
|
||||
import org.spongepowered.asm.mixin.injection.struct.Target;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
|
||||
|
||||
@@ -41,7 +41,6 @@ import org.spongepowered.asm.lib.tree.MethodInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.TypeInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.VarInsnNode;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionNodes.InjectionNode;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.code.Injector;
|
||||
@@ -49,6 +48,7 @@ import org.spongepowered.asm.mixin.injection.points.BeforeFieldAccess;
|
||||
import org.spongepowered.asm.mixin.injection.points.BeforeNew;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
|
||||
import org.spongepowered.asm.mixin.injection.struct.Target;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
|
||||
import org.spongepowered.asm.util.Annotations;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
|
||||
+2
-23
@@ -37,11 +37,11 @@ import org.spongepowered.asm.lib.util.CheckClassAdapter;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArgs;
|
||||
import org.spongepowered.asm.mixin.transformer.IClassGenerator;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.IClassGenerator;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
import org.spongepowered.asm.util.SignaturePrinter;
|
||||
import org.spongepowered.asm.util.visitor.MethodVisitorEx;
|
||||
import org.spongepowered.asm.util.asm.MethodVisitorEx;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
@@ -83,11 +83,6 @@ public final class ArgsClassGenerator implements IClassGenerator {
|
||||
private static final String ACE = "org/spongepowered/asm/mixin/injection/invoke/arg/ArgumentCountException";
|
||||
private static final String ACE_CTOR_DESC = "(IILjava/lang/String;)V";
|
||||
|
||||
/**
|
||||
* Singleton instance
|
||||
*/
|
||||
private static ArgsClassGenerator instance;
|
||||
|
||||
/**
|
||||
* The next subclass number, classes generated in sequence eg.
|
||||
* <tt>Args$1</tt>, <tt>Args$2</tt>, etc.
|
||||
@@ -107,10 +102,6 @@ public final class ArgsClassGenerator implements IClassGenerator {
|
||||
*/
|
||||
private final Map<String, byte[]> classBytes = new HashMap<String, byte[]>();
|
||||
|
||||
private ArgsClassGenerator() {
|
||||
// singleton (for now)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get (or generate) the class name for the specified descriptor. The class
|
||||
* will not be generated until it is used. Calling this method simply
|
||||
@@ -540,17 +531,5 @@ public final class ArgsClassGenerator implements IClassGenerator {
|
||||
private static String getSignature(Type[] args) {
|
||||
return new SignaturePrinter("", null, args).setFullyQualified(true).getFormattedArgs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the singleton instance
|
||||
*
|
||||
* @return the singleton instance
|
||||
*/
|
||||
public static ArgsClassGenerator getInstance() {
|
||||
if (ArgsClassGenerator.instance == null) {
|
||||
ArgsClassGenerator.instance = new ArgsClassGenerator();
|
||||
}
|
||||
return ArgsClassGenerator.instance;
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -33,12 +33,12 @@ import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.spongepowered.asm.lib.tree.VarInsnNode;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionNodes.InjectionNode;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
import org.spongepowered.asm.mixin.injection.code.Injector;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
|
||||
import org.spongepowered.asm.mixin.injection.struct.Target;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
|
||||
@@ -39,13 +39,10 @@ import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.tree.AnnotationNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionNodes.InjectionNode;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.InjectorGroupInfo;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArgs;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyConstant;
|
||||
@@ -56,6 +53,7 @@ import org.spongepowered.asm.mixin.injection.code.Injector;
|
||||
import org.spongepowered.asm.mixin.injection.code.InjectorTarget;
|
||||
import org.spongepowered.asm.mixin.injection.code.MethodSlice;
|
||||
import org.spongepowered.asm.mixin.injection.code.MethodSlices;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InjectionError;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
@@ -274,7 +272,7 @@ public abstract class InjectionInfo extends SpecialMethodInfo implements ISliceC
|
||||
}
|
||||
|
||||
String refMapStatus = this.mixin.getReferenceMapper().getStatus();
|
||||
if ((MixinEnvironment.getCurrentEnvironment().getOption(Option.DEBUG_INJECTORS) && this.injectedCallbackCount < this.expectedCallbackCount)) {
|
||||
if ((this.mixin.getEnvironment().getOption(Option.DEBUG_INJECTORS) && this.injectedCallbackCount < this.expectedCallbackCount)) {
|
||||
throw new InvalidInjectionException(this,
|
||||
String.format("Injection validation failed: %s %s%s in %s expected %d invocation(s) but %d succeeded. %s", this.getDescription(),
|
||||
this.method.name, this.method.desc, this.mixin, this.expectedCallbackCount, this.injectedCallbackCount, refMapStatus));
|
||||
|
||||
+1
-2
@@ -22,14 +22,13 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.injection;
|
||||
package org.spongepowered.asm.mixin.injection.struct;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.mixin.injection.struct.Target;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
|
||||
/**
|
||||
+2
-2
@@ -22,7 +22,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.injection;
|
||||
package org.spongepowered.asm.mixin.injection.struct;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -33,7 +33,7 @@ import java.util.List;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.spongepowered.asm.lib.tree.AnnotationNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
|
||||
import org.spongepowered.asm.mixin.injection.Group;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InjectionValidationException;
|
||||
import org.spongepowered.asm.util.Annotations;
|
||||
|
||||
@@ -39,9 +39,8 @@ import org.spongepowered.asm.lib.tree.LocalVariableNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.spongepowered.asm.lib.tree.TypeInsnNode;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionNodes;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionNodes.InjectionNode;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.injection.throwables;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.InjectorGroupInfo;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectorGroupInfo;
|
||||
|
||||
/**
|
||||
* Thrown when an injector group fails an injection check
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||
import org.spongepowered.asm.mixin.injection.struct.Target;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.Extensions;
|
||||
|
||||
/**
|
||||
* Context for performing reference mapping
|
||||
@@ -38,6 +39,11 @@ public interface IMixinContext {
|
||||
* Get the mixin info
|
||||
*/
|
||||
public abstract IMixinInfo getMixin();
|
||||
|
||||
/**
|
||||
* Get the mixin transformer extension manager
|
||||
*/
|
||||
public abstract Extensions getExtensions();
|
||||
|
||||
/**
|
||||
* Get the internal mixin class name
|
||||
|
||||
@@ -31,7 +31,8 @@ public interface IReferenceMapper {
|
||||
|
||||
/**
|
||||
* Get whether this mapper is defaulted. Use this flag rather than reference
|
||||
* comparison to {@link #DEFAULT_MAPPER} because of classloader shenanigans
|
||||
* comparison to {@link ReferenceMapper#DEFAULT_MAPPER} because of
|
||||
* classloader shenanigans
|
||||
*
|
||||
* @return true if this mapper is a defaulted mapper
|
||||
*/
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.transformer;
|
||||
package org.spongepowered.asm.mixin.struct;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.tree.FieldInsnNode;
|
||||
+10
-5
@@ -22,7 +22,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.transformer.meta;
|
||||
package org.spongepowered.asm.mixin.struct;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -39,6 +39,7 @@ import org.spongepowered.asm.util.Bytecode;
|
||||
*/
|
||||
public class SourceMap {
|
||||
|
||||
private static final String DEFAULT_STRATUM = "Mixin";
|
||||
private static final String NEWLINE = "\n";
|
||||
|
||||
/**
|
||||
@@ -154,6 +155,10 @@ public class SourceMap {
|
||||
*/
|
||||
static class Stratum {
|
||||
|
||||
private static final String STRATUM_MARK = "*S";
|
||||
private static final String FILE_MARK = "*F";
|
||||
private static final String LINES_MARK = "*L";
|
||||
|
||||
/**
|
||||
* Stratum name
|
||||
*/
|
||||
@@ -175,14 +180,14 @@ public class SourceMap {
|
||||
}
|
||||
|
||||
void appendTo(StringBuilder sb) {
|
||||
sb.append("*S ").append(this.name).append(SourceMap.NEWLINE);
|
||||
sb.append(Stratum.STRATUM_MARK).append(" ").append(this.name).append(SourceMap.NEWLINE);
|
||||
|
||||
sb.append("*F").append(SourceMap.NEWLINE);
|
||||
sb.append(Stratum.FILE_MARK).append(SourceMap.NEWLINE);
|
||||
for (File file : this.files.values()) {
|
||||
file.appendFile(sb);
|
||||
}
|
||||
|
||||
sb.append("*L").append(SourceMap.NEWLINE);
|
||||
sb.append(Stratum.LINES_MARK).append(SourceMap.NEWLINE);
|
||||
for (File file : this.files.values()) {
|
||||
file.appendLines(sb);
|
||||
}
|
||||
@@ -202,7 +207,7 @@ public class SourceMap {
|
||||
|
||||
private int nextLineOffset = 1;
|
||||
|
||||
private String defaultStratum = "Mixin";
|
||||
private String defaultStratum = SourceMap.DEFAULT_STRATUM;
|
||||
|
||||
public SourceMap(String sourceFile) {
|
||||
this.sourceFile = sourceFile;
|
||||
@@ -33,6 +33,7 @@ import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.ClassNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.struct.MemberRef;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo.Method;
|
||||
|
||||
/**
|
||||
|
||||
@@ -125,4 +125,5 @@ public class Config {
|
||||
public static Config create(String configFile) {
|
||||
return MixinConfig.create(configFile, MixinEnvironment.getDefaultEnvironment());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,7 +39,9 @@ import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.commons.Remapper;
|
||||
import org.spongepowered.asm.lib.commons.ClassRemapper;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo.Method;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.IClassGenerator;
|
||||
import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException;
|
||||
import org.spongepowered.asm.transformers.MixinClassWriter;
|
||||
|
||||
/**
|
||||
* Class generator which creates unique copies of inner classes within mixins
|
||||
@@ -205,11 +207,6 @@ final class InnerClassGenerator implements IClassGenerator {
|
||||
* Logger
|
||||
*/
|
||||
private static final Logger logger = LogManager.getLogger("mixin");
|
||||
|
||||
/**
|
||||
* Singleton instance (for now)
|
||||
*/
|
||||
private static InnerClassGenerator instance;
|
||||
|
||||
/**
|
||||
* Mapping of target class context ids to generated inner class names, used
|
||||
@@ -222,10 +219,6 @@ final class InnerClassGenerator implements IClassGenerator {
|
||||
*/
|
||||
private final Map<String, InnerClassInfo> innerClasses = new HashMap<String, InnerClassInfo>();
|
||||
|
||||
private InnerClassGenerator() {
|
||||
// private, use factory
|
||||
}
|
||||
|
||||
/**
|
||||
* @param owner Mixin which owns the original inner class
|
||||
* @param originalName Original inner class name
|
||||
@@ -298,14 +291,4 @@ final class InnerClassGenerator implements IClassGenerator {
|
||||
return String.format("%s$%s$%s", context.getTargetClassRef(), name, UUID.randomUUID().toString().replace("-", ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the singleton instance
|
||||
*/
|
||||
public static InnerClassGenerator getInstance() {
|
||||
if (InnerClassGenerator.instance == null) {
|
||||
InnerClassGenerator.instance = new InnerClassGenerator();
|
||||
}
|
||||
return InnerClassGenerator.instance;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -969,13 +969,12 @@ class MixinApplicatorStandard {
|
||||
protected final void checkConstraints(MixinTargetContext mixin, MethodNode method, AnnotationNode annotation) {
|
||||
try {
|
||||
Constraint constraint = ConstraintParser.parse(annotation);
|
||||
MixinEnvironment environment = MixinEnvironment.getCurrentEnvironment();
|
||||
try {
|
||||
constraint.check(environment);
|
||||
constraint.check(mixin.getEnvironment());
|
||||
} catch (ConstraintViolationException ex) {
|
||||
String message = String.format("Constraint violation: %s on %s in %s", ex.getMessage(), method, mixin);
|
||||
this.logger.warn(message);
|
||||
if (!environment.getOption(Option.IGNORE_CONSTRAINTS)) {
|
||||
if (!mixin.getEnvironment().getOption(Option.IGNORE_CONSTRAINTS)) {
|
||||
throw new InvalidMixinException(mixin, message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -802,7 +802,7 @@ class MixinInfo extends TreeInfo implements Comparable<MixinInfo>, IMixinInfo {
|
||||
this.priority = this.readPriority(this.pendingState.getClassNode());
|
||||
this.virtual = this.readPseudo(this.pendingState.getClassNode());
|
||||
this.targetClasses = this.readTargetClasses(this.pendingState.getClassNode(), suppressPlugin);
|
||||
this.targetClassNames = Collections.unmodifiableList(Lists.transform(this.targetClasses, Functions.toStringFunction()));
|
||||
this.targetClassNames = Collections.<String>unmodifiableList(Lists.transform(this.targetClasses, Functions.toStringFunction()));
|
||||
} catch (InvalidMixinException ex) {
|
||||
throw ex;
|
||||
} catch (Exception ex) {
|
||||
@@ -1094,28 +1094,28 @@ class MixinInfo extends TreeInfo implements Comparable<MixinInfo>, IMixinInfo {
|
||||
* Get the soft implementations for this mixin
|
||||
*/
|
||||
List<InterfaceInfo> getSoftImplements() {
|
||||
return Collections.unmodifiableList(this.getState().getSoftImplements());
|
||||
return Collections.<InterfaceInfo>unmodifiableList(this.getState().getSoftImplements());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the synthetic inner classes for this mixin
|
||||
*/
|
||||
Set<String> getSyntheticInnerClasses() {
|
||||
return Collections.unmodifiableSet(this.getState().getSyntheticInnerClasses());
|
||||
return Collections.<String>unmodifiableSet(this.getState().getSyntheticInnerClasses());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user-defined inner classes for this mixin
|
||||
*/
|
||||
Set<String> getInnerClasses() {
|
||||
return Collections.unmodifiableSet(this.getState().getInnerClasses());
|
||||
return Collections.<String>unmodifiableSet(this.getState().getInnerClasses());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the target class list for this mixin
|
||||
*/
|
||||
List<ClassInfo> getTargets() {
|
||||
return Collections.unmodifiableList(this.targetClasses);
|
||||
return Collections.<ClassInfo>unmodifiableList(this.targetClasses);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,6 +49,7 @@ import org.spongepowered.asm.mixin.transformer.ClassInfo.Method;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinInfo.MixinClassNode;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinInfo.MixinMethodNode;
|
||||
import org.spongepowered.asm.mixin.transformer.throwables.MixinTransformerError;
|
||||
import org.spongepowered.asm.transformers.MixinClassWriter;
|
||||
import org.spongepowered.asm.transformers.TreeTransformer;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
|
||||
|
||||
@@ -51,19 +51,21 @@ import org.spongepowered.asm.mixin.SoftOverride;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||
import org.spongepowered.asm.mixin.gen.AccessorInfo;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.InjectorGroupInfo;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectorGroupInfo;
|
||||
import org.spongepowered.asm.mixin.injection.struct.Target;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InjectionError;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InjectionValidationException;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
import org.spongepowered.asm.mixin.refmap.IReferenceMapper;
|
||||
import org.spongepowered.asm.mixin.struct.MemberRef;
|
||||
import org.spongepowered.asm.mixin.struct.SourceMap.File;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo.Field;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo.Method;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo.SearchType;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo.Traversal;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.Extensions;
|
||||
import org.spongepowered.asm.mixin.transformer.meta.MixinMerged;
|
||||
import org.spongepowered.asm.mixin.transformer.meta.SourceMap.File;
|
||||
import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException;
|
||||
import org.spongepowered.asm.mixin.transformer.throwables.MixinTransformerError;
|
||||
import org.spongepowered.asm.obfuscation.RemapperChain;
|
||||
@@ -189,7 +191,7 @@ public class MixinTargetContext extends ClassContext implements IMixinContext {
|
||||
this.sessionId = context.getSessionId();
|
||||
this.requireVersion(classNode.version);
|
||||
|
||||
InnerClassGenerator icg = InnerClassGenerator.getInstance();
|
||||
InnerClassGenerator icg = context.getExtensions().getGenerator(InnerClassGenerator.class);
|
||||
for (String innerClass : this.mixin.getInnerClasses()) {
|
||||
this.innerClasses.put(innerClass, icg.registerInnerClass(this.mixin, innerClass, this));
|
||||
}
|
||||
@@ -944,7 +946,7 @@ public class MixinTargetContext extends ClassContext implements IMixinContext {
|
||||
}
|
||||
|
||||
MethodNode findRemappedMethod(MethodNode method) {
|
||||
RemapperChain remapperChain = MixinEnvironment.getCurrentEnvironment().getRemappers();
|
||||
RemapperChain remapperChain = this.getEnvironment().getRemappers();
|
||||
String remappedName = remapperChain.mapMethodName(this.getTarget().getClassRef(), method.name, method.desc);
|
||||
if (remappedName.equals(method.name)) {
|
||||
return null;
|
||||
@@ -970,7 +972,7 @@ public class MixinTargetContext extends ClassContext implements IMixinContext {
|
||||
}
|
||||
|
||||
FieldNode findRemappedField(FieldNode field) {
|
||||
RemapperChain remapperChain = MixinEnvironment.getCurrentEnvironment().getRemappers();
|
||||
RemapperChain remapperChain = this.getEnvironment().getRemappers();
|
||||
String remappedName = remapperChain.mapFieldName(this.getTarget().getClassRef(), field.name, field.desc);
|
||||
if (remappedName.equals(field.name)) {
|
||||
return null;
|
||||
@@ -999,8 +1001,15 @@ public class MixinTargetContext extends ClassContext implements IMixinContext {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.mixin.refmap.IMixinContext
|
||||
* #getMixin()
|
||||
* @see org.spongepowered.asm.mixin.refmap.IMixinContext#getExtensions()
|
||||
*/
|
||||
@Override
|
||||
public Extensions getExtensions() {
|
||||
return this.targetClass.getExtensions();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.mixin.refmap.IMixinContext#getMixin()
|
||||
*/
|
||||
@Override
|
||||
public IMixinInfo getMixin() {
|
||||
|
||||
@@ -24,16 +24,12 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.transformer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -53,14 +49,17 @@ import org.spongepowered.asm.mixin.throwables.MixinApplyError;
|
||||
import org.spongepowered.asm.mixin.throwables.MixinException;
|
||||
import org.spongepowered.asm.mixin.throwables.MixinPrepareError;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinConfig.IListener;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinTransformerModuleCheckClass.ValidationFailedException;
|
||||
import org.spongepowered.asm.mixin.transformer.debug.IDecompiler;
|
||||
import org.spongepowered.asm.mixin.transformer.debug.IHotSwap;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.Extensions;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.IClassGenerator;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.IHotSwap;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.extensions.ExtensionCheckClass;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.extensions.ExtensionCheckClass.ValidationFailedException;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.extensions.ExtensionCheckInterfaces;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.extensions.ExtensionClassExporter;
|
||||
import org.spongepowered.asm.mixin.transformer.meta.MixinMerged;
|
||||
import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException;
|
||||
import org.spongepowered.asm.mixin.transformer.throwables.MixinTransformerError;
|
||||
import org.spongepowered.asm.transformers.TreeTransformer;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
import org.spongepowered.asm.util.PrettyPrinter;
|
||||
import org.spongepowered.asm.util.perf.Profiler;
|
||||
import org.spongepowered.asm.util.perf.Profiler.Section;
|
||||
@@ -294,94 +293,9 @@ public class MixinTransformer extends TreeTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug exporter
|
||||
*/
|
||||
static class Exporter {
|
||||
|
||||
/**
|
||||
* Directory to export classes to when debug.export is enabled
|
||||
*/
|
||||
private final File classExportDir = new File(MixinTransformer.DEBUG_OUTPUT, "class");
|
||||
|
||||
/**
|
||||
* Runtime decompiler for exported classes
|
||||
*/
|
||||
private final IDecompiler decompiler;
|
||||
|
||||
Exporter() {
|
||||
this.decompiler = this.initDecompiler(new File(MixinTransformer.DEBUG_OUTPUT, "java"));
|
||||
private static final String MIXIN_AGENT_CLASS = "org.spongepowered.tools.agent.MixinAgent";
|
||||
private static final String METRONOME_AGENT_CLASS = "org.spongepowered.metronome.Agent";
|
||||
|
||||
try {
|
||||
FileUtils.deleteDirectory(this.classExportDir);
|
||||
} catch (IOException ex) {
|
||||
MixinTransformer.logger.warn("Error cleaning class output directory: {}", ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private IDecompiler initDecompiler(File outputPath) {
|
||||
MixinEnvironment env = MixinEnvironment.getCurrentEnvironment();
|
||||
if (!env.getOption(Option.DEBUG_EXPORT_DECOMPILE)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
boolean as = env.getOption(Option.DEBUG_EXPORT_DECOMPILE_THREADED);
|
||||
MixinTransformer.logger.info("Attempting to load Fernflower decompiler{}", as ? " (Threaded mode)" : "");
|
||||
String className = "org.spongepowered.asm.mixin.transformer.debug.RuntimeDecompiler" + (as ? "Async" : "");
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends IDecompiler> clazz = (Class<? extends IDecompiler>)Class.forName(className);
|
||||
Constructor<? extends IDecompiler> ctor = clazz.getDeclaredConstructor(File.class);
|
||||
IDecompiler decompiler = ctor.newInstance(outputPath);
|
||||
MixinTransformer.logger.info("Fernflower decompiler was successfully initialised, exported classes will be decompiled{}",
|
||||
as ? " in a separate thread" : "");
|
||||
return decompiler;
|
||||
} catch (Throwable th) {
|
||||
MixinTransformer.logger.info("Fernflower could not be loaded, exported classes will not be decompiled. {}: {}",
|
||||
th.getClass().getSimpleName(), th.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String prepareFilter(String filter) {
|
||||
filter = "^\\Q" + filter.replace("**", "\201").replace("*", "\202").replace("?", "\203") + "\\E$";
|
||||
return filter.replace("\201", "\\E.*\\Q").replace("\202", "\\E[^\\.]+\\Q").replace("\203", "\\E.\\Q").replace("\\Q\\E", "");
|
||||
}
|
||||
|
||||
private boolean applyFilter(String filter, String subject) {
|
||||
return Pattern.compile(this.prepareFilter(filter), Pattern.CASE_INSENSITIVE).matcher(subject).matches();
|
||||
}
|
||||
|
||||
void export(String transformedName, boolean force, byte[] bytes) {
|
||||
// Export transformed class for debugging purposes
|
||||
MixinEnvironment environment = MixinEnvironment.getCurrentEnvironment();
|
||||
if (force || environment.getOption(Option.DEBUG_EXPORT)) {
|
||||
String filter = environment.getOptionValue(Option.DEBUG_EXPORT_FILTER);
|
||||
if (force || filter == null || this.applyFilter(filter, transformedName)) {
|
||||
Section exportTimer = MixinEnvironment.getProfiler().begin("debug.export");
|
||||
File outputFile = this.dumpClass(transformedName.replace('.', '/'), bytes);
|
||||
if (this.decompiler != null) {
|
||||
this.decompiler.decompile(outputFile);
|
||||
}
|
||||
exportTimer.end();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File dumpClass(String fileName, byte[] bytes) {
|
||||
File outputFile = new File(this.classExportDir, fileName + ".class");
|
||||
try {
|
||||
FileUtils.writeByteArrayToFile(outputFile, bytes);
|
||||
} catch (IOException ex) {
|
||||
// don't care
|
||||
}
|
||||
return outputFile;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static final File DEBUG_OUTPUT = new File(Constants.DEBUG_OUTPUT_PATH);
|
||||
|
||||
/**
|
||||
* Log all the things
|
||||
*/
|
||||
@@ -397,16 +311,6 @@ public class MixinTransformer extends TreeTransformer {
|
||||
*/
|
||||
private final List<MixinConfig> pendingConfigs = new ArrayList<MixinConfig>();
|
||||
|
||||
/**
|
||||
* Transformer modules
|
||||
*/
|
||||
private final List<IMixinTransformerModule> modules = new ArrayList<IMixinTransformerModule>();
|
||||
|
||||
/**
|
||||
* Modules which generate synthetic classes required by mixins
|
||||
*/
|
||||
private final List<IClassGenerator> generators = new ArrayList<IClassGenerator>();
|
||||
|
||||
/**
|
||||
* Re-entrance detector
|
||||
*/
|
||||
@@ -418,11 +322,11 @@ public class MixinTransformer extends TreeTransformer {
|
||||
* circumvent mixin application
|
||||
*/
|
||||
private final String sessionId = UUID.randomUUID().toString();
|
||||
|
||||
|
||||
/**
|
||||
* Export manager
|
||||
* Transformer extensions
|
||||
*/
|
||||
private final Exporter exporter;
|
||||
private final Extensions extensions;
|
||||
|
||||
/**
|
||||
* Hot-Swap agent
|
||||
@@ -475,18 +379,22 @@ public class MixinTransformer extends TreeTransformer {
|
||||
|
||||
TreeInfo.setLock(this.lock);
|
||||
|
||||
this.exporter = new Exporter();
|
||||
this.hotSwapper = this.initHotSwapper();
|
||||
this.extensions = new Extensions(this);
|
||||
this.hotSwapper = this.initHotSwapper(environment);
|
||||
this.postProcessor = new MixinPostProcessor();
|
||||
|
||||
this.generators.add(ArgsClassGenerator.getInstance());
|
||||
this.generators.add(InnerClassGenerator.getInstance());
|
||||
this.extensions.add(new ArgsClassGenerator());
|
||||
this.extensions.add(new InnerClassGenerator());
|
||||
|
||||
this.extensions.add(new ExtensionClassExporter(environment));
|
||||
this.extensions.add(new ExtensionCheckClass());
|
||||
this.extensions.add(new ExtensionCheckInterfaces());
|
||||
|
||||
this.profiler = MixinEnvironment.getProfiler();
|
||||
}
|
||||
|
||||
private IHotSwap initHotSwapper() {
|
||||
if (!MixinEnvironment.getCurrentEnvironment().getOption(Option.HOT_SWAP)) {
|
||||
private IHotSwap initHotSwapper(MixinEnvironment environment) {
|
||||
if (!environment.getOption(Option.HOT_SWAP)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -494,7 +402,7 @@ public class MixinTransformer extends TreeTransformer {
|
||||
MixinTransformer.logger.info("Attempting to load Hot-Swap agent");
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends IHotSwap> clazz =
|
||||
(Class<? extends IHotSwap>)Class.forName("org.spongepowered.tools.agent.MixinAgent");
|
||||
(Class<? extends IHotSwap>)Class.forName(MixinTransformer.MIXIN_AGENT_CLASS);
|
||||
Constructor<? extends IHotSwap> ctor = clazz.getDeclaredConstructor(MixinTransformer.class);
|
||||
return ctor.newInstance(this);
|
||||
} catch (Throwable th) {
|
||||
@@ -507,8 +415,10 @@ public class MixinTransformer extends TreeTransformer {
|
||||
|
||||
/**
|
||||
* Force-load all classes targetted by mixins but not yet applied
|
||||
*
|
||||
* @param environment current environment
|
||||
*/
|
||||
public void audit() {
|
||||
public void audit(MixinEnvironment environment) {
|
||||
Set<String> unhandled = new HashSet<String>();
|
||||
|
||||
for (MixinConfig config : this.configs) {
|
||||
@@ -533,7 +443,7 @@ public class MixinTransformer extends TreeTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
if (MixinEnvironment.getCurrentEnvironment().getOption(Option.DEBUG_PROFILER)) {
|
||||
if (environment.getOption(Option.DEBUG_PROFILER)) {
|
||||
this.printProfilerSummary();
|
||||
}
|
||||
}
|
||||
@@ -598,7 +508,7 @@ public class MixinTransformer extends TreeTransformer {
|
||||
printer.add();
|
||||
|
||||
try {
|
||||
Class<?> agent = Class.forName("org.spongepowered.metronome.Agent", false, Launch.class.getClassLoader());
|
||||
Class<?> agent = Class.forName(MixinTransformer.METRONOME_AGENT_CLASS, false, Launch.class.getClassLoader());
|
||||
Method mdGetTimes = agent.getDeclaredMethod("getTimes");
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -648,13 +558,15 @@ public class MixinTransformer extends TreeTransformer {
|
||||
return basicClass;
|
||||
}
|
||||
|
||||
MixinEnvironment environment = MixinEnvironment.getCurrentEnvironment();
|
||||
|
||||
if (basicClass == null) {
|
||||
for (IClassGenerator generator : this.generators) {
|
||||
for (IClassGenerator generator : this.extensions.getGenerators()) {
|
||||
Section genTimer = this.profiler.begin("generator", generator.getClass().getSimpleName().toLowerCase());
|
||||
basicClass = generator.generate(transformedName);
|
||||
genTimer.end();
|
||||
if (basicClass != null) {
|
||||
this.exporter.export(transformedName.replace('.', '/'), false, basicClass);
|
||||
this.extensions.export(environment, transformedName.replace('.', '/'), false, basicClass);
|
||||
return basicClass;
|
||||
}
|
||||
}
|
||||
@@ -663,7 +575,6 @@ public class MixinTransformer extends TreeTransformer {
|
||||
|
||||
boolean locked = this.lock.push().check();
|
||||
|
||||
MixinEnvironment environment = MixinEnvironment.getCurrentEnvironment();
|
||||
Section mixinTimer = this.profiler.begin("mixin");
|
||||
|
||||
if (!locked) {
|
||||
@@ -681,7 +592,7 @@ public class MixinTransformer extends TreeTransformer {
|
||||
Section postTimer = this.profiler.begin("postprocessor");
|
||||
byte[] bytes = this.postProcessor.transform(name, transformedName, basicClass);
|
||||
postTimer.end();
|
||||
this.exporter.export(transformedName, false, bytes);
|
||||
this.extensions.export(environment, transformedName, false, bytes);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@@ -723,9 +634,10 @@ public class MixinTransformer extends TreeTransformer {
|
||||
// Tree for target class
|
||||
Section timer = this.profiler.begin("read");
|
||||
ClassNode targetClassNode = this.readClass(basicClass, true);
|
||||
TargetClassContext context = new TargetClassContext(this.sessionId, transformedName, targetClassNode, mixins);
|
||||
TargetClassContext context = new TargetClassContext(environment, this.extensions, this.sessionId,
|
||||
transformedName, targetClassNode, mixins);
|
||||
timer.end();
|
||||
basicClass = this.applyMixins(context);
|
||||
basicClass = this.applyMixins(environment, context);
|
||||
this.transformedCount++;
|
||||
} catch (InvalidMixinException th) {
|
||||
this.dumpClassOnFailure(transformedName, basicClass, environment);
|
||||
@@ -787,7 +699,7 @@ public class MixinTransformer extends TreeTransformer {
|
||||
Section prepareTimer = this.profiler.begin("prepare");
|
||||
|
||||
this.selectConfigs(environment);
|
||||
this.selectModules(environment);
|
||||
this.extensions.select(environment);
|
||||
int totalMixins = this.prepareConfigs(environment);
|
||||
this.currentEnvironment = environment;
|
||||
this.transformedCount = 0;
|
||||
@@ -835,25 +747,6 @@ public class MixinTransformer extends TreeTransformer {
|
||||
Collections.sort(this.pendingConfigs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up this transformer using options from the supplied environment
|
||||
*
|
||||
* @param environment Environment to query
|
||||
*/
|
||||
private void selectModules(MixinEnvironment environment) {
|
||||
this.modules.clear();
|
||||
|
||||
// Run CheckClassAdapter on the mixin bytecode if debug option is enabled
|
||||
if (environment.getOption(Option.DEBUG_VERIFY)) {
|
||||
this.modules.add(new MixinTransformerModuleCheckClass());
|
||||
}
|
||||
|
||||
// Run implementation checker if option is enabled
|
||||
if (environment.getOption(Option.CHECK_IMPLEMENTS)) {
|
||||
this.modules.add(new MixinTransformerModuleInterfaceChecker());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare mixin configs
|
||||
*
|
||||
@@ -905,7 +798,7 @@ public class MixinTransformer extends TreeTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
plugin.acceptTargets(config.getTargets(), Collections.unmodifiableSet(otherTargets));
|
||||
plugin.acceptTargets(config.getTargets(), Collections.<String>unmodifiableSet(otherTargets));
|
||||
}
|
||||
|
||||
for (MixinConfig config : this.pendingConfigs) {
|
||||
@@ -930,21 +823,22 @@ public class MixinTransformer extends TreeTransformer {
|
||||
* Apply mixins for specified target class to the class described by the
|
||||
* supplied byte array.
|
||||
*
|
||||
* @param environment current environment
|
||||
* @param context target class context
|
||||
* @return class bytecode after application of mixins
|
||||
*/
|
||||
private byte[] applyMixins(TargetClassContext context) {
|
||||
private byte[] applyMixins(MixinEnvironment environment, TargetClassContext context) {
|
||||
Section timer = this.profiler.begin("preapply");
|
||||
this.preApply(context);
|
||||
this.extensions.preApply(context);
|
||||
timer = timer.next("apply");
|
||||
this.apply(context);
|
||||
timer = timer.next("postapply");
|
||||
try {
|
||||
this.postApply(context);
|
||||
this.extensions.postApply(context);
|
||||
} catch (ValidationFailedException ex) {
|
||||
MixinTransformer.logger.info(ex.getMessage());
|
||||
// If verify is enabled and failed, write out the bytecode to allow us to inspect it
|
||||
if (context.isExportForced() || MixinEnvironment.getCurrentEnvironment().getOption(Option.DEBUG_EXPORT)) {
|
||||
if (context.isExportForced() || environment.getOption(Option.DEBUG_EXPORT)) {
|
||||
this.writeClass(context);
|
||||
}
|
||||
}
|
||||
@@ -952,17 +846,6 @@ public class MixinTransformer extends TreeTransformer {
|
||||
return this.writeClass(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process tasks before mixin application
|
||||
*
|
||||
* @param context Target class context
|
||||
*/
|
||||
private void preApply(TargetClassContext context) {
|
||||
for (IMixinTransformerModule module : this.modules) {
|
||||
module.preApply(context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the mixins to the target class
|
||||
*
|
||||
@@ -972,17 +855,6 @@ public class MixinTransformer extends TreeTransformer {
|
||||
context.applyMixins();
|
||||
}
|
||||
|
||||
/**
|
||||
* Process tasks after mixin application
|
||||
*
|
||||
* @param context Target class context
|
||||
*/
|
||||
private void postApply(TargetClassContext context) {
|
||||
for (IMixinTransformerModule module : this.modules) {
|
||||
module.postApply(context);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleMixinPrepareError(MixinConfig config, InvalidMixinException ex, MixinEnvironment environment) throws MixinPrepareError {
|
||||
this.handleMixinError(config.getName(), ex, environment, ErrorPhase.PREPARE);
|
||||
}
|
||||
@@ -1067,13 +939,14 @@ public class MixinTransformer extends TreeTransformer {
|
||||
Section writeTimer = this.profiler.begin("write");
|
||||
byte[] bytes = this.writeClass(targetClass);
|
||||
writeTimer.end();
|
||||
this.exporter.export(transformedName, forceExport, bytes);
|
||||
this.extensions.export(this.currentEnvironment, transformedName, forceExport, bytes);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
private void dumpClassOnFailure(String className, byte[] bytes, MixinEnvironment env) {
|
||||
if (env.getOption(Option.DUMP_TARGET_ON_FAILURE)) {
|
||||
this.exporter.dumpClass(className.replace('.', '/') + ".target", bytes);
|
||||
ExtensionClassExporter exporter = this.extensions.<ExtensionClassExporter>getExtension(ExtensionClassExporter.class);
|
||||
exporter.dumpClass(className.replace('.', '/') + ".target", bytes);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,9 @@ import org.spongepowered.asm.mixin.Debug;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.injection.struct.Target;
|
||||
import org.spongepowered.asm.mixin.transformer.meta.SourceMap;
|
||||
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.util.Annotations;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
import org.spongepowered.asm.util.ClassSignature;
|
||||
@@ -50,13 +52,23 @@ import org.spongepowered.asm.util.ClassSignature;
|
||||
/**
|
||||
* Struct for containing target class information during mixin application
|
||||
*/
|
||||
class TargetClassContext extends ClassContext {
|
||||
class TargetClassContext extends ClassContext implements ITargetClassContext {
|
||||
|
||||
/**
|
||||
* Logger
|
||||
*/
|
||||
private static final Logger logger = LogManager.getLogger("mixin");
|
||||
|
||||
/**
|
||||
* Mixin environment
|
||||
*/
|
||||
private final MixinEnvironment env;
|
||||
|
||||
/**
|
||||
* Mixin transformer extensions
|
||||
*/
|
||||
private final Extensions extensions;
|
||||
|
||||
/**
|
||||
* Transformer session ID
|
||||
*/
|
||||
@@ -121,7 +133,9 @@ class TargetClassContext extends ClassContext {
|
||||
*/
|
||||
private boolean forceExport;
|
||||
|
||||
TargetClassContext(String sessionId, String name, ClassNode classNode, SortedSet<MixinInfo> mixins) {
|
||||
TargetClassContext(MixinEnvironment env, Extensions extensions, String sessionId, String name, ClassNode classNode, SortedSet<MixinInfo> mixins) {
|
||||
this.env = env;
|
||||
this.extensions = extensions;
|
||||
this.sessionId = sessionId;
|
||||
this.className = name;
|
||||
this.classNode = classNode;
|
||||
@@ -145,6 +159,13 @@ class TargetClassContext extends ClassContext {
|
||||
return this.forceExport;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the transformer extensions
|
||||
*/
|
||||
Extensions getExtensions() {
|
||||
return this.extensions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the transformer session ID
|
||||
*/
|
||||
@@ -171,7 +192,7 @@ class TargetClassContext extends ClassContext {
|
||||
* Get the class tree
|
||||
*/
|
||||
@Override
|
||||
ClassNode getClassNode() {
|
||||
public ClassNode getClassNode() {
|
||||
return this.classNode;
|
||||
}
|
||||
|
||||
@@ -193,7 +214,7 @@ class TargetClassContext extends ClassContext {
|
||||
* Get the target class metadata
|
||||
*/
|
||||
@Override
|
||||
ClassInfo getClassInfo() {
|
||||
public ClassInfo getClassInfo() {
|
||||
return this.classInfo;
|
||||
}
|
||||
|
||||
@@ -358,7 +379,7 @@ class TargetClassContext extends ClassContext {
|
||||
* Process {@link Debug} annotations on the class after application
|
||||
*/
|
||||
void processDebugTasks() {
|
||||
if (!MixinEnvironment.getCurrentEnvironment().getOption(Option.DEBUG_VERBOSE)) {
|
||||
if (!this.env.getOption(Option.DEBUG_VERBOSE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.transformer.ext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinTransformer;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableList.Builder;
|
||||
|
||||
/**
|
||||
* Mixin transformer extensions and common modules such as class generators
|
||||
*/
|
||||
public final class Extensions {
|
||||
|
||||
/**
|
||||
* Mixin transformer
|
||||
*/
|
||||
private final MixinTransformer transformer;
|
||||
|
||||
/**
|
||||
* All transformer extensions
|
||||
*/
|
||||
private final List<IExtension> extensions = new ArrayList<IExtension>();
|
||||
|
||||
/**
|
||||
* Map of extension class types to extension instances, used to fetch
|
||||
* generators using {@link #getExtension}
|
||||
*/
|
||||
private final Map<Class<? extends IExtension>, IExtension> extensionMap
|
||||
= new HashMap<Class<? extends IExtension>, IExtension>();
|
||||
|
||||
/**
|
||||
* Modules which generate synthetic classes required by mixins
|
||||
*/
|
||||
private final List<IClassGenerator> generators = new ArrayList<IClassGenerator>();
|
||||
|
||||
/**
|
||||
* Read-only view of available generators
|
||||
*/
|
||||
private final List<IClassGenerator> generatorsView = Collections.<IClassGenerator>unmodifiableList(this.generators);
|
||||
|
||||
/**
|
||||
* Map of generator class types to generator instances, used to fetch
|
||||
* generators using {@link #getGenerator}
|
||||
*/
|
||||
private final Map<Class<? extends IClassGenerator>, IClassGenerator> generatorMap
|
||||
= new HashMap<Class<? extends IClassGenerator>, IClassGenerator>();
|
||||
|
||||
/**
|
||||
* Active transformer extensions
|
||||
*/
|
||||
private List<IExtension> activeExtensions = Collections.<IExtension>emptyList();
|
||||
|
||||
public Extensions(MixinTransformer transformer) {
|
||||
this.transformer = transformer;
|
||||
}
|
||||
|
||||
public MixinTransformer getTransformer() {
|
||||
return this.transformer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new transformer extension
|
||||
*
|
||||
* @param extension extension to add
|
||||
*/
|
||||
public void add(IExtension extension) {
|
||||
this.extensions.add(extension);
|
||||
this.extensionMap.put(extension.getClass(), extension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all extensions
|
||||
*/
|
||||
public List<IExtension> getExtensions() {
|
||||
return Collections.<IExtension>unmodifiableList(this.extensions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all active extensions
|
||||
*/
|
||||
public List<IExtension> getActiveExtensions() {
|
||||
return this.activeExtensions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific extension
|
||||
*
|
||||
* @param extensionClass extension class to look up
|
||||
* @param <T> extension type
|
||||
* @return extension instance or null
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends IExtension> T getExtension(Class<? extends IExtension> extensionClass) {
|
||||
return (T)Extensions.<IExtension>lookup(extensionClass, this.extensionMap, this.extensions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Selectively activate extensions based on the current environment
|
||||
*
|
||||
* @param environment current environment
|
||||
*/
|
||||
public void select(MixinEnvironment environment) {
|
||||
Builder<IExtension> activeExtensions = ImmutableList.<IExtension>builder();
|
||||
|
||||
for (IExtension extension : this.extensions) {
|
||||
if (extension.checkActive(environment)) {
|
||||
activeExtensions.add(extension);
|
||||
}
|
||||
}
|
||||
|
||||
this.activeExtensions = activeExtensions.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Process tasks before mixin application
|
||||
*
|
||||
* @param context Target class context
|
||||
*/
|
||||
public void preApply(ITargetClassContext context) {
|
||||
for (IExtension extension : this.activeExtensions) {
|
||||
extension.preApply(context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process tasks after mixin application
|
||||
*
|
||||
* @param context Target class context
|
||||
*/
|
||||
public void postApply(ITargetClassContext context) {
|
||||
for (IExtension extension : this.activeExtensions) {
|
||||
extension.postApply(context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Export class bytecode to disk
|
||||
*
|
||||
* @param env Environment
|
||||
* @param name Class name
|
||||
* @param force True to export even if the current environment settings
|
||||
* would normally disable it
|
||||
* @param bytes Bytes to export
|
||||
*/
|
||||
public void export(MixinEnvironment env, String name, boolean force, byte[] bytes) {
|
||||
for (IExtension extension : this.activeExtensions) {
|
||||
extension.export(env, name, force, bytes);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new generator to the mixin extensions
|
||||
*
|
||||
* @param generator generator to add
|
||||
*/
|
||||
public void add(IClassGenerator generator) {
|
||||
this.generators.add(generator);
|
||||
this.generatorMap.put(generator.getClass(), generator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all active generators
|
||||
*/
|
||||
public List<IClassGenerator> getGenerators() {
|
||||
return this.generatorsView;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param generatorClass generator class or interface to look up
|
||||
* @param <T> genenerator class for duck typing
|
||||
* @return generator
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends IClassGenerator> T getGenerator(Class<? extends IClassGenerator> generatorClass) {
|
||||
return (T)Extensions.<IClassGenerator>lookup(generatorClass, this.generatorMap, this.generators);
|
||||
}
|
||||
|
||||
private static <T> T lookup(Class<? extends T> extensionClass, Map<Class<? extends T>, T> map, List<T> list) {
|
||||
T extension = map.get(extensionClass);
|
||||
if (extension == null) {
|
||||
for (T classGenerator : list) {
|
||||
if (extensionClass.isAssignableFrom(classGenerator.getClass())) {
|
||||
extension = classGenerator;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (extension == null) {
|
||||
throw new IllegalArgumentException("Extension for <" + extensionClass.getName() + "> could not be found");
|
||||
}
|
||||
|
||||
map.put(extensionClass, extension);
|
||||
}
|
||||
|
||||
return extension;
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.transformer;
|
||||
package org.spongepowered.asm.mixin.transformer.ext;
|
||||
|
||||
/**
|
||||
* Base interface for class generators
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.transformer.debug;
|
||||
package org.spongepowered.asm.mixin.transformer.ext;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.transformer.ext;
|
||||
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
|
||||
/**
|
||||
* Mixin Transformer extension interface for pre- and post-processors
|
||||
*/
|
||||
public interface IExtension {
|
||||
|
||||
/**
|
||||
* Check whether this extension is active for the specified environment
|
||||
*
|
||||
* @param environment current environment
|
||||
* @return true if the module should be active in the specified environment
|
||||
*/
|
||||
public abstract boolean checkActive(MixinEnvironment environment);
|
||||
|
||||
/**
|
||||
* Called before the mixins are applied
|
||||
*
|
||||
* @param context Target class context
|
||||
*/
|
||||
public abstract void preApply(ITargetClassContext context);
|
||||
|
||||
/**
|
||||
* Called after the mixins are applied
|
||||
*
|
||||
* @param context Target class context
|
||||
*/
|
||||
public abstract void postApply(ITargetClassContext context);
|
||||
|
||||
/**
|
||||
* Called when a class needs to be exported
|
||||
*
|
||||
* @param env Environment
|
||||
* @param name Class name
|
||||
* @param force True to export even if the current environment settings
|
||||
* would normally disable it
|
||||
* @param bytes Bytes to export
|
||||
*/
|
||||
public abstract void export(MixinEnvironment env, String name, boolean force, byte[] bytes);
|
||||
|
||||
}
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.transformer.debug;
|
||||
package org.spongepowered.asm.mixin.transformer.ext;
|
||||
|
||||
/**
|
||||
* Interface to allow the hot-swap agent to be loaded on-demand
|
||||
+11
-11
@@ -22,25 +22,25 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.transformer;
|
||||
package org.spongepowered.asm.mixin.transformer.ext;
|
||||
|
||||
import org.spongepowered.asm.lib.tree.ClassNode;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo;
|
||||
|
||||
/**
|
||||
* Mixin Transformer Module interface for pre- and post-processors
|
||||
* Interface for target classes passed into transformer modules via
|
||||
* {@link IExtension}
|
||||
*/
|
||||
public interface IMixinTransformerModule {
|
||||
public interface ITargetClassContext {
|
||||
|
||||
/**
|
||||
* Called before the mixins are applied
|
||||
*
|
||||
* @param context Target class context
|
||||
* Get the target class metadata
|
||||
*/
|
||||
public abstract void preApply(TargetClassContext context);
|
||||
public abstract ClassInfo getClassInfo();
|
||||
|
||||
/**
|
||||
* Called after the mixins are applied
|
||||
*
|
||||
* @param context Target class context
|
||||
* Get the class tree
|
||||
*/
|
||||
public abstract void postApply(TargetClassContext context);
|
||||
public abstract ClassNode getClassNode();
|
||||
|
||||
}
|
||||
+27
-4
@@ -22,17 +22,22 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.transformer;
|
||||
package org.spongepowered.asm.mixin.transformer.ext.extensions;
|
||||
|
||||
import org.spongepowered.asm.lib.ClassWriter;
|
||||
import org.spongepowered.asm.lib.util.CheckClassAdapter;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.throwables.MixinException;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.IExtension;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.ITargetClassContext;
|
||||
import org.spongepowered.asm.transformers.MixinClassWriter;
|
||||
|
||||
/**
|
||||
* Mixin transformer module which runs CheckClassAdapter on the post-mixin
|
||||
* bytecode
|
||||
*/
|
||||
public class MixinTransformerModuleCheckClass implements IMixinTransformerModule {
|
||||
public class ExtensionCheckClass implements IExtension {
|
||||
|
||||
/**
|
||||
* Exception thrown when checkclass fails
|
||||
@@ -54,13 +59,22 @@ public class MixinTransformerModuleCheckClass implements IMixinTransformerModule
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.mixin.transformer.ext.IExtension#checkActive(
|
||||
* org.spongepowered.asm.mixin.MixinEnvironment)
|
||||
*/
|
||||
@Override
|
||||
public boolean checkActive(MixinEnvironment environment) {
|
||||
return environment.getOption(Option.DEBUG_VERIFY);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.mixin.transformer.IMixinTransformerModule
|
||||
* #preApply(org.spongepowered.asm.mixin.transformer.TargetClassContext)
|
||||
*/
|
||||
@Override
|
||||
public void preApply(TargetClassContext context) {
|
||||
public void preApply(ITargetClassContext context) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -68,12 +82,21 @@ public class MixinTransformerModuleCheckClass implements IMixinTransformerModule
|
||||
* #postApply(org.spongepowered.asm.mixin.transformer.TargetClassContext)
|
||||
*/
|
||||
@Override
|
||||
public void postApply(TargetClassContext context) {
|
||||
public void postApply(ITargetClassContext context) {
|
||||
try {
|
||||
context.getClassNode().accept(new CheckClassAdapter(new MixinClassWriter(ClassWriter.COMPUTE_FRAMES)));
|
||||
} catch (RuntimeException ex) {
|
||||
throw new ValidationFailedException(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.mixin.transformer.ext.IExtension#export(
|
||||
* org.spongepowered.asm.mixin.MixinEnvironment, java.lang.String,
|
||||
* boolean, byte[])
|
||||
*/
|
||||
@Override
|
||||
public void export(MixinEnvironment env, String name, boolean force, byte[] bytes) {
|
||||
}
|
||||
|
||||
}
|
||||
+44
-10
@@ -22,7 +22,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.transformer;
|
||||
package org.spongepowered.asm.mixin.transformer.ext.extensions;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -38,9 +38,13 @@ import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo.Method;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo.SearchType;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo.Traversal;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.IExtension;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.ITargetClassContext;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
import org.spongepowered.asm.util.PrettyPrinter;
|
||||
import org.spongepowered.asm.util.SignaturePrinter;
|
||||
|
||||
@@ -53,7 +57,12 @@ import com.google.common.io.Files;
|
||||
* Checks whether interfaces declared on mixin target classes are actually fully
|
||||
* implemented and generates reports to the console and to files on disk
|
||||
*/
|
||||
public class MixinTransformerModuleInterfaceChecker implements IMixinTransformerModule {
|
||||
public class ExtensionCheckInterfaces implements IExtension {
|
||||
|
||||
private static final String AUDIT_DIR = "audit";
|
||||
private static final String IMPL_REPORT_FILENAME = "mixin_implementation_report";
|
||||
private static final String IMPL_REPORT_CSV_FILENAME = ExtensionCheckInterfaces.IMPL_REPORT_FILENAME + ".csv";
|
||||
private static final String IMPL_REPORT_TXT_FILENAME = ExtensionCheckInterfaces.IMPL_REPORT_FILENAME + ".txt";
|
||||
|
||||
private static final Logger logger = LogManager.getLogger("mixin");
|
||||
|
||||
@@ -72,12 +81,17 @@ public class MixinTransformerModuleInterfaceChecker implements IMixinTransformer
|
||||
* applied.
|
||||
*/
|
||||
private final Multimap<ClassInfo, Method> interfaceMethods = HashMultimap.create();
|
||||
|
||||
/**
|
||||
* Strict mode
|
||||
*/
|
||||
private boolean strict;
|
||||
|
||||
public MixinTransformerModuleInterfaceChecker() {
|
||||
File debugOutputFolder = new File(MixinTransformer.DEBUG_OUTPUT, "audit");
|
||||
public ExtensionCheckInterfaces() {
|
||||
File debugOutputFolder = new File(Constants.DEBUG_OUTPUT_DIR, ExtensionCheckInterfaces.AUDIT_DIR);
|
||||
debugOutputFolder.mkdirs();
|
||||
this.csv = new File(debugOutputFolder, "mixin_implementation_report.csv");
|
||||
this.report = new File(debugOutputFolder, "mixin_implementation_report.txt");
|
||||
this.csv = new File(debugOutputFolder, ExtensionCheckInterfaces.IMPL_REPORT_CSV_FILENAME);
|
||||
this.report = new File(debugOutputFolder, ExtensionCheckInterfaces.IMPL_REPORT_TXT_FILENAME);
|
||||
|
||||
try {
|
||||
Files.write("Class,Method,Signature,Interface\n", this.csv, Charsets.ISO_8859_1);
|
||||
@@ -92,13 +106,23 @@ public class MixinTransformerModuleInterfaceChecker implements IMixinTransformer
|
||||
// hmm :(
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.mixin.transformer.ext.IExtension#checkActive(
|
||||
* org.spongepowered.asm.mixin.MixinEnvironment)
|
||||
*/
|
||||
@Override
|
||||
public boolean checkActive(MixinEnvironment environment) {
|
||||
this.strict = environment.getOption(Option.CHECK_IMPLEMENTS_STRICT);
|
||||
return environment.getOption(Option.CHECK_IMPLEMENTS);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.mixin.transformer.IMixinTransformerModule
|
||||
* #preApply(org.spongepowered.asm.mixin.transformer.TargetClassContext)
|
||||
*/
|
||||
@Override
|
||||
public void preApply(TargetClassContext context) {
|
||||
public void preApply(ITargetClassContext context) {
|
||||
ClassInfo targetClassInfo = context.getClassInfo();
|
||||
for (Method m : targetClassInfo.getInterfaceMethods(false)) {
|
||||
this.interfaceMethods.put(targetClassInfo, m);
|
||||
@@ -110,12 +134,12 @@ public class MixinTransformerModuleInterfaceChecker implements IMixinTransformer
|
||||
* #postApply(org.spongepowered.asm.mixin.transformer.TargetClassContext)
|
||||
*/
|
||||
@Override
|
||||
public void postApply(TargetClassContext context) {
|
||||
public void postApply(ITargetClassContext context) {
|
||||
ClassInfo targetClassInfo = context.getClassInfo();
|
||||
|
||||
// If the target is abstract and strict mode is not enabled, skip this class
|
||||
if (targetClassInfo.isAbstract() && !MixinEnvironment.getCurrentEnvironment().getOption(Option.CHECK_IMPLEMENTS_STRICT)) {
|
||||
MixinTransformerModuleInterfaceChecker.logger.info("{} is skipping abstract target {}", this.getClass().getSimpleName(), context);
|
||||
if (targetClassInfo.isAbstract() && !this.strict) {
|
||||
ExtensionCheckInterfaces.logger.info("{} is skipping abstract target {}", this.getClass().getSimpleName(), context);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -162,6 +186,15 @@ public class MixinTransformerModuleInterfaceChecker implements IMixinTransformer
|
||||
this.appendToTextReport(printer);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.mixin.transformer.ext.IExtension#export(
|
||||
* org.spongepowered.asm.mixin.MixinEnvironment, java.lang.String,
|
||||
* boolean, byte[])
|
||||
*/
|
||||
@Override
|
||||
public void export(MixinEnvironment env, String name, boolean force, byte[] bytes) {
|
||||
}
|
||||
|
||||
private void appendToCSVReport(String className, Method method, String iface) {
|
||||
try {
|
||||
@@ -185,4 +218,5 @@ public class MixinTransformerModuleInterfaceChecker implements IMixinTransformer
|
||||
IOUtils.closeQuietly(fos);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.transformer.ext.extensions;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.IDecompiler;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.IExtension;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.ITargetClassContext;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
import org.spongepowered.asm.util.perf.Profiler.Section;
|
||||
|
||||
/**
|
||||
* Debug exporter
|
||||
*/
|
||||
public class ExtensionClassExporter implements IExtension {
|
||||
|
||||
private static final String DECOMPILER_CLASS = "org.spongepowered.asm.mixin.transformer.debug.RuntimeDecompiler";
|
||||
|
||||
private static final String EXPORT_CLASS_DIR = "class";
|
||||
private static final String EXPORT_JAVA_DIR = "java";
|
||||
|
||||
/**
|
||||
* Logger
|
||||
*/
|
||||
private static final Logger logger = LogManager.getLogger("mixin");
|
||||
|
||||
/**
|
||||
* Directory to export classes to when debug.export is enabled
|
||||
*/
|
||||
private final File classExportDir = new File(Constants.DEBUG_OUTPUT_DIR, ExtensionClassExporter.EXPORT_CLASS_DIR);
|
||||
|
||||
/**
|
||||
* Runtime decompiler for exported classes
|
||||
*/
|
||||
private final IDecompiler decompiler;
|
||||
|
||||
public ExtensionClassExporter(MixinEnvironment env) {
|
||||
this.decompiler = this.initDecompiler(env, new File(Constants.DEBUG_OUTPUT_DIR, ExtensionClassExporter.EXPORT_JAVA_DIR));
|
||||
|
||||
try {
|
||||
FileUtils.deleteDirectory(this.classExportDir);
|
||||
} catch (IOException ex) {
|
||||
ExtensionClassExporter.logger.warn("Error cleaning class output directory: {}", ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private IDecompiler initDecompiler(MixinEnvironment env, File outputPath) {
|
||||
if (!env.getOption(Option.DEBUG_EXPORT_DECOMPILE)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
boolean as = env.getOption(Option.DEBUG_EXPORT_DECOMPILE_THREADED);
|
||||
ExtensionClassExporter.logger.info("Attempting to load Fernflower decompiler{}", as ? " (Threaded mode)" : "");
|
||||
String className = ExtensionClassExporter.DECOMPILER_CLASS + (as ? "Async" : "");
|
||||
@SuppressWarnings("unchecked")
|
||||
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" : "");
|
||||
return decompiler;
|
||||
} catch (Throwable th) {
|
||||
ExtensionClassExporter.logger.info("Fernflower could not be loaded, exported classes will not be decompiled. {}: {}",
|
||||
th.getClass().getSimpleName(), th.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String prepareFilter(String filter) {
|
||||
filter = "^\\Q" + filter.replace("**", "\201").replace("*", "\202").replace("?", "\203") + "\\E$";
|
||||
return filter.replace("\201", "\\E.*\\Q").replace("\202", "\\E[^\\.]+\\Q").replace("\203", "\\E.\\Q").replace("\\Q\\E", "");
|
||||
}
|
||||
|
||||
private boolean applyFilter(String filter, String subject) {
|
||||
return Pattern.compile(this.prepareFilter(filter), Pattern.CASE_INSENSITIVE).matcher(subject).matches();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkActive(MixinEnvironment environment) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preApply(ITargetClassContext context) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postApply(ITargetClassContext context) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void export(MixinEnvironment env, String name, boolean force, byte[] bytes) {
|
||||
// Export transformed class for debugging purposes
|
||||
if (force || env.getOption(Option.DEBUG_EXPORT)) {
|
||||
String filter = env.getOptionValue(Option.DEBUG_EXPORT_FILTER);
|
||||
if (force || filter == null || this.applyFilter(filter, name)) {
|
||||
Section exportTimer = MixinEnvironment.getProfiler().begin("debug.export");
|
||||
File outputFile = this.dumpClass(name.replace('.', '/'), bytes);
|
||||
if (this.decompiler != null) {
|
||||
this.decompiler.decompile(outputFile);
|
||||
}
|
||||
exportTimer.end();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write class bytecode to disk for debug purposes
|
||||
*
|
||||
* @param fileName filename to write (.class will be automatically appended)
|
||||
* @param bytes class bytes
|
||||
* @return written file
|
||||
*/
|
||||
public File dumpClass(String fileName, byte[] bytes) {
|
||||
File outputFile = new File(this.classExportDir, fileName + ".class");
|
||||
try {
|
||||
FileUtils.writeByteArrayToFile(outputFile, bytes);
|
||||
} catch (IOException ex) {
|
||||
// don't care
|
||||
}
|
||||
return outputFile;
|
||||
}
|
||||
|
||||
}
|
||||
+2
-1
@@ -22,10 +22,11 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.transformer;
|
||||
package org.spongepowered.asm.transformers;
|
||||
|
||||
import org.spongepowered.asm.lib.ClassReader;
|
||||
import org.spongepowered.asm.lib.ClassWriter;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo;
|
||||
|
||||
/**
|
||||
* ClassWriter which resolves common superclasses using Mixin's metadata instead
|
||||
@@ -27,7 +27,6 @@ package org.spongepowered.asm.transformers;
|
||||
import org.spongepowered.asm.lib.ClassReader;
|
||||
import org.spongepowered.asm.lib.ClassWriter;
|
||||
import org.spongepowered.asm.lib.tree.ClassNode;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinClassWriter;
|
||||
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
*/
|
||||
package org.spongepowered.asm.util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
/**
|
||||
@@ -45,6 +47,8 @@ public abstract class Constants {
|
||||
public static final String SYNTHETIC_PACKAGE = "org.spongepowered.asm.synthetic";
|
||||
public static final char UNICODE_SNOWMAN = '\u2603';
|
||||
|
||||
public static final File DEBUG_OUTPUT_DIR = new File(Constants.DEBUG_OUTPUT_PATH);
|
||||
|
||||
private Constants() {}
|
||||
|
||||
/**
|
||||
|
||||
@@ -48,7 +48,7 @@ import org.spongepowered.asm.lib.tree.analysis.Frame;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo.FrameData;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo.Method;
|
||||
import org.spongepowered.asm.mixin.transformer.verify.MixinVerifier;
|
||||
import org.spongepowered.asm.util.asm.MixinVerifier;
|
||||
import org.spongepowered.asm.util.throwables.LVTGeneratorException;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.util.visitor;
|
||||
package org.spongepowered.asm.util.asm;
|
||||
|
||||
import org.spongepowered.asm.lib.MethodVisitor;
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.transformer.verify;
|
||||
package org.spongepowered.asm.util.asm;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -41,6 +41,11 @@ import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
*/
|
||||
public final class LaunchClassLoaderUtil {
|
||||
|
||||
private static final String CACHED_CLASSES_FIELD = "cachedClasses";
|
||||
private static final String INVALID_CLASSES_FIELD = "invalidClasses";
|
||||
private static final String CLASS_LOADER_EXCEPTIONS_FIELD = "classLoaderExceptions";
|
||||
private static final String TRANSFORMER_EXCEPTIONS_FIELD = "transformerExceptions";
|
||||
|
||||
/**
|
||||
* ClassLoader -> util mapping
|
||||
*/
|
||||
@@ -64,10 +69,10 @@ public final class LaunchClassLoaderUtil {
|
||||
*/
|
||||
private LaunchClassLoaderUtil(LaunchClassLoader classLoader) {
|
||||
this.classLoader = classLoader;
|
||||
this.cachedClasses = LaunchClassLoaderUtil.<Map<String, Class<?>>>getField(classLoader, "cachedClasses");
|
||||
this.invalidClasses = LaunchClassLoaderUtil.<Set<String>>getField(classLoader, "invalidClasses");
|
||||
this.classLoaderExceptions = LaunchClassLoaderUtil.<Set<String>>getField(classLoader, "classLoaderExceptions");
|
||||
this.transformerExceptions = LaunchClassLoaderUtil.<Set<String>>getField(classLoader, "transformerExceptions");
|
||||
this.cachedClasses = LaunchClassLoaderUtil.<Map<String, Class<?>>>getField(classLoader, LaunchClassLoaderUtil.CACHED_CLASSES_FIELD);
|
||||
this.invalidClasses = LaunchClassLoaderUtil.<Set<String>>getField(classLoader, LaunchClassLoaderUtil.INVALID_CLASSES_FIELD);
|
||||
this.classLoaderExceptions = LaunchClassLoaderUtil.<Set<String>>getField(classLoader, LaunchClassLoaderUtil.CLASS_LOADER_EXCEPTIONS_FIELD);
|
||||
this.transformerExceptions = LaunchClassLoaderUtil.<Set<String>>getField(classLoader, LaunchClassLoaderUtil.TRANSFORMER_EXCEPTIONS_FIELD);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -199,4 +204,5 @@ public final class LaunchClassLoaderUtil {
|
||||
}
|
||||
return util;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user