Search in sources :

Example 1 with ModificationCondition

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

the class PatchStepAssertions method assertContentModification.

static void assertContentModification(final String patchID, final PatchableTarget target, final ContentModification modification) {
    final ContentItem item = modification.getItem();
    final ContentType contentType = item.getContentType();
    switch(contentType) {
        case MODULE:
            assertModule(patchID, target, (ModuleItem) item);
            break;
        case BUNDLE:
            break;
        case MISC:
            final File home = target.getDirectoryStructure().getInstalledImage().getJbossHome();
            final ModificationCondition condition = modification.getCondition();
            if (condition != null) {
                if (condition instanceof ModificationCondition.ExistsCondition) {
                    final ContentItem requiredItem = ((ModificationCondition.ExistsCondition) condition).getContentItem();
                    File requiredFile;
                    switch(requiredItem.getContentType()) {
                        case MISC:
                            requiredFile = PatchContentLoader.getMiscPath(home, (MiscContentItem) requiredItem);
                            break;
                        case MODULE:
                        case BUNDLE:
                        default:
                            throw new IllegalStateException("Unsupported content type");
                    }
                    if (!requiredFile.exists()) {
                        final File file = PatchContentLoader.getMiscPath(home, (MiscContentItem) item);
                        Assert.assertFalse(file.exists());
                        return;
                    }
                }
            }
            assertMisc(home, modification.getType(), (MiscContentItem) item);
            break;
        default:
            Assert.fail();
    }
}
Also used : ContentType(org.jboss.as.patching.metadata.ContentType) ModificationCondition(org.jboss.as.patching.metadata.ModificationCondition) MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) File(java.io.File) MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) ContentItem(org.jboss.as.patching.metadata.ContentItem)

Example 2 with ModificationCondition

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

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

use of org.jboss.as.patching.metadata.ModificationCondition 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)

Aggregations

MiscContentItem (org.jboss.as.patching.metadata.MiscContentItem)4 ModificationCondition (org.jboss.as.patching.metadata.ModificationCondition)4 File (java.io.File)3 ContentModification (org.jboss.as.patching.metadata.ContentModification)3 HashUtils.hashFile (org.jboss.as.patching.HashUtils.hashFile)2 IoUtils.newFile (org.jboss.as.patching.IoUtils.newFile)2 ContentItem (org.jboss.as.patching.metadata.ContentItem)2 ContentType (org.jboss.as.patching.metadata.ContentType)1 TestUtils.randomString (org.jboss.as.patching.runner.TestUtils.randomString)1