@Override public File getPatchHistoryDir(String patchId) { return newFile(getInstallationMetadata(), PATCHES, patchId); }
public static void assertFileDoesNotExist(File rootFile, String... segments) { File f = IoUtils.newFile(rootFile, segments); assertFalse(f + " exists", f.exists()); }
final File modulesDir = newFile(env.getInstalledImage().getModulesDir(), SYSTEM, LAYERS, BASE); if(!modulesDir.exists()) { modulesDir.mkdirs();
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); }
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); } }
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; }
public static ContentModification addModule(File patchDir, String patchElementID, String moduleName) throws IOException { File modulesDir = newFile(patchDir, patchElementID, MODULES); File moduleDir = createModule0(modulesDir, moduleName); byte[] newHash = hashFile(moduleDir); ContentModification moduleAdded = new ContentModification(new ModuleItem(moduleName, ModuleItem.MAIN_SLOT, newHash), NO_CONTENT, ADD); return moduleAdded; }
public static ContentModification modifyModule(File patchDir, String patchElementID, String moduleName, byte[] existingHash, TestUtils.ContentTask task) throws IOException { File modulesDir = newFile(patchDir, patchElementID, MODULES); File modifiedModule = createModule0(modulesDir, moduleName, task); byte[] updatedHash = hashFile(modifiedModule); ContentModification moduleUpdated = new ContentModification(new ModuleItem(moduleName, ModuleItem.MAIN_SLOT, updatedHash), existingHash, MODIFY); return moduleUpdated; }
public static ContentModification addModule(File patchDir, String patchElementID, String moduleName, String... resourceContents) throws IOException { File modulesDir = newFile(patchDir, patchElementID, MODULES); File moduleDir = createModule0(modulesDir, moduleName, resourceContents); byte[] newHash = hashFile(moduleDir); ContentModification moduleAdded = new ContentModification(new ModuleItem(moduleName, ModuleItem.MAIN_SLOT, newHash), NO_CONTENT, ADD); return moduleAdded; }
@Test public void baseLayerIsAlwaysInstalled() throws Exception { tree(env.getInstalledImage().getJbossHome()); InstalledIdentity installedIdentity = loadInstalledIdentity(); List<Layer> layers = installedIdentity.getLayers(); assertEquals(1, layers.size()); Layer layer = layers.get(0); assertEquals(BASE, layer.getName()); PatchableTarget.TargetInfo targetInfo = layer.loadTargetInfo(); assertEquals(BASE, targetInfo.getCumulativePatchID()); assertTrue(targetInfo.getPatchIDs().isEmpty()); DirectoryStructure directoryStructure = targetInfo.getDirectoryStructure(); assertEquals(newFile(env.getBundleRepositoryRoot(), "system", LAYERS, BASE), directoryStructure.getBundleRepositoryRoot()); assertEquals(newFile(env.getModuleRoot(), "system", LAYERS, BASE), directoryStructure.getModuleRoot()); }
@Test public void installedAddOn() throws Exception { String addOnName = randomString(); installAddOn(env.getModuleRoot(), addOnName); TestUtils.tree(env.getInstalledImage().getJbossHome()); InstalledIdentity installedIdentity = loadInstalledIdentity(); Collection<AddOn> addOns = installedIdentity.getAddOns(); assertEquals(1, addOns.size()); AddOn addOn = addOns.iterator().next(); assertEquals(addOnName, addOn.getName()); PatchableTarget.TargetInfo targetInfo = addOn.loadTargetInfo(); assertEquals(BASE, targetInfo.getCumulativePatchID()); assertTrue(targetInfo.getPatchIDs().isEmpty()); DirectoryStructure directoryStructure = targetInfo.getDirectoryStructure(); assertEquals(newFile(env.getModuleRoot(), "system", ADD_ONS, addOnName), directoryStructure.getModuleRoot()); assertNull(directoryStructure.getBundleRepositoryRoot()); }
@Test public void installedLayer() throws Exception { String layerName = randomString(); installLayers(layerName); TestUtils.tree(env.getInstalledImage().getJbossHome()); InstalledIdentity installedIdentity = loadInstalledIdentity(); Identity identity = installedIdentity.getIdentity(); assertEquals(productConfig.getProductName(), identity.getName()); assertEquals(productConfig.resolveVersion(), identity.getVersion()); List<Layer> layers = installedIdentity.getLayers(); assertEquals(2, layers.size()); Layer layer = layers.get(0); assertEquals(layerName, layer.getName()); assertEquals(BASE, layers.get(1).getName()); // base layer is always appended PatchableTarget.TargetInfo targetInfo = layer.loadTargetInfo(); assertEquals(BASE, targetInfo.getCumulativePatchID()); assertTrue(targetInfo.getPatchIDs().isEmpty()); DirectoryStructure directoryStructure = targetInfo.getDirectoryStructure(); assertEquals(newFile(env.getModuleRoot(), "system", "layers", layerName), directoryStructure.getModuleRoot()); assertNull(directoryStructure.getBundleRepositoryRoot()); }
final File baseModule2Dir = IoUtils.newFile( installedIdentity.getLayer("base").loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(baseCP1ID), "org", "jboss", "test2"); cp2BaseModule2Removed = ContentModificationUtils.removeModule(baseModule2Dir, moduleName + 2); final File layer2ModuleDir = IoUtils.newFile( installedIdentity.getLayer("layer2").loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layer2CP1ID), "org", "jboss", "test");
private void prepareCP3(final InstalledIdentity installedIdentity) throws IOException, Exception { final String cp3ID = "CP3"; final File cp3Dir = mkdir(tempDir, cp3ID); cp3StandaloneModified = ContentModificationUtils.modifyMisc(cp3Dir, cp3ID, "updated by cp3", standaloneSh, "bin", standaloneSh.getName()); cp3BaseModuleModified = ContentModificationUtils.modifyModule(cp3Dir, baseCP3ID, moduleName, cp2BaseModuleModified.getItem().getContentHash(), "cp3 content"); // cp3BaseModule2Added = ContentModificationUtils.addModule(cp3Dir, baseCP3ID, moduleName + "2"); the patchgen tool // would generate an update instead final File absentModuleXml = IoUtils.newFile(installedIdentity.getLayer("base").loadTargetInfo() .getDirectoryStructure().getModulePatchDirectory(baseCP2ID), "org", "jboss", "test2", "main", "module.xml"); cp3BaseModule2Added = ContentModificationUtils.modifyModule(cp3Dir, baseCP3ID, moduleName + "2", HashUtils.hashFile(absentModuleXml), "cp3 content"); final ContentModification cp3AddedByCP1RemovedByCP3Removed = ContentModificationUtils.removeMisc(addedByCP1RemovedByCP3, "bin", addedByCP1RemovedByCP3.getName()); cp3 = PatchBuilder.create() .setPatchId(cp3ID) .setDescription(randomString()) .upgradeIdentity(installedIdentity.getIdentity().getName(), productConfig.getProductVersion() + "_CP2", productConfig.getProductVersion() + "_CP3") .getParent() .upgradeElement(baseCP3ID, BASE, false) .addContentModification(cp3BaseModuleModified) .addContentModification(cp3BaseModule2Added) .getParent() .addContentModification(cp3StandaloneModified) .addContentModification(cp3AddedByCP1RemovedByCP3Removed) .build(); createPatchXMLFile(cp3Dir, cp3); cp3Zip = createZippedPatchFile(cp3Dir, cp3ID); }
File baseModuleDir = newFile(env.getInstalledImage().getModulesDir(), SYSTEM, LAYERS, BASE); String moduleConflictName = "module-conflict"; File moduleConflictDir = createModule0(baseModuleDir, moduleConflictName);
@Test public void testRemoveModule() throws Exception { String moduleName = randomString(); // create an empty module in the AS7 installation File baseModuleDir = newFile(env.getInstalledImage().getModulesDir(), SYSTEM, LAYERS, BASE); File moduleDir = createModule0(baseModuleDir, moduleName); // build a one-off patch for the installation base layer // with 1 module removed String baseLayerPatchID = randomString(); Patch patch = PatchBuilder.create() .setPatchId(randomString()) .setDescription(randomString()) .oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()) .getParent() .oneOffPatchElement(baseLayerPatchID, BASE, false) .addContentModification(ContentModificationUtils.removeModule(moduleDir)) .getParent() .build(); // create the patch File patchDir = mkdir(tempDir, patch.getPatchId()); createPatchXMLFile(patchDir, patch); File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId()); PatchingResult result = executePatch(zippedPatch); assertPatchHasBeenApplied(result, patch); InstalledIdentity installedIdentity = loadInstalledIdentity(); File modulesPatchDir = installedIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(baseLayerPatchID); assertDirExists(modulesPatchDir); assertDefinedAbsentModule(modulesPatchDir, moduleName); }
File baseModuleDir = newFile(env.getInstalledImage().getModulesDir(), SYSTEM, LAYERS, BASE); File moduleDir = createModule0(baseModuleDir, moduleName);
private void assertCP3State(PatchingResult result) throws Exception { assertPatchHasBeenApplied(result, cp3); assertFileExists(standaloneSh); assertFileContent(cp3StandaloneModified.getItem().getContentHash(), standaloneSh); assertFileExists(addedByCP1); assertFileContent(cp1AddedByCP1Added.getItem().getContentHash(), addedByCP1); assertFileDoesNotExist(addedByCP1RemovedByCP3); assertFileExists(addedByCP2); assertFileContent(cp2AddedByCp2Added.getItem().getContentHash(), addedByCP2); final InstalledIdentity installedIdentity = loadInstalledIdentity(); File modulePatchDir = installedIdentity.getLayer(BASE).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(baseCP3ID); assertDirExists(modulePatchDir); assertDefinedModule(modulePatchDir, moduleName, cp3BaseModuleModified.getItem().getContentHash()); assertDefinedModule(modulePatchDir, moduleName + 2, cp3BaseModule2Added.getItem().getContentHash()); modulePatchDir = installedIdentity.getLayer("layer1").loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layer1CP1ID); assertDirExists(modulePatchDir); assertDefinedModule(modulePatchDir, moduleName, cp1Layer1ModuleAdded.getItem().getContentHash()); modulePatchDir = installedIdentity.getLayer("layer2").loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layer2CP2ID); assertDirExists(modulePatchDir); assertDefinedModule(modulePatchDir, moduleName + "2", cp1Layer2Module2Added.getItem().getContentHash()); assertDefinedModule(modulePatchDir, moduleName + "3", cp2Layer2Module3Added.getItem().getContentHash()); if(IoUtils.newFile(modulePatchDir, "org", "jboss", "test").exists()) { assertDefinedAbsentModule(modulePatchDir, moduleName); } }
File oneOffPatchDir = mkdir(tempDir, oneOffPatchID); ContentModification moduleModified = ContentModificationUtils.modifyModule(oneOffPatchDir, oneOffLayerPatchID, newFile(modulePatchDirectory, moduleName), "new resource in the module");