use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.
the class ConfigurationBackupTestCase method testOneOffPatch.
@Test
public void testOneOffPatch() throws Exception {
// build a one-off 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).setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(installedIdentity.getIdentity().getName(), installedIdentity.getIdentity().getVersion()).getParent().oneOffPatchElement(layerPatchID, BASE, false).addContentModification(moduleAdded);
Patch patch = builder.build();
checkApplyPatchAndRollbackRestoresBackupConfiguration(patchDir, patch);
}
use of org.jboss.as.patching.metadata.ContentModification 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.ContentModification 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;
}
use of org.jboss.as.patching.metadata.ContentModification 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.ContentModification in project wildfly-core by wildfly.
the class ContentModificationUtils method modifyModule.
public static ContentModification modifyModule(File patchDir, String patchElementID, String moduleName, byte[] existingHash, String newContent) throws IOException {
File modulesDir = newFile(patchDir, patchElementID, MODULES);
File modifiedModule = createModule0(modulesDir, moduleName, newContent);
byte[] updatedHash = hashFile(modifiedModule);
ContentModification moduleUpdated = new ContentModification(new ModuleItem(moduleName, ModuleItem.MAIN_SLOT, updatedHash), existingHash, MODIFY);
return moduleUpdated;
}
Aggregations