More internal service refactoring

This commit is contained in:
Mumfrey committed 2017-10-09 16:36:48 +01:00
1 parent 02ba7b73e1
commit 0d4300980d
7 files changed
+104 -32

No files matched your search

@@ -42,6 +42,7 @@ import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.MixinEnvironment.CompatibilityLevel;
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.Constants;
import org.spongepowered.asm.mixin.Mixins;
//import com.google.common.collect.ImmutableList;
@@ -52,7 +53,6 @@ import org.spongepowered.asm.mixin.Mixins;
*/
public class MixinPlatformManager {
private static final String MFATT_TWEAKER = "TweakClass";
private static final String DEFAULT_MAIN_CLASS = "net.minecraft.client.main.Main";
private static final String MIXIN_TWEAKER_CLASS = "org.spongepowered.asm.launch.MixinTweaker";
@@ -224,7 +224,7 @@ public class MixinPlatformManager {
continue;
}
MainAttributes attributes = MainAttributes.of(uri);
String tweaker = attributes.get(MixinPlatformManager.MFATT_TWEAKER);
String tweaker = attributes.get(Constants.ManifestAttributes.TWEAKER);
if (MixinPlatformManager.MIXIN_TWEAKER_CLASS.equals(tweaker)) {
MixinPlatformManager.logger.debug("{} contains a mixin tweaker, adding agents", uri);
this.addContainer(uri);
@@ -881,10 +881,8 @@ public final class MixinEnvironment implements ITokenProvider {
throw new MixinException("Environment conflict, mismatched versions or you didn't call MixinBootstrap.init()");
}
// Also sanity check
if (this.getClass().getClassLoader() != this.service.getApplicationClassLoader()) {
throw new MixinException("Attempted to init the mixin environment in the wrong classloader");
}
// More sanity check
this.service.checkEnv(this);
this.options = new boolean[Option.values().length];
for (Option option : Option.values()) {
@@ -1002,7 +1000,7 @@ public final class MixinEnvironment implements ITokenProvider {
try {
@SuppressWarnings("unchecked")
Class<? extends IEnvironmentTokenProvider> providerClass =
(Class<? extends IEnvironmentTokenProvider>)Class.forName(providerName, true, this.service.getClassLoader());
(Class<? extends IEnvironmentTokenProvider>)this.service.getClassProvider().findClass(providerName, true);
IEnvironmentTokenProvider provider = providerClass.newInstance();
this.registerTokenProvider(provider);
} catch (Throwable th) {
@@ -390,7 +390,7 @@ final class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
for (String injectionPoint : this.injectorOptions.injectionPoints) {
try {
Class<?> injectionPointClass = Class.forName(injectionPoint, true, this.service.getClassLoader());
Class<?> injectionPointClass = this.service.getClassProvider().findClass(injectionPoint, true);
if (InjectionPoint.class.isAssignableFrom(injectionPointClass)) {
InjectionPoint.register((Class<? extends InjectionPoint>)injectionPointClass);
} else {
@@ -438,7 +438,7 @@ final class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
void onSelect() {
if (this.pluginClassName != null) {
try {
Class<?> pluginClass = Class.forName(this.pluginClassName, true, this.service.getClassLoader());
Class<?> pluginClass = this.service.getClassProvider().findClass(this.pluginClassName, true);
this.plugin = (IMixinConfigPlugin)pluginClass.newInstance();
if (this.plugin != null) {
@@ -282,7 +282,7 @@ public class MixinTransformer extends TreeTransformer {
for (String target : unhandled) {
try {
auditLogger.info("Force-loading class {}", target);
Class.forName(target, true, this.service.getClassLoader());
this.service.getClassProvider().findClass(target, true);
} catch (ClassNotFoundException ex) {
auditLogger.error("Could not force-load " + target, ex);
}
@@ -360,7 +360,7 @@ public class MixinTransformer extends TreeTransformer {
printer.add();
try {
Class<?> agent = Class.forName(MixinTransformer.METRONOME_AGENT_CLASS, false, this.service.getApplicationClassLoader());
Class<?> agent = this.service.getClassProvider().findAgentClass(MixinTransformer.METRONOME_AGENT_CLASS, false);
Method mdGetTimes = agent.getDeclaredMethod("getTimes");
@SuppressWarnings("unchecked")
@@ -786,7 +786,7 @@ public class MixinTransformer extends TreeTransformer {
for (String handlerClassName : Mixins.getErrorHandlerClasses()) {
try {
MixinTransformer.logger.info("Instancing error handler class {}", handlerClassName);
Class<?> handlerClass = Class.forName(handlerClassName, true, this.service.getClassLoader());
Class<?> handlerClass = this.service.getClassProvider().findClass(handlerClassName, true);
IMixinErrorHandler handler = (IMixinErrorHandler)handlerClass.newInstance();
if (handler != null) {
handlers.add(handler);
@@ -0,0 +1,50 @@
/*
* 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;
/**
* Interface for marshal object which can retrieve classes from the environment
*/
public interface IClassProvider {
/**
* Marshal a call to <tt>Class.forName</tt> for a regular class
*
* @param name class name
* @param initialize init flag
* @return Klass
*/
public abstract Class<?> findClass(String name, boolean initialize) throws ClassNotFoundException;
/**
* Marshal a call to <tt>Class.forName</tt> for an agent class
*
* @param name agent class name
* @param initialize init flag
* @return Klass
*/
public abstract Class<?> findAgentClass(String name, boolean initialize) throws ClassNotFoundException;
}
@@ -73,6 +73,14 @@ public interface IMixinService {
*/
public abstract void beginPhase();
/**
* Check whether the supplied object is a valid boot source for mixin
* environment
*
* @param bootSource boot source
*/
public abstract void checkEnv(Object bootSource);
/**
* Get the transformer re-entrance lock for this service, the transformer
* uses this lock to track transformer re-entrance when co-operative load
@@ -80,21 +88,15 @@ public interface IMixinService {
*/
public abstract ReEntranceLock getReEntranceLock();
/**
* Return the class provider for this service
*/
public abstract IClassProvider getClassProvider();
/**
* Get additional platform agents for this service
*/
public abstract Collection<String> getPlatformAgents();
/**
* Get the main classloader for this service
*/
public abstract ClassLoader getClassLoader();
/**
* Get the application classloader for this service (usually the system
* classloader)
*/
public abstract ClassLoader getApplicationClassLoader();
/**
* Get a resource as a stream from the appropriate classloader, this is
@@ -188,5 +190,5 @@ public interface IMixinService {
* Get the detected side name for this environment
*/
public abstract String getSideName();
}