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();
}
}
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);
}
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);
}
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));
}
Aggregations