@Override public boolean isSatisfied(PatchingTaskContext ctx) throws PatchingException { return ctx.getTargetFile(contentItem).exists(); }
@Override public boolean isSatisfied(PatchingTaskContext ctx) throws PatchingException { return ctx.getTargetFile(contentItem).exists(); }
@Override byte[] apply(PatchingTaskContext context, PatchContentLoader loader) throws IOException { final File targetDir = context.getTargetFile(contentItem); if(!targetDir.exists() && ! targetDir.mkdirs()) { throw PatchLogger.ROOT_LOGGER.cannotCreateDirectory(targetDir.getAbsolutePath()); } final File moduleXml = new File(targetDir, MODULE_XML); try (final ByteArrayInputStream is = new ByteArrayInputStream(PatchUtils.getAbsentModuleContent(contentItem))){ return copy(is, moduleXml); } }
@Override byte[] apply(PatchingTaskContext context, PatchContentLoader loader) throws IOException { final File targetDir = context.getTargetFile(contentItem); if(!targetDir.exists() && ! targetDir.mkdirs()) { throw PatchLogger.ROOT_LOGGER.cannotCreateDirectory(targetDir.getAbsolutePath()); } final File moduleXml = new File(targetDir, MODULE_XML); try (final ByteArrayInputStream is = new ByteArrayInputStream(PatchUtils.getAbsentModuleContent(contentItem))){ return copy(is, moduleXml); } }
@Override byte[] apply(PatchingTaskContext context, PatchContentLoader loader) throws IOException { // Copy the new module resources to the patching directory final File targetDir = context.getTargetFile(contentItem); final File sourceDir = loader.getFile(contentItem); if(sourceDir.exists()) { // Recursively copy module contents (incl. native libs) IoUtils.copyFile(sourceDir, targetDir); } else { // ADD an absent module // this situation happens when merging ADD and REMOVE modifications // which results in an ADD of an absent module if(!targetDir.exists() && ! targetDir.mkdirs()) { throw PatchLogger.ROOT_LOGGER.cannotCreateDirectory(targetDir.getAbsolutePath()); } final Path moduleXml = targetDir.toPath().resolve(MODULE_XML); final ByteArrayInputStream is = new ByteArrayInputStream(PatchUtils.getAbsentModuleContent(contentItem)); Files.copy(is, moduleXml, StandardCopyOption.REPLACE_EXISTING); } // return contentItem.getContentHash(); return HashUtils.hashFile(targetDir); }
@Override byte[] apply(PatchingTaskContext context, PatchContentLoader loader) throws IOException { // Copy the new module resources to the patching directory final File targetDir = context.getTargetFile(contentItem); final File sourceDir = loader.getFile(contentItem); if(sourceDir.exists()) { // Recursively copy module contents (incl. native libs) IoUtils.copyFile(sourceDir, targetDir); } else { // ADD an absent module // this situation happens when merging ADD and REMOVE modifications // which results in an ADD of an absent module if(!targetDir.exists() && ! targetDir.mkdirs()) { throw PatchLogger.ROOT_LOGGER.cannotCreateDirectory(targetDir.getAbsolutePath()); } final Path moduleXml = targetDir.toPath().resolve(MODULE_XML); final ByteArrayInputStream is = new ByteArrayInputStream(PatchUtils.getAbsentModuleContent(contentItem)); Files.copy(is, moduleXml, StandardCopyOption.REPLACE_EXISTING); } // return contentItem.getContentHash(); return HashUtils.hashFile(targetDir); }
@Override byte[] apply(PatchingTaskContext context, PatchContentLoader loader) throws IOException { if (context.getCurrentMode() == PatchingTaskContext.Mode.ROLLBACK) { return getContentItem().getContentHash(); } // Copy the new bundle resources to the patching directory final File targetDir = context.getTargetFile(contentItem); final File sourceDir = loader.getFile(contentItem); final File[] moduleResources = sourceDir.listFiles(); if(! targetDir.mkdirs() && ! targetDir.exists()) { throw PatchLogger.ROOT_LOGGER.cannotCreateDirectory(targetDir.getAbsolutePath()); } if(moduleResources == null || moduleResources.length == 0) { return NO_CONTENT; } for(final File file : moduleResources) { final File target = new File(targetDir, file.getName()); IoUtils.copy(file, target); } return contentItem.getContentHash(); }
@Override byte[] apply(PatchingTaskContext context, PatchContentLoader loader) throws IOException { if (context.getCurrentMode() == PatchingTaskContext.Mode.ROLLBACK) { return getContentItem().getContentHash(); } // Copy the new bundle resources to the patching directory final File targetDir = context.getTargetFile(contentItem); final File sourceDir = loader.getFile(contentItem); final File[] moduleResources = sourceDir.listFiles(); if(! targetDir.mkdirs() && ! targetDir.exists()) { throw PatchLogger.ROOT_LOGGER.cannotCreateDirectory(targetDir.getAbsolutePath()); } if(moduleResources == null || moduleResources.length == 0) { return NO_CONTENT; } for(final File file : moduleResources) { final File target = new File(targetDir, file.getName()); IoUtils.copy(file, target); } return contentItem.getContentHash(); }
static PatchingTask createMiscTask(final PatchingTaskDescription description, final MiscContentItem item, final PatchingTaskContext context) { // Create the task final File target = context.getTargetFile(item); final File backup = context.getBackupFile(item); final ModificationType type = description.getModificationType(); switch (type) { case ADD: case MODIFY: return new FileUpdateTask(description, target, backup); case REMOVE: return new FileRemoveTask(description, target, backup); default: throw new IllegalStateException(); } } }
static PatchingTask createMiscTask(final PatchingTaskDescription description, final MiscContentItem item, final PatchingTaskContext context) { // Create the task final File target = context.getTargetFile(item); final File backup = context.getBackupFile(item); final ModificationType type = description.getModificationType(); switch (type) { case ADD: case MODIFY: return new FileUpdateTask(description, target, backup); case REMOVE: return new FileRemoveTask(description, target, backup); default: throw new IllegalStateException(); } } }