use of org.jboss.modules.ModuleSpec in project jboss-modules by jboss-modules.
the class ModuleXmlParser method parseDocument.
private static ModuleSpec parseDocument(final MavenResolver mavenResolver, final ResourceRootFactory factory, final String rootPath, XmlPullParser reader, final ModuleLoader moduleLoader, final String moduleName) throws XmlPullParserException, IOException {
int eventType;
for (; ; ) {
eventType = reader.nextTag();
switch(eventType) {
case START_DOCUMENT:
{
return parseRootElement(mavenResolver, factory, rootPath, reader, moduleLoader, moduleName);
}
case START_TAG:
{
validateNamespace(reader);
final String element = reader.getName();
switch(element) {
case E_MODULE:
{
final ModuleSpec.Builder specBuilder = parseModuleContents(mavenResolver, reader, factory, moduleLoader, moduleName, rootPath);
parseEndDocument(reader);
return specBuilder.create();
}
case E_MODULE_ALIAS:
{
final ModuleSpec moduleSpec = parseModuleAliasContents(reader, moduleName);
parseEndDocument(reader);
return moduleSpec;
}
case E_MODULE_ABSENT:
{
parseModuleAbsentContents(reader, moduleName);
return null;
}
default:
{
throw unexpectedContent(reader);
}
}
}
default:
{
throw unexpectedContent(reader);
}
}
}
}
use of org.jboss.modules.ModuleSpec in project jboss-modules by jboss-modules.
the class ModuleXmlParser method parseRootElement.
private static ModuleSpec parseRootElement(final MavenResolver mavenResolver, final ResourceRootFactory factory, final String rootPath, final XmlPullParser reader, final ModuleLoader moduleLoader, final String moduleName) throws XmlPullParserException, IOException {
assertNoAttributes(reader);
int eventType;
while ((eventType = reader.nextTag()) != END_DOCUMENT) {
switch(eventType) {
case START_TAG:
{
validateNamespace(reader);
final String element = reader.getName();
switch(element) {
case E_MODULE:
{
final ModuleSpec.Builder specBuilder = parseModuleContents(mavenResolver, reader, factory, moduleLoader, moduleName, rootPath);
parseEndDocument(reader);
return specBuilder.create();
}
case E_MODULE_ALIAS:
{
final ModuleSpec moduleSpec = parseModuleAliasContents(reader, moduleName);
parseEndDocument(reader);
return moduleSpec;
}
case E_MODULE_ABSENT:
{
parseModuleAbsentContents(reader, moduleName);
return null;
}
default:
{
throw unexpectedContent(reader);
}
}
}
default:
{
throw unexpectedContent(reader);
}
}
}
throw endOfDocument(reader);
}
use of org.jboss.modules.ModuleSpec in project pentaho-platform by pentaho.
the class SystemPackageExtrapolatorTest method testJBossProvider.
@Test
public void testJBossProvider() {
SystemPackageExtrapolator.JBossModulePackageProvider jBossModulePackageProvider = new SystemPackageExtrapolator.JBossModulePackageProvider();
Set<String> packages = jBossModulePackageProvider.getPackages();
assertThat(packages, is(empty()));
ModuleIdentifier moduleIdentifier = ModuleIdentifier.create("org.pentaho.test.module");
ModuleSpec.Builder builder = ModuleSpec.build(moduleIdentifier);
builder.addDependency(DependencySpec.createSystemDependencySpec(new HashSet<String>(Arrays.asList("org.apache", "org.apache.log4j"))));
final ModuleSpec moduleSpec = builder.create();
ModuleLoader loader = new ModuleLoader(new ModuleFinder[] { new ModuleFinder() {
@Override
public ModuleSpec findModule(ModuleIdentifier moduleIdentifier, ModuleLoader moduleLoader) throws ModuleLoadException {
return moduleSpec;
}
} });
try {
Module module = loader.loadModule(moduleIdentifier);
jBossModulePackageProvider.setModule(module);
} catch (ModuleLoadException e) {
e.printStackTrace();
}
packages = jBossModulePackageProvider.getPackages();
assertThat(packages, contains("org.apache.log4j", "org.apache"));
assertThat(packages, not(contains("org.not.there")));
}
use of org.jboss.modules.ModuleSpec in project wildfly-swarm by wildfly-swarm.
the class BootstrapClasspathModuleFinder 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: 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) -> NestedJarResourceLoader.loaderFor(base, rootPath, loaderPath, loaderName), MavenResolvers.get(), "/", in, path.toString(), 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);
}
}
use of org.jboss.modules.ModuleSpec in project wildfly-swarm by wildfly-swarm.
the class BootstrapClasspathModuleFinderTest method testSlot.
@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();
}
}
Aggregations