InputStream content = resource.adapt(ResourceContent.class).getContent();
Bundle bundle;
try {
bundle = context.installBundle(identity.toString(), content);
} catch (BundleException ex) {
throw new ProvisionException(ex);
}
// Attempt to start the bundle. This relies on provision ordering.
ThreadResourceAssociation.putResource(resource);
try {
bundle.start();
} catch (BundleException ex) {
// ignore
} finally {
ThreadResourceAssociation.removeResource();
}
// Install the bundle as module if it has not already happened
// A bundle that could not get resolved will have no 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