try {
while (!expectedBundles.isEmpty()) {
AbstractInfo entry = source.getNextEntry();
if (entry == null) {
throw new DeploymentException(CODE_OTHER_ERROR, "Expected more bundles in the stream: " + expectedBundles.keySet());
}
String name = entry.getPath();
BundleInfoImpl bundleInfo = (BundleInfoImpl) expectedBundles.remove(name);
if (bundleInfo == null) {
throw new DeploymentException(CODE_OTHER_ERROR, "Resource '" + name + "' is not described in the manifest.");
}
String bsn = bundleInfo.getSymbolicName();
Version sourceVersion = bundleInfo.getVersion();
Bundle bundle = targetPackage.getBundle(bsn);
try {
if (bundle == null) {
// new bundle, install it
bundle = context.installBundle(BUNDLE_LOCATION_PREFIX + bsn, new BundleInputStream(source.getCurrentEntryStream()));
addRollback(new UninstallBundleRunnable(bundle, log));
}
else {
// existing bundle, update it
Version currentVersion = getVersion(bundle);
if (!sourceVersion.equals(currentVersion)) {
bundle.update(new BundleInputStream(source.getCurrentEntryStream()));
addRollback(new UpdateBundleRunnable(bundle, targetPackage, log));
}
}
}
catch (Exception be) {
if (isCancelled()) {
return;
}
throw new DeploymentException(CODE_OTHER_ERROR, "Could not install new bundle '" + name + "' (" + bsn + ")", be);
}
if (!bundle.getSymbolicName().equals(bsn)) {
throw new DeploymentException(CODE_BUNDLE_NAME_ERROR, "Installed/updated bundle symbolicname (" + bundle.getSymbolicName() + ") do not match what was installed/updated: " + bsn);
}
Version targetVersion = getVersion(bundle);
if (!sourceVersion.equals(targetVersion)) {
throw new DeploymentException(CODE_OTHER_ERROR, "Installed/updated bundle version (" + targetVersion + ") do not match what was installed/updated: " + sourceVersion
+ ", offending bundle = " + bsn);
}
}
}
catch (IOException e) {
throw new DeploymentException(CODE_OTHER_ERROR, "Problem while reading stream", e);
}
}