Skip to content

Commit aaca412

Browse files
committed
moved launch target logic to its own system...
1 parent 65fa5e8 commit aaca412

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

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

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
import com.google.gson.Gson;
44
import org.mangorage.bootstrap.api.launch.ILaunchTarget;
55
import org.mangorage.bootstrap.internal.util.Util;
6+
67
import java.lang.module.Configuration;
78
import java.lang.module.ModuleFinder;
8-
import java.net.URL;
9-
import java.net.URLClassLoader;
109
import java.nio.file.Files;
1110
import java.nio.file.Path;
1211
import java.util.HashMap;
@@ -32,11 +31,17 @@ public static void main(String[] args) throws Throwable {
3231

3332
ModuleLayer parent = null;
3433

34+
if (Bootstrap.class.getModule() != null) {
35+
parent = Bootstrap.class.getModule().getLayer();
36+
}
37+
3538
if (parent == null)
3639
parent = ModuleLayer.boot();
3740

3841
// Where additional launch targets can be defined...
39-
final Path launchPath = Path.of("boot").toAbsolutePath();
42+
Path launchPath = Path.of(
43+
"launch"
44+
);
4045

4146
final var moduleCfg = Configuration
4247
.resolveAndBind(
@@ -48,9 +53,9 @@ public static void main(String[] args) throws Throwable {
4853
),
4954
ModuleFinder.of(),
5055
Files.exists(launchPath) ?
51-
Util.getModuleNames(
52-
launchPath
53-
) : Set.of()
56+
Util.getModuleNames(
57+
launchPath
58+
) : Set.of()
5459
);
5560

5661
final var moduleLayerController = ModuleLayer.defineModulesWithOneLoader(
@@ -59,27 +64,14 @@ public static void main(String[] args) throws Throwable {
5964
Thread.currentThread().getContextClassLoader()
6065
);
6166
final var moduleLayer = moduleLayerController.layer();
62-
final var moduleCL = new URLClassLoader(
63-
new URL[]{
64-
Path.of("boot/boot.jar").toUri().toURL()
65-
},
66-
Thread.currentThread().getContextClassLoader()
67-
);
68-
69-
moduleLayer.defineModulesWithOneLoader(moduleCfg, moduleCL);
70-
Thread.currentThread().setContextClassLoader(moduleCL);
7167

7268
final Map<String, ILaunchTarget> launchTargetMap = new HashMap<>();
7369

7470
ServiceLoader.load(moduleLayer, ILaunchTarget.class)
7571
.stream()
7672
.forEach(provider -> {
77-
try {
78-
final var target = provider.get();
79-
launchTargetMap.put(target.getId(), target);
80-
} catch (Exception e) {
81-
throw new IllegalStateException(e);
82-
}
73+
final var target = provider.get();
74+
launchTargetMap.put(target.getId(), target);
8375
});
8476

8577
if (!launchTargetMap.containsKey(launchTarget)) {
@@ -88,4 +80,4 @@ public static void main(String[] args) throws Throwable {
8880

8981
launchTargetMap.get(launchTarget).launch(moduleLayer, parent, args);
9082
}
91-
}
83+
}

0 commit comments

Comments
 (0)