use of org.jboss.modules.ModuleSpec in project wildfly-swarm by wildfly-swarm.
the class BootstrapClasspathModuleFinderTest method testMissingSlot.
@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();
}
}
use of org.jboss.modules.ModuleSpec in project wildfly-swarm by wildfly-swarm.
the class ClasspathModuleFinderTest method testMain.
@Test
public void testMain() {
ClasspathModuleFinder finder = new ClasspathModuleFinder();
try {
ModuleSpec spec = finder.findModule("classpath.module.load.test", null);
assertNotNull(spec);
} catch (ModuleLoadException e) {
fail();
}
}
use of org.jboss.modules.ModuleSpec in project wildfly-swarm by wildfly-swarm.
the class ClasspathModuleFinderTest method testMissingMain.
@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();
}
}
use of org.jboss.modules.ModuleSpec in project wildfly-swarm by wildfly-swarm.
the class ClasspathModuleFinderTest method testSlot.
@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();
}
}
use of org.jboss.modules.ModuleSpec in project wildfly-swarm by wildfly-swarm.
the class ClasspathModuleFinder method findModule.
@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 = cl.getResource(path);
if (url == null && cl != ClasspathModuleFinder.class.getClassLoader()) {
url = ClasspathModuleFinder.class.getClassLoader().getResource(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) -> NestedJarResourceLoader.loaderFor(base, rootPath, loaderPath, loaderName), MavenResolvers.get(), (explodedJar == null ? "/" : explodedJar.toAbsolutePath().toString()), in, path.toString(), 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);
}
}
Aggregations