in core/bootstrap/src/main/java/org/wildfly/swarm/bootstrap/modules/ClasspathModuleFinder.java [48:130]
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)) { // Maven artifact TODO is there a better way to recognize this?
return ResourceLoaders.createJarResourceLoader(loaderName,
JarFileManager.INSTANCE.getJarFile(new File(loaderPath)));
} else { // resource root
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);
}
}