ClasspathModuleFinder 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: Classpath")) { final String[] nameAndSlot = identifier.split("\\:", 2); final String path = "modules/" + nameAndSlot[0].replace('.', MODULE_SEPARATOR) + MODULE_SEPARATOR + nameAndSlot[1] + "/module.xml"; if (LOG.isTraceEnabled()) { LOG.trace("attempt:" + identifier); } try { ClassLoader cl = ApplicationEnvironment.get().getBootstrapClassLoader(); if (LOG.isTraceEnabled()) { LOG.trace("classloader: " + cl); LOG.trace("path: " + path); } URL url = findResourceInClassLoader(cl, path); if (url == null && cl != ClasspathModuleFinder.class.getClassLoader()) { url = findResourceInClassLoader(ClasspathModuleFinder.class.getClassLoader(), path); } if (url == null) { if (LOG.isTraceEnabled()) { LOG.trace("not found: " + identifier); } return null; } final URL base = new URL(url, "./"); if (LOG.isTraceEnabled()) { LOG.trace("base of " + identifier + ": " + base); } InputStream in = url.openStream(); Path explodedJar = NestedJarResourceLoader.explodedJar(base); ModuleSpec moduleSpec = null; try { 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(), (explodedJar == null ? "/" : explodedJar.toAbsolutePath().toString()), in, path, delegateLoader, simpleIdentifier); } catch (IOException e) { throw new ModuleLoadException(e); } finally { try { in.close(); } catch (IOException e) { throw new ModuleLoadException(e); } } if (LOG.isTraceEnabled()) { LOG.trace("Loaded ModuleSpec: " + moduleSpec.getName()); } return moduleSpec; } catch (IOException e) { throw new ModuleLoadException(e); } } catch (Exception e) { throw new RuntimeException(e); } }  String toString(); @Override ModuleSpec findModule(String identifier, ModuleLoader delegateLoader);  }
@Test public void testMain() { ClasspathModuleFinder finder = new ClasspathModuleFinder(); try { ModuleSpec spec = finder.findModule("classpath.module.load.test", null); assertNotNull(spec); } catch (ModuleLoadException e) { fail(); } }
@Test public void testMissingMain() { ClasspathModuleFinder finder = new ClasspathModuleFinder(); try { ModuleSpec spec = finder.findModule("classpath.module.load.test.missing", null); assertNull(spec); } catch (ModuleLoadException e) { fail(); } }
@Test public void testSlot() { ClasspathModuleFinder finder = new ClasspathModuleFinder(); try { ModuleSpec spec = finder.findModule("classpath.module.load.test:1.0.0.Final", null); assertNotNull(spec); } catch (ModuleLoadException e) { fail(); } }
@Test public void testMissingSlot() { ClasspathModuleFinder finder = new ClasspathModuleFinder(); try { ModuleSpec spec = finder.findModule("classpath.module.load.test:missing", null); assertNull(spec); } catch (ModuleLoadException e) { fail(); } }