@Override public byte[] getMetadataHash() { try { if (cachedMetadataHash == null) { cachedMetadataHash = HashUtils.hashFile(file); } return cachedMetadataHash; } catch (IOException e) { throw processingError(e, "failed to generate hash"); } }
public static ContentModification modifyMisc(File patchDir, String patchElementID, String modifiedContent, File existingFile, String... fileSegments) throws IOException { byte[] existingHash = hashFile(existingFile); return modifyMisc(patchDir, patchElementID, modifiedContent, existingHash, fileSegments); }
public static ContentModification modifyModule(File patchDir, String patchElementID, File existingModule, String newContent) throws IOException { byte[] existingHash = hashFile(existingModule); return modifyModule(patchDir, patchElementID, existingModule.getName(), existingHash, newContent); }
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; }
static void assertDefinedBundle(File bundlesDir, String moduleName, byte[] expectedHash) throws Exception { final File bundlePath = PatchContentLoader.getModulePath(bundlesDir, moduleName, "main"); if(bundlePath.exists()) { if(expectedHash != null) { byte[] actualHash = hashFile(bundlePath); assertTrue("content of bundle differs", Arrays.equals(expectedHash, actualHash)); } } else { fail("content not found bundle for " + moduleName + " in " + bundlesDir); } }
public static void assertDefinedModule(File moduleRoot, String moduleName, byte[] expectedHash) throws Exception { final File modulePath = PatchContentLoader.getModulePath(moduleRoot, moduleName, "main"); final File moduleXml = new File(modulePath, "module.xml"); if (moduleXml.exists()) { assertDefinedModuleWithRootElement(moduleXml, moduleName, "<module"); if (expectedHash != null) { byte[] actualHash = hashFile(modulePath); assertTrue("content of module differs", Arrays.equals(expectedHash, actualHash)); } return; } fail("count not find module for " + moduleName + " in " + moduleRoot); }
@Before public void init() throws Exception { installLayers("layer1", "layer2"); final File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin"); standaloneSh = touch(binDir, "standalone.sh"); dump(standaloneSh, "original script to run standalone server"); originalStandaloneHash = hashFile(standaloneSh); addedByCP1 = new File(binDir, "added-by-cp1.txt"); addedByCP1RemovedByCP3 = new File(binDir, "added-by-cp1-removed-by-cp3.txt"); addedByCP2 = new File(binDir, "added-by-cp2.txt"); tool = newPatchTool(); }
protected void assertRestoredConfig(File baseDir, String xmlName, byte[] updatedHash, byte[] originalHash) throws IOException { File rolledBackXmlFile = assertFileExists(baseDir, "configuration", xmlName); assertEquals(bytesToHexString(updatedHash), bytesToHexString(hashFile(rolledBackXmlFile))); File restoredXmlFile = assertFileExists(baseDir, "configuration", "restored-configuration", xmlName); assertEquals(bytesToHexString(originalHash), bytesToHexString(hashFile(restoredXmlFile))); }
@Test public void testUpdateModifiedFileWithOVERRIDE_ALL() throws Exception { PatchingResult result = runner.applyPatch(zippedPatch, ContentVerificationPolicy.OVERRIDE_ALL); assertPatchHasBeenApplied(result, patch); /// file has been updated in the AS7 installation // and it's the new one assertFileExists(modifiedFile); assertArrayEquals(updatedHash, hashFile(modifiedFile)); // the existing file has been backed up File backupFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "misc", "bin", modifiedFile.getName()); assertArrayEquals(expectedModifiedHash, hashFile(backupFile)); }
@Before public void setUp() throws Exception { // with some files in the configuration directories File appClientXmlFile = touch(env.getInstalledImage().getAppClientDir(), "configuration", "appclient.xml"); dump(appClientXmlFile, "<original content of appclient configuration>"); originalAppClientHash = hashFile(appClientXmlFile); standaloneXmlFile = touch(env.getInstalledImage().getStandaloneDir(), "configuration", "standalone.xml"); dump(standaloneXmlFile, "<original content of standalone configuration>"); originalStandaloneHash = hashFile(standaloneXmlFile); File domainXmlFile = touch(env.getInstalledImage().getDomainDir(), "configuration", "domain.xml"); dump(domainXmlFile, "<original content of domain configuration>"); originalDomainHash = hashFile(domainXmlFile); }
@Before public void setUp() throws Exception { // with some files in the configuration directories appClientXmlFile = touch(env.getInstalledImage().getAppClientDir(), "configuration", "appclient.xml"); dump(appClientXmlFile, "<original content of appclient configuration>"); originalAppClientHash = hashFile(appClientXmlFile); standaloneXmlFile = touch(env.getInstalledImage().getStandaloneDir(), "configuration", "standalone.xml"); dump(standaloneXmlFile, "<original content of standalone configuration>"); originalStandaloneHash = hashFile(standaloneXmlFile); domainXmlFile = touch(env.getInstalledImage().getDomainDir(), "configuration", "domain.xml"); dump(domainXmlFile, "<original content of domain configuration>"); originalDomainHash = hashFile(domainXmlFile); }
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 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, 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 testUpdateModifiedFileWithPRESERVE_ALL() throws Exception { try { runner.applyPatch(zippedPatch, ContentVerificationPolicy.PRESERVE_ALL); } catch (ContentConflictsException e) { assertPatchHasNotBeenApplied(e, patch, fileUpdated.getItem(), env); /// file has not been modified in the AS7 installation assertFileExists(modifiedFile); assertArrayEquals(expectedModifiedHash, hashFile(modifiedFile)); } } }
@Test public void testUpdateModifiedFileWithSTRICT() throws Exception { try { runner.applyPatch(zippedPatch, ContentVerificationPolicy.STRICT); } catch (ContentConflictsException e) { assertPatchHasNotBeenApplied(e, patch, fileUpdated.getItem(), env); /// file has not been modified in the AS7 installation assertFileExists(modifiedFile); assertArrayEquals(expectedModifiedHash, hashFile(modifiedFile)); } }
@Test public void testRemovedModifiedFileWithOVERRIDE_ALL() throws Exception { PatchingResult result = runner.applyPatch(zippedPatch, ContentVerificationPolicy.OVERRIDE_ALL); assertPatchHasBeenApplied(result, patch); /// file has been removed from the AS7 installation // and it's the new one assertFileDoesNotExist(removedFile); // the existing file has been backed up File backupFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "misc", "bin", removedFile.getName()); assertArrayEquals(expectedModifiedHash, hashFile(backupFile)); }
@Test public void testRemoveModifiedFileWithSTRICT() throws Exception { try { runner.applyPatch(zippedPatch, ContentVerificationPolicy.STRICT); fail("Patch shouldn't be applied - ContentVerificationPolicy.STRICT"); } catch (ContentConflictsException e) { assertPatchHasNotBeenApplied(e, patch, fileRemoved.getItem(), env); /// file has not been modified in the AS7 installation assertFileExists(removedFile); assertArrayEquals(expectedModifiedHash, hashFile(removedFile)); } }
@Test public void testRemoveModifiedFileWithPRESERVE_ALL() throws Exception { try { runner.applyPatch(zippedPatch, ContentVerificationPolicy.PRESERVE_ALL); fail("Patch shouldn't be applied - ContentVerificationPolicy.PRESERVE_ALL"); } catch (ContentConflictsException e) { assertPatchHasNotBeenApplied(e, patch, fileRemoved.getItem(), env); /// file has not been modified in the AS7 installation assertFileExists(removedFile); assertArrayEquals(expectedModifiedHash, hashFile(removedFile)); } } }