/** * Get the target entry for a given patch element. * * @param element the patch element * @return the patch entry * @throws PatchingException */ protected PatchEntry resolveForElement(final PatchElement element) throws PatchingException { assert state == State.NEW; final PatchElementProvider provider = element.getProvider(); final String layerName = provider.getName(); final LayerType layerType = provider.getLayerType(); final Map<String, PatchEntry> map; if (layerType == LayerType.Layer) { map = layers; } else { map = addOns; } PatchEntry entry = map.get(layerName); if (entry == null) { final InstallationManager.MutablePatchingTarget target = modification.resolve(layerName, layerType); if (target == null) { throw PatchMessages.MESSAGES.noSuchLayer(layerName); } entry = new PatchEntry(target, element); map.put(layerName, entry); } // Maintain the most recent element entry.updateElement(element); return entry; }
/** * Backup all xml files in a given directory. * * @param source the source directory * @param target the target directory * @throws IOException for any error */ static void backupDirectory(final File source, final File target) throws IOException { if (!target.exists()) { if (!target.mkdirs()) { throw PatchMessages.MESSAGES.cannotCreateDirectory(target.getAbsolutePath()); } } final File[] files = source.listFiles(CONFIG_FILTER); for (final File file : files) { final File t = new File(target, file.getName()); IoUtils.copyFile(file, t); } }
/** * Write the patch.xml * * @param rollbackPatch the patch * @param file the target file * @throws IOException */ static void writePatch(final Patch rollbackPatch, final File file) throws IOException { final File parent = file.getParentFile(); if (!parent.isDirectory()) { if (!parent.mkdirs() && !parent.exists()) { throw PatchMessages.MESSAGES.cannotCreateDirectory(file.getAbsolutePath()); } } try { final OutputStream os = new FileOutputStream(file); try { PatchXml.marshal(os, rollbackPatch); } finally { IoUtils.safeClose(os); } } catch (XMLStreamException e) { throw new IOException(e); } }