mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-25 20:24:28 +00:00
Add audit support
This commit is contained in:
1 parent
7c8da4fd76
commit
433fc6648a
4 files changed
+60
-4
No files matched your search
@@ -31,6 +31,7 @@ import java.util.List;
|
||||
|
||||
import org.apache.logging.log4j.core.helpers.Booleans;
|
||||
import org.spongepowered.asm.launch.MixinBootstrap;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinTransformer;
|
||||
import org.spongepowered.asm.util.PrettyPrinter;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -391,6 +392,14 @@ public class MixinEnvironment {
|
||||
this.options[option.ordinal()] = value;
|
||||
}
|
||||
|
||||
public void audit() {
|
||||
Object activeTransformer = this.getActiveTransformer();
|
||||
if (activeTransformer instanceof MixinTransformer) {
|
||||
MixinTransformer transformer = (MixinTransformer)activeTransformer;
|
||||
transformer.audit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s[%s]", this.getClass().getSimpleName(), this.phase);
|
||||
|
||||
@@ -26,6 +26,7 @@ package org.spongepowered.asm.mixin.transformer;
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@@ -38,6 +39,7 @@ import net.minecraft.launchwrapper.Launch;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.spongepowered.asm.launch.MixinInitialisationError;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
@@ -74,6 +76,11 @@ class MixinConfig implements Comparable<MixinConfig> {
|
||||
*/
|
||||
private final transient Map<String, List<MixinInfo>> mixinMapping = new HashMap<String, List<MixinInfo>>();
|
||||
|
||||
/**
|
||||
* Targets for this configuration which haven't been mixed yet
|
||||
*/
|
||||
private final transient Set<String> unhandledTargets = new HashSet<String>();
|
||||
|
||||
/**
|
||||
* All mixins loaded by this config
|
||||
*/
|
||||
@@ -326,7 +333,9 @@ class MixinConfig implements Comparable<MixinConfig> {
|
||||
if (mixin.getTargetClasses().size() > 0) {
|
||||
MixinConfig.globalMixinList.add(mixinClass);
|
||||
for (String targetClass : mixin.getTargetClasses()) {
|
||||
this.mixinsFor(targetClass.replace('/', '.')).add(mixin);
|
||||
String targetClassName = targetClass.replace('/', '.');
|
||||
this.mixinsFor(targetClassName).add(mixin);
|
||||
this.unhandledTargets.add(targetClassName);
|
||||
}
|
||||
this.mixins.add(mixin);
|
||||
}
|
||||
@@ -335,7 +344,11 @@ class MixinConfig implements Comparable<MixinConfig> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void postApply(String transformedName, ClassNode targetClass) {
|
||||
this.unhandledTargets.remove(transformedName);
|
||||
}
|
||||
|
||||
/**
|
||||
* True if this mixin is <em>required</em> (failure to apply a defined mixin
|
||||
* is an <em>error</em> condition).
|
||||
@@ -363,7 +376,7 @@ class MixinConfig implements Comparable<MixinConfig> {
|
||||
* Get the list of mixin classes we will be applying
|
||||
*/
|
||||
public List<String> getClasses() {
|
||||
return this.mixinClasses;
|
||||
return Collections.<String>unmodifiableList(this.mixinClasses);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -392,7 +405,14 @@ class MixinConfig implements Comparable<MixinConfig> {
|
||||
* Get targets for this configuration
|
||||
*/
|
||||
public Set<String> getTargets() {
|
||||
return this.mixinMapping.keySet();
|
||||
return Collections.<String>unmodifiableSet(this.mixinMapping.keySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get targets for this configuration
|
||||
*/
|
||||
public Set<String> getUnhandledTargets() {
|
||||
return Collections.<String>unmodifiableSet(this.unhandledTargets);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -542,6 +542,8 @@ class MixinInfo extends TreeInfo implements Comparable<MixinInfo>, IMixinInfo {
|
||||
if (this.plugin != null) {
|
||||
this.plugin.postApply(transformedName, targetClass, this.className, this);
|
||||
}
|
||||
|
||||
this.parent.postApply(transformedName, targetClass);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
||||
@@ -36,6 +36,7 @@ import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.logging.log4j.Level;
|
||||
@@ -269,6 +270,30 @@ public class MixinTransformer extends TreeTransformer {
|
||||
|
||||
TreeInfo.setLock(this.lock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force-load all classes targetted by mixins but not yet applied
|
||||
*/
|
||||
public void audit() {
|
||||
if (!this.currentEnvironment.getOption(Option.CHECK_IMPLEMENTS)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Set<String> unhandled = new HashSet<String>();
|
||||
|
||||
for (MixinConfig config : this.configs) {
|
||||
unhandled.addAll(config.getUnhandledTargets());
|
||||
}
|
||||
|
||||
for (String nextClass : unhandled) {
|
||||
try {
|
||||
this.logger.info("Force-loading class {}", nextClass);
|
||||
Class.forName(nextClass, true, Launch.classLoader);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
throw new Error("Could not force-load " + nextClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.minecraft.launchwrapper.IClassTransformer
|
||||
|
||||
Reference in new issue
Block a user