Skip to content

Commit

Permalink
More internal service refactoring, remove temp launchwrapper dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Mumfrey committed Oct 9, 2017
1 parent d6a244e commit c218a4a
Show file tree
Hide file tree
Showing 20 changed files with 438 additions and 250 deletions.
5 changes: 0 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,6 @@ dependencies {
compile 'com.google.code.gson:gson:2.2.4'
compile files(tasks.renamedASM.outputs.files[0]) // Establish implicit dependency on remapped ASM

// AMS - temp fix, see #210
compile('net.minecraft:launchwrapper:1.11') {
exclude module: 'lwjgl'
}

// Tests
// testCompile 'junit:junit:4.11'
// testCompile 'org.hamcrest:hamcrest-library:1.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.jar.Manifest;

import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.java.decompiler.main.Fernflower;
Expand All @@ -48,6 +49,8 @@
*/
public class RuntimeDecompiler extends IFernflowerLogger implements IDecompiler, IResultSaver {

private static final Level[] SEVERITY_LEVELS = { Level.TRACE, Level.INFO, Level.WARN, Level.ERROR };

private final Map<String, Object> options = ImmutableMap.<String, Object>builder()
.put("din", "0").put("rbr", "0").put("dgs", "1").put("asc", "1")
.put("den", "1").put("hdc", "1").put("ind", " ").build();
Expand Down Expand Up @@ -114,13 +117,18 @@ public void startReadingClass(String className) {

@Override
public void writeMessage(String message, Severity severity) {
this.logger.info(message);
this.logger.log(RuntimeDecompiler.SEVERITY_LEVELS[severity.ordinal()], message);
}

@Override
public void writeMessage(String message, Throwable t) {
this.logger.warn("{} {}: {}", message, t.getClass().getSimpleName(), t.getMessage());
}

@Override
public void writeMessage(String message, Severity severity, Throwable t) {
this.logger.log(RuntimeDecompiler.SEVERITY_LEVELS[severity.ordinal()], message, t);
}

@Override
public void copyFile(String source, String path, String entryName) {
Expand All @@ -145,4 +153,5 @@ public void saveClassEntry(String path, String archiveName, String qualifiedName
@Override
public void closeArchive(String path, String archiveName) {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import java.util.Set;

import org.apache.logging.log4j.Level;
import org.spongepowered.asm.launch.Blackboard;
import org.spongepowered.asm.launch.GlobalProperties;
import org.spongepowered.asm.mixin.MixinEnvironment;
//import org.spongepowered.asm.mixin.environment.IPhaseProvider;
//import org.spongepowered.asm.mixin.environment.PhaseDefinition;
Expand Down Expand Up @@ -187,8 +187,8 @@ private void loadAsMod() {
*/
private void addReparseableJar() {
try {
Method mdGetReparsedCoremods = this.clCoreModManager.getDeclaredMethod(Blackboard.getString(
Blackboard.Keys.FML_GET_REPARSEABLE_COREMODS, MixinPlatformAgentFML.GET_REPARSEABLE_COREMODS_METHOD));
Method mdGetReparsedCoremods = this.clCoreModManager.getDeclaredMethod(GlobalProperties.getString(
GlobalProperties.Keys.FML_GET_REPARSEABLE_COREMODS, MixinPlatformAgentFML.GET_REPARSEABLE_COREMODS_METHOD));
@SuppressWarnings("unchecked")
List<String> reparsedCoremods = (List<String>)mdGetReparsedCoremods.invoke(null);
if (!reparsedCoremods.contains(this.fileName)) {
Expand All @@ -212,8 +212,8 @@ private ITweaker injectCorePlugin() throws NoSuchMethodException, IllegalAccessE
}

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);
Method mdLoadCoreMod = this.clCoreModManager.getDeclaredMethod(GlobalProperties.getString(GlobalProperties.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) {
Expand All @@ -237,7 +237,7 @@ private boolean isAlreadyInjected(String coreModName) {

// Was it already loaded, check the tweakers list
try {
List<ITweaker> tweakers = Blackboard.<List<ITweaker>>get(Blackboard.Keys.TWEAKS);
List<ITweaker> tweakers = GlobalProperties.<List<ITweaker>>get(GlobalProperties.Keys.TWEAKS);
if (tweakers == null) {
return false;
}
Expand Down Expand Up @@ -347,7 +347,7 @@ protected final boolean checkForCoInitialisation() {
* @return true if a tweaker with the specified name is queued
*/
private static boolean isTweakerQueued(String tweakerName) {
for (String tweaker : Blackboard.<List<String>>get(Blackboard.Keys.TWEAKCLASSES)) {
for (String tweaker : GlobalProperties.<List<String>>get(GlobalProperties.Keys.TWEAKCLASSES)) {
if (tweaker.endsWith(tweakerName)) {
return true;
}
Expand All @@ -361,8 +361,8 @@ private static boolean isTweakerQueued(String tweakerName) {
*/
private static Class<?> getCoreModManagerClass() throws ClassNotFoundException {
try {
return Class.forName(Blackboard.getString(
Blackboard.Keys.FML_CORE_MOD_MANAGER, MixinPlatformAgentFML.CORE_MOD_MANAGER_CLASS));
return Class.forName(GlobalProperties.getString(
GlobalProperties.Keys.FML_CORE_MOD_MANAGER, MixinPlatformAgentFML.CORE_MOD_MANAGER_CLASS));
} catch (ClassNotFoundException ex) {
return Class.forName(MixinPlatformAgentFML.CORE_MOD_MANAGER_CLASS_LEGACY);
}
Expand All @@ -373,8 +373,8 @@ private static List<String> getIgnoredMods(Class<?> clCoreModManager) throws Ill
Method mdGetIgnoredMods = null;

try {
mdGetIgnoredMods = clCoreModManager.getDeclaredMethod(Blackboard.getString(
Blackboard.Keys.FML_GET_IGNORED_MODS, MixinPlatformAgentFML.GET_IGNORED_MODS_METHOD));
mdGetIgnoredMods = clCoreModManager.getDeclaredMethod(GlobalProperties.getString(
GlobalProperties.Keys.FML_GET_IGNORED_MODS, MixinPlatformAgentFML.GET_IGNORED_MODS_METHOD));
} catch (NoSuchMethodException ex1) {
try {
// Legacy name
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* 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.mojang;

import org.spongepowered.asm.service.IGlobalPropertyService;

import net.minecraft.launchwrapper.Launch;

/**
* Global property service backed by LaunchWrapper blackboard
*/
public class Blackboard implements IGlobalPropertyService {

/**
* Get a value from the blackboard and duck-type it to the specified type
*
* @param key blackboard key
* @return value
* @param <T> duck type
*/
@Override
@SuppressWarnings("unchecked")
public final <T> T getProperty(String key) {
return (T)Launch.blackboard.get(key);
}

/**
* Put the specified value onto the blackboard
*
* @param key blackboard key
* @param value new value
*/
@Override
public final void setProperty(String key, Object value) {
Launch.blackboard.put(key, value);
}

/**
* Get the value from the 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
* @return value from blackboard or default value
* @param <T> duck type
*/
@Override
@SuppressWarnings("unchecked")
public final <T> T getProperty(String key, T defaultValue) {
Object value = Launch.blackboard.get(key);
return value != null ? (T)value : defaultValue;
}

/**
* Get a string from the 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
*/
@Override
public final String getPropertyString(String key, String defaultValue) {
Object value = Launch.blackboard.get(key);
return value != null ? value.toString() : defaultValue;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

import java.lang.reflect.Field;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

Expand All @@ -39,25 +37,20 @@
* them to perform some validation tasks, and insert entries for mixin "classes"
* into the invalid classes set.
*/
public final class LaunchClassLoaderUtil {
final class LaunchClassLoaderUtil {

private static final String CACHED_CLASSES_FIELD = "cachedClasses";
private static final String INVALID_CLASSES_FIELD = "invalidClasses";
private static final String CLASS_LOADER_EXCEPTIONS_FIELD = "classLoaderExceptions";
private static final String TRANSFORMER_EXCEPTIONS_FIELD = "transformerExceptions";

/**
* ClassLoader -> util mapping
*/
private static final Map<LaunchClassLoader, LaunchClassLoaderUtil> utils = new HashMap<LaunchClassLoader, LaunchClassLoaderUtil>();

/**
* ClassLoader for this util
*/
private final LaunchClassLoader classLoader;

// Reflected fields
private Map<String, Class<?>> cachedClasses;
private final Map<String, Class<?>> cachedClasses;
private final Set<String> invalidClasses;
private final Set<String> classLoaderExceptions;
private final Set<String> transformerExceptions;
Expand All @@ -67,7 +60,7 @@ public final class LaunchClassLoaderUtil {
*
* @param classLoader class loader
*/
private LaunchClassLoaderUtil(LaunchClassLoader classLoader) {
LaunchClassLoaderUtil(LaunchClassLoader classLoader) {
this.classLoader = classLoader;
this.cachedClasses = LaunchClassLoaderUtil.<Map<String, Class<?>>>getField(classLoader, LaunchClassLoaderUtil.CACHED_CLASSES_FIELD);
this.invalidClasses = LaunchClassLoaderUtil.<Set<String>>getField(classLoader, LaunchClassLoaderUtil.INVALID_CLASSES_FIELD);
Expand All @@ -78,43 +71,19 @@ private LaunchClassLoaderUtil(LaunchClassLoader classLoader) {
/**
* Get the classloader
*/
public LaunchClassLoader getClassLoader() {
LaunchClassLoader getClassLoader() {
return this.classLoader;
}

/**
* Get all loaded class names from the cache
*/
public Set<String> getLoadedClasses() {
return this.getLoadedClasses(null);
}

/**
* Get the names of loaded classes from the cache, filter using the supplied
* filter string
*
* @param filter filter string or null
* @return set of class names
*/
public Set<String> getLoadedClasses(String filter) {
Set<String> loadedClasses = new HashSet<String>();
for (String className : this.cachedClasses.keySet()) {
if (filter == null || className.startsWith(filter)) {
loadedClasses.add(className);
}
}
return loadedClasses;
}

/**
* Get whether a class name exists in the cache (indicating it was loaded
* via the inner loader
*
* @param name class name
* @return true if the class name exists in the cache
*/
public boolean isClassLoaded(String name) {
return this.cachedClasses != null && this.cachedClasses.containsKey(name);
boolean isClassLoaded(String name) {
return this.cachedClasses.containsKey(name);
}

/**
Expand All @@ -125,7 +94,7 @@ public boolean isClassLoaded(String name) {
* @param transformedName transformed class name
* @return true if either exclusion list contains either of the names
*/
public boolean isClassExcluded(String name, String transformedName) {
boolean isClassExcluded(String name, String transformedName) {
for (final String exception : this.getClassLoaderExceptions()) {
if (transformedName.startsWith(exception) || name.startsWith(exception)) {
return true;
Expand All @@ -148,7 +117,7 @@ public boolean isClassExcluded(String name, String transformedName) {
*
* @param name class name
*/
public void registerInvalidClass(String name) {
void registerInvalidClass(String name) {
if (this.invalidClasses != null) {
this.invalidClasses.add(name);
}
Expand All @@ -157,7 +126,7 @@ public void registerInvalidClass(String name) {
/**
* Get the classloader exclusions from the target classloader
*/
public Set<String> getClassLoaderExceptions() {
Set<String> getClassLoaderExceptions() {
if (this.classLoaderExceptions != null) {
return this.classLoaderExceptions;
}
Expand All @@ -167,7 +136,7 @@ public Set<String> getClassLoaderExceptions() {
/**
* Get the transformer exclusions from the target classloader
*/
public Set<String> getTransformerExceptions() {
Set<String> getTransformerExceptions() {
if (this.transformerExceptions != null) {
return this.transformerExceptions;
}
Expand All @@ -186,19 +155,4 @@ private static <T> T getField(LaunchClassLoader classLoader, String fieldName) {
return null;
}

/**
* Get the utility class for the supplied classloader
*
* @param classLoader classLoader to fetch utility wrapper for
* @return utility wrapper
*/
public static LaunchClassLoaderUtil forClassLoader(LaunchClassLoader classLoader) {
LaunchClassLoaderUtil util = LaunchClassLoaderUtil.utils.get(classLoader);
if (util == null) {
util = new LaunchClassLoaderUtil(classLoader);
LaunchClassLoaderUtil.utils.put(classLoader, util);
}
return util;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
* A handle for a legacy {@link IClassTransformer} for processing as a legacy
* transformer
*/
public class LegacyTransformerHandle implements ILegacyClassTransformer {
class LegacyTransformerHandle implements ILegacyClassTransformer {

/**
* Wrapped transformer
*/
private final IClassTransformer transformer;

public LegacyTransformerHandle(IClassTransformer transformer) {
LegacyTransformerHandle(IClassTransformer transformer) {
this.transformer = transformer;
}

Expand Down
Loading

0 comments on commit c218a4a

Please sign in to comment.