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