protected ModuleItem createBundleItem(final String moduleName, final String slot, final byte[] hash) { return new BundleItem(moduleName, slot, hash); }
@Override ContentModification createRollbackEntry(ContentModification original, byte[] targetHash, byte[] itemHash) { final BundleItem item = new BundleItem(contentItem.getName(), contentItem.getSlot(), itemHash); switch (original.getType()) { case ADD: return new ContentModification(item, targetHash, ModificationType.REMOVE, original.getCondition()); case REMOVE: return new ContentModification(item, targetHash, ModificationType.ADD, original.getCondition()); default: return new ContentModification(item, targetHash, ModificationType.MODIFY, original.getCondition()); } }
} else { // bundle final BundleItem bundle = (BundleItem) cp2Item; elementBuilder.addBundle(bundle.getName(), bundle.getSlot(), bundle.getContentHash()); } else { // bundle final BundleItem bundle = (BundleItem) cp2Mod.getItem(); elementBuilder.removeBundle(bundle.getName(), bundle.getSlot(), cp1Mod.getTargetHash()); } else { // bundle final BundleItem bundle = (BundleItem) cp2Mod.getItem(); elementBuilder.modifyBundle(bundle.getName(), bundle.getSlot(), cp1Mod.getTargetHash(), bundle.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(); }
modSrcDir = new File(modSrcDir, Constants.BUNDLES); modTrgDir = new File(modTrgDir, Constants.BUNDLES); slot = ((BundleItem)mod.getItem()).getSlot(); } else { throw new PatchingException("Unexpected content type " + contentType);
@Override ContentModification createRollbackEntry(ContentModification original, byte[] targetHash, byte[] itemHash) { final BundleItem item = new BundleItem(contentItem.getName(), contentItem.getSlot(), itemHash); switch (original.getType()) { case ADD: return new ContentModification(item, targetHash, ModificationType.REMOVE, original.getCondition()); case REMOVE: return new ContentModification(item, targetHash, ModificationType.ADD, original.getCondition()); default: return new ContentModification(item, targetHash, ModificationType.MODIFY, original.getCondition()); } }
} else { // bundle final BundleItem bundle = (BundleItem) cp2Item; elementBuilder.addBundle(bundle.getName(), bundle.getSlot(), bundle.getContentHash()); } else { // bundle final BundleItem bundle = (BundleItem) cp2Mod.getItem(); elementBuilder.removeBundle(bundle.getName(), bundle.getSlot(), cp1Mod.getTargetHash()); } else { // bundle final BundleItem bundle = (BundleItem) cp2Mod.getItem(); elementBuilder.modifyBundle(bundle.getName(), bundle.getSlot(), cp1Mod.getTargetHash(), bundle.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(); }
modSrcDir = new File(modSrcDir, Constants.BUNDLES); modTrgDir = new File(modTrgDir, Constants.BUNDLES); slot = ((BundleItem)mod.getItem()).getSlot(); } else { throw new PatchingException("Unexpected content type " + contentType);
protected ModuleItem createBundleItem(final String moduleName, final String slot, final byte[] hash) { return new BundleItem(moduleName, slot, hash); }
static ModuleItem createContentItem(final ModuleItem original, final byte[] contentHash) { final ContentType type = original.getContentType(); if(type == ContentType.BUNDLE) { return new BundleItem(original.getName(), original.getSlot(), contentHash); } else { return new ModuleItem(original.getName(), original.getSlot(), contentHash); } }
static ModuleItem createContentItem(final ModuleItem original, final byte[] contentHash) { final ContentType type = original.getContentType(); if(type == ContentType.BUNDLE) { return new BundleItem(original.getName(), original.getSlot(), contentHash); } else { return new ModuleItem(original.getName(), original.getSlot(), contentHash); } }
private void parseSlottedItem(final XMLExtendedStreamReader reader, ModificationType modificationType, final boolean bundle, final PatchElementConfigBuilder builder) throws XMLStreamException { String name = null; String slot = "main"; final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { final String value = reader.getAttributeValue(i); final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case NAME: name = value; break; case SLOT: slot = value; break; default: throw unexpectedAttribute(reader, i); } } requireNoContent(reader); final ModuleItem item; if (bundle) { item = new BundleItem(name, slot, IoUtils.NO_CONTENT); } else { item = new ModuleItem(name, slot, IoUtils.NO_CONTENT); } builder.getSpecifiedContent().add(item); }
@Override byte[] backup(PatchingTaskContext context) throws IOException { // Check the bundle dir hash final File[] repoRoots = context.getTargetBundlePath(); final String bundleName = contentItem.getName(); final String slot = contentItem.getSlot(); for(final File path : repoRoots) { // Check the bundle path final File bundlePath = PatchContentLoader.getModulePath(path, bundleName, slot); if(bundlePath.exists()) { PatchLogger.ROOT_LOGGER.debugf("found in path (%s)", bundlePath.getAbsolutePath()); // Bundles don't contain a modules.xml final File[] children = bundlePath.listFiles(); if(children == null || children.length == 0) { return NO_CONTENT; } context.invalidateRoot(bundlePath); return HashUtils.hashFile(bundlePath); } } return NO_CONTENT; }
final ModuleItem item = contentType == ContentType.MODULE ? new ModuleItem(moduleName, slot, hash) : new BundleItem(moduleName, slot, hash); return new ContentModification(item, targetHash, modificationType);
@Override byte[] backup(PatchingTaskContext context) throws IOException { // Check the bundle dir hash final File[] repoRoots = context.getTargetBundlePath(); final String bundleName = contentItem.getName(); final String slot = contentItem.getSlot(); for(final File path : repoRoots) { // Check the bundle path final File bundlePath = PatchContentLoader.getModulePath(path, bundleName, slot); if(bundlePath.exists()) { PatchLogger.ROOT_LOGGER.debugf("found in path (%s)", bundlePath.getAbsolutePath()); // Bundles don't contain a modules.xml final File[] children = bundlePath.listFiles(); if(children == null || children.length == 0) { return NO_CONTENT; } context.invalidateRoot(bundlePath); return HashUtils.hashFile(bundlePath); } } return NO_CONTENT; }