Replace functionality for error handler that was nuked in mixin
*/
package org.spongepowered.mod.mixin.handler;
+import com.google.common.collect.ImmutableSet;
import net.minecraft.launchwrapper.Launch;
+import net.minecraft.launchwrapper.LaunchClassLoader;
import net.minecraftforge.common.ForgeVersion;
+import net.minecraftforge.fml.relauncher.ReflectionHelper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.mixin.extensibility.IMixinConfig;
import org.spongepowered.asm.util.throwables.ConstraintViolationException;
import org.spongepowered.launch.Main;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
/**
* Error handler for Sponge mixins
*/
@@ -71,7 +78,8 @@ private PrettyPrinter forgeVersionNotValid(Constraint constraint) {
.add()
.add(" * Use a version of Sponge for built for your version of Forge")
.add()
- .addWrapped(" The patch which failed requires Forge a build of %s but you are running build %d", constraint.getRangeHumanReadable(), ForgeVersion.getBuildVersion());
+ .addWrapped(" The patch which failed requires Forge a build of %s but you are running build %d",
+ constraint.getRangeHumanReadable(), ForgeVersion.getBuildVersion());
}
private PrettyPrinter patchConstraintFailed(Constraint constraint, ConstraintViolationException ex) {
@@ -101,13 +109,12 @@ private PrettyPrinter badCoreMod(MixinTargetAlreadyLoadedException ex) {
.kv("Class Name", ex.getTarget())
.add();
- // TODO: fix
- /*if (ex.getTarget().startsWith("net.minecraftforge")) {
+ if (ex.getTarget().startsWith("net.minecraftforge")) {
pp.hr('-').add().add("Loaded forge classes: ").add();
- for (String loadedClass : LaunchClassLoaderUtil.forClassLoader(Launch.classLoader).getLoadedClasses("net.minecraftforge")) {
+ for (String loadedClass : MixinErrorHandler.getLoadedClasses("net.minecraftforge")) {
pp.add(" %s", loadedClass);
}
- }*/
+ }
return pp;
}
@@ -122,7 +129,7 @@ private PrettyPrinter itsAllGoneHorriblyWrong() {
.add()
.hr('-')
.add()
- .add("A errpr was encountered whilst patching:")
+ .add("A error was encountered whilst patching:")
.add()
.add(" One or more Sponge patches could not be applied whilst loading Sponge, this is")
.add(" a permanent error and you must either:")
@@ -210,4 +217,30 @@ public PrettyPrinter getPrettyPrinter(Throwable th) {
}
return this.itsAllGoneHorriblyWrong();
}
+
+
+ /**
+ * 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
+ */
+ private static Set<String> getLoadedClasses(String filter) {
+ Map<String, Class<?>> cachedClasses = ReflectionHelper.<Map<String, Class<?>>, LaunchClassLoader>getPrivateValue(LaunchClassLoader.class,
+ Launch.classLoader, "cachedClasses");
+
+ if (cachedClasses == null) {
+ return ImmutableSet.<String>of("Unable to determine classloader state");
+ }
+
+ Set<String> loadedClasses = new HashSet<String>();
+ for (String className : cachedClasses.keySet()) {
+ if (filter == null || className.startsWith(filter)) {
+ loadedClasses.add(className);
+ }
+ }
+ return loadedClasses;
+ }
+
}
