public static List<String> readRefs(final Properties properties) { return readRefs(properties, Constants.PATCHES); }
public static byte[] getAbsentModuleContentHash(final ModuleItem item) throws IOException { final byte[] content = getAbsentModuleContent(item); return HashUtils.hashBytes(content); } }
public void renameFiles() throws IOException { List<String> failures = PatchUtils.readRefs(renamingFailureMarker); for(String path : failures) { File toBeRenamed = new File(path); if(toBeRenamed.exists()) { if(!toBeRenamed.renameTo(PatchUtils.getRenamedFileName(toBeRenamed))) { log.cannotDeleteFile(path); } } } renamingFailureMarker.delete(); } }
public static TargetInfo loadTargetInfo(final Properties properties, final DirectoryStructure structure) { final String ref = PatchUtils.readRef(properties, Constants.CUMULATIVE); final List<String> patches = PatchUtils.readRefs(properties); return new TargetInfoImpl(properties, ref, patches, structure); }
protected void persist(final String cumulativeID, final List<String> patches, final Properties properties) throws IOException { assert cumulativeID != null; // Create the parent IoUtils.mkdir(structure.getInstallationInfo().getParentFile()); final List<String> consolidate = new ArrayList<String>(); consolidate.addAll(patches); if (!Constants.BASE.equals(cumulativeID)) { consolidate.add(cumulativeID); } if (structure.getModuleRoot() != null) { final File overlays = new File(structure.getModuleRoot(), Constants.OVERLAYS); final File refs = new File(overlays, Constants.OVERLAYS); PatchUtils.writeRefs(refs, consolidate); } // Update the properties properties.put(Constants.CUMULATIVE, cumulativeID); properties.put(Constants.PATCHES, PatchUtils.asString(patches)); if(version != null) { properties.put(Constants.CURRENT_VERSION, version); } // Write layer.conf PatchUtils.writeProperties(structure.getInstallationInfo(), properties); }
final Properties properties = PatchUtils.loadProperties(identity.getDirectoryStructure().getInstallationInfo()); final List<String> allPatches = PatchUtils.readRefs(properties, Constants.ALL_PATCHES);
@Override public File[] getTargetModulePath() { // We need the updated state for invalidating one-off patches // When applying the overlay directory should not exist yet final PatchableTarget.TargetInfo updated = mode == Mode.APPLY ? delegate : delegate.getModifiedState(); return PatchUtils.getModulePath(delegate.getDirectoryStructure(), updated); }
@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()); }
@Override public void finishPatch(final Patch processedPatch, final RollbackPatch rollbackPatch, final IdentityPatchContext context) throws Exception { final File historyDir = structure.getInstalledImage().getPatchHistoryDir(patchId); if (!historyDir.exists()) { historyDir.mkdirs(); } // Backup the current active patch Info final File timestamp = new File(historyDir, Constants.TIMESTAMP); PatchUtils.writeRef(timestamp, generateTimestamp()); // Persist the processed patch, which contains the records of changes final File backupPatchXml = new File(historyDir, PatchXml.PATCH_XML); IdentityPatchContext.writePatch(processedPatch, backupPatchXml); // Persist the rollback.xml in the history directory final File rollbackPatchXml = new File(historyDir, Constants.ROLLBACK_XML); IdentityPatchContext.writePatch(rollbackPatch, rollbackPatchXml); // Backup the configuration context.backupConfiguration(); }
static String readRef(final InputStream is) throws IOException { final StringBuffer buffer = new StringBuffer(); readLine(is, buffer); return buffer.toString(); }
@Override protected void persist() throws IOException { getMutableProperties().put(Constants.ALL_PATCHES, PatchUtils.asString(allPatches)); super.persist(); }
private static void backup(final IdentityPatchContext context, final File file) { String fileName = file.getName(); if (fileName.endsWith(JAR_EXT)) { File targetFile = PatchUtils.getRenamedFileName(file); if (!file.renameTo(targetFile)) { if (context != null) { context.failedToRenameFile(file, targetFile); } else { throw PatchLogger.ROOT_LOGGER.cannotRenameFileDuringBackup(file.getAbsolutePath()); } } } }
/** * Process the layers.conf file. * * @param repoRoot the root * @return the layers conf * @throws java.io.IOException */ public static LayersConfig getLayersConfig(final File repoRoot) throws IOException { final File layersList = new File(repoRoot, LAYERS_CONF); if (!layersList.exists()) { return new LayersConfig(); } final Properties properties = PatchUtils.loadProperties(layersList); return new LayersConfig(properties); }
@Override public File[] getTargetBundlePath() { // We need the updated state for invalidating one-off patches // When applying the overlay directory should not exist yet final PatchableTarget.TargetInfo updated = mode == Mode.APPLY ? delegate : delegate.getModifiedState(); return PatchUtils.getBundlePath(delegate.getDirectoryStructure(), updated); }
public static TargetInfo loadTargetInfo(final Properties properties, final DirectoryStructure structure) { final String ref = PatchUtils.readRef(properties, Constants.CUMULATIVE); final List<String> patches = PatchUtils.readRefs(properties); return new TargetInfoImpl(properties, ref, patches, structure); }
protected void persist(final String cumulativeID, final List<String> patches, final Properties properties) throws IOException { assert cumulativeID != null; // Create the parent IoUtils.mkdir(structure.getInstallationInfo().getParentFile()); final List<String> consolidate = new ArrayList<String>(); consolidate.addAll(patches); if (!Constants.BASE.equals(cumulativeID)) { consolidate.add(cumulativeID); } if (structure.getModuleRoot() != null) { final File overlays = new File(structure.getModuleRoot(), Constants.OVERLAYS); final File refs = new File(overlays, Constants.OVERLAYS); PatchUtils.writeRefs(refs, consolidate); } // Update the properties properties.put(Constants.CUMULATIVE, cumulativeID); properties.put(Constants.PATCHES, PatchUtils.asString(patches)); if(version != null) { properties.put(Constants.CURRENT_VERSION, version); } // Write layer.conf PatchUtils.writeProperties(structure.getInstallationInfo(), properties); }
final Properties properties = PatchUtils.loadProperties(identity.getDirectoryStructure().getInstallationInfo()); final List<String> allPatches = PatchUtils.readRefs(properties, Constants.ALL_PATCHES);
@Override public File[] getTargetModulePath() { // We need the updated state for invalidating one-off patches // When applying the overlay directory should not exist yet final PatchableTarget.TargetInfo updated = mode == Mode.APPLY ? delegate : delegate.getModifiedState(); return PatchUtils.getModulePath(delegate.getDirectoryStructure(), updated); }
if(cp2Type.equals(ModificationType.REMOVE)) { try { elementBuilder.addModule(module.getName(), module.getSlot(), PatchUtils.getAbsentModuleContentHash(module)); } catch (IOException e) { throw new PatchingException("Failed to calculate hash for the removed module " + module.getName(), e);
@Override public void finishPatch(final Patch processedPatch, final RollbackPatch rollbackPatch, final IdentityPatchContext context) throws Exception { final File historyDir = structure.getInstalledImage().getPatchHistoryDir(patchId); if (!historyDir.exists()) { historyDir.mkdirs(); } // Backup the current active patch Info final File timestamp = new File(historyDir, Constants.TIMESTAMP); PatchUtils.writeRef(timestamp, generateTimestamp()); // Persist the processed patch, which contains the records of changes final File backupPatchXml = new File(historyDir, PatchXml.PATCH_XML); IdentityPatchContext.writePatch(processedPatch, backupPatchXml); // Persist the rollback.xml in the history directory final File rollbackPatchXml = new File(historyDir, Constants.ROLLBACK_XML); IdentityPatchContext.writePatch(rollbackPatch, rollbackPatchXml); // Backup the configuration context.backupConfiguration(); }