protected ModuleItem createModuleItem(final String moduleName, final String slot, final byte[] hash) { return new ModuleItem(moduleName, slot, hash); }
protected ModuleItem createModuleItem(final String moduleName, final String slot, final byte[] hash) { return new ModuleItem(moduleName, slot, hash); }
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); }
static void assertModule(final String patchID, final PatchableTarget target, final String moduleName, final String slot) { assertModule(patchID, target, new ModuleItem(moduleName, slot, IoUtils.NO_CONTENT)); }
public static ContentModification addModule(File patchDir, String patchElementID, String moduleName, String... resourceContents) throws IOException { File modulesDir = newFile(patchDir, patchElementID, MODULES); File moduleDir = createModule0(modulesDir, moduleName, resourceContents); byte[] newHash = hashFile(moduleDir); ContentModification moduleAdded = new ContentModification(new ModuleItem(moduleName, ModuleItem.MAIN_SLOT, newHash), NO_CONTENT, ADD); return moduleAdded; }
public static ContentModification modifyModule(File patchDir, String patchElementID, String moduleName, byte[] existingHash, String newContent) throws IOException { File modulesDir = newFile(patchDir, patchElementID, MODULES); File modifiedModule = createModule0(modulesDir, moduleName, newContent); byte[] updatedHash = hashFile(modifiedModule); ContentModification moduleUpdated = new ContentModification(new ModuleItem(moduleName, ModuleItem.MAIN_SLOT, updatedHash), existingHash, MODIFY); return moduleUpdated; }
public static ContentModification addModule(File patchDir, String patchElementID, String moduleName) throws IOException { File modulesDir = newFile(patchDir, patchElementID, MODULES); File moduleDir = createModule0(modulesDir, moduleName); byte[] newHash = hashFile(moduleDir); ContentModification moduleAdded = new ContentModification(new ModuleItem(moduleName, ModuleItem.MAIN_SLOT, newHash), NO_CONTENT, ADD); return moduleAdded; }
public static ContentModification modifyModule(File patchDir, String patchElementID, String moduleName, byte[] existingHash, TestUtils.ContentTask task) throws IOException { File modulesDir = newFile(patchDir, patchElementID, MODULES); File modifiedModule = createModule0(modulesDir, moduleName, task); byte[] updatedHash = hashFile(modifiedModule); ContentModification moduleUpdated = new ContentModification(new ModuleItem(moduleName, ModuleItem.MAIN_SLOT, updatedHash), existingHash, MODIFY); return moduleUpdated; }
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); } }
@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 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()); }
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); }
final ModuleItem item = contentType == ContentType.MODULE ? new ModuleItem(moduleName, slot, hash) : new BundleItem(moduleName, slot, hash); return new ContentModification(item, targetHash, modificationType);
protected PatchingTestStepBuilder testModuleConflicts(final ContentVerificationPolicy resolvePolicy) throws Exception { final PatchingTestBuilder builder = createDefaultBuilder(); final byte[] moduleHash = new byte[20]; // Create a conflict final File base = builder.getFile("modules", "system", "layers", "base"); createModule0(base, "org.jboss.test", randomString()); final PatchingTestStepBuilder oneOff1 = builder.createStepBuilder(); oneOff1.setPatchId("one-off-1") .oneOffPatchIdentity(PRODUCT_VERSION) .oneOffPatchElement("base-oo1", BASE, false) .updateModuleWithRandomContent("org.jboss.test", NO_CONTENT, moduleHash) ; try { apply(oneOff1); Assert.fail("should have detected conflicts"); } catch (ContentConflictsException expected) { final ModuleItem item = new ModuleItem("org.jboss.test", "main", moduleHash); Assert.assertTrue(expected.getConflicts().contains(item)); } // Apply patch and override all apply(oneOff1, resolvePolicy); return oneOff1; }
final ModuleItem item = contentType == ContentType.MODULE ? new ModuleItem(moduleName, slot, hash) : new BundleItem(moduleName, slot, hash); return new ContentModification(item, targetHash, modificationType);
@Test public void testWrongModuleContent() throws Exception { final PatchingTestBuilder builder = createDefaultBuilder(); // Add some random content ContentModificationUtils.addModule(builder.getRoot(), "base-patch-001", "test.module", randomString()); // Override the hash with a wrong one final ModuleItem item = new ModuleItem("test.module", "main", WRONG_HASH); final ContentModification wrongModification = new ContentModification(item, IoUtils.NO_CONTENT, ModificationType.ADD); final PatchingTestStepBuilder step1 = builder.createStepBuilder(); step1.oneOffPatchIdentity(PRODUCT_VERSION) .setPatchId("oo1") .oneOffPatchElement("base-patch-001", "base", false) .addContentModification(wrongModification) .getParent() .addFileWithRandomContent(null, "test", "content"); // try { apply(step1); Assert.fail("should have failed"); } catch (PatchingException e) { Assert.assertFalse(builder.hasFile("test", "content")); final InstalledIdentity identity = loadInstallationManager().getDefaultIdentity(); final PatchableTarget base = identity.getLayer("base"); Assert.assertFalse(base.getDirectoryStructure().getModulePatchDirectory("base-patch-001").exists()); Assert.assertFalse(identity.getInstalledImage().getPatchHistoryDir("oo1").exists()); } }