mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-26 23:13:23 +00:00
More internal service refactoring, remove temp launchwrapper dependency
This commit is contained in:
1 parent
d6a244ed8d
commit
c218a4a76e
20 files changed
+438
-250
No files matched your search
+19
-15
@@ -24,16 +24,18 @@
|
||||
*/
|
||||
package org.spongepowered.asm.launch;
|
||||
|
||||
import org.spongepowered.asm.service.IMixinService;
|
||||
import org.spongepowered.asm.service.MixinService;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
import org.spongepowered.asm.service.IGlobalPropertyService;
|
||||
|
||||
/**
|
||||
* Abstractions for working with the blackboard
|
||||
* Access to underlying global property service provided by the current
|
||||
* environment
|
||||
*/
|
||||
public final class Blackboard {
|
||||
public final class GlobalProperties {
|
||||
|
||||
/**
|
||||
* Blackboard keys
|
||||
* Global property keys
|
||||
*/
|
||||
public static final class Keys {
|
||||
|
||||
@@ -55,15 +57,17 @@ public final class Blackboard {
|
||||
|
||||
}
|
||||
|
||||
private static IMixinService service;
|
||||
private static IGlobalPropertyService service;
|
||||
|
||||
private Blackboard() {}
|
||||
private GlobalProperties() {}
|
||||
|
||||
private static IMixinService getService() {
|
||||
if (Blackboard.service == null) {
|
||||
Blackboard.service = MixinService.getService();
|
||||
private static IGlobalPropertyService getService() {
|
||||
if (GlobalProperties.service == null) {
|
||||
ServiceLoader<IGlobalPropertyService> serviceLoader =
|
||||
ServiceLoader.<IGlobalPropertyService>load(IGlobalPropertyService.class, GlobalProperties.class.getClassLoader());
|
||||
GlobalProperties.service = serviceLoader.iterator().next();
|
||||
}
|
||||
return Blackboard.service;
|
||||
return GlobalProperties.service;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +78,7 @@ public final class Blackboard {
|
||||
* @return value
|
||||
*/
|
||||
public static <T> T get(String key) {
|
||||
return Blackboard.getService().<T>getGlobalProperty(key);
|
||||
return GlobalProperties.getService().<T>getProperty(key);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,7 +88,7 @@ public final class Blackboard {
|
||||
* @param value new value
|
||||
*/
|
||||
public static void put(String key, Object value) {
|
||||
Blackboard.getService().setGlobalProperty(key, value);
|
||||
GlobalProperties.getService().setProperty(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,7 +101,7 @@ public final class Blackboard {
|
||||
* @return value from blackboard or default value
|
||||
*/
|
||||
public static <T> T get(String key, T defaultValue) {
|
||||
return Blackboard.getService().getGlobalProperty(key, defaultValue);
|
||||
return GlobalProperties.getService().getProperty(key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,7 +114,7 @@ public final class Blackboard {
|
||||
* @return value from blackboard or default
|
||||
*/
|
||||
public static String getString(String key, String defaultValue) {
|
||||
return Blackboard.getService().getGlobalPropertyString(key, defaultValue);
|
||||
return GlobalProperties.getService().getPropertyString(key, defaultValue);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,8 +33,6 @@ import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
|
||||
import org.spongepowered.asm.service.MixinService;
|
||||
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
|
||||
/**
|
||||
* Bootstaps the mixin subsystem. This class acts as a bridge between the mixin
|
||||
* subsystem and the tweaker or coremod which is boostrapping it. Without this
|
||||
@@ -73,10 +71,9 @@ public abstract class MixinBootstrap {
|
||||
private static boolean initialised = false;
|
||||
private static boolean initState = true;
|
||||
|
||||
// Static initialiser, add classloader exclusions as early as possible
|
||||
// Static initialiser, run boot services as early as possible
|
||||
static {
|
||||
// AMS - temp fix, see #210
|
||||
Launch.classLoader.addClassLoaderExclusion("org.spongepowered.asm.service.");
|
||||
MixinService.boot();
|
||||
MixinService.getService().prepare();
|
||||
}
|
||||
|
||||
@@ -100,12 +97,12 @@ public abstract class MixinBootstrap {
|
||||
*/
|
||||
public static MixinPlatformManager getPlatform() {
|
||||
if (MixinBootstrap.platform == null) {
|
||||
Object globalPlatformManager = Blackboard.<Object>get(Blackboard.Keys.PLATFORM_MANAGER);
|
||||
Object globalPlatformManager = GlobalProperties.<Object>get(GlobalProperties.Keys.PLATFORM_MANAGER);
|
||||
if (globalPlatformManager instanceof MixinPlatformManager) {
|
||||
MixinBootstrap.platform = (MixinPlatformManager)globalPlatformManager;
|
||||
} else {
|
||||
MixinBootstrap.platform = new MixinPlatformManager();
|
||||
Blackboard.put(Blackboard.Keys.PLATFORM_MANAGER, MixinBootstrap.platform);
|
||||
GlobalProperties.put(GlobalProperties.Keys.PLATFORM_MANAGER, MixinBootstrap.platform);
|
||||
MixinBootstrap.platform.init();
|
||||
}
|
||||
}
|
||||
@@ -145,16 +142,17 @@ public abstract class MixinBootstrap {
|
||||
System.setProperty("mixin.env.remapRefMap", "true");
|
||||
}
|
||||
|
||||
if (MixinBootstrap.findInStackTrace("net.minecraft.launchwrapper.Launch", "launch") > 132) {
|
||||
Phase initialPhase = MixinService.getService().getInitialPhase();
|
||||
if (initialPhase == Phase.DEFAULT) {
|
||||
MixinBootstrap.logger.error("Initialising mixin subsystem after game pre-init phase! Some mixins may be skipped.");
|
||||
MixinEnvironment.init(Phase.DEFAULT);
|
||||
MixinEnvironment.init(initialPhase);
|
||||
MixinBootstrap.getPlatform().prepare(null);
|
||||
MixinBootstrap.initState = false;
|
||||
} else {
|
||||
MixinEnvironment.init(Phase.PREINIT);
|
||||
MixinEnvironment.init(initialPhase);
|
||||
}
|
||||
|
||||
MixinBootstrap.addProxy();
|
||||
MixinService.getService().beginPhase();
|
||||
}
|
||||
|
||||
MixinBootstrap.getPlatform();
|
||||
@@ -183,11 +181,6 @@ public abstract class MixinBootstrap {
|
||||
|
||||
if (MixinBootstrap.initState) {
|
||||
MixinBootstrap.getPlatform().prepare(args);
|
||||
|
||||
if (MixinBootstrap.findInStackTrace("net.minecraft.launchwrapper.Launch", "launch") < 4) {
|
||||
MixinBootstrap.logger.warn("MixinBootstrap.doInit() called during a tweak constructor. Expect CoModificationException in 5.. 4..");
|
||||
}
|
||||
|
||||
MixinService.getService().init();
|
||||
}
|
||||
}
|
||||
@@ -197,7 +190,7 @@ public abstract class MixinBootstrap {
|
||||
}
|
||||
|
||||
private static boolean isSubsystemRegistered() {
|
||||
return Blackboard.<Object>get(Blackboard.Keys.INIT) != null;
|
||||
return GlobalProperties.<Object>get(GlobalProperties.Keys.INIT) != null;
|
||||
}
|
||||
|
||||
private static boolean checkSubsystemVersion() {
|
||||
@@ -205,29 +198,12 @@ public abstract class MixinBootstrap {
|
||||
}
|
||||
|
||||
private static Object getActiveSubsystemVersion() {
|
||||
Object version = Blackboard.get(Blackboard.Keys.INIT);
|
||||
Object version = GlobalProperties.get(GlobalProperties.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();
|
||||
|
||||
if (!"main".equals(currentThread.getName())) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
StackTraceElement[] stackTrace = currentThread.getStackTrace();
|
||||
for (StackTraceElement s : stackTrace) {
|
||||
if (className.equals(s.getClassName()) && methodName.equals(s.getMethodName())) {
|
||||
return s.getLineNumber();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
GlobalProperties.put(GlobalProperties.Keys.INIT, version);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,7 +32,7 @@ import java.util.List;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.launch.Blackboard;
|
||||
import org.spongepowered.asm.launch.GlobalProperties;
|
||||
import org.spongepowered.asm.service.MixinService;
|
||||
|
||||
/**
|
||||
@@ -43,7 +43,7 @@ public class MixinContainer {
|
||||
private static final List<String> agentClasses = new ArrayList<String>();
|
||||
|
||||
static {
|
||||
Blackboard.put(Blackboard.Keys.AGENTS, MixinContainer.agentClasses);
|
||||
GlobalProperties.put(GlobalProperties.Keys.AGENTS, MixinContainer.agentClasses);
|
||||
for (String agent : MixinService.getService().getPlatformAgents()) {
|
||||
MixinContainer.agentClasses.add(agent);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.apache.logging.log4j.core.Filter;
|
||||
import org.apache.logging.log4j.core.Layout;
|
||||
import org.apache.logging.log4j.core.LogEvent;
|
||||
import org.apache.logging.log4j.core.appender.AbstractAppender;
|
||||
import org.spongepowered.asm.launch.Blackboard;
|
||||
import org.spongepowered.asm.launch.GlobalProperties;
|
||||
import org.spongepowered.asm.launch.MixinBootstrap;
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.mixin.extensibility.IEnvironmentTokenProvider;
|
||||
@@ -873,7 +873,7 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
MixinEnvironment(Phase phase) {
|
||||
this.service = MixinService.getService();
|
||||
this.phase = phase;
|
||||
this.configsKey = Blackboard.Keys.CONFIGS + "." + this.phase.name.toLowerCase();
|
||||
this.configsKey = GlobalProperties.Keys.CONFIGS + "." + this.phase.name.toLowerCase();
|
||||
|
||||
// Sanity check
|
||||
Object version = this.getVersion();
|
||||
@@ -949,10 +949,10 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
*/
|
||||
@Deprecated
|
||||
public List<String> getMixinConfigs() {
|
||||
List<String> mixinConfigs = Blackboard.<List<String>>get(this.configsKey);
|
||||
List<String> mixinConfigs = GlobalProperties.<List<String>>get(this.configsKey);
|
||||
if (mixinConfigs == null) {
|
||||
mixinConfigs = new ArrayList<String>();
|
||||
this.service.setGlobalProperty(this.configsKey, mixinConfigs);
|
||||
GlobalProperties.put(this.configsKey, mixinConfigs);
|
||||
}
|
||||
return mixinConfigs;
|
||||
}
|
||||
@@ -1069,7 +1069,7 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
* @return active mixin transformer instance
|
||||
*/
|
||||
public Object getActiveTransformer() {
|
||||
return Blackboard.get(Blackboard.Keys.TRANSFORMER);
|
||||
return GlobalProperties.get(GlobalProperties.Keys.TRANSFORMER);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1079,7 +1079,7 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
*/
|
||||
public void setActiveTransformer(ITransformer transformer) {
|
||||
if (transformer != null) {
|
||||
Blackboard.put(Blackboard.Keys.TRANSFORMER, transformer);
|
||||
GlobalProperties.put(GlobalProperties.Keys.TRANSFORMER, transformer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1120,7 +1120,7 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
* @return current version
|
||||
*/
|
||||
public String getVersion() {
|
||||
return Blackboard.<String>get(Blackboard.Keys.INIT);
|
||||
return GlobalProperties.<String>get(GlobalProperties.Keys.INIT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,9 +30,8 @@ import java.util.Set;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.launch.Blackboard;
|
||||
import org.spongepowered.asm.launch.GlobalProperties;
|
||||
import org.spongepowered.asm.mixin.transformer.Config;
|
||||
import org.spongepowered.asm.service.MixinService;
|
||||
|
||||
/**
|
||||
* Entry point for registering global mixin resources. Compatibility with
|
||||
@@ -47,9 +46,9 @@ public final class Mixins {
|
||||
private static final Logger logger = LogManager.getLogger("mixin");
|
||||
|
||||
/**
|
||||
* Blackboard key storing mixin configs which are pending
|
||||
* GlobalProperties key storing mixin configs which are pending
|
||||
*/
|
||||
private static final String CONFIGS_KEY = Blackboard.Keys.CONFIGS + ".queue";
|
||||
private static final String CONFIGS_KEY = GlobalProperties.Keys.CONFIGS + ".queue";
|
||||
|
||||
/**
|
||||
* Error handlers for environment
|
||||
@@ -139,10 +138,10 @@ public final class Mixins {
|
||||
* consumed are present in this set
|
||||
*/
|
||||
public static Set<Config> getConfigs() {
|
||||
Set<Config> mixinConfigs = Blackboard.<Set<Config>>get(Mixins.CONFIGS_KEY);
|
||||
Set<Config> mixinConfigs = GlobalProperties.<Set<Config>>get(Mixins.CONFIGS_KEY);
|
||||
if (mixinConfigs == null) {
|
||||
mixinConfigs = new LinkedHashSet<Config>();
|
||||
MixinService.getService().setGlobalProperty(Mixins.CONFIGS_KEY, mixinConfigs);
|
||||
GlobalProperties.put(Mixins.CONFIGS_KEY, mixinConfigs);
|
||||
}
|
||||
return mixinConfigs;
|
||||
}
|
||||
|
||||
@@ -138,8 +138,8 @@ class MixinPostProcessor extends TreeTransformer implements MixinConfig.IListene
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.minecraft.launchwrapper.IClassTransformer
|
||||
* #transform(java.lang.String, java.lang.String, byte[])
|
||||
* @see org.spongepowered.asm.service.ILegacyClassTransformer
|
||||
* #transformClassBytes(java.lang.String, java.lang.String, byte[])
|
||||
*/
|
||||
@Override
|
||||
public byte[] transformClassBytes(String name, String transformedName, byte[] bytes) {
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.service;
|
||||
|
||||
/**
|
||||
* Global property service
|
||||
*/
|
||||
public interface IGlobalPropertyService {
|
||||
|
||||
/**
|
||||
* Get a value from the global property store (blackboard) and duck-type it
|
||||
* to the specified type
|
||||
*
|
||||
* @param key blackboard key
|
||||
* @param <T> duck type
|
||||
* @return value
|
||||
*/
|
||||
public abstract <T> T getProperty(String key);
|
||||
|
||||
/**
|
||||
* Set the specified value in the global property store (blackboard)
|
||||
*
|
||||
* @param key blackboard key
|
||||
* @param value new value
|
||||
*/
|
||||
public abstract void setProperty(String key, Object value);
|
||||
|
||||
/**
|
||||
* Get the value from the global property store (blackboard) but return
|
||||
* <tt>defaultValue</tt> if the specified key is not set.
|
||||
*
|
||||
* @param key blackboard key
|
||||
* @param defaultValue value to return if the key is not set or is null
|
||||
* @param <T> duck type
|
||||
* @return value from blackboard or default value
|
||||
*/
|
||||
public abstract <T> T getProperty(String key, T defaultValue);
|
||||
|
||||
/**
|
||||
* Get a string from the global property store (blackboard), returns default
|
||||
* value if not set or null.
|
||||
*
|
||||
* @param key blackboard key
|
||||
* @param defaultValue default value to return if the specified key is not
|
||||
* set or is null
|
||||
* @return value from blackboard or default
|
||||
*/
|
||||
public abstract String getPropertyString(String key, String defaultValue);
|
||||
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import java.net.URL;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.spongepowered.asm.lib.tree.ClassNode;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
|
||||
import org.spongepowered.asm.util.ReEntranceLock;
|
||||
|
||||
/**
|
||||
@@ -56,12 +57,17 @@ public interface IMixinService {
|
||||
* Called at subsystem boot
|
||||
*/
|
||||
public abstract void prepare();
|
||||
|
||||
/**
|
||||
* Get the initial subsystem phase
|
||||
*/
|
||||
public abstract Phase getInitialPhase();
|
||||
|
||||
/**
|
||||
* Called at the end of subsystem boot
|
||||
*/
|
||||
public abstract void init();
|
||||
|
||||
|
||||
/**
|
||||
* Called whenever a new phase is started
|
||||
*/
|
||||
@@ -182,45 +188,5 @@ public interface IMixinService {
|
||||
* Get the detected side name for this environment
|
||||
*/
|
||||
public abstract String getSideName();
|
||||
|
||||
/**
|
||||
* Get a value from the global property store (blackboard) and duck-type it
|
||||
* to the specified type
|
||||
*
|
||||
* @param key blackboard key
|
||||
* @param <T> duck type
|
||||
* @return value
|
||||
*/
|
||||
public abstract <T> T getGlobalProperty(String key);
|
||||
|
||||
/**
|
||||
* Set the specified value in the global property store (blackboard)
|
||||
*
|
||||
* @param key blackboard key
|
||||
* @param value new value
|
||||
*/
|
||||
public abstract void setGlobalProperty(String key, Object value);
|
||||
|
||||
/**
|
||||
* Get the value from the global property store (blackboard) but return
|
||||
* <tt>defaultValue</tt> if the specified key is not set.
|
||||
*
|
||||
* @param key blackboard key
|
||||
* @param defaultValue value to return if the key is not set or is null
|
||||
* @param <T> duck type
|
||||
* @return value from blackboard or default value
|
||||
*/
|
||||
public abstract <T> T getGlobalProperty(String key, T defaultValue);
|
||||
|
||||
/**
|
||||
* Get a string from the global property store (blackboard), returns default
|
||||
* value if not set or null.
|
||||
*
|
||||
* @param key blackboard key
|
||||
* @param defaultValue default value to return if the specified key is not
|
||||
* set or is null
|
||||
* @return value from blackboard or default
|
||||
*/
|
||||
public abstract String getGlobalPropertyString(String key, String defaultValue);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.service;
|
||||
|
||||
/**
|
||||
* Bootstrap interface for Mixin services. Because of the nature of service
|
||||
* environments, it may be necessary to provide bootstrap logic to prepare
|
||||
* the classloader environment before the services themselves are enumerated.
|
||||
*/
|
||||
public interface IMixinServiceBootstrap {
|
||||
|
||||
/**
|
||||
* Get the friendly name for the underlying service
|
||||
*/
|
||||
public abstract String getName();
|
||||
|
||||
/**
|
||||
* Get the fully qualified class name of the underlying service
|
||||
*/
|
||||
public abstract String getServiceClassName();
|
||||
|
||||
/**
|
||||
* Run bootstrap-time preparation for the underlying service
|
||||
*/
|
||||
public abstract void boostrap();
|
||||
|
||||
}
|
||||
@@ -24,9 +24,14 @@
|
||||
*/
|
||||
package org.spongepowered.asm.service;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.ServiceConfigurationError;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Provides access to the service layer which connects the mixin transformer to
|
||||
@@ -35,11 +40,20 @@ import java.util.ServiceLoader;
|
||||
* core. This allows us to support LegacyLauncher
|
||||
*/
|
||||
public final class MixinService {
|
||||
|
||||
/**
|
||||
* Log all the things
|
||||
*/
|
||||
private static final Logger logger = LogManager.getLogger("mixin");
|
||||
|
||||
/**
|
||||
* Singleton
|
||||
*/
|
||||
private static MixinService instance;
|
||||
|
||||
private ServiceLoader<IMixinServiceBootstrap> bootstrapServiceLoader;
|
||||
|
||||
private final Set<String> bootedServices = new HashSet<String>();
|
||||
|
||||
/**
|
||||
* Service loader
|
||||
@@ -55,12 +69,25 @@ public final class MixinService {
|
||||
* Singleton pattern
|
||||
*/
|
||||
private MixinService() {
|
||||
this.runBootServices();
|
||||
}
|
||||
|
||||
private void runBootServices() {
|
||||
this.bootstrapServiceLoader = ServiceLoader.<IMixinServiceBootstrap>load(IMixinServiceBootstrap.class, this.getClass().getClassLoader());
|
||||
for (IMixinServiceBootstrap bootService : this.bootstrapServiceLoader) {
|
||||
try {
|
||||
bootService.boostrap();
|
||||
this.bootedServices.add(bootService.getServiceClassName());
|
||||
} catch (Throwable th) {
|
||||
MixinService.logger.catching(th);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Singleton pattern, get or create the instance
|
||||
*/
|
||||
private static MixinService getCanonicalInstance() {
|
||||
private static MixinService getInstance() {
|
||||
if (MixinService.instance == null) {
|
||||
MixinService.instance = new MixinService();
|
||||
}
|
||||
@@ -68,8 +95,15 @@ public final class MixinService {
|
||||
return MixinService.instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Boot
|
||||
*/
|
||||
public static void boot() {
|
||||
MixinService.getInstance();
|
||||
}
|
||||
|
||||
public static IMixinService getService() {
|
||||
return MixinService.getCanonicalInstance().getServiceInstance();
|
||||
return MixinService.getInstance().getServiceInstance();
|
||||
}
|
||||
|
||||
private synchronized IMixinService getServiceInstance() {
|
||||
@@ -88,6 +122,9 @@ public final class MixinService {
|
||||
while (iter.hasNext()) {
|
||||
try {
|
||||
IMixinService service = iter.next();
|
||||
if (this.bootedServices.contains(service.getClass().getName())) {
|
||||
MixinService.logger.debug("MixinService [{}] was successfully booted in {}", service.getName(), this.getClass().getClassLoader());
|
||||
}
|
||||
if (service.isValid()) {
|
||||
return service;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user