static void doMarshall(final String fileName) throws Exception { final String original = toString(fileName); try (final InputStream is = getResource(fileName)) { final BundledPatch patch = PatchBundleXml.parse(is); final StringWriter writer = new StringWriter(); PatchBundleXml.marshal(writer, patch); final String marshalled = writer.toString(); XMLUtils.compareXml(original, marshalled, false); } }
public static BundledPatch parse(final InputStream stream) throws XMLStreamException { try { final XMLInputFactory inputFactory = INPUT_FACTORY; setIfSupported(inputFactory, XMLInputFactory.IS_VALIDATING, Boolean.FALSE); setIfSupported(inputFactory, XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); final XMLStreamReader streamReader = inputFactory.createXMLStreamReader(stream); // final PatchXml.Result<BundledPatch> result = new PatchXml.Result<BundledPatch>(); MAPPER.parseDocument(result, streamReader); return result.getResult(); } finally { safeClose(stream); } }
} else { is = patchZip.getInputStream(patchXmlEntry); final List<BundledPatchEntry> patches = PatchBundleXml.parse(is).getPatches(); displayPatchBundleXml(ctx, patches, patchZip);
public static void createPatchBundleXMLFile(File dir, final List<BundledPatch.BundledPatchEntry> patches) throws Exception { File bundleXMLFile = new File(dir, "patches.xml"); FileOutputStream fos = new FileOutputStream(bundleXMLFile); try { PatchBundleXml.marshal(fos, new BundledPatch() { @Override public List<BundledPatchEntry> getPatches() { return patches; } }); } finally { safeClose(fos); } }
} else { is = patchZip.getInputStream(patchXmlEntry); final List<BundledPatch.BundledPatchEntry> patches = PatchBundleXml.parse(is).getPatches(); displayPatchBundleXml(ctx, patches, patchZip);
final OutputStream os = new FileOutputStream(multiPatchXml); try { PatchBundleXml.marshal(os, new BundledPatch() { @Override public List<BundledPatchEntry> getPatches() {
} else { is = patchZip.getInputStream(patchXmlEntry); final List<BundledPatchEntry> patches = PatchBundleXml.parse(is).getPatches(); displayPatchBundleXml(ctx, patches, patchZip);
public static BundledPatch parse(final InputStream stream) throws XMLStreamException { try { final XMLInputFactory inputFactory = INPUT_FACTORY; setIfSupported(inputFactory, XMLInputFactory.IS_VALIDATING, Boolean.FALSE); setIfSupported(inputFactory, XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); final XMLStreamReader streamReader = inputFactory.createXMLStreamReader(stream); // final PatchXml.Result<BundledPatch> result = new PatchXml.Result<BundledPatch>(); MAPPER.parseDocument(result, streamReader); return result.getResult(); } finally { safeClose(stream); } }
} else { is = patchZip.getInputStream(patchXmlEntry); final List<BundledPatch.BundledPatchEntry> patches = PatchBundleXml.parse(is).getPatches(); displayPatchBundleXml(ctx, patches, patchZip);
protected PatchingResult execute(final File workDir, final ContentVerificationPolicy contentPolicy) throws PatchingException, IOException, XMLStreamException { final File patchBundleXml = new File(workDir, PatchBundleXml.MULTI_PATCH_XML); if (patchBundleXml.exists()) { final InputStream patchIs = new FileInputStream(patchBundleXml); try { // Handle multi patch installs final BundledPatch bundledPatch = PatchBundleXml.parse(patchIs); return applyPatchBundle(workDir, bundledPatch, contentPolicy); } finally { safeClose(patchIs); } } else { // Parse the xml File patchXml = new File(workDir, PatchXml.PATCH_XML); PatchMetadataResolver patchResolver = parsePatchXml(patchXml); Patch patch = patchResolver.resolvePatch(null, null); final InstalledIdentity installedIdentity = manager.getInstalledIdentity(patch.getIdentity().getName(), null); final String currentVersion = installedIdentity.getIdentity().getVersion(); if(!Constants.UNKNOWN.equals(currentVersion) && !patch.getIdentity().getVersion().equals(currentVersion)) { patchXml = new File(workDir, currentVersion + PatchMerger.PATCH_XML_SUFFIX); if(!patchXml.exists()) { throw new PatchingException("The patch does not contain metadata for currently installed " + patch.getIdentity().getName() + " version " + currentVersion); } patchResolver = parsePatchXml(patchXml); patch = patchResolver.resolvePatch(null, null); } return apply(patchResolver, PatchContentProvider.DefaultContentProvider.create(workDir), contentPolicy); } }
protected PatchingResult execute(final File workDir, final ContentVerificationPolicy contentPolicy) throws PatchingException, IOException, XMLStreamException { final File patchBundleXml = new File(workDir, PatchBundleXml.MULTI_PATCH_XML); if (patchBundleXml.exists()) { final InputStream patchIs = new FileInputStream(patchBundleXml); try { // Handle multi patch installs final BundledPatch bundledPatch = PatchBundleXml.parse(patchIs); return applyPatchBundle(workDir, bundledPatch, contentPolicy); } finally { safeClose(patchIs); } } else { // Parse the xml File patchXml = new File(workDir, PatchXml.PATCH_XML); PatchMetadataResolver patchResolver = parsePatchXml(patchXml); Patch patch = patchResolver.resolvePatch(null, null); final InstalledIdentity installedIdentity = manager.getInstalledIdentity(patch.getIdentity().getName(), null); final String currentVersion = installedIdentity.getIdentity().getVersion(); if(!Constants.UNKNOWN.equals(currentVersion) && !patch.getIdentity().getVersion().equals(currentVersion)) { patchXml = new File(workDir, currentVersion + PatchMerger.PATCH_XML_SUFFIX); if(!patchXml.exists()) { throw new PatchingException("The patch does not contain metadata for currently installed " + patch.getIdentity().getName() + " version " + currentVersion); } patchResolver = parsePatchXml(patchXml); patch = patchResolver.resolvePatch(null, null); } return apply(patchResolver, PatchContentProvider.DefaultContentProvider.create(workDir), contentPolicy); } }
@Test public void testBasic() throws Exception { try (final InputStream is = getResource("multi-patch-01.xml")) { final BundledPatch bundledPatch = PatchBundleXml.parse(is); Assert.assertNotNull(bundledPatch); Assert.assertFalse(bundledPatch.getPatches().isEmpty()); } }