Search in sources :

Example 16 with MiscContentItem

use of org.jboss.as.patching.metadata.MiscContentItem 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 17 with MiscContentItem

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

the class AbstractPatchTestBuilder method removeFile.

public T removeFile(final String name, final String[] path, final byte[] existingHash, final boolean isDirectory, final String[] requiredPath) {
    final ContentItem item = createMiscItem(name, Arrays.asList(path), NO_CONTENT, isDirectory);
    ModificationCondition condition = null;
    if (requiredPath != null && requiredPath.length > 0) {
        final String[] subdir = new String[requiredPath.length - 1];
        System.arraycopy(requiredPath, 0, subdir, 0, requiredPath.length - 1);
        condition = ModificationCondition.Factory.exists(new MiscContentItem(requiredPath[requiredPath.length - 1], subdir, null));
    }
    return addContentModification(new ContentModification(item, existingHash, ModificationType.REMOVE, condition));
}
Also used : ModificationCondition(org.jboss.as.patching.metadata.ModificationCondition) MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) ContentModification(org.jboss.as.patching.metadata.ContentModification) MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) ContentItem(org.jboss.as.patching.metadata.ContentItem)

Example 18 with MiscContentItem

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

the class RemoveModifiedFileTaskTestCase method setUp.

@Before
public void setUp() throws Exception {
    // with a file in it
    File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin");
    String fileName = "standalone.sh";
    removedFile = touch(binDir, fileName);
    dump(removedFile, "modified script to run standalone AS");
    expectedModifiedHash = hashFile(removedFile);
    // 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);
    String patchID = randomString();
    File patchDir = mkdir(tempDir, patchID);
    File updatedFile = touch(patchDir, "misc", "bin", fileName);
    dump(updatedFile, "updated script");
    // build a one-off patch for the base installation
    // with 1 removed file
    fileRemoved = new ContentModification(new MiscContentItem(fileName, new String[] { "bin" }, NO_CONTENT), unmodifiedHash, REMOVE);
    patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(fileRemoved).build();
    // create the patch
    createPatchXMLFile(patchDir, patch);
    zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
    runner = newPatchTool();
}
Also used : 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 19 with MiscContentItem

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

the class FileTaskTestCase method testAddDirectory.

@Test
public void testAddDirectory() throws Exception {
    final ContentItem item = new MiscContentItem("dir", new String[] { "test" }, NO_CONTENT, true, false);
    final ContentModification addDir = new ContentModification(item, NO_CONTENT, ModificationType.ADD);
    final String patchID = randomString();
    final Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(addDir).build();
    // create the patch
    final File patchDir = mkdir(tempDir, patch.getPatchId());
    createPatchXMLFile(patchDir, patch);
    final File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
    // Apply
    PatchingResult result = executePatch(zippedPatch);
    assertPatchHasBeenApplied(result, patch);
    final File test = new File(env.getInstalledImage().getJbossHome(), "test");
    assertTrue(test.exists());
    assertTrue(test.isDirectory());
    final File dir = new File(test, "dir");
    assertTrue(dir.exists());
    assertTrue(dir.isDirectory());
    rollback(patchID);
}
Also used : PatchingResult(org.jboss.as.patching.tool.PatchingResult) MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch) TestUtils.createPatchXMLFile(org.jboss.as.patching.runner.TestUtils.createPatchXMLFile) File(java.io.File) TestUtils.createZippedPatchFile(org.jboss.as.patching.runner.TestUtils.createZippedPatchFile) MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) ContentItem(org.jboss.as.patching.metadata.ContentItem) Test(org.junit.Test)

Example 20 with MiscContentItem

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

the class ContentModificationUtils method addMisc.

public static ContentModification addMisc(File patchDir, String patchElementID, String content, String... fileSegments) throws IOException {
    File miscDir = newFile(patchDir, patchElementID, MISC);
    File addedFile = touch(miscDir, fileSegments);
    dump(addedFile, content);
    byte[] newHash = hashFile(addedFile);
    String[] subdir = new String[fileSegments.length - 1];
    System.arraycopy(fileSegments, 0, subdir, 0, fileSegments.length - 1);
    ContentModification fileAdded = new ContentModification(new MiscContentItem(addedFile.getName(), subdir, newHash), NO_CONTENT, ADD);
    return fileAdded;
}
Also used : MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) 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

MiscContentItem (org.jboss.as.patching.metadata.MiscContentItem)20 ContentModification (org.jboss.as.patching.metadata.ContentModification)17 File (java.io.File)9 HashUtils.hashFile (org.jboss.as.patching.HashUtils.hashFile)6 Test (org.junit.Test)6 IoUtils.newFile (org.jboss.as.patching.IoUtils.newFile)5 ContentItem (org.jboss.as.patching.metadata.ContentItem)4 ModificationCondition (org.jboss.as.patching.metadata.ModificationCondition)4 TestUtils.randomString (org.jboss.as.patching.runner.TestUtils.randomString)4 ContentType (org.jboss.as.patching.metadata.ContentType)3 TestUtils.createPatchXMLFile (org.jboss.as.patching.runner.TestUtils.createPatchXMLFile)3 TestUtils.createZippedPatchFile (org.jboss.as.patching.runner.TestUtils.createZippedPatchFile)3 PatchingException (org.jboss.as.patching.PatchingException)2 Patch (org.jboss.as.patching.metadata.Patch)2 Before (org.junit.Before)2 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)1 PatchableTarget (org.jboss.as.patching.installation.PatchableTarget)1 ModuleItem (org.jboss.as.patching.metadata.ModuleItem)1 PatchBuilder (org.jboss.as.patching.metadata.PatchBuilder)1 PatchingResult (org.jboss.as.patching.tool.PatchingResult)1