diff --git a/src/main/java/org/spongepowered/asm/launch/MixinBootstrap.java b/src/main/java/org/spongepowered/asm/launch/MixinBootstrap.java index 2407da88..9cb27cd7 100644 --- a/src/main/java/org/spongepowered/asm/launch/MixinBootstrap.java +++ b/src/main/java/org/spongepowered/asm/launch/MixinBootstrap.java @@ -91,7 +91,10 @@ public abstract class MixinBootstrap { Launch.classLoader.addClassLoaderExclusion(MixinBootstrap.LAUNCH_PACKAGE); } - private static MixinPlatformManager platformManager = new MixinPlatformManager(); + /** + * Platform manager instance + */ + private static MixinPlatformManager platform; private MixinBootstrap() {} @@ -106,7 +109,10 @@ public abstract class MixinBootstrap { * Get the platform manager */ public static MixinPlatformManager getPlatform() { - return MixinBootstrap.platformManager; + if (MixinBootstrap.platform == null) { + MixinBootstrap.platform = new MixinPlatformManager(); + } + return MixinBootstrap.platform; } /** @@ -124,17 +130,15 @@ public abstract class MixinBootstrap { * Phase 1 of mixin initialisation */ static boolean start() { - Object registeredVersion = Blackboard.get(Blackboard.Keys.INIT); - if (registeredVersion != null) { - if (!registeredVersion.equals(MixinBootstrap.VERSION)) { - throw new MixinInitialisationError("Mixin subsystem version " + registeredVersion + if (MixinBootstrap.isSubsystemRegistered()) { + if (!MixinBootstrap.checkSubsystemVersion()) { + throw new MixinInitialisationError("Mixin subsystem version " + MixinBootstrap.getActiveSubsystemVersion() + " was already initialised. Cannot bootstrap version " + MixinBootstrap.VERSION); } - return false; } - - Blackboard.put(Blackboard.Keys.INIT, MixinBootstrap.VERSION); + + MixinBootstrap.registerSubsystem(MixinBootstrap.VERSION); if (!MixinBootstrap.initialised) { MixinBootstrap.initialised = true; @@ -156,6 +160,8 @@ public abstract class MixinBootstrap { MixinBootstrap.addProxy(); } + MixinBootstrap.getPlatform(); + return true; } @@ -164,7 +170,12 @@ public abstract class MixinBootstrap { */ static void doInit(List args) { if (!MixinBootstrap.initialised) { - throw new IllegalStateException("MixinBootstrap.doInit() called before MixinBootstrap.preInit()"); + if (MixinBootstrap.isSubsystemRegistered()) { + MixinBootstrap.logger.warn("Multiple Mixin containers present, init suppressed for " + MixinBootstrap.VERSION); + return; + } + + throw new IllegalStateException("MixinBootstrap.doInit() called before MixinBootstrap.start()"); } MixinBootstrap.getPlatform().getPhaseProviderClasses(); @@ -191,6 +202,23 @@ public abstract class MixinBootstrap { MixinBootstrap.getPlatform().injectIntoClassLoader(classLoader); } + private static boolean isSubsystemRegistered() { + return Blackboard.get(Blackboard.Keys.INIT) != null; + } + + private static boolean checkSubsystemVersion() { + return MixinBootstrap.VERSION.equals(MixinBootstrap.getActiveSubsystemVersion()); + } + + private static Object getActiveSubsystemVersion() { + Object version = Blackboard.get(Blackboard.Keys.INIT); + return version != null ? version : ""; + } + + private static void registerSubsystem(String version) { + Blackboard.put(Blackboard.Keys.INIT, version); + } + private static int findInStackTrace(String className, String methodName) { Thread currentThread = Thread.currentThread(); diff --git a/src/main/java/org/spongepowered/asm/launch/platform/MixinContainer.java b/src/main/java/org/spongepowered/asm/launch/platform/MixinContainer.java index 0c274329..ef71f19c 100644 --- a/src/main/java/org/spongepowered/asm/launch/platform/MixinContainer.java +++ b/src/main/java/org/spongepowered/asm/launch/platform/MixinContainer.java @@ -63,6 +63,7 @@ public class MixinContainer { @SuppressWarnings("unchecked") Class clazz = (Class)Class.forName(agentClass); Constructor ctor = clazz.getDeclaredConstructor(MixinPlatformManager.class, URI.class); + this.logger.debug("Instancing new {} for {}", clazz.getSimpleName(), this.uri); IMixinPlatformAgent agent = ctor.newInstance(manager, uri); this.agents.add(agent); } catch (Exception ex) { @@ -94,6 +95,7 @@ public class MixinContainer { */ public void prepare() { for (IMixinPlatformAgent agent : this.agents) { + this.logger.debug("Processing prepare() for {}", agent); agent.prepare(); } } @@ -110,6 +112,7 @@ public class MixinContainer { */ public void injectIntoClassLoader(LaunchClassLoader classLoader) { for (IMixinPlatformAgent agent : this.agents) { + this.logger.debug("Processing injectIntoClassLoader() for {}", agent); agent.injectIntoClassLoader(classLoader); } } diff --git a/src/main/java/org/spongepowered/asm/launch/platform/MixinPlatformAgentFML.java b/src/main/java/org/spongepowered/asm/launch/platform/MixinPlatformAgentFML.java index 404e4b76..ecdc63d5 100644 --- a/src/main/java/org/spongepowered/asm/launch/platform/MixinPlatformAgentFML.java +++ b/src/main/java/org/spongepowered/asm/launch/platform/MixinPlatformAgentFML.java @@ -104,6 +104,7 @@ public class MixinPlatformAgentFML extends MixinPlatformAgentAbstract { this.clCoreModManager = MixinPlatformAgentFML.getCoreModManagerClass(); if ("true".equalsIgnoreCase(this.attributes.get(MixinPlatformAgentFML.MFATT_FORCELOADASMOD))) { + MixinPlatformAgentAbstract.logger.debug("ForceLoadAsMod was specified for {}, attempting force-load", this.fileName); this.loadAsMod(); } @@ -147,6 +148,7 @@ public class MixinPlatformAgentFML extends MixinPlatformAgentAbstract { @SuppressWarnings("unchecked") List reparsedCoremods = (List)mdGetReparsedCoremods.invoke(null); if (!reparsedCoremods.contains(this.fileName)) { + MixinPlatformAgentAbstract.logger.debug("Adding {} to reparseable coremod collection", this.fileName); reparsedCoremods.add(this.fileName); } } catch (Exception ex) { @@ -160,11 +162,13 @@ public class MixinPlatformAgentFML extends MixinPlatformAgentAbstract { return null; } + MixinPlatformAgentAbstract.logger.debug("{} has core plugin {}. Injecting it into FML for co-initialisation:", this.fileName, coreModName); Method mdLoadCoreMod = this.clCoreModManager.getDeclaredMethod(Blackboard.getString( Blackboard.Keys.FML_LOAD_CORE_MOD, MixinPlatformAgentFML.LOAD_CORE_MOD_METHOD), LaunchClassLoader.class, String.class, File.class); mdLoadCoreMod.setAccessible(true); ITweaker wrapper = (ITweaker)mdLoadCoreMod.invoke(null, Launch.classLoader, coreModName, this.container); if (wrapper == null) { + MixinPlatformAgentAbstract.logger.debug("Core plugin {} could not be loaded.", coreModName); return null; } @@ -197,6 +201,7 @@ public class MixinPlatformAgentFML extends MixinPlatformAgentAbstract { private void injectRemapper() { try { + MixinPlatformAgentAbstract.logger.debug("Creating FML remapper adapter: {}", MixinPlatformAgentFML.FML_REMAPPER_ADAPTER_CLASS); Class clFmlRemapperAdapter = Class.forName(MixinPlatformAgentFML.FML_REMAPPER_ADAPTER_CLASS, true, Launch.classLoader); Method mdCreate = clFmlRemapperAdapter.getDeclaredMethod("create"); IRemapper remapper = (IRemapper)mdCreate.invoke(null); @@ -212,8 +217,13 @@ public class MixinPlatformAgentFML extends MixinPlatformAgentAbstract { */ @Override public void injectIntoClassLoader(LaunchClassLoader classLoader) { - if (this.coreModWrapper != null && !this.isFMLInjected()) { - this.coreModWrapper.injectIntoClassLoader(classLoader); + if (this.coreModWrapper != null) { + if (!this.isFMLInjected()) { + MixinPlatformAgentAbstract.logger.debug("FML agent is co-initialising coremod instance {} for {}", this.coreModWrapper, this.uri); + this.coreModWrapper.injectIntoClassLoader(classLoader); + } else { + MixinPlatformAgentAbstract.logger.debug("FML agent is skipping co-init for {} because FML already started", this.coreModWrapper); + } } } diff --git a/src/main/java/org/spongepowered/asm/launch/platform/MixinPlatformManager.java b/src/main/java/org/spongepowered/asm/launch/platform/MixinPlatformManager.java index efde7e32..ee22084a 100644 --- a/src/main/java/org/spongepowered/asm/launch/platform/MixinPlatformManager.java +++ b/src/main/java/org/spongepowered/asm/launch/platform/MixinPlatformManager.java @@ -91,19 +91,22 @@ public class MixinPlatformManager { public MixinPlatformManager() { //Delegate delegate) { // this.delegate = delegate; - + + MixinPlatformManager.logger.debug("Initialising Mixin Platform Manager"); + // Add agents for the tweak container URI uri = null; try { uri = this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI(); if (uri != null) { + MixinPlatformManager.logger.debug("Mixin platform: primary container is {}", uri); this.primaryContainer = this.addContainer(uri); } } catch (URISyntaxException ex) { ex.printStackTrace(); } } - + public Collection getPhaseProviderClasses() { Collection phaseProviders = this.primaryContainer.getPhaseProviders(); if (phaseProviders != null) {