Bundle bundle;
try {
String location = "resource://" + getRuntimeName(resource, false);
bundle = context.installBundle(location, content.getContent());
} catch (BundleException ex) {
throw new ProvisionException(ex);
}
// Start the bundle. This relies on provision ordering.
ThreadResourceAssociation.putResource(resource);
try {
bundle.start();
} catch (BundleException ex) {
// The start exception must be reported back to the client
// WildFly also relies on provision ordering.
throw new ProvisionException(ex);
} finally {
ThreadResourceAssociation.removeResource();
}
// Install the bundle as module if it has not already happened
// A bundle that could not get resolved will not have an associated module
Runtime runtime = RuntimeLocator.getRequiredRuntime();
Module module = runtime.getModule(identity);
BundleWiring wiring = bundle.adapt(BundleWiring.class);
if (module == null && wiring != null) {
try {
ClassLoader classLoader = wiring.getClassLoader();
module = runtime.installModule(classLoader, resource, null);
} catch (ModuleException ex) {
throw new ProvisionException(ex);
}
}
// Installing a bundle does not trigger a {@link ModuleEvent#INSTALLED}
// event because the Bundle's class loader is not (yet) available