static PatchingTaskDescription create(final PatchingTasks.ContentTaskDefinition definition, final PatchContentLoader loader) { final ContentModification modification = resolveDefinition(definition); // Check if we already have the new content final ContentItem item = definition.getTarget().getItem(); final byte[] currentHash = definition.getLatest().getTargetHash(); final byte[] newContentHash = item.getContentHash(); boolean skipIfExists = Arrays.equals(currentHash, newContentHash); return new PatchingTaskDescription(definition.getTarget().getPatchId(), modification, loader, definition.hasConflicts(), skipIfExists, definition.isRollback()); }
ContentTaskDefinition definition = modifications.get(location); if (definition == null) { definition = new ContentTaskDefinition(location, contentEntry, true); modifications.put(location, definition); } else { if (strict) { final ContentEntry previous = definition.getTarget(); final byte[] hash = previous.getItem().getContentHash(); if (!Arrays.equals(hash, contentEntry.getTargetHash())) { definition.setTarget(contentEntry); definition.addConflict(contentEntry); } else { definition.addConflict(contentEntry);
ContentTaskDefinition definition = modifications.get(location); if (definition == null) { definition = new ContentTaskDefinition(location, contentEntry, true); modifications.put(location, definition); } else { if (strict) { final ContentEntry previous = definition.getTarget(); final byte[] hash = previous.getItem().getContentHash(); if (!Arrays.equals(hash, contentEntry.getTargetHash())) { definition.setTarget(contentEntry); definition.addConflict(contentEntry); } else { definition.addConflict(contentEntry);
/** * Prepare all tasks. * * @param entry the patch entry * @param context the patch context * @param tasks a list for prepared tasks * @param conflicts a list for conflicting content items * @throws PatchingException */ static void prepareTasks(final IdentityPatchContext.PatchEntry entry, final IdentityPatchContext context, final List<PreparedTask> tasks, final List<ContentItem> conflicts) throws PatchingException { for (final PatchingTasks.ContentTaskDefinition definition : entry.getTaskDefinitions()) { final PatchingTask task = createTask(definition, context, entry); if(!task.isRelevant(entry)) { continue; } try { // backup and validate content if (!task.prepare(entry) || definition.hasConflicts()) { // Unless it a content item was manually ignored (or excluded) final ContentItem item = task.getContentItem(); if (!context.isIgnored(item)) { conflicts.add(item); } } tasks.add(new PreparedTask(task, entry)); } catch (IOException e) { throw new PatchingException(e); } } }
/** * Prepare all tasks. * * @param entry the patch entry * @param context the patch context * @param tasks a list for prepared tasks * @param conflicts a list for conflicting content items * @throws PatchingException */ static void prepareTasks(final IdentityPatchContext.PatchEntry entry, final IdentityPatchContext context, final List<PreparedTask> tasks, final List<ContentItem> conflicts) throws PatchingException { for (final PatchingTasks.ContentTaskDefinition definition : entry.getTaskDefinitions()) { final PatchingTask task = createTask(definition, context, entry); if(!task.isRelevant(entry)) { continue; } try { // backup and validate content if (!task.prepare(entry) || definition.hasConflicts()) { // Unless it a content item was manually ignored (or excluded) final ContentItem item = task.getContentItem(); if (!context.isIgnored(item)) { conflicts.add(item); } } tasks.add(new PreparedTask(task, entry)); } catch (IOException e) { throw new PatchingException(e); } } }
/** * Apply modifications to a content task definition. * * @param patchId the patch id * @param modifications the modifications * @param definitions the task definitions * @param filter the content item filter */ static void apply(final String patchId, final Collection<ContentModification> modifications, final PatchEntry patchEntry, final ContentItemFilter filter) { for (final ContentModification modification : modifications) { final ContentItem item = modification.getItem(); // Check if we accept the item if (!filter.accepts(item)) { continue; } final Location location = new Location(item); final ContentEntry contentEntry = new ContentEntry(patchId, modification); ContentTaskDefinition definition = patchEntry.get(location); if (definition == null) { definition = new ContentTaskDefinition(location, contentEntry, false); patchEntry.put(location, definition); } else { definition.setTarget(contentEntry); } } }
@Test public void testOverrideExisting() throws Exception { // content-item 'two' replacing 'four', originally targeting 'one' final RollbackInfo patch01 = createRollbackInfo("patch01", two, one, four, two); // content-item 'three' replacing 'two' final RollbackInfo patch02 = createRollbackInfo("patch02", three, two); // [patch-two, patch-one] final ContentTaskDefinitions defs = process(patch02, patch01); Assert.assertEquals(1, defs.size()); final PatchingTasks.ContentTaskDefinition def = defs.get(new Location(new MiscContentItem(name, path, one))); Assert.assertNotNull(def); Assert.assertTrue(def.hasConflicts()); // We want to restore four (from the backup) Assert.assertEquals(four, def.getTarget().getItem().getContentHash()); // The original target was two Assert.assertEquals(two, def.getTarget().getTargetHash()); // The current content however is three Assert.assertEquals(three, def.getLatest().getTargetHash()); // And originally replaced two Assert.assertEquals(two, def.getLatest().getItem().getContentHash()); // The resulting operation should replace 'three' with 'four' final ContentModification modification = PatchingTaskDescription.resolveDefinition(def); Assert.assertEquals(four, modification.getItem().getContentHash()); Assert.assertEquals(three, modification.getTargetHash()); }
/** * Apply modifications to a content task definition. * * @param patchId the patch id * @param modifications the modifications * @param definitions the task definitions * @param filter the content item filter */ static void apply(final String patchId, final Collection<ContentModification> modifications, final PatchEntry patchEntry, final ContentItemFilter filter) { for (final ContentModification modification : modifications) { final ContentItem item = modification.getItem(); // Check if we accept the item if (!filter.accepts(item)) { continue; } final Location location = new Location(item); final ContentEntry contentEntry = new ContentEntry(patchId, modification); ContentTaskDefinition definition = patchEntry.get(location); if (definition == null) { definition = new ContentTaskDefinition(location, contentEntry, false); patchEntry.put(location, definition); } else { definition.setTarget(contentEntry); } } }
@Test public void testSimple() throws Exception { // content-item 'two' replacing 'one' final RollbackInfo patch01 = createRollbackInfo("patch01", two, one); // content-item 'three' replacing 'two' final RollbackInfo patch02 = createRollbackInfo("patch02", three, two); // [patch-two, patch-one] final ContentTaskDefinitions defs = process(patch02, patch01); Assert.assertEquals(1, defs.size()); final PatchingTasks.ContentTaskDefinition def = defs.get(new Location(new MiscContentItem(name, path, one))); Assert.assertNotNull(def); Assert.assertFalse(def.hasConflicts()); // We want to restore one (from the backup) Assert.assertEquals(one, def.getTarget().getItem().getContentHash()); // The original target was two Assert.assertEquals(two, def.getTarget().getTargetHash()); // The current content however is three Assert.assertEquals(three, def.getLatest().getTargetHash()); // And originally replaced two Assert.assertEquals(two, def.getLatest().getItem().getContentHash()); // The resulting operation should replace 'three' with 'one' final ContentModification modification = PatchingTaskDescription.resolveDefinition(def); Assert.assertEquals(one, modification.getItem().getContentHash()); Assert.assertEquals(three, modification.getTargetHash()); }
@Test public void testPreserveExisting() throws Exception { // content-item 'two' replacing 'one', but kept 'four' final RollbackInfo patch01 = createRollbackInfo("patch01", two, one, four, four); // content-item 'three' replacing 'two' final RollbackInfo patch02 = createRollbackInfo("patch02", three, four); // [patch-two, patch-one] final ContentTaskDefinitions defs = process(patch02, patch01); Assert.assertEquals(1, defs.size()); final PatchingTasks.ContentTaskDefinition def = defs.get(new Location(new MiscContentItem(name, path, one))); Assert.assertNotNull(def); Assert.assertTrue(def.hasConflicts()); // We want to got back to four Assert.assertEquals(four, def.getTarget().getItem().getContentHash()); // The recorded action was preserving four Assert.assertEquals(four, def.getTarget().getTargetHash()); // The current content however is three Assert.assertEquals(three, def.getLatest().getTargetHash()); // And originally replaced four Assert.assertEquals(four, def.getLatest().getItem().getContentHash()); // The resulting operation should replace 'three' with 'four' final ContentModification modification = PatchingTaskDescription.resolveDefinition(def); Assert.assertEquals(four, modification.getItem().getContentHash()); Assert.assertEquals(three, modification.getTargetHash()); }
static void addMissingModifications(IdentityPatchContext.PatchEntry target, Collection<ContentModification> modifications, final ContentItemFilter filter) throws IOException { final String cpId = target.getCumulativePatchID(); for (final ContentModification modification : modifications) { final ContentItem item = modification.getItem(); // Check if we accept the item if (!filter.accepts(item)) { continue; } final Location location = new Location(item); final ContentTaskDefinition definition = target.get(location); if (definition == null) { target.put(location, new ContentTaskDefinition(location, new ContentEntry(cpId, modification), false)); } else if(definition.isRollback()) { target.prepareForPortForward(item, cpId); definition.setTarget(new ContentEntry(cpId, modification)); } } }
static void addMissingModifications(IdentityPatchContext.PatchEntry target, Collection<ContentModification> modifications, final ContentItemFilter filter) throws IOException { final String cpId = target.getCumulativePatchID(); for (final ContentModification modification : modifications) { final ContentItem item = modification.getItem(); // Check if we accept the item if (!filter.accepts(item)) { continue; } final Location location = new Location(item); final ContentTaskDefinition definition = target.get(location); if (definition == null) { target.put(location, new ContentTaskDefinition(location, new ContentEntry(cpId, modification), false)); } else if(definition.isRollback()) { target.prepareForPortForward(item, cpId); definition.setTarget(new ContentEntry(cpId, modification)); } } }
/** * Create the patching task based on the definition. * * @param definition the task description * @param provider the content provider * @param context the task context * @return the created task */ static PatchingTask createTask(final PatchingTasks.ContentTaskDefinition definition, final PatchContentProvider provider, final IdentityPatchContext.PatchEntry context) { final PatchContentLoader contentLoader = provider.getLoader(definition.getTarget().getPatchId()); final PatchingTaskDescription description = PatchingTaskDescription.create(definition, contentLoader); return PatchingTask.Factory.create(description, context); }
/** * Create the patching task based on the definition. * * @param definition the task description * @param provider the content provider * @param context the task context * @return the created task */ static PatchingTask createTask(final PatchingTasks.ContentTaskDefinition definition, final PatchContentProvider provider, final IdentityPatchContext.PatchEntry context) { final PatchContentLoader contentLoader = provider.getLoader(definition.getTarget().getPatchId()); final PatchingTaskDescription description = PatchingTaskDescription.create(definition, contentLoader); return PatchingTask.Factory.create(description, context); }
static ContentModification resolveDefinition(final PatchingTasks.ContentTaskDefinition definition) { // Only available in a single patch, yay! if(definition.getLatest() == definition.getTarget()) { return definition.getTarget().getModification(); } // Create a new modification replacing the latest final ContentItem backupItem = definition.getTarget().getItem(); final ContentModification modification = definition.getTarget().getModification(); final byte[] target = definition.getLatest().getTargetHash(); return new ContentModification(backupItem, target, modification.getType(), modification.getCondition()); }
protected void reenableRolledBackInBase(final IdentityPatchContext.PatchEntry target) throws IOException { for(ContentTaskDefinition def : target.getTaskDefinitions()) { if(def.isRollback()) { final ContentItem item = def.getTarget().getItem(); if(item.getContentType() == ContentType.MODULE) { target.reenableBaseModule((ModuleItem)item); } } } }
protected void reenableRolledBackInBase(final IdentityPatchContext.PatchEntry target) throws IOException { for(ContentTaskDefinition def : target.getTaskDefinitions()) { if(def.isRollback()) { final ContentItem item = def.getTarget().getItem(); if(item.getContentType() == ContentType.MODULE) { target.reenableBaseModule((ModuleItem)item); } } } }
static ContentModification resolveDefinition(final PatchingTasks.ContentTaskDefinition definition) { // Only available in a single patch, yay! if(definition.getLatest() == definition.getTarget()) { return definition.getTarget().getModification(); } // Create a new modification replacing the latest final ContentItem backupItem = definition.getTarget().getItem(); final ContentModification modification = definition.getTarget().getModification(); final byte[] target = definition.getLatest().getTargetHash(); return new ContentModification(backupItem, target, modification.getType(), modification.getCondition()); }
static PatchingTaskDescription create(final PatchingTasks.ContentTaskDefinition definition, final PatchContentLoader loader) { final ContentModification modification = resolveDefinition(definition); // Check if we already have the new content final ContentItem item = definition.getTarget().getItem(); final byte[] currentHash = definition.getLatest().getTargetHash(); final byte[] newContentHash = item.getContentHash(); boolean skipIfExists = Arrays.equals(currentHash, newContentHash); return new PatchingTaskDescription(definition.getTarget().getPatchId(), modification, loader, definition.hasConflicts(), skipIfExists, definition.isRollback()); }