org.eclipse.emf.compare.ide.ui.internal.logical

## Class EMFResourceMappingMerger

- java.lang.Object
- - org.eclipse.emf.compare.ide.ui.internal.logical.EMFResourceMappingMerger

All Implemented Interfaces:
  org.eclipse.team.core.mapping.IResourceMappingMerger

Direct Known Subclasses:
  AdditiveResourceMappingMerger

    public class EMFResourceMappingMerger
    extends Object
    implements org.eclipse.team.core.mapping.IResourceMappingMerger

A customized merger for the `EMFResourceMapping`s. This will use EMF Compare to recompute the logical model of the mappings it needs to merge, then merge everything to the left model if there are no conflicts, stopping dead if there is any conflict.

Mapping mergers are usually retrieved through an adapter registered on the ModelProvider. In this case, `org.eclipse.core.runtime.Platform.getAdapterManager().getAdapter(emfModelProvider, IResourceMappingMerger.class)` .

See Also:
  `EMFLogicalModelAdapterFactory`

### Nested Class Summary

Nested Classes
`protected static class` `EMFResourceMappingMerger.ResourceAdditionAndDeletionTracker`

### Field Summary

Fields
`protected static IMerger.Registry2` `MERGER_REGISTRY` The merger registry.

### Constructor Summary

Constructors
Constructor and Description
`EMFResourceMappingMerger()`

### Method Summary

All Methods Instance Methods Concrete Methods
`protected Set<URI>` `collectConflictingResources(Iterator<Diff> diffIterator)` Iterates over the given diffs to collect the resources they impact.

`protected void`

`delegateMergeOfUnmergedResourcesAndMarkDiffsAsMerged(SynchronizationModel syncModel, org.eclipse.team.core.mapping.IMergeContext mergeContext, EMFResourceMappingMerger.ResourceAdditionAndDeletionTracker resourceTracker, org.eclipse.core.runtime.SubMonitor subMonitor)`
Delegates the merge of so far non-merged resource additions and deletions and marks all other already merged resources as merged.

`protected void` `doMergeForDiff(Monitor emfMonitor, Set<URI> conflictingURIs, Diff diff)`
`org.eclipse.core.runtime.jobs.ISchedulingRule` `getMergeRule(org.eclipse.team.core.mapping.IMergeContext context)`
`protected void` `markAsMerged(org.eclipse.team.core.diff.IDiff diff, org.eclipse.team.core.mapping.IMergeContext mergeContext, org.eclipse.core.runtime.SubMonitor subMonitor)` Marks the given `diff` as merged.
`protected void` `markResourcesAsMerged(org.eclipse.team.core.mapping.IMergeContext context, Set<org.eclipse.core.resources.IResource> resources, Set<URI> conflictingURIs, org.eclipse.core.runtime.SubMonitor subMonitor)` Marks the resources as merged if their URIs are not included in the given set of known `conflictingURIs`.
`protected void` `merge(org.eclipse.team.core.diff.IDiff diff, org.eclipse.team.core.mapping.IMergeContext mergeContext, org.eclipse.core.runtime.SubMonitor subMonitor)` Merges the given `diff`.
`org.eclipse.core.runtime.IStatus` `merge(org.eclipse.team.core.mapping.IMergeContext mergeContext, org.eclipse.core.runtime.IProgressMonitor monitor)`
`protected void` `mergeMapping(org.eclipse.core.resources.mapping.ResourceMapping mapping, org.eclipse.team.core.mapping.IMergeContext mergeContext, Set<org.eclipse.core.resources.mapping.ResourceMapping> failingMappings, org.eclipse.core.runtime.IProgressMonitor monitor)` Merges one mapping.
`protected void` `removeNonExistingStorages(StorageTraversal traversal)` Removes storages that do not exist from the specified `traversal`.
`protected void` `save(Notifier notifier, StorageTraversal leftTraversal, StorageTraversal rightTraversal, StorageTraversal originTraversal)` Saves the given notifier to disk after a successful merge.
`org.eclipse.core.runtime.IStatus` `validateMerge(org.eclipse.team.core.mapping.IMergeContext mergeContext, org.eclipse.core.runtime.IProgressMonitor monitor)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### MERGER_REGISTRY

    protected static final IMerger.Registry2 MERGER_REGISTRY

The merger registry.

### Constructor Detail

#### EMFResourceMappingMerger

    public EMFResourceMappingMerger()

### Method Detail

#### merge

    public org.eclipse.core.runtime.IStatus merge(org.eclipse.team.core.mapping.IMergeContext mergeContext,
                                                  org.eclipse.core.runtime.IProgressMonitor monitor)
                                           throws org.eclipse.core.runtime.CoreException

Specified by:
  `merge` in interface `org.eclipse.team.core.mapping.IResourceMappingMerger`
Throws:
  `org.eclipse.core.runtime.CoreException`

#### mergeMapping

    protected void mergeMapping(org.eclipse.core.resources.mapping.ResourceMapping mapping,
                                org.eclipse.team.core.mapping.IMergeContext mergeContext,
                                Set<org.eclipse.core.resources.mapping.ResourceMapping> failingMappings,
                                org.eclipse.core.runtime.IProgressMonitor monitor)
                         throws org.eclipse.core.runtime.CoreException

Merges one mapping.

Parameters:
  `mapping` - The mapping to merge
  `mergeContext` - The merge context
  `failingMappings` - The set of failing mappings
  `monitor` - The progress monitor to use, 10 ticks will be consumed
Throws:
  `org.eclipse.core.runtime.CoreException`

#### removeNonExistingStorages

    protected void removeNonExistingStorages(StorageTraversal traversal)

Removes storages that do not exist from the specified `traversal`.

In the current implementation, the check for existence is based on the assumption that the storage is an `IFile`. This is fine, since we currently need it on the local side only anyways.

Parameters:
  `traversal` - The traversal to remove non-existing storages from.

#### doMergeForDiff

    protected void doMergeForDiff(Monitor emfMonitor,
                                  Set<URI> conflictingURIs,
                                  Diff diff)

#### collectConflictingResources

    protected Set<URI> collectConflictingResources(Iterator<Diff> diffIterator)

Iterates over the given diffs to collect the resources they impact. This will be called in case of conflicts in order to know exactly which resources should be marked as conflicting.

Parameters:
  `diffIterator` - Iterator over the conflicting differences and their dependent diffs.
Returns:
  The uris of all resources impacted by conflicting differences.

#### markResourcesAsMerged

    protected void markResourcesAsMerged(org.eclipse.team.core.mapping.IMergeContext context,
                                         Set<org.eclipse.core.resources.IResource> resources,
                                         Set<URI> conflictingURIs,
                                         org.eclipse.core.runtime.SubMonitor subMonitor)

Marks the resources as merged if their URIs are not included in the given set of known `conflictingURIs`.

Parameters:
  `context` - The current merge context.
  `resources` - The resources to be marked as merged.
  `conflictingURIs` - The set of known `conflictingURIs`.
  `subMonitor` - Monitor on which to report progress to the user.

#### delegateMergeOfUnmergedResourcesAndMarkDiffsAsMerged

    protected void delegateMergeOfUnmergedResourcesAndMarkDiffsAsMerged(SynchronizationModel syncModel,
                                                                        org.eclipse.team.core.mapping.IMergeContext mergeContext,
                                                                        EMFResourceMappingMerger.ResourceAdditionAndDeletionTracker resourceTracker,
                                                                        org.eclipse.core.runtime.SubMonitor subMonitor)
                                                                 throws org.eclipse.core.runtime.CoreException

Delegates the merge of so far non-merged resource additions and deletions and marks all other already merged resources as merged.

Parameters:
  `syncModel` - The synchronization model to obtain the storages.
  `mergeContext` - The merge context.
  `resourceTracker` - The tracker that tracked already merged file additions and deletions.
  `subMonitor` - The progress monitor to use.
Throws:
  `org.eclipse.core.runtime.CoreException`

#### merge

    protected void merge(org.eclipse.team.core.diff.IDiff diff,
                         org.eclipse.team.core.mapping.IMergeContext mergeContext,
                         org.eclipse.core.runtime.SubMonitor subMonitor)

Merges the given `diff`.

Parameters:
  `diff` - The difference to be merged.
  `mergeContext` - The merge context.
  `subMonitor` - The process monitor to use.

#### markAsMerged

    protected void markAsMerged(org.eclipse.team.core.diff.IDiff diff,
                                org.eclipse.team.core.mapping.IMergeContext mergeContext,
                                org.eclipse.core.runtime.SubMonitor subMonitor)

Marks the given `diff` as merged.

Parameters:
  `diff` - The difference to be marked as merge.
  `mergeContext` - The merge context.
  `subMonitor` - The progress monitor to use.

#### save

    protected void save(Notifier notifier,
                        StorageTraversal leftTraversal,
                        StorageTraversal rightTraversal,
                        StorageTraversal originTraversal)

Saves the given notifier to disk after a successful merge.

Parameters:
  `notifier` - The notifier.
  `leftTraversal` - The traversal corresponding to the left side.
  `rightTraversal` - The traversal corresponding to the right side.
  `originTraversal` - The traversal corresponding to the common ancestor of both other side. Can be `null`.

#### getMergeRule

    public org.eclipse.core.runtime.jobs.ISchedulingRule getMergeRule(org.eclipse.team.core.mapping.IMergeContext context)

Specified by:
  `getMergeRule` in interface `org.eclipse.team.core.mapping.IResourceMappingMerger`

#### validateMerge

    public org.eclipse.core.runtime.IStatus validateMerge(org.eclipse.team.core.mapping.IMergeContext mergeContext,
                                                          org.eclipse.core.runtime.IProgressMonitor monitor)

Specified by:
  `validateMerge` in interface `org.eclipse.team.core.mapping.IResourceMappingMerger`