Patch load(File file) throws IOException { FileInputStream is = new FileInputStream(file); try { PatchImpl patch = doLoad(this, is); File fr = new File(file.getParent(), file.getName() + ".result"); if (fr.isFile()) { patch.setResult(loadResult(patch, fr)); } return patch; } finally { close(is); } }
void rollback(Patch patch, boolean force) throws PatchException { Result result = patch.getResult(); if (result == null) { throw new PatchException("Patch " + patch.getId() + " is not installed"); } Bundle[] allBundles = bundleContext.getBundles(); List<BundleUpdate> badUpdates = new ArrayList<BundleUpdate>(); for (BundleUpdate update : result.getUpdates()) { boolean found = false; Version v = Version.parseVersion(update.getNewVersion()); for (Bundle bundle : allBundles) { if (stripSymbolicName(bundle.getSymbolicName()) .equals(stripSymbolicName(update.getSymbolicName())) && bundle.getVersion().equals(v)) { found = true; break; } } if (!found) { badUpdates.add(update); } } if (!badUpdates.isEmpty() && !force) { StringBuilder sb = new StringBuilder(); sb.append("Unable to rollback patch ") .append(patch.getId()) .append(" because of the following missing bundles:\n"); for (BundleUpdate up : badUpdates) { sb.append("\t") .append(up.getSymbolicName()) .append("/") .append(up.getNewVersion()) .append("\n"); } throw new PatchException(sb.toString()); } Map<Bundle, String> toUpdate = new HashMap<Bundle, String>(); for (BundleUpdate update : result.getUpdates()) { Version v = Version.parseVersion(update.getNewVersion()); for (Bundle bundle : allBundles) { if (stripSymbolicName(bundle.getSymbolicName()) .equals(stripSymbolicName(update.getSymbolicName())) && bundle.getVersion().equals(v)) { toUpdate.put(bundle, update.getPreviousLocation()); } } } try { applyChanges(toUpdate); writeFully( new File(System.getProperty("karaf.base"), "etc/startup.properties"), ((ResultImpl) result).getStartup()); writeFully( new File(System.getProperty("karaf.base"), "etc/overrides.properties"), ((ResultImpl) result).getOverrides()); } catch (Exception e) { throw new PatchException( "Unable to rollback patch " + patch.getId() + ": " + e.getMessage(), e); } ((PatchImpl) patch).setResult(null); File file = new File(patchDir, result.getPatch().getId() + ".patch.result"); file.delete(); }