Search in sources :

Example 11 with MiscContentItem

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

the class Location method hashCode.

static int hashCode(final ContentItem item) {
    final ContentType type = item.getContentType();
    switch(type) {
        case MODULE:
        case BUNDLE:
            final ModuleItem module = (ModuleItem) item;
            final String[] path = module.getName().split("\\.");
            return hashCode(type.toString(), module.getSlot(), path);
        case MISC:
            final MiscContentItem misc = (MiscContentItem) item;
            return hashCode(type.toString(), misc.getName(), misc.getPath());
        default:
            throw new IllegalStateException();
    }
}
Also used : ModuleItem(org.jboss.as.patching.metadata.ModuleItem) ContentType(org.jboss.as.patching.metadata.ContentType) MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem)

Example 12 with MiscContentItem

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

the class ContentPolicyBuilderImpl method createPolicy.

@Override
public ContentVerificationPolicy createPolicy() {
    return new ContentVerificationPolicy() {

        @Override
        public boolean ignoreContentValidation(ContentItem item) {
            final ContentType type = item.getContentType();
            if (type == ContentType.MODULE || type == ContentType.BUNDLE) {
                return ignoreModulesChanges || overrideAll;
            }
            final MiscContentItem misc = (MiscContentItem) item;
            final String path = misc.getRelativePath();
            if (override.contains(path)) {
                return true;
            }
            // Preserve should skip content verification
            if (preserve.contains(path)) {
                return true;
            }
            return overrideAll;
        }

        @Override
        public boolean preserveExisting(ContentItem item) {
            final ContentType type = item.getContentType();
            if (type == ContentType.MISC) {
                final MiscContentItem misc = (MiscContentItem) item;
                final String path = misc.getRelativePath();
                return preserve.contains(path);
            }
            return false;
        }
    };
}
Also used : ContentType(org.jboss.as.patching.metadata.ContentType) MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) ContentItem(org.jboss.as.patching.metadata.ContentItem)

Example 13 with MiscContentItem

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

the class PatchingTestUtil method updateModulesJar.

static ContentModification updateModulesJar(final File installation, final File patchDir) throws IOException {
    final String fileName = "jboss-modules.jar";
    final File source = new File(installation, fileName);
    final File misc = new File(patchDir, "misc");
    misc.mkdirs();
    final File target = new File(misc, fileName);
    updateJar(source, target);
    final byte[] sourceHash = HashUtils.hashFile(source);
    final byte[] targetHash = HashUtils.hashFile(target);
    assert !Arrays.equals(sourceHash, targetHash);
    final MiscContentItem item = new MiscContentItem(fileName, new String[0], targetHash, false, false);
    return new ContentModification(item, sourceHash, ModificationType.MODIFY);
}
Also used : MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) File(java.io.File) ContentModification(org.jboss.as.patching.metadata.ContentModification)

Example 14 with MiscContentItem

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

use of org.jboss.as.patching.metadata.MiscContentItem 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) 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);
    }
    ContentModification fileUpdated = new ContentModification(new MiscContentItem(modifiedFile.getName(), subdir, modifiedHash), existingHash, MODIFY);
    return fileUpdated;
}
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