|
1 | 1 | package org.mangorage.bootstrap; |
2 | 2 |
|
| 3 | +import org.mangorage.bootstrap.internal.JarHandler; |
| 4 | +import org.mangorage.bootstrap.internal.MangoLoader; |
3 | 5 | import org.mangorage.bootstrap.internal.Util; |
4 | 6 |
|
5 | 7 | import java.io.IOException; |
| 8 | +import java.lang.module.Configuration; |
| 9 | +import java.lang.module.ModuleFinder; |
| 10 | +import java.nio.file.Files; |
6 | 11 | import java.nio.file.Path; |
7 | 12 | import java.util.List; |
8 | 13 |
|
|
11 | 16 | public final class Bootstrap { |
12 | 17 |
|
13 | 18 | public static void main(String[] args) throws IOException { |
14 | | - final var cfgOptional = Util.findBootConfig(Path.of("")); |
15 | 19 |
|
16 | | - if (!cfgOptional.isPresent()) { |
17 | | - throw new IllegalStateException("Failed to find any boot.cfg from the root folder/sub folders"); |
18 | | - } |
| 20 | + final var librariesPath = Path.of("libraries"); |
| 21 | + final var pluginsPath = Path.of("plugins"); |
19 | 22 |
|
20 | | - final var cfg = cfgOptional.get(); |
| 23 | + JarHandler.safeHandle(Path.of("libraries"), Path.of("sorted-libraries")); |
21 | 24 |
|
| 25 | + List<Path> deleteFiles = List.of( |
| 26 | + Path.of("sorted-libraries").resolve("okio-jvm-3.6.0.jar") |
| 27 | + ); |
22 | 28 |
|
23 | | - cfg.handleJars(); |
| 29 | + for (Path deleteFile : deleteFiles) { |
| 30 | + Files.deleteIfExists(deleteFile); |
| 31 | + } |
24 | 32 |
|
25 | | - final var moduleCfg = cfg.constructModuleConfiguration(); |
| 33 | + final var moduleCfg = Configuration.resolve( |
| 34 | + ModuleFinder.of(pluginsPath), |
| 35 | + List.of( |
| 36 | + ModuleLayer.boot().configuration() |
| 37 | + ), |
| 38 | + ModuleFinder.of( |
| 39 | + Path.of("sorted-libraries") |
| 40 | + ), |
| 41 | + Util.getModuleNames(pluginsPath) |
| 42 | + ); |
26 | 43 |
|
27 | | - final var cl = cfg.constructClassloaders(); |
28 | | - Thread.currentThread().setContextClassLoader(cl); |
| 44 | + final var moduleCl = new MangoLoader(fetchJars(librariesPath, pluginsPath), moduleCfg.modules(), Thread.currentThread().getContextClassLoader()); |
29 | 45 |
|
30 | | - final var moduleController = ModuleLayer.defineModules(moduleCfg, List.of(ModuleLayer.boot()), s -> { |
31 | | - if (s.startsWith("org.mangorage") & !s.contains("scanner")) { |
32 | | - return cl; |
33 | | - } else { |
34 | | - return cl.getParent(); |
35 | | - } |
36 | | - }); |
| 46 | + final var moduleLayerController = ModuleLayer.defineModules(moduleCfg, List.of(ModuleLayer.boot()), s -> moduleCl); |
| 47 | + final var moduleLayer = moduleLayerController.layer(); |
37 | 48 |
|
38 | 49 |
|
39 | | -// moduleControllaer.layer().modules().forEach(moduleControllaer::enableNativeAccess); |
| 50 | + System.out.println("Imagiine we worked!"); |
| 51 | + Thread.currentThread().setContextClassLoader(moduleCl); |
40 | 52 |
|
41 | | - callMain(cfg.getMainClass(), args, moduleController.layer().findModule("org.mangorage.mangobotcore").get()); |
| 53 | + callMain("org.mangorage.entrypoint.MangoBotCore", args, moduleLayer.findModule("org.mangorage.mangobotcore").get()); |
42 | 54 | } |
43 | 55 | } |
0 commit comments