From 8d4bef4d385f59e5d421055c81c62058e063b210 Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Sat, 16 Dec 2023 12:49:45 +0100 Subject: [PATCH] Add a test entrypoint. --- build.gradle | 2 +- .../mods/bootstraplauncher/BootstrapLauncher.java | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index c292bdf..10dd4ea 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ repositories { } dependencies { - implementation('cpw.mods:securejarhandler:2.1.2') + implementation('cpw.mods:securejarhandler:2.1.24') } java { diff --git a/src/main/java/cpw/mods/bootstraplauncher/BootstrapLauncher.java b/src/main/java/cpw/mods/bootstraplauncher/BootstrapLauncher.java index 0762557..6d96076 100644 --- a/src/main/java/cpw/mods/bootstraplauncher/BootstrapLauncher.java +++ b/src/main/java/cpw/mods/bootstraplauncher/BootstrapLauncher.java @@ -35,8 +35,16 @@ public class BootstrapLauncher { private static final boolean DEBUG = System.getProperties().containsKey("bsl.debug"); - @SuppressWarnings("unchecked") + public static void testMain(String... args) { + run(false, args); + } + public static void main(String... args) { + run(true, args); + } + + @SuppressWarnings("unchecked") + private static void run(boolean classloaderIsolation, String... args) { var legacyClasspath = loadLegacyClassPath(); // Ensure backwards compatibility if somebody reads this value later on. System.setProperty("legacyClassPath", String.join(File.pathSeparator, legacyClasspath)); @@ -126,9 +134,11 @@ public static void main(String... args) { // And the list of root modules for this configuration (that is, the modules that 'belong' to the configuration) are // the above modules from the SecureJars var bootstrapConfiguration = bootModuleConfiguration.resolveAndBind(jarModuleFinder, ModuleFinder.ofSystem(), allTargets); + // If the classloading should be isolated, we do not configure a parent loader, otherwise we use the context CL + ClassLoader parentLoader = classloaderIsolation ? null : Thread.currentThread().getContextClassLoader(); // Creates the module class loader, which does the loading of classes and resources from the bootstrap module layer/configuration, // falling back to the boot layer if not in the bootstrap layer - var moduleClassLoader = new ModuleClassLoader("MC-BOOTSTRAP", bootstrapConfiguration, List.of(ModuleLayer.boot())); + var moduleClassLoader = new ModuleClassLoader("MC-BOOTSTRAP", bootstrapConfiguration, List.of(ModuleLayer.boot()), parentLoader); // Actually create the module layer, using the bootstrap configuration above, the boot layer as the parent layer (as configured), // and mapping all modules to the module class loader var layer = ModuleLayer.defineModules(bootstrapConfiguration, List.of(ModuleLayer.boot()), m -> moduleClassLoader);