Search in sources :

Example 6 with ContentModification

use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.

the class ConfigurationBackupTestCase method testOneOffPatch.

@Test
public void testOneOffPatch() throws Exception {
    // build a one-off patch for the base installation
    // with 1 added module
    String patchID = randomString();
    String layerPatchID = randomString();
    File patchDir = mkdir(tempDir, patchID);
    String moduleName = randomString();
    ContentModification moduleAdded = ContentModificationUtils.addModule(patchDir, layerPatchID, moduleName);
    InstalledIdentity installedIdentity = loadInstalledIdentity();
    final PatchBuilder builder = PatchBuilder.create();
    builder.setPatchId(patchID).setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(installedIdentity.getIdentity().getName(), installedIdentity.getIdentity().getVersion()).getParent().oneOffPatchElement(layerPatchID, BASE, false).addContentModification(moduleAdded);
    Patch patch = builder.build();
    checkApplyPatchAndRollbackRestoresBackupConfiguration(patchDir, patch);
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchBuilder(org.jboss.as.patching.metadata.PatchBuilder) HashUtils.bytesToHexString(org.jboss.as.patching.HashUtils.bytesToHexString) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) TestUtils.createPatchXMLFile(org.jboss.as.patching.runner.TestUtils.createPatchXMLFile) HashUtils.hashFile(org.jboss.as.patching.HashUtils.hashFile) File(java.io.File) TestUtils.createZippedPatchFile(org.jboss.as.patching.runner.TestUtils.createZippedPatchFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch) Test(org.junit.Test)

Example 7 with ContentModification

use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.

the class ContentModificationUtils method modifyMisc.

public static ContentModification modifyMisc(File patchDir, String patchElementID, String modifiedContent, byte[] existingHash, String[] fileSegments, String[] requiredSegments) throws IOException {
    File miscDir = newFile(patchDir, patchElementID, MISC);
    File modifiedFile = touch(miscDir, fileSegments);
    dump(modifiedFile, modifiedContent);
    byte[] modifiedHash = hashFile(modifiedFile);
    String[] subdir = new String[0];
    if (fileSegments.length > 0) {
        subdir = new String[fileSegments.length - 1];
        System.arraycopy(fileSegments, 0, subdir, 0, fileSegments.length - 1);
    }
    final MiscContentItem item = new MiscContentItem(modifiedFile.getName(), subdir, modifiedHash);
    ModificationCondition condition = null;
    if (requiredSegments != null && requiredSegments.length > 0) {
        subdir = new String[requiredSegments.length - 1];
        System.arraycopy(requiredSegments, 0, subdir, 0, requiredSegments.length - 1);
        condition = ModificationCondition.Factory.exists(new MiscContentItem(requiredSegments[requiredSegments.length - 1], subdir, null));
    }
    return new ContentModification(item, existingHash, MODIFY, condition);
}
Also used : MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) ModificationCondition(org.jboss.as.patching.metadata.ModificationCondition) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) HashUtils.hashFile(org.jboss.as.patching.HashUtils.hashFile) File(java.io.File) ContentModification(org.jboss.as.patching.metadata.ContentModification)

Example 8 with ContentModification

use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.

the class ContentModificationUtils method removeMisc.

public static ContentModification removeMisc(File existingFile, String... fileSegments) throws IOException {
    byte[] existingHash = hashFile(existingFile);
    String[] subdir = new String[0];
    if (fileSegments.length > 0) {
        subdir = new String[fileSegments.length - 1];
        System.arraycopy(fileSegments, 0, subdir, 0, fileSegments.length - 1);
    }
    ContentModification fileRemoved = new ContentModification(new MiscContentItem(existingFile.getName(), subdir, NO_CONTENT), existingHash, REMOVE);
    return fileRemoved;
}
Also used : MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) ContentModification(org.jboss.as.patching.metadata.ContentModification)

Example 9 with ContentModification

use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.

the class ContentModificationUtils method addMisc.

public static ContentModification addMisc(File patchDir, String patchElementID, String content, String[] contentSegments, String[] requiredSegments) throws IOException {
    File miscDir = newFile(patchDir, patchElementID, MISC);
    File addedFile = touch(miscDir, contentSegments);
    dump(addedFile, content);
    byte[] newHash = hashFile(addedFile);
    String[] subdir = new String[contentSegments.length - 1];
    System.arraycopy(contentSegments, 0, subdir, 0, contentSegments.length - 1);
    final MiscContentItem contentItem = new MiscContentItem(addedFile.getName(), subdir, newHash);
    ModificationCondition condition = null;
    if (requiredSegments != null && requiredSegments.length > 0) {
        subdir = new String[requiredSegments.length - 1];
        System.arraycopy(requiredSegments, 0, subdir, 0, requiredSegments.length - 1);
        condition = ModificationCondition.Factory.exists(new MiscContentItem(requiredSegments[requiredSegments.length - 1], subdir, null));
    }
    return new ContentModification(contentItem, NO_CONTENT, ADD, condition);
}
Also used : MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) ModificationCondition(org.jboss.as.patching.metadata.ModificationCondition) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) HashUtils.hashFile(org.jboss.as.patching.HashUtils.hashFile) File(java.io.File) ContentModification(org.jboss.as.patching.metadata.ContentModification)

Example 10 with ContentModification

use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.

the class ContentModificationUtils method modifyModule.

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;
}
Also used : ModuleItem(org.jboss.as.patching.metadata.ModuleItem) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) HashUtils.hashFile(org.jboss.as.patching.HashUtils.hashFile) File(java.io.File) ContentModification(org.jboss.as.patching.metadata.ContentModification)

Aggregations

ContentModification (org.jboss.as.patching.metadata.ContentModification)129 File (java.io.File)100 Patch (org.jboss.as.patching.metadata.Patch)94 Test (org.junit.Test)72 IoUtils.newFile (org.jboss.as.patching.IoUtils.newFile)70 PatchingTestUtil.createPatchXMLFile (org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile)55 PatchingTestUtil.createZippedPatchFile (org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile)52 PatchingTestUtil.randomString (org.jboss.as.test.patching.PatchingTestUtil.randomString)47 ProductConfig (org.jboss.as.version.ProductConfig)39 TestUtils.randomString (org.jboss.as.patching.runner.TestUtils.randomString)36 TestUtils.createPatchXMLFile (org.jboss.as.patching.runner.TestUtils.createPatchXMLFile)34 TestUtils.createZippedPatchFile (org.jboss.as.patching.runner.TestUtils.createZippedPatchFile)34 Module (org.jboss.as.test.patching.util.module.Module)29 HashUtils.hashFile (org.jboss.as.patching.HashUtils.hashFile)25 PatchingTestUtil.readFile (org.jboss.as.test.patching.PatchingTestUtil.readFile)24 PatchingResult (org.jboss.as.patching.tool.PatchingResult)20 MiscContentItem (org.jboss.as.patching.metadata.MiscContentItem)18 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)17 PatchBuilder (org.jboss.as.patching.metadata.PatchBuilder)16 ContentItem (org.jboss.as.patching.metadata.ContentItem)12