private Module createFrameworkModule(final Bundle systemBundle) {
// Setup the extended framework module spec
Module systemModule = injectedSystemModule.getValue();
ModuleIdentifier systemIdentifier = systemModule.getIdentifier();
ModuleLoader systemLoader = systemModule.getModuleLoader();
ModuleSpec.Builder specBuilder = ModuleSpec.build(ModuleIdentifier.create(JBOSGI_PREFIX + ".framework"));
PathFilter acceptAll = PathFilters.acceptAll();
specBuilder.addDependency(DependencySpec.createModuleDependencySpec(acceptAll, acceptAll, systemLoader, systemIdentifier, false));
// Add a dependency on the default framework module
ModuleLoader bootLoader = Module.getBootModuleLoader();
ModuleIdentifier frameworkIdentifier = ModuleIdentifier.create("org.jboss.osgi.framework");
specBuilder.addDependency(DependencySpec.createModuleDependencySpec(acceptAll, acceptAll, bootLoader, frameworkIdentifier, false));
// Add the user defined module dependencies
String modulesProps = (String) injectedSubsystemState.getValue().getProperties().get(PROP_JBOSS_OSGI_SYSTEM_MODULES);
if (modulesProps != null) {
for (String moduleProp : modulesProps.split(",")) {
moduleProp = moduleProp.trim();
if (moduleProp.length() > 0) {
ModuleIdentifier moduleId = ModuleIdentifier.create(moduleProp);
DependencySpec moduleDep = DependencySpec.createModuleDependencySpec(acceptAll, acceptAll, bootLoader, moduleId, false);
specBuilder.addDependency(moduleDep);
}
}
}
specBuilder.setModuleClassLoaderFactory(new BundleReferenceClassLoader.Factory(systemBundle));
try {
final ModuleSpec moduleSpec = specBuilder.create();
ModuleLoader moduleLoader = new ModuleLoader() {
@Override
protected ModuleSpec findModule(ModuleIdentifier identifier) throws ModuleLoadException {
return (moduleSpec.getModuleIdentifier().equals(identifier) ? moduleSpec : null);
}
@Override
public String toString() {
return getClass().getSimpleName();
}
};
return moduleLoader.loadModule(specBuilder.getIdentifier());
} catch (ModuleLoadException ex) {
throw new IllegalStateException(ex);
}
}