Skip to content

Commit b23d99a

Browse files
committed
Fixed the class stuff
1 parent 5f67fac commit b23d99a

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/main/java/org/mangorage/bootstrap/Bootstrap.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.io.IOException;
66
import java.nio.file.Path;
7+
import java.util.List;
78

89
import static org.mangorage.bootstrap.internal.Util.*;
910

@@ -26,7 +27,14 @@ public static void main(String[] args) throws IOException {
2627
final var cl = cfg.constructClassloaders();
2728
Thread.currentThread().setContextClassLoader(cl);
2829

29-
final var moduleLayer = ModuleLayer.boot().defineModulesWithOneLoader(moduleCfg, cl);
30-
callMain(cfg.getMainClass(), args, cl, moduleLayer);
30+
final var moduleLayer = ModuleLayer.boot().defineModules(moduleCfg, s -> {
31+
if (s.startsWith("org.mangorage") & !s.contains("scanner")) {
32+
return cl;
33+
} else {
34+
return cl.getParent();
35+
}
36+
});
37+
38+
callMain(cfg.getMainClass(), args, cl);
3139
}
3240
}

src/main/java/org/mangorage/bootstrap/internal/Config.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public ClassLoader constructClassloaders() {
9494
}
9595

9696
String[] folderNames = classloaderPath.split(":");
97-
ClassLoader parentClassLoader = Thread.currentThread().getContextClassLoader().getParent();
97+
ClassLoader parentClassLoader = Thread.currentThread().getContextClassLoader();
9898
URLClassLoader currentClassLoader = null;
9999

100100
for (String folderName : folderNames) {
@@ -146,7 +146,7 @@ public Configuration constructModuleConfiguration() {
146146
.configuration()
147147
.resolveAndBind(
148148
moduleFinder,
149-
ModuleFinder.of(),
149+
ModuleFinder.ofSystem(),
150150
rootPaths.length != 0 ? Util.getModuleNames(rootPaths[0]) : Set.of()
151151
);
152152
} else {

src/main/java/org/mangorage/bootstrap/internal/Util.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ public static String getModuleName(File jarFile) {
8686
return null; // Jar was either not modular or you're just unlucky
8787
}
8888

89-
public static void callMain(String className, String[] args, ClassLoader classLoader, ModuleLayer moduleLayer) {
89+
public static void callMain(String className, String[] args, ClassLoader classLoader) {
9090
try {
91-
Class<?> clazz = Class.forName(moduleLayer.findModule("org.mangorage.mangobotcore").get(), className);
91+
Class<?> clazz = Class.forName(className, false, classLoader);
9292
Method mainMethod = clazz.getMethod("main", String[].class);
9393

9494
// Make sure it's static and public
@@ -98,7 +98,7 @@ public static void callMain(String className, String[] args, ClassLoader classLo
9898

9999
// Invoke the main method with a godawful cast
100100
mainMethod.invoke(null, (Object) args);
101-
} catch (Exception e) {
101+
} catch (Throwable e) {
102102
e.printStackTrace();
103103
throw new RuntimeException("Couldn't reflectively call main because something exploded.", e);
104104
}

0 commit comments

Comments
 (0)