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