add found mods to classloader
This commit is contained in:
parent
5f8ed35231
commit
0b55824be0
|
@ -1,9 +1,10 @@
|
|||
plugins {
|
||||
id("java")
|
||||
java
|
||||
id("io.freefair.lombok").version("8.+")
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
group = "org.example"
|
||||
group = "org.ecorous.esnesnon"
|
||||
version = "0.0.1-SNAPSHOT"
|
||||
|
||||
repositories {
|
||||
|
@ -29,4 +30,32 @@ dependencies {
|
|||
}
|
||||
|
||||
tasks.test {
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("mavenJava") {
|
||||
from(components["java"])
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
name = "EsnesnonSnapshotsMaven"
|
||||
url = uri("https://maven-esnesnon.ecorous.org/snapshots")
|
||||
credentials(PasswordCredentials::class)
|
||||
authentication {
|
||||
create<BasicAuthentication>("basic")
|
||||
}
|
||||
}
|
||||
|
||||
maven {
|
||||
name = "EsnesnonReleasesMaven"
|
||||
url = uri("https://maven-esnesnon.ecorous.org/releases")
|
||||
credentials(PasswordCredentials::class)
|
||||
authentication {
|
||||
create<BasicAuthentication>("basic")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -37,7 +37,7 @@ public class Launcher {
|
|||
private final Env env;
|
||||
|
||||
public static void run(String[] args, Env env) {
|
||||
Configurator.setRootLevel(Level.INFO); // TODO replace with actual log4j config
|
||||
//Configurator.setRootLevel(Level.INFO); // TODO replace with actual log4j config
|
||||
new Launcher(args, env);
|
||||
}
|
||||
|
||||
|
@ -58,14 +58,15 @@ public class Launcher {
|
|||
}).toArray(URL[]::new), this.getClass().getClassLoader());
|
||||
|
||||
Thread.currentThread().setContextClassLoader(targetClassLoader);
|
||||
|
||||
System.setProperty("mixin.service", NonsenseMixinService.class.getName());
|
||||
MixinBootstrap.init();
|
||||
|
||||
try {
|
||||
MethodHandle ctor = MethodHandles.publicLookup().findStatic(targetClassLoader.loadClass(LoaderImpl.class.getName()), "run", MethodType.methodType(void.class, String[].class, Env.class));
|
||||
ctor.invoke(args, env);
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
System.setProperty("mixin.service", NonsenseMixinService.class.getName());
|
||||
MixinBootstrap.init();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ import io.github.moehreag.nonsense.loader.impl.plugin.NonsensePlugin;
|
|||
import lombok.Getter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.slf4j.event.Level;
|
||||
|
||||
public class LoaderImpl implements Loader {
|
||||
|
||||
|
@ -38,9 +37,12 @@ public class LoaderImpl implements Loader {
|
|||
@Getter
|
||||
private final Path gameDir, configDir, modsDir;
|
||||
|
||||
@Getter
|
||||
private final MixinClassloader classloader;
|
||||
|
||||
private LoaderImpl(String[] args, Env env) {
|
||||
instance = this;
|
||||
System.out.println("info logging: "+ LOGGER.isEnabledForLevel(Level.INFO));
|
||||
this.classloader = (MixinClassloader) this.getClass().getClassLoader();
|
||||
this.args = args;
|
||||
this.env = env;
|
||||
|
||||
|
|
|
@ -10,6 +10,10 @@ public class MixinClassloader extends URLClassLoader {
|
|||
super(urls, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addURL(URL url) {
|
||||
super.addURL(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> findClass(String name) throws ClassNotFoundException {
|
||||
|
|
|
@ -138,7 +138,7 @@ public class NonsenseMixinService implements IMixinService, IClassProvider, ICla
|
|||
|
||||
|
||||
@Override
|
||||
public ClassNode getClassNode(String name) throws ClassNotFoundException, IOException {
|
||||
public ClassNode getClassNode(String name) throws IOException {
|
||||
return getClassNode(name, true);
|
||||
}
|
||||
|
||||
|
@ -158,6 +158,7 @@ public class NonsenseMixinService implements IMixinService, IClassProvider, ICla
|
|||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public URL[] getClassPath() {
|
||||
return new URL[0];
|
||||
}
|
||||
|
|
|
@ -9,6 +9,10 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.net.MalformedURLException;
|
||||
import java.nio.file.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -43,6 +47,15 @@ public class Minecraft implements NonsensePlugin {
|
|||
mods.addAll(Discovery.find(loader.getModsDir(), path ->
|
||||
version.equals(path.getFileName().toString()), path ->
|
||||
path.getFileName().toString().endsWith(LoaderImpl.MOD_FILE_EXTENSION)));
|
||||
// TODO add mods found on the classpath
|
||||
mods.stream().map(Path::toUri).map(uri -> {
|
||||
try {
|
||||
return uri.toURL();
|
||||
} catch (MalformedURLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}).forEach(LoaderImpl.getInstance().getClassloader()::addURL);
|
||||
LOGGER.info("Found {} mods", mods.size());
|
||||
|
||||
if (!Files.exists(remappedGamePath)){
|
||||
Path gameJar = findGame();
|
||||
|
@ -59,6 +72,7 @@ public class Minecraft implements NonsensePlugin {
|
|||
}
|
||||
|
||||
private Path findGame() {
|
||||
LOGGER.info("Locating game..");
|
||||
for (String s : System.getProperty("java.class.path", "").split(File.pathSeparator)) {
|
||||
Path p = Paths.get(s);
|
||||
if (!Files.exists(p) || Files.isDirectory(p)){
|
||||
|
@ -83,10 +97,12 @@ public class Minecraft implements NonsensePlugin {
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
LOGGER.info("Launching main class: {}", foundMainClass);
|
||||
//Class<?> mainClass = Class.forName(foundMainClass);
|
||||
//MethodHandle main = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class));
|
||||
//main.invoke((Object)LoaderImpl.getInstance().getArgs());
|
||||
if (foundMainClass != null) {
|
||||
LOGGER.info("Launching main class: {}", foundMainClass);
|
||||
Class<?> mainClass = Class.forName(foundMainClass);
|
||||
MethodHandle main = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class));
|
||||
main.invoke((Object) LoaderImpl.getInstance().getArgs());
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
|
|
Loading…
Reference in a new issue