BootstrapClasspathModuleFinder implements ModuleFinder { @Override public ModuleSpec findModule(String identifier, ModuleLoader delegateLoader) throws ModuleLoadException { String simpleIdentifier = identifier; if (!identifier.contains(":")) { identifier = identifier + ":main"; } try (AutoCloseable handle = Performance.accumulate("module: BootstrapClassPath")) { final String[] nameAndSlot = identifier.split("\\:", 2); final String path = "modules/" + nameAndSlot[0].replace('.', MODULE_SEPARATOR) + MODULE_SEPARATOR + nameAndSlot[1] + "/module.xml"; ClassLoader cl = BootstrapClasspathModuleFinder.class.getClassLoader(); URL url = cl.getResource(path); if (url == null) { return null; } ModuleSpec moduleSpec = null; InputStream in = null; try { final URL base = new URL(url, "./"); in = url.openStream(); moduleSpec = ModuleXmlParser.parseModuleXml( (rootPath, loaderPath, loaderName) -> { if ("".equals(rootPath)) { return ResourceLoaders.createJarResourceLoader(loaderName, JarFileManager.INSTANCE.getJarFile(new File(loaderPath))); } else { return NestedJarResourceLoader.loaderFor(base, rootPath, loaderPath, loaderName); } }, MavenResolvers.get(), "/", in, path, delegateLoader, simpleIdentifier); } catch (IOException e) { throw new ModuleLoadException(e); } catch (Throwable t) { throw t; } finally { try { if (in != null) { in.close(); } } catch (IOException e) { throw new ModuleLoadException(e); } } return moduleSpec; } catch (Exception e) { throw new RuntimeException(e); } }  String toString(); @Override ModuleSpec findModule(String identifier, ModuleLoader delegateLoader);  }
@Test public void testMain() { BootstrapClasspathModuleFinder finder = new BootstrapClasspathModuleFinder(); try { ModuleSpec spec = finder.findModule("classpath.module.load.test", null); assertNotNull(spec); } catch (ModuleLoadException e) { fail(); } }
@Test public void testMissingMain() { BootstrapClasspathModuleFinder finder = new BootstrapClasspathModuleFinder(); try { ModuleSpec spec = finder.findModule("classpath.module.load.test.missing", null); assertNull(spec); } catch (ModuleLoadException e) { fail(); } }
@Test public void testSlot() { BootstrapClasspathModuleFinder finder = new BootstrapClasspathModuleFinder(); try { ModuleSpec spec = finder.findModule("classpath.module.load.test:1.0.0.Final", null); assertNotNull(spec); } catch (ModuleLoadException e) { fail(); } }
@Test public void testMissingSlot() { BootstrapClasspathModuleFinder finder = new BootstrapClasspathModuleFinder(); try { ModuleSpec spec = finder.findModule("classpath.module.load.test:missing", null); assertNull(spec); } catch (ModuleLoadException e) { fail(); } }