Quick and dirty merge of platform refactor for remapper, closes #91

This commit is contained in:
Mumfrey committed 2016-06-21 15:20:18 +01:00
1 parent 75f327fa56
commit adf1c040a6
13 files changed
+481 -278

No files matched your search

@@ -24,14 +24,19 @@
*/
package org.spongepowered.asm.launch;
import java.util.Arrays;
import java.util.List;
import java.util.TreeMap;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.launch.platform.MixinPlatformManager;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
import org.spongepowered.asm.util.PrettyPrinter;
import net.minecraft.launchwrapper.Launch;
import net.minecraft.launchwrapper.LaunchClassLoader;
/**
* Bootstaps the mixin subsystem. This class acts as a bridge between the mixin
@@ -60,7 +65,7 @@ public abstract class MixinBootstrap {
/**
* Subsystem version
*/
public static final String VERSION = "0.5.10";
public static final String VERSION = "0.6";
// Consts
private static final String LAUNCH_PACKAGE = "org.spongepowered.asm.launch.";
@@ -76,7 +81,7 @@ public abstract class MixinBootstrap {
// These are Klass local, with luck this shouldn't be a problem
private static boolean initialised = false;
private static boolean injectStateTweaker = true;
private static boolean initState = true;
// Static initialiser, add classloader exclusions as early as possible
static {
@@ -88,6 +93,8 @@ public abstract class MixinBootstrap {
// Only needed in dev, in production this would be handled by the tweaker
Launch.classLoader.addClassLoaderExclusion(MixinBootstrap.LAUNCH_PACKAGE);
}
private static MixinPlatformManager platformManager = new MixinPlatformManager();
private MixinBootstrap() {}
@@ -98,21 +105,28 @@ public abstract class MixinBootstrap {
Launch.classLoader.registerTransformer(MixinBootstrap.TRANSFORMER_PROXY_CLASS);
}
/**
* Get the platform manager
*/
public static MixinPlatformManager getPlatform() {
return MixinBootstrap.platformManager;
}
/**
* Initialise the mixin subsystem
*/
public static void init() {
if (!MixinBootstrap.preInit()) {
if (!MixinBootstrap.start()) {
return;
}
MixinBootstrap.register();
MixinBootstrap.doInit(null);
}
/**
* Phase 1 of mixin initialisation
*/
static boolean preInit() {
static boolean start() {
Object registeredVersion = Blackboard.get(Blackboard.Keys.INIT);
if (registeredVersion != null) {
if (!registeredVersion.equals(MixinBootstrap.VERSION)) {
@@ -132,11 +146,12 @@ public abstract class MixinBootstrap {
if (command != null && command.contains("GradleStart")) {
System.setProperty("mixin.env.disableRefMap", "true");
}
if (MixinBootstrap.findInStackTrace(Launch.class.getName(), "launch") > 132) {
MixinBootstrap.logger.error("Initialising mixin subsystem after game pre-init phase! Some mixins may be skipped.");
MixinEnvironment.init(Phase.DEFAULT);
MixinBootstrap.injectStateTweaker = false;
MixinBootstrap.getPlatform().prepare(null);
MixinBootstrap.initState = false;
} else {
MixinEnvironment.init(Phase.PREINIT);
}
@@ -148,16 +163,23 @@ public abstract class MixinBootstrap {
}
/**
* Phase 2 of mixin initialisation, register the state tweaker
* Phase 2 of mixin initialisation, initialise the phases
*/
static void register() {
static void doInit(List<String> args) {
if (!MixinBootstrap.initialised) {
throw new IllegalStateException("MixinBootstrap.register() called before MixinBootstrap.preInit()");
throw new IllegalStateException("MixinBootstrap.doInit() called before MixinBootstrap.preInit()");
}
if (MixinBootstrap.injectStateTweaker) {
for (String platformProviderClass : MixinBootstrap.getPlatform().getPhaseProviderClasses()) {
// System.err.printf("Registering %s\n", platformProviderClass);
// MixinEnvironment.registerPhaseProvider(platformProviderClass);
}
if (MixinBootstrap.initState) {
MixinBootstrap.getPlatform().prepare(args);
if (MixinBootstrap.findInStackTrace(Launch.class.getName(), "launch") < 4) {
MixinBootstrap.logger.warn("MixinBootstrap.register() called during a tweak constructor. Expect CoModificationException in 5.. 4..");
MixinBootstrap.logger.warn("MixinBootstrap.doInit() called during a tweak constructor. Expect CoModificationException in 5.. 4..");
}
List<String> tweakClasses = Blackboard.<List<String>>get(Blackboard.Keys.TWEAKCLASSES);
@@ -167,6 +189,10 @@ public abstract class MixinBootstrap {
}
}
static void injectIntoClassLoader(LaunchClassLoader classLoader) {
MixinBootstrap.getPlatform().injectIntoClassLoader(classLoader);
}
private static int findInStackTrace(String className, String methodName) {
Thread currentThread = Thread.currentThread();
@@ -183,4 +209,5 @@ public abstract class MixinBootstrap {
return 0;
}
}