Search in sources :

Example 6 with PatchBuilder

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

the class UpdateModifiedFileTaskTestCase method setUp.

@Before
public void setUp() throws Exception {
    // with a file in it
    File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin");
    String fileName = "standalone.sh";
    modifiedFile = touch(binDir, fileName);
    dump(modifiedFile, "modified script to run standalone AS7");
    expectedModifiedHash = hashFile(modifiedFile);
    // let's simulate that the file has been modified by the users by using a hash that is not the file checksum
    byte[] unmodifiedHash = randomString().getBytes(StandardCharsets.UTF_8);
    // build a one-off patch for the base installation
    // with 1 updated file
    String patchID = randomString();
    File patchDir = mkdir(tempDir, patchID);
    File updatedFile = touch(patchDir, patchID, "misc", "bin", fileName);
    dump(updatedFile, "updated script");
    updatedHash = hashFile(updatedFile);
    fileUpdated = new ContentModification(new MiscContentItem(fileName, new String[] { "bin" }, updatedHash), unmodifiedHash, MODIFY);
    PatchBuilder builder = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent();
    // PatchElementImpl element = new PatchElementImpl("patch element 01");
    // builder.addElement(element);
    // element.setDescription("patch element 01 description");
    // element.setNoUpgrade();
    // 
    // PatchElementProviderImpl provider = new PatchElementProviderImpl("base", "4.5.6", false);
    // provider.require("patch element 02");
    // element.setProvider(provider);
    builder.addContentModification(fileUpdated);
    patch = builder.build();
    // create the patch
    createPatchXMLFile(patchDir, patch);
    zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
    runner = newPatchTool();
}
Also used : PatchBuilder(org.jboss.as.patching.metadata.PatchBuilder) MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) 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) Before(org.junit.Before)

Example 7 with PatchBuilder

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

the class MergingPatchMetadataTestCase method generateCP.

protected Patch generateCP(final String currentCP, final String nextCP, ModificationType type) {
    final PatchBuilder patchBuilder = PatchBuilder.create().setPatchId(nextCP).setDescription(nextCP + " description");
    patchBuilder.upgradeIdentity("identity", currentCP, nextCP);
    final PatchElementBuilder elementBuilder = patchBuilder.upgradeElement("base-" + nextCP, "base", false);
    if (ModificationType.ADD.equals(type)) {
        elementBuilder.addModule("org.jboss.test", "main", moduleHash(nextCP)).addBundle("org.jboss.test", "main", bundleHash(nextCP)).addFile("test.txt", Arrays.asList(new String[] { "org", "jboss", "test" }), miscHash(nextCP), false);
    } else if (ModificationType.MODIFY.equals(type)) {
        elementBuilder.modifyModule("org.jboss.test", "main", moduleHash(currentCP), moduleHash(nextCP)).modifyBundle("org.jboss.test", "main", bundleHash(currentCP), bundleHash(nextCP)).modifyFile("test.txt", Arrays.asList(new String[] { "org", "jboss", "test" }), miscHash(currentCP), miscHash(nextCP), false);
    } else {
        elementBuilder.removeModule("org.jboss.test", "main", moduleHash(currentCP)).removeBundle("org.jboss.test", "main", bundleHash(currentCP)).removeFile("test.txt", Arrays.asList(new String[] { "org", "jboss", "test" }), miscHash(currentCP), false);
    }
    return patchBuilder.build();
}
Also used : PatchBuilder(org.jboss.as.patching.metadata.PatchBuilder) PatchElementBuilder(org.jboss.as.patching.metadata.PatchElementBuilder)

Example 8 with PatchBuilder

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

the class ConfigurationBackupTestCase method testCumulativePatch.

@Test
public void testCumulativePatch() throws Exception {
    // build a cumulative 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).setDescription(randomString()).upgradeIdentity(installedIdentity.getIdentity().getName(), installedIdentity.getIdentity().getVersion(), productConfig.getProductVersion() + "-CP1").getParent().upgradeElement(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)

Aggregations

PatchBuilder (org.jboss.as.patching.metadata.PatchBuilder)8 File (java.io.File)7 ContentModification (org.jboss.as.patching.metadata.ContentModification)7 Patch (org.jboss.as.patching.metadata.Patch)5 TestUtils.createPatchXMLFile (org.jboss.as.patching.runner.TestUtils.createPatchXMLFile)4 TestUtils.createZippedPatchFile (org.jboss.as.patching.runner.TestUtils.createZippedPatchFile)4 TestUtils.randomString (org.jboss.as.patching.runner.TestUtils.randomString)4 HashUtils.hashFile (org.jboss.as.patching.HashUtils.hashFile)3 PatchingTestUtil.createPatchXMLFile (org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile)3 PatchingTestUtil.createZippedPatchFile (org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile)3 Test (org.junit.Test)3 HashUtils.bytesToHexString (org.jboss.as.patching.HashUtils.bytesToHexString)2 IoUtils.newFile (org.jboss.as.patching.IoUtils.newFile)2 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)2 Module (org.jboss.as.test.patching.util.module.Module)2 MiscContentItem (org.jboss.as.patching.metadata.MiscContentItem)1 PatchElementBuilder (org.jboss.as.patching.metadata.PatchElementBuilder)1 PatchingTestUtil.randomString (org.jboss.as.test.patching.PatchingTestUtil.randomString)1 ProductConfig (org.jboss.as.version.ProductConfig)1 Before (org.junit.Before)1