/** * Restore the recorded state from the rollback xml. * * @param target the patchable target * @param rollbackPatchId the rollback patch id * @param patchType the the current patch type * @param history the recorded history * @throws PatchingException */ static void restoreFromHistory(final InstallationManager.MutablePatchingTarget target, final String rollbackPatchId, final Patch.PatchType patchType, final PatchableTarget.TargetInfo history) throws PatchingException { if (patchType == Patch.PatchType.CUMULATIVE) { assert history.getCumulativePatchID().equals(rollbackPatchId); target.apply(rollbackPatchId, patchType); // Restore one off state final List<String> oneOffs = new ArrayList<String>(history.getPatchIDs()); Collections.reverse(oneOffs); for (final String oneOff : oneOffs) { target.apply(oneOff, Patch.PatchType.ONE_OFF); } } checkState(history, history); // Just check for tests, that rollback should restore the old state }
@Override public File getTargetFile(ContentItem item) { if (item.getContentType() == ContentType.MISC) { return IdentityPatchContext.this.getTargetFile((MiscContentItem) item); } if (applyPatchId == null || state == State.ROLLBACK_ONLY) { throw new IllegalStateException("cannot process rollback tasks for modules/bundles"); // internal wrong usage, no i18n } final File root; final DirectoryStructure structure = delegate.getDirectoryStructure(); if (item.getContentType() == ContentType.BUNDLE) { root = structure.getBundlesPatchDirectory(applyPatchId); } else { root = structure.getModulePatchDirectory(applyPatchId); } return PatchContentLoader.getModulePath(root, (ModuleItem) item); }
@Override public void rollback(String patchId) { rollbacks.add(patchId); // Rollback delegate.rollback(patchId); // Record rollback loader recordRollbackLoader(patchId, delegate); }
/** * Check whether the patch can be applied to a given target. * * @param condition the conditions * @param target the target * @throws PatchingException */ static void checkUpgradeConditions(final UpgradeCondition condition, final InstallationManager.MutablePatchingTarget target) throws PatchingException { // See if the prerequisites are met for (final String required : condition.getRequires()) { if (!target.isApplied(required)) { throw PatchLogger.ROOT_LOGGER.requiresPatch(required); } } // Check for incompatibilities for (final String incompatible : condition.getIncompatibleWith()) { if (target.isApplied(incompatible)) { throw PatchLogger.ROOT_LOGGER.incompatiblePatch(incompatible); } } }
/** * Check whether the patch can be applied to a given target. * * @param condition the conditions * @param target the target * @throws PatchingException */ static void checkUpgradeConditions(final UpgradeCondition condition, final InstallationManager.MutablePatchingTarget target) throws PatchingException { // See if the prerequisites are met for (final String required : condition.getRequires()) { if (!target.isApplied(required)) { throw PatchLogger.ROOT_LOGGER.requiresPatch(required); } } // Check for incompatibilities for (final String incompatible : condition.getIncompatibleWith()) { if (target.isApplied(incompatible)) { throw PatchLogger.ROOT_LOGGER.incompatiblePatch(incompatible); } } }
/** * Restore the recorded state from the rollback xml. * * @param target the patchable target * @param rollbackPatchId the rollback patch id * @param patchType the the current patch type * @param history the recorded history * @throws PatchingException */ static void restoreFromHistory(final InstallationManager.MutablePatchingTarget target, final String rollbackPatchId, final Patch.PatchType patchType, final PatchableTarget.TargetInfo history) throws PatchingException { if (patchType == Patch.PatchType.CUMULATIVE) { assert history.getCumulativePatchID().equals(rollbackPatchId); target.apply(rollbackPatchId, patchType); // Restore one off state final List<String> oneOffs = new ArrayList<String>(history.getPatchIDs()); Collections.reverse(oneOffs); for (final String oneOff : oneOffs) { target.apply(oneOff, Patch.PatchType.ONE_OFF); } } checkState(history, history); // Just check for tests, that rollback should restore the old state }
@Override public File getTargetFile(ContentItem item) { if (item.getContentType() == ContentType.MISC) { return IdentityPatchContext.this.getTargetFile((MiscContentItem) item); } if (applyPatchId == null || state == State.ROLLBACK_ONLY) { throw new IllegalStateException("cannot process rollback tasks for modules/bundles"); // internal wrong usage, no i18n } final File root; final DirectoryStructure structure = delegate.getDirectoryStructure(); if (item.getContentType() == ContentType.BUNDLE) { root = structure.getBundlesPatchDirectory(applyPatchId); } else { root = structure.getModulePatchDirectory(applyPatchId); } return PatchContentLoader.getModulePath(root, (ModuleItem) item); }
@Override public PatchableTarget.TargetInfo getModifiedState() { return delegate.getModifiedState(); }
@Override public boolean isApplied(String patchId) { return delegate.isApplied(patchId); }
@Override public Properties getProperties() { return delegate.getProperties(); }
@Override public List<String> getPatchIDs() { return delegate.getPatchIDs(); }
@Override public String getCumulativePatchID() { return delegate.getCumulativePatchID(); }
@Override public void apply(String patchId, Patch.PatchType patchType) { delegate.apply(patchId, patchType); applyPatchId = patchId; }
void prepareForPortForward(ContentItem item, String patchId) throws IOException { if (item.getContentType() == ContentType.MODULE) { final File targetFile = delegate.getDirectoryStructure().getModulePatchDirectory(patchId); final List<File> files = listFiles(targetFile); if (files != null && files.size() > 0) { for (final File file : files) { moduleInvalidations.add(file); PatchModuleInvalidationUtils.processFile(IdentityPatchContext.this, file, PatchingTaskContext.Mode.ROLLBACK); } } } }
@Override public List<String> getPatchIDs() { return delegate.getPatchIDs(); }
@Override public String getCumulativePatchID() { return delegate.getCumulativePatchID(); }
@Override public boolean isApplied(String patchId) { return delegate.isApplied(patchId); }
@Override public File[] getTargetModulePath() { // We need the updated state for invalidating one-off patches // When applying the overlay directory should not exist yet final PatchableTarget.TargetInfo updated = mode == Mode.APPLY ? delegate : delegate.getModifiedState(); return PatchUtils.getModulePath(delegate.getDirectoryStructure(), updated); }
@Override public File[] getTargetBundlePath() { // We need the updated state for invalidating one-off patches // When applying the overlay directory should not exist yet final PatchableTarget.TargetInfo updated = mode == Mode.APPLY ? delegate : delegate.getModifiedState(); return PatchUtils.getBundlePath(delegate.getDirectoryStructure(), updated); }
@Override public DirectoryStructure getDirectoryStructure() { return delegate.getDirectoryStructure(); }