class loading seems to work again like this
This commit is contained in:
parent
0b55824be0
commit
8a75f71ab4
|
@ -16,8 +16,6 @@ import java.util.Map;
|
||||||
|
|
||||||
import io.github.moehreag.nonsense.loader.impl.mixin.NonsenseMixinService;
|
import io.github.moehreag.nonsense.loader.impl.mixin.NonsenseMixinService;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.apache.logging.log4j.Level;
|
|
||||||
import org.apache.logging.log4j.core.config.Configurator;
|
|
||||||
import org.spongepowered.asm.launch.MixinBootstrap;
|
import org.spongepowered.asm.launch.MixinBootstrap;
|
||||||
import org.spongepowered.asm.service.IPropertyKey;
|
import org.spongepowered.asm.service.IPropertyKey;
|
||||||
|
|
||||||
|
@ -37,7 +35,6 @@ public class Launcher {
|
||||||
private final Env env;
|
private final Env env;
|
||||||
|
|
||||||
public static void run(String[] args, Env env) {
|
public static void run(String[] args, Env env) {
|
||||||
//Configurator.setRootLevel(Level.INFO); // TODO replace with actual log4j config
|
|
||||||
new Launcher(args, env);
|
new Launcher(args, env);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,9 +60,11 @@ public class Launcher {
|
||||||
MixinBootstrap.init();
|
MixinBootstrap.init();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MethodHandle ctor = MethodHandles.publicLookup().findStatic(targetClassLoader.loadClass(LoaderImpl.class.getName()), "run", MethodType.methodType(void.class, String[].class, Env.class));
|
Class<?> clazz = targetClassLoader.findClass("io.github.moehreag.nonsense.loader.impl.LoaderImpl");
|
||||||
|
MethodHandle ctor = MethodHandles.publicLookup().findStatic(clazz, "run", MethodType.methodType(void.class, String[].class, Env.class));
|
||||||
ctor.invoke(args, env);
|
ctor.invoke(args, env);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
// TODO
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ public class LoaderImpl implements Loader {
|
||||||
|
|
||||||
classes.stream().map((String className) -> {
|
classes.stream().map((String className) -> {
|
||||||
try {
|
try {
|
||||||
return Class.forName(className);
|
return classloader.findClass(className);
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
// TODO error handling
|
// TODO error handling
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|
|
@ -15,15 +15,15 @@ public class MixinClassloader extends URLClassLoader {
|
||||||
super.addURL(url);
|
super.addURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isClassLoaded(String name){
|
||||||
|
return findLoadedClass(name) != null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<?> findClass(String name) throws ClassNotFoundException {
|
public Class<?> findClass(String name) throws ClassNotFoundException {
|
||||||
return super.findClass(name);
|
return super.findClass(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isClassLoaded(String name){
|
|
||||||
return findLoadedClass(name) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getClassBytes(String name) throws IOException {
|
public byte[] getClassBytes(String name) throws IOException {
|
||||||
String binName = name.replace(".", "/");
|
String binName = name.replace(".", "/");
|
||||||
String path = binName.concat(".class");
|
String path = binName.concat(".class");
|
||||||
|
@ -34,4 +34,5 @@ public class MixinClassloader extends URLClassLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,18 +57,25 @@ public class Minecraft implements NonsensePlugin {
|
||||||
}).forEach(LoaderImpl.getInstance().getClassloader()::addURL);
|
}).forEach(LoaderImpl.getInstance().getClassloader()::addURL);
|
||||||
LOGGER.info("Found {} mods", mods.size());
|
LOGGER.info("Found {} mods", mods.size());
|
||||||
|
|
||||||
|
Path gameJar = findGame();
|
||||||
|
if (gameJar == null){
|
||||||
|
throw new IllegalStateException("Could not find game jar!");
|
||||||
|
}
|
||||||
if (!Files.exists(remappedGamePath)){
|
if (!Files.exists(remappedGamePath)){
|
||||||
Path gameJar = findGame();
|
|
||||||
if (gameJar == null){
|
|
||||||
throw new IllegalStateException("Could not find game jar!");
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
MojMapPatcher.run(version, gameJar, remappedGamePath);
|
MojMapPatcher.run(version, gameJar, remappedGamePath);
|
||||||
} catch (IOException e) {
|
} catch (Throwable e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
LoaderImpl.getInstance().getClassloader().addURL(remappedGamePath.toUri().toURL());
|
||||||
|
} catch (Throwable e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Path findGame() {
|
private Path findGame() {
|
||||||
|
@ -102,6 +109,8 @@ public class Minecraft implements NonsensePlugin {
|
||||||
Class<?> mainClass = Class.forName(foundMainClass);
|
Class<?> mainClass = Class.forName(foundMainClass);
|
||||||
MethodHandle main = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class));
|
MethodHandle main = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class));
|
||||||
main.invoke((Object) LoaderImpl.getInstance().getArgs());
|
main.invoke((Object) LoaderImpl.getInstance().getArgs());
|
||||||
|
} else {
|
||||||
|
LOGGER.warn("Failed to locate main class!");
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
Loading…
Reference in a new issue