code: public PatchingResult applyPatch(final PatchMetadataResolver patchResolver, final PatchContentProvider contentProvider, final ContentVerificationPolicy contentPolicy, final InstallationManager.InstallationModification modification) throws PatchingException {
          try {
              // Check if we can apply this patch
              final Patch patch = patchResolver.resolvePatch(modification.getName(), modification.getVersion());
              if (patch == null) {
                  throw PatchLogger.ROOT_LOGGER.failedToResolvePatch(modification.getName(), modification.getVersion());
              }
              final String patchId = patch.getPatchId();
              final Identity identity = patch.getIdentity();
              final String appliesTo = identity.getVersion();
              if (!appliesTo.equals(modification.getVersion())) {
                  throw PatchLogger.ROOT_LOGGER.doesNotApply(appliesTo, modification.getVersion());
              }
              // Cannot apply the same patch twice
              if (modification.isApplied(patchId)) {
                  throw PatchLogger.ROOT_LOGGER.alreadyApplied(patchId);
              }
              // See if the prerequisites are met
              checkUpgradeConditions(identity, modification);
              // Apply the patch
              final File backup = installedImage.getPatchHistoryDir(patchId);
              final IdentityPatchContext context = new IdentityPatchContext(backup, contentProvider, contentPolicy, modification, APPLY, installedImage);
              try {
                  return applyPatch(patchId, patch, context);
              } catch (Exception e) {
                  PatchLogger.ROOT_LOGGER.debugf(e, "failed to apply patch %s", patchId);
                  throw rethrowException(e);
              } finally {
                  context.cleanup();
              }
          } finally {
              contentProvider.cleanup();
          }
      }
docs: Apply a patch.
  
  @param patchResolver   the patch metadata resolver
  @param contentProvider the patch content provider
  @param contentPolicy   the content verification policy
  @param modification    the installation modification
  @throws PatchingException for any error