Adjust platform manager bootstrapping, add logging to platform agents

This commit is contained in:
Mumfrey committed 2016-06-23 00:54:59 +01:00
1 parent a3b98d8a15
commit 15709d089b
4 files changed
+58 -14

No files matched your search

@@ -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<String> 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.<Object>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();
@@ -63,6 +63,7 @@ public class MixinContainer {
@SuppressWarnings("unchecked")
Class<IMixinPlatformAgent> clazz = (Class<IMixinPlatformAgent>)Class.forName(agentClass);
Constructor<IMixinPlatformAgent> 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);
}
}
@@ -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<String> reparsedCoremods = (List<String>)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);
}
}
}
@@ -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<String> getPhaseProviderClasses() {
Collection<String> phaseProviders = this.primaryContainer.getPhaseProviders();
if (phaseProviders != null) {