private File createNextCumulativePatchAddingRandomModule( String patchID, String asVersion, final String currentPatch, final String targetAsVersion, File targetDir) throws Exception { String layerPatchID = "layer" + patchID; File cpPatchDir = mkdir(tempDir, patchID); final String moduleName = "org.wildfly.test." + randomString(); // Create the version module final String versionModuleName = ProductInfo.getVersionModule(); final Module modifiedModule = PatchingTestUtil.createVersionModule(targetAsVersion); // Calculate the target hash of the currently active module final String currentLayerPatchID = "layer" + currentPatch; File originalVersionModulePath = new File(tempDir, currentPatch); originalVersionModulePath = new File(originalVersionModulePath, currentLayerPatchID); originalVersionModulePath = new File(originalVersionModulePath, Constants.MODULES); originalVersionModulePath = newFile(originalVersionModulePath, versionModuleName.split("\\.")); originalVersionModulePath = new File(originalVersionModulePath, ProductInfo.getVersionModuleSlot()); byte[] patchedAsVersionHash = HashUtils.hashFile(originalVersionModulePath); assert patchedAsVersionHash != null; final ResourceItem resourceItem1 = new ResourceItem("testFile1", "content1".getBytes()); final ResourceItem resourceItem2 = new ResourceItem("testFile2", "content2".getBytes()); Module newModule = new Module.Builder(moduleName).miscFile(resourceItem1).miscFile(resourceItem2).build(); ContentModification moduleAdded = ContentModificationUtils.addModule(cpPatchDir, layerPatchID, newModule); ContentModification versionModuleModified = ContentModificationUtils.modifyModule( cpPatchDir, layerPatchID, patchedAsVersionHash, modifiedModule); ProductConfig productConfig = new ProductConfig(PRODUCT, asVersion, "main"); Patch cpPatch = PatchBuilder.create() .setPatchId(patchID) .setDescription("A cp patch.") .upgradeIdentity( productConfig.getProductName(), productConfig.getProductVersion(), targetAsVersion) .getParent() .upgradeElement(layerPatchID, "base", false) .addContentModification(versionModuleModified) .addContentModification(moduleAdded) .getParent() .build(); createPatchXMLFile(cpPatchDir, cpPatch); return createZippedPatchFile(cpPatchDir, patchID, targetDir); }
private File createOneOffPatchAddingMiscFile(String patchID, String asVersion) throws Exception { File oneOffPatchDir = mkdir(tempDir, patchID); ContentModification miscFileAdded = ContentModificationUtils.addMisc( oneOffPatchDir, patchID, "test content", "awesomeDirectory", "awesomeFile"); ProductConfig productConfig = new ProductConfig(PRODUCT, asVersion, "main"); Patch oneOffPatch = PatchBuilder.create() .setPatchId(patchID) .setDescription("A one-off patch adding a misc file.") .oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()) .getParent() .addContentModification(miscFileAdded) .build(); createPatchXMLFile(oneOffPatchDir, oneOffPatch); return createZippedPatchFile(oneOffPatchDir, patchID); }