targetBundle.update(fi);
} finally {
close(fi);
}
FrameworkWiring wiring = context.getBundle(0).adapt(FrameworkWiring.class);
Collection<Bundle> bundles = Arrays.asList(targetBundle);
// resolve the bundle
if (!wiring.resolveBundles(bundles)) {
StringBuilder builder = new StringBuilder();
builder.append("Updated ").append(bundleName).append(" bundle cannot be resolved.");
// check for resolver errors
ResolverErrorAnalyzer errorAnalyzer = new ResolverErrorAnalyzer(context);
String resolverErrors = errorAnalyzer.getErrorsAsString(bundles);
if (resolverErrors != null) {
builder.append(" ").append(resolverErrors);
}
throw new BundleException(builder.toString());
}
// log dependents
Collection<Bundle> dependents = wiring.getDependencyClosure(bundles);
dependents.removeAll(bundles);
if (!dependents.isEmpty()) {
String bundleListString = bundleCollectionToString(dependents);
LOG.info("Update of {} bundle will cause the following bundles to be refreshed: {}", bundleName, bundleListString);
}
// update application archive
try {
updateEBA(targetBundle, bundleFile);
} catch (Exception e) {
LOG.warn("Error updating application archive with the new contents. " +
"Changes made might be gone next time the application or server is restarted.", e.getMessage());
}
// refresh the bundle and its dependents
RefreshListener refreshListener = new RefreshListener();
wiring.refreshBundles(bundles, refreshListener);
refreshListener.waitForRefresh(bundleRefreshTimeout);
// start the bundle
if (BundleUtils.canStart(targetBundle)) {
targetBundle.start(Bundle.START_TRANSIENT);