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); } }
@Override byte[] apply(final PatchingTaskContext context, final PatchContentLoader loader) throws IOException { return getContentItem().getContentHash(); }
protected ModuleItem createModuleItem(final String moduleName, final String slot, final byte[] hash) { return new ModuleItem(moduleName, slot, hash); }
protected static void writeSlottedItem(final XMLExtendedStreamWriter writer, Element element, ContentModification modification) throws XMLStreamException { writer.writeEmptyElement(element.name); final ModuleItem item = (ModuleItem) modification.getItem(); final ModificationType type = modification.getType(); writer.writeAttribute(Attribute.NAME.name, item.getName()); if (!MAIN_SLOT.equals(item.getSlot())) { writer.writeAttribute(Attribute.SLOT.name, item.getSlot()); } byte[] hash = item.getContentHash(); if (hash.length > 0 && type != ModificationType.REMOVE) { writer.writeAttribute(Attribute.HASH.name, bytesToHexString(hash)); } if(type == ModificationType.REMOVE) { final byte[] existingHash = modification.getTargetHash(); if (existingHash.length > 0) { writer.writeAttribute(Attribute.HASH.name, bytesToHexString(existingHash)); } } else if(type == ModificationType.MODIFY) { final byte[] existingHash = modification.getTargetHash(); if (existingHash.length > 0) { writer.writeAttribute(Attribute.NEW_HASH.name, bytesToHexString(existingHash)); } } }
@Override protected ContentModification getOriginalModification(byte[] targetHash, byte[] itemHash) { final ModuleItem original = getContentItem(); final ModuleItem item = new ModuleItem(original.getName(), original.getSlot(), targetHash); return new ContentModification(item, description.getModification().getTargetHash(), ModificationType.MODIFY, description.getModification().getCondition()); }
@Override public String getRelativePath() { return getName() + ":" + slot; }
modSrcDir = new File(modSrcDir, Constants.MODULES); modTrgDir = new File(modTrgDir, Constants.MODULES); slot = ((ModuleItem)mod.getItem()).getSlot(); } else if (contentType.equals(ContentType.BUNDLE)) { modSrcDir = new File(modSrcDir, Constants.BUNDLES);
static void assertModulePath(final File[] mp, final ModuleItem item, final File reference) { File resolved = null; for (final File root : mp) { final File moduleRoot = PatchContentLoader.getModulePath(root, item); final File moduleXml = new File(moduleRoot, "module.xml"); if (moduleXml.exists()) { resolved = moduleRoot; break; } } Assert.assertEquals(item.toString(), reference, resolved); }
protected ModuleItem createModuleItem(final String moduleName, final String slot, final byte[] hash) { return new ModuleItem(moduleName, slot, hash); }
protected static void writeSlottedItem(final XMLExtendedStreamWriter writer, Element element, ContentModification modification) throws XMLStreamException { writer.writeEmptyElement(element.name); final ModuleItem item = (ModuleItem) modification.getItem(); final ModificationType type = modification.getType(); writer.writeAttribute(Attribute.NAME.name, item.getName()); if (!MAIN_SLOT.equals(item.getSlot())) { writer.writeAttribute(Attribute.SLOT.name, item.getSlot()); } byte[] hash = item.getContentHash(); if (hash.length > 0 && type != ModificationType.REMOVE) { writer.writeAttribute(Attribute.HASH.name, bytesToHexString(hash)); } if(type == ModificationType.REMOVE) { final byte[] existingHash = modification.getTargetHash(); if (existingHash.length > 0) { writer.writeAttribute(Attribute.HASH.name, bytesToHexString(existingHash)); } } else if(type == ModificationType.MODIFY) { final byte[] existingHash = modification.getTargetHash(); if (existingHash.length > 0) { writer.writeAttribute(Attribute.NEW_HASH.name, bytesToHexString(existingHash)); } } }
@Override protected ContentModification getOriginalModification(byte[] targetHash, byte[] itemHash) { final ModuleItem original = getContentItem(); final ModuleItem item = new ModuleItem(original.getName(), original.getSlot(), targetHash); return new ContentModification(item, description.getModification().getTargetHash(), ModificationType.MODIFY, description.getModification().getCondition()); }
@Override public String getRelativePath() { return getName() + ":" + slot; }
modSrcDir = new File(modSrcDir, Constants.MODULES); modTrgDir = new File(modTrgDir, Constants.MODULES); slot = ((ModuleItem)mod.getItem()).getSlot(); } else if (contentType.equals(ContentType.BUNDLE)) { modSrcDir = new File(modSrcDir, Constants.BUNDLES);
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); } }
public static ContentModification removeModule(File moduleDir, String moduleName) throws IOException { byte[] existingHash = hashFile(moduleDir); return new ContentModification(new ModuleItem(moduleName, ModuleItem.MAIN_SLOT, NO_CONTENT), existingHash, REMOVE); }
if(cp2Type.equals(ModificationType.REMOVE)) { try { elementBuilder.addModule(module.getName(), module.getSlot(), PatchUtils.getAbsentModuleContentHash(module)); } catch (IOException e) { throw new PatchingException("Failed to calculate hash for the removed module " + module.getName(), e); elementBuilder.addModule(module.getName(), module.getSlot(), module.getContentHash()); if (cp1Item.getContentType().equals(ContentType.MODULE)) { final ModuleItem module = (ModuleItem) cp2Mod.getItem(); elementBuilder.removeModule(module.getName(), module.getSlot(), cp1Mod.getTargetHash()); } else if (cp1Item.getContentType().equals(ContentType.MISC)) { final MiscContentItem misc = (MiscContentItem) cp2Mod.getItem(); if (cp1Item.getContentType().equals(ContentType.MODULE)) { final ModuleItem module = (ModuleItem) cp2Mod.getItem(); elementBuilder.modifyModule(module.getName(), module.getSlot(), cp1Mod.getTargetHash(), module.getContentHash()); } else if (cp1Item.getContentType().equals(ContentType.MISC)) { final MiscContentItem misc = (MiscContentItem) cp2Mod.getItem();
@Override public String toString() { final StringBuilder builder = new StringBuilder(); builder.append(ModuleItem.class.getSimpleName()).append("{"); builder.append(getName()).append(":").append(slot).append("}"); return builder.toString(); } }