public static Patch merge(Patch cp1, Patch cp2) throws PatchingException { return merge(cp1, cp2, true); }
static File createTempDir() throws PatchingException { return createTempDir(TEMP_DIR); }
public static File merge(File patch1, File patch2, File merged) throws PatchingException { final File workDir = createTempDir(); final File patch1Dir = expandContent(patch1, workDir, "patch1"); final File patch2Dir = expandContent(patch2, workDir, "patch2"); final File mergedDir = new File(workDir, "merged"); final Patch patch1Metadata = parsePatchXml(patch1Dir, patch1); final Patch patch2Metadata = parsePatchXml(patch2Dir, patch2); final Patch mergedMetadata = merge(patch1Metadata, patch2Metadata); patch = merge(patch, patch2Metadata); copyFile(new File(patch2Dir, PatchXml.PATCH_XML), new File(mergedDir, patch2Metadata.getIdentity().getVersion() + PATCH_XML_SUFFIX)); mergeRootContent(new File(patch1Dir, patch1Metadata.getPatchId()), new File(patch2Dir, patch2Metadata.getPatchId()), new File(mergedDir, patch2Metadata.getPatchId())); } catch (IOException e) { mergeElementContent(patch1Dir, patch2Dir, mergedDir, patch1Metadata, patch2Metadata); } catch (IOException e) { throw new PatchingException("Failed to merge element modifications", e);
final Identity.IdentityUpgrade cp2Identity = cp2.getIdentity().forType(Patch.PatchType.CUMULATIVE, Identity.IdentityUpgrade.class); assertUpgrade(cp1Identity.getPatchType()); assertUpgrade(cp2Identity.getPatchType()); for (PatchElement pe : cp2.getElements()) { final PatchElementProvider provider = pe.getProvider(); assertUpgrade(provider.getPatchType()); if (provider.isAddOn()) { cp2AddonElements.put(provider.getName(), pe); assertUpgrade(provider.getPatchType()); final PatchElement cp2El; if (provider.isAddOn()) { provider.isAddOn()).setDescription(cp2El.getDescription()); mergeModifications(elementBuilder, cp1El.getModifications(), cp2El.getModifications(), cp1, cp2); mergeModifications(builder, cp1.getModifications(), cp2.getModifications(), cp1, cp2);
final ContentModification cp2Mod = cp2Mods.remove(cp1Mod.getItem()); if (cp2Mod == null) { copyModificationContent(patch1Dir, e1.getId(), mergedDir, e2.getId(), cp1Mod); } else { copyModificationContent(patch2Dir, e2.getId(), mergedDir, e2.getId(), cp2Mod); copyModificationContent(patch2Dir, e2.getId(), mergedDir, e2.getId(), cp2Mod);
public static File merge(File patch1, File patch2, File merged) throws PatchingException { final File workDir = createTempDir(); final File patch1Dir = expandContent(patch1, workDir, "patch1"); final File patch2Dir = expandContent(patch2, workDir, "patch2"); final File mergedDir = new File(workDir, "merged"); final Patch patch1Metadata = parsePatchXml(patch1Dir, patch1); final Patch patch2Metadata = parsePatchXml(patch2Dir, patch2); final Patch mergedMetadata = merge(patch1Metadata, patch2Metadata); patch = merge(patch, patch2Metadata); copyFile(new File(patch2Dir, PatchXml.PATCH_XML), new File(mergedDir, patch2Metadata.getIdentity().getVersion() + PATCH_XML_SUFFIX)); mergeRootContent(new File(patch1Dir, patch1Metadata.getPatchId()), new File(patch2Dir, patch2Metadata.getPatchId()), new File(mergedDir, patch2Metadata.getPatchId())); } catch (IOException e) { mergeElementContent(patch1Dir, patch2Dir, mergedDir, patch1Metadata, patch2Metadata); } catch (IOException e) { throw new PatchingException("Failed to merge element modifications", e);
final Identity.IdentityUpgrade cp2Identity = cp2.getIdentity().forType(Patch.PatchType.CUMULATIVE, Identity.IdentityUpgrade.class); assertUpgrade(cp1Identity.getPatchType()); assertUpgrade(cp2Identity.getPatchType()); for (PatchElement pe : cp2.getElements()) { final PatchElementProvider provider = pe.getProvider(); assertUpgrade(provider.getPatchType()); if (provider.isAddOn()) { cp2AddonElements.put(provider.getName(), pe); assertUpgrade(provider.getPatchType()); final PatchElement cp2El; if (provider.isAddOn()) { provider.isAddOn()).setDescription(cp2El.getDescription()); mergeModifications(elementBuilder, cp1El.getModifications(), cp2El.getModifications(), cp1, cp2); mergeModifications(builder, cp1.getModifications(), cp2.getModifications(), cp1, cp2);
final ContentModification cp2Mod = cp2Mods.remove(cp1Mod.getItem()); if (cp2Mod == null) { copyModificationContent(patch1Dir, e1.getId(), mergedDir, e2.getId(), cp1Mod); } else { copyModificationContent(patch2Dir, e2.getId(), mergedDir, e2.getId(), cp2Mod); copyModificationContent(patch2Dir, e2.getId(), mergedDir, e2.getId(), cp2Mod);
public static Patch merge(Patch cp1, Patch cp2) throws PatchingException { return merge(cp1, cp2, true); }
static File createTempDir() throws PatchingException { return createTempDir(TEMP_DIR); }
PatchMerger.merge(previousCp, tmp, patchFile); } else { ZipUtils.zip(tmp, patchFile);
@Test public void testAddRemove() throws Exception { final Patch cp1 = generateCP("base", "cp1", ModificationType.ADD); final Patch cp2 = generateCP("cp1", "cp2", ModificationType.REMOVE); final Patch merged = PatchMerger.merge(cp1, cp2); assertEquals("cp2", merged.getPatchId()); assertEquals("cp2" + " description", merged.getDescription()); final IdentityUpgrade identity = merged.getIdentity().forType(PatchType.CUMULATIVE, Identity.IdentityUpgrade.class); assertEquals("base", identity.getVersion()); assertEquals("cp2", identity.getResultingVersion()); assertEquals(PatchType.CUMULATIVE, identity.getPatchType()); final List<PatchElement> elements = merged.getElements(); assertEquals(1, elements.size()); final PatchElement e = elements.get(0); assertEquals("base-" + "cp2", e.getId()); final PatchElementProvider provider = e.getProvider(); assertEquals("base", provider.getName()); assertEquals(PatchType.CUMULATIVE, provider.getPatchType()); assertEquals(LayerType.Layer, provider.getLayerType()); //assertEquals(0, e.getModifications().size()); // for modules remove is effectively a modify which changes the module xml to indicate an absent module // so, it will remain an add of an absent module assertEquals(1, e.getModifications().size()); final ContentModification mod = e.getModifications().iterator().next(); assertEquals(ModificationType.ADD, mod.getType()); Assert.assertArrayEquals(PatchUtils.getAbsentModuleContentHash((ModuleItem) mod.getItem()), mod.getItem().getContentHash()); }
final Patch merged = PatchMerger.merge(cp1, cp2);
final Patch merged = PatchMerger.merge(cp1, cp2);
final Patch merged = PatchMerger.merge(cp1, cp2);
final Patch merged = PatchMerger.merge(cp1, cp2);