Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Richard2015-05-21 12:45:41 +0000
committerAxel Richard2015-05-26 13:37:10 +0000
commit93ab38a616826ca9d9ed6703955330e840414c54 (patch)
treec3ef845393cda4b059f5e4fa43a799b0ab321ed7 /plugins
parent24bd6b8f6993255f21b71d9e99c9dbc14d31983d (diff)
downloadorg.eclipse.emf.compare-93ab38a616826ca9d9ed6703955330e840414c54.tar.gz
org.eclipse.emf.compare-93ab38a616826ca9d9ed6703955330e840414c54.tar.xz
org.eclipse.emf.compare-93ab38a616826ca9d9ed6703955330e840414c54.zip
[467668] Fix Accept/Reject All buttons behaviour with shared models3.1.0RC2
Change-Id: Ic13b0030a7894413765ba749193fea6b69017503 Signed-off-by: Axel Richard <axel.richard@obeo.fr>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/command/impl/MergeAllNonConflictingCommand.java48
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/command/MergeAllCommandTests.java344
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/command/data/MergeAllCommandInputData.java32
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/command/data/modelLeft.ecore11
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/command/data/modelOrigin.ecore11
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/command/data/modelRight.ecore11
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/suite/AllTests.java3
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/EMFResourceMappingMerger.java2
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AbstractMergeRunnable.java4
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeAllNonConflictingRunnable.java203
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/util/MergeViewerUtil.java18
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/MergeDependenciesUtil.java13
12 files changed, 605 insertions, 95 deletions
diff --git a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/command/impl/MergeAllNonConflictingCommand.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/command/impl/MergeAllNonConflictingCommand.java
index 2d35a03ef..d728157a0 100644
--- a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/command/impl/MergeAllNonConflictingCommand.java
+++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/command/impl/MergeAllNonConflictingCommand.java
@@ -10,23 +10,12 @@
*******************************************************************************/
package org.eclipse.emf.compare.command.impl;
-import static com.google.common.base.Predicates.and;
-import static com.google.common.base.Predicates.not;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.hasConflict;
-
import com.google.common.annotations.Beta;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
import java.util.Collection;
-import java.util.List;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.compare.Comparison;
-import org.eclipse.emf.compare.ConflictKind;
-import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.DifferenceSource;
import org.eclipse.emf.compare.internal.domain.IMergeAllNonConflictingRunnable;
import org.eclipse.emf.compare.merge.IMerger;
import org.eclipse.emf.ecore.change.util.ChangeRecorder;
@@ -64,8 +53,12 @@ public class MergeAllNonConflictingCommand extends AbstractCopyCommand {
public MergeAllNonConflictingCommand(ChangeRecorder changeRecorder, Collection<Notifier> notifiers,
Comparison comparison, boolean leftToRight, IMerger.Registry mergerRegistry,
IMergeAllNonConflictingRunnable runnable) {
- super(changeRecorder, notifiers, getDifferencesToMerge(comparison, leftToRight), leftToRight,
- mergerRegistry);
+ // We don't use differences in this case.
+ // The IMergeAllNonConflictingRunnable computes all differences he needs.
+ // So just take the differences to let the command executable.
+ // (A command with no differences isn't executable; see
+ // org.eclipse.emf.compare.command.impl.AbstractCopyCommand.canExecute())
+ super(changeRecorder, notifiers, comparison.getDifferences(), leftToRight, mergerRegistry);
this.comparison = comparison;
this.runnable = runnable;
}
@@ -79,33 +72,4 @@ public class MergeAllNonConflictingCommand extends AbstractCopyCommand {
protected void doExecute() {
runnable.merge(comparison, isLeftToRight(), mergerRegistry);
}
-
- /**
- * Returns the set of differences this command will operate on.
- * <p>
- * <b>Note</b> that this is not the set of affected objects! The command will operate on all of these
- * differences, but only after execution can we tell whether the diffs have actually been merged.
- * </p>
- *
- * @param comparison
- * The comparison we're operating on.
- * @param leftToRight
- * Direction of the merge.
- * @return The list of differences this command will try and merge
- */
- private static List<Diff> getDifferencesToMerge(Comparison comparison, boolean leftToRight) {
- final boolean threeWay = comparison.isThreeWay();
- final Iterable<Diff> diffs;
- if (threeWay && leftToRight) {
- diffs = Iterables.filter(comparison.getDifferences(), and(fromSide(DifferenceSource.LEFT),
- not(hasConflict(ConflictKind.REAL, ConflictKind.PSEUDO))));
- } else if (threeWay) {
- diffs = Iterables.filter(comparison.getDifferences(), and(fromSide(DifferenceSource.RIGHT),
- not(hasConflict(ConflictKind.REAL, ConflictKind.PSEUDO))));
- } else {
- // We're in a 2way-comparison, so all differences come from left side.
- diffs = Iterables.filter(comparison.getDifferences(), fromSide(DifferenceSource.LEFT));
- }
- return Lists.newArrayList(diffs);
- }
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/command/MergeAllCommandTests.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/command/MergeAllCommandTests.java
new file mode 100644
index 000000000..21a169cef
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/command/MergeAllCommandTests.java
@@ -0,0 +1,344 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Obeo.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.ide.ui.tests.command;
+
+import static com.google.common.base.Predicates.and;
+import static com.google.common.collect.Iterables.filter;
+import static com.google.common.collect.Iterables.size;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.hasState;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
+import static org.junit.Assert.assertEquals;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+
+import java.io.IOException;
+
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.DifferenceKind;
+import org.eclipse.emf.compare.DifferenceSource;
+import org.eclipse.emf.compare.DifferenceState;
+import org.eclipse.emf.compare.EMFCompare;
+import org.eclipse.emf.compare.command.impl.MergeAllNonConflictingCommand;
+import org.eclipse.emf.compare.domain.impl.EMFCompareEditingDomain;
+import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.MergeAllNonConflictingRunnable;
+import org.eclipse.emf.compare.ide.ui.tests.command.data.MergeAllCommandInputData;
+import org.eclipse.emf.compare.internal.merge.MergeMode;
+import org.eclipse.emf.compare.merge.IMerger;
+import org.eclipse.emf.compare.scope.DefaultComparisonScope;
+import org.eclipse.emf.compare.scope.IComparisonScope;
+import org.eclipse.emf.ecore.change.util.ChangeRecorder;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.junit.Test;
+
+@SuppressWarnings({"restriction", "unchecked" })
+public class MergeAllCommandTests {
+
+ private MergeAllCommandInputData input = new MergeAllCommandInputData();
+
+ private final IMerger.Registry mergerRegistry = IMerger.RegistryImpl.createStandaloneInstance();
+
+ @Test
+ public void testMergeAllNonConflictingFromLeftToRight() throws IOException {
+ MergeMode mergeMode = MergeMode.LEFT_TO_RIGHT;
+ boolean leftToRight = true;
+ boolean isLeftEditable = true;
+ boolean isRightEditable = true;
+
+ Resource left = input.getLeftScope();
+ Resource right = input.getRightScope();
+ Resource origin = input.getOriginScope();
+
+ IComparisonScope scope = new DefaultComparisonScope(left, right, origin);
+ Comparison comparison = EMFCompare.builder().build().compare(scope);
+
+ EMFCompareEditingDomain editingDomain = (EMFCompareEditingDomain)EMFCompareEditingDomain.create(left,
+ right, origin);
+ ChangeRecorder changeRecorder = editingDomain.getChangeRecorder();
+
+ ImmutableSet.Builder<Notifier> notifiersBuilder = ImmutableSet.builder();
+ ImmutableSet<Notifier> notifiers = notifiersBuilder.add(comparison).addAll(
+ ImmutableList.of(left, right, origin)).build();
+
+ MergeAllNonConflictingRunnable runnable = new MergeAllNonConflictingRunnable(isLeftEditable,
+ isRightEditable, mergeMode);
+
+ MergeAllNonConflictingCommand command = new MergeAllNonConflictingCommand(changeRecorder, notifiers,
+ comparison, leftToRight, mergerRegistry, runnable);
+
+ EList<Diff> differencesBefore = comparison.getDifferences();
+ // Test state of differences before command
+ // 3 Left Delete differences
+ Iterable<Diff> leftDelete = filter(differencesBefore, and(fromSide(DifferenceSource.LEFT),
+ ofKind(DifferenceKind.DELETE), hasState(DifferenceState.UNRESOLVED)));
+ assertEquals(3, size(leftDelete));
+ // 3 Right Delete differences
+ Iterable<Diff> rightDelete = filter(differencesBefore, and(fromSide(DifferenceSource.RIGHT),
+ ofKind(DifferenceKind.DELETE), hasState(DifferenceState.UNRESOLVED)));
+ assertEquals(3, size(rightDelete));
+ // 3 Left Add differences
+ Iterable<Diff> leftAdd = filter(differencesBefore, and(fromSide(DifferenceSource.LEFT),
+ ofKind(DifferenceKind.ADD), hasState(DifferenceState.UNRESOLVED)));
+ assertEquals(3, size(leftAdd));
+ // 3 Right Add differences
+ Iterable<Diff> rightAdd = filter(differencesBefore, and(fromSide(DifferenceSource.RIGHT),
+ ofKind(DifferenceKind.ADD), hasState(DifferenceState.UNRESOLVED)));
+ assertEquals(3, size(rightAdd));
+
+ // Execute command
+ command.execute();
+
+ EList<Diff> differencesAfter = comparison.getDifferences();
+ // Test state of differences before command
+ // 3 Left Delete differences merged
+ leftDelete = filter(differencesAfter, and(fromSide(DifferenceSource.LEFT),
+ ofKind(DifferenceKind.DELETE), hasState(DifferenceState.MERGED)));
+ assertEquals(3, size(leftDelete));
+ // 0 Right Delete differences merged
+ rightDelete = filter(differencesAfter, and(fromSide(DifferenceSource.RIGHT),
+ ofKind(DifferenceKind.DELETE), hasState(DifferenceState.MERGED)));
+ assertEquals(0, size(rightDelete));
+ // 3 Left Add differences merged
+ leftAdd = filter(differencesAfter, and(fromSide(DifferenceSource.LEFT), ofKind(DifferenceKind.ADD),
+ hasState(DifferenceState.MERGED)));
+ assertEquals(3, size(leftAdd));
+ // 0 Right Add differences merged
+ rightAdd = filter(differencesAfter, and(fromSide(DifferenceSource.RIGHT), ofKind(DifferenceKind.ADD),
+ hasState(DifferenceState.MERGED)));
+ assertEquals(0, size(rightAdd));
+
+ command.dispose();
+ editingDomain.dispose();
+ }
+
+ @Test
+ public void testMergeAllNonConflictingFromRightToLeft() throws IOException {
+ MergeMode mergeMode = MergeMode.RIGHT_TO_LEFT;
+ boolean leftToRight = false;
+ boolean isLeftEditable = true;
+ boolean isRightEditable = true;
+
+ Resource left = input.getLeftScope();
+ Resource right = input.getRightScope();
+ Resource origin = input.getOriginScope();
+
+ IComparisonScope scope = new DefaultComparisonScope(left, right, origin);
+ Comparison comparison = EMFCompare.builder().build().compare(scope);
+
+ EMFCompareEditingDomain editingDomain = (EMFCompareEditingDomain)EMFCompareEditingDomain.create(left,
+ right, origin);
+ ChangeRecorder changeRecorder = editingDomain.getChangeRecorder();
+
+ ImmutableSet.Builder<Notifier> notifiersBuilder = ImmutableSet.builder();
+ ImmutableSet<Notifier> notifiers = notifiersBuilder.add(comparison).addAll(
+ ImmutableList.of(left, right, origin)).build();
+
+ MergeAllNonConflictingRunnable runnable = new MergeAllNonConflictingRunnable(isLeftEditable,
+ isRightEditable, mergeMode);
+
+ MergeAllNonConflictingCommand command = new MergeAllNonConflictingCommand(changeRecorder, notifiers,
+ comparison, leftToRight, mergerRegistry, runnable);
+
+ EList<Diff> differencesBefore = comparison.getDifferences();
+ // Test state of differences before command
+ // 3 Left Delete differences
+ Iterable<Diff> leftDelete = filter(differencesBefore, and(fromSide(DifferenceSource.LEFT),
+ ofKind(DifferenceKind.DELETE), hasState(DifferenceState.UNRESOLVED)));
+ assertEquals(3, size(leftDelete));
+ // 3 Right Delete differences
+ Iterable<Diff> rightDelete = filter(differencesBefore, and(fromSide(DifferenceSource.RIGHT),
+ ofKind(DifferenceKind.DELETE), hasState(DifferenceState.UNRESOLVED)));
+ assertEquals(3, size(rightDelete));
+ // 3 Left Add differences
+ Iterable<Diff> leftAdd = filter(differencesBefore, and(fromSide(DifferenceSource.LEFT),
+ ofKind(DifferenceKind.ADD), hasState(DifferenceState.UNRESOLVED)));
+ assertEquals(3, size(leftAdd));
+ // 3 Right Add differences
+ Iterable<Diff> rightAdd = filter(differencesBefore, and(fromSide(DifferenceSource.RIGHT),
+ ofKind(DifferenceKind.ADD), hasState(DifferenceState.UNRESOLVED)));
+ assertEquals(3, size(rightAdd));
+
+ // Execute command
+ command.execute();
+
+ EList<Diff> differencesAfter = comparison.getDifferences();
+ // Test state of differences before command
+ // 0 Left Delete differences merged
+ leftDelete = filter(differencesAfter, and(fromSide(DifferenceSource.LEFT),
+ ofKind(DifferenceKind.DELETE), hasState(DifferenceState.MERGED)));
+ assertEquals(0, size(leftDelete));
+ // 3 Right Delete differences merged
+ rightDelete = filter(differencesAfter, and(fromSide(DifferenceSource.RIGHT),
+ ofKind(DifferenceKind.DELETE), hasState(DifferenceState.MERGED)));
+ assertEquals(3, size(rightDelete));
+ // 0 Left Add differences merged
+ leftAdd = filter(differencesAfter, and(fromSide(DifferenceSource.LEFT), ofKind(DifferenceKind.ADD),
+ hasState(DifferenceState.MERGED)));
+ assertEquals(0, size(leftAdd));
+ // 3 Right Add differences merged
+ rightAdd = filter(differencesAfter, and(fromSide(DifferenceSource.RIGHT), ofKind(DifferenceKind.ADD),
+ hasState(DifferenceState.MERGED)));
+ assertEquals(3, size(rightAdd));
+
+ command.dispose();
+ editingDomain.dispose();
+ }
+
+ @Test
+ public void testAcceptAllNonConflictingChanges() throws IOException {
+ MergeMode mergeMode = MergeMode.ACCEPT;
+ boolean leftToRight = false;
+ boolean isLeftEditable = true;
+ boolean isRightEditable = false;
+
+ Resource left = input.getLeftScope();
+ Resource right = input.getRightScope();
+ Resource origin = input.getOriginScope();
+
+ IComparisonScope scope = new DefaultComparisonScope(left, right, origin);
+ Comparison comparison = EMFCompare.builder().build().compare(scope);
+
+ EMFCompareEditingDomain editingDomain = (EMFCompareEditingDomain)EMFCompareEditingDomain.create(left,
+ right, origin);
+ ChangeRecorder changeRecorder = editingDomain.getChangeRecorder();
+
+ ImmutableSet.Builder<Notifier> notifiersBuilder = ImmutableSet.builder();
+ ImmutableSet<Notifier> notifiers = notifiersBuilder.add(comparison).addAll(
+ ImmutableList.of(left, right, origin)).build();
+
+ MergeAllNonConflictingRunnable runnable = new MergeAllNonConflictingRunnable(isLeftEditable,
+ isRightEditable, mergeMode);
+
+ MergeAllNonConflictingCommand command = new MergeAllNonConflictingCommand(changeRecorder, notifiers,
+ comparison, leftToRight, mergerRegistry, runnable);
+
+ EList<Diff> differencesBefore = comparison.getDifferences();
+ // Test state of differences before command
+ // 3 Left Delete differences
+ Iterable<Diff> leftDelete = filter(differencesBefore, and(fromSide(DifferenceSource.LEFT),
+ ofKind(DifferenceKind.DELETE), hasState(DifferenceState.UNRESOLVED)));
+ assertEquals(3, size(leftDelete));
+ // 3 Right Delete differences
+ Iterable<Diff> rightDelete = filter(differencesBefore, and(fromSide(DifferenceSource.RIGHT),
+ ofKind(DifferenceKind.DELETE), hasState(DifferenceState.UNRESOLVED)));
+ assertEquals(3, size(rightDelete));
+ // 3 Left Add differences
+ Iterable<Diff> leftAdd = filter(differencesBefore, and(fromSide(DifferenceSource.LEFT),
+ ofKind(DifferenceKind.ADD), hasState(DifferenceState.UNRESOLVED)));
+ assertEquals(3, size(leftAdd));
+ // 3 Right Add differences
+ Iterable<Diff> rightAdd = filter(differencesBefore, and(fromSide(DifferenceSource.RIGHT),
+ ofKind(DifferenceKind.ADD), hasState(DifferenceState.UNRESOLVED)));
+ assertEquals(3, size(rightAdd));
+
+ // Execute command
+ command.execute();
+
+ EList<Diff> differencesAfter = comparison.getDifferences();
+ // Test state of differences before command
+ // 3 Left Delete differences merged
+ leftDelete = filter(differencesAfter, and(fromSide(DifferenceSource.LEFT),
+ ofKind(DifferenceKind.DELETE), hasState(DifferenceState.MERGED)));
+ assertEquals(3, size(leftDelete));
+ // 3 Right Delete differences merged
+ rightDelete = filter(differencesAfter, and(fromSide(DifferenceSource.RIGHT),
+ ofKind(DifferenceKind.DELETE), hasState(DifferenceState.MERGED)));
+ assertEquals(3, size(rightDelete));
+ // 3 Left Add differences merged
+ leftAdd = filter(differencesAfter, and(fromSide(DifferenceSource.LEFT), ofKind(DifferenceKind.ADD),
+ hasState(DifferenceState.MERGED)));
+ assertEquals(3, size(leftAdd));
+ // 3 Right Add differences merged
+ rightAdd = filter(differencesAfter, and(fromSide(DifferenceSource.RIGHT), ofKind(DifferenceKind.ADD),
+ hasState(DifferenceState.MERGED)));
+ assertEquals(3, size(rightAdd));
+
+ command.dispose();
+ editingDomain.dispose();
+ }
+
+ @Test
+ public void testRejectAllNonConflictingChanges() throws IOException {
+ MergeMode mergeMode = MergeMode.REJECT;
+ boolean leftToRight = false;
+ boolean isLeftEditable = true;
+ boolean isRightEditable = false;
+
+ Resource left = input.getLeftScope();
+ Resource right = input.getRightScope();
+ Resource origin = input.getOriginScope();
+
+ IComparisonScope scope = new DefaultComparisonScope(left, right, origin);
+ Comparison comparison = EMFCompare.builder().build().compare(scope);
+
+ EMFCompareEditingDomain editingDomain = (EMFCompareEditingDomain)EMFCompareEditingDomain.create(left,
+ right, origin);
+ ChangeRecorder changeRecorder = editingDomain.getChangeRecorder();
+
+ ImmutableSet.Builder<Notifier> notifiersBuilder = ImmutableSet.builder();
+ ImmutableSet<Notifier> notifiers = notifiersBuilder.add(comparison).addAll(
+ ImmutableList.of(left, right, origin)).build();
+
+ MergeAllNonConflictingRunnable runnable = new MergeAllNonConflictingRunnable(isLeftEditable,
+ isRightEditable, mergeMode);
+
+ MergeAllNonConflictingCommand command = new MergeAllNonConflictingCommand(changeRecorder, notifiers,
+ comparison, leftToRight, mergerRegistry, runnable);
+
+ EList<Diff> differencesBefore = comparison.getDifferences();
+ // Test state of differences before command
+ // 3 Left Delete differences
+ Iterable<Diff> leftDelete = filter(differencesBefore, and(fromSide(DifferenceSource.LEFT),
+ ofKind(DifferenceKind.DELETE), hasState(DifferenceState.UNRESOLVED)));
+ assertEquals(3, size(leftDelete));
+ // 3 Right Delete differences
+ Iterable<Diff> rightDelete = filter(differencesBefore, and(fromSide(DifferenceSource.RIGHT),
+ ofKind(DifferenceKind.DELETE), hasState(DifferenceState.UNRESOLVED)));
+ assertEquals(3, size(rightDelete));
+ // 3 Left Add differences
+ Iterable<Diff> leftAdd = filter(differencesBefore, and(fromSide(DifferenceSource.LEFT),
+ ofKind(DifferenceKind.ADD), hasState(DifferenceState.UNRESOLVED)));
+ assertEquals(3, size(leftAdd));
+ // 3 Right Add differences
+ Iterable<Diff> rightAdd = filter(differencesBefore, and(fromSide(DifferenceSource.RIGHT),
+ ofKind(DifferenceKind.ADD), hasState(DifferenceState.UNRESOLVED)));
+ assertEquals(3, size(rightAdd));
+
+ // Execute command
+ command.execute();
+
+ EList<Diff> differencesAfter = comparison.getDifferences();
+ // Test state of differences before command
+ // 3 Left Delete differences merged
+ leftDelete = filter(differencesAfter, and(fromSide(DifferenceSource.LEFT),
+ ofKind(DifferenceKind.DELETE), hasState(DifferenceState.MERGED)));
+ assertEquals(3, size(leftDelete));
+ // 3 Right Delete differences merged
+ rightDelete = filter(differencesAfter, and(fromSide(DifferenceSource.RIGHT),
+ ofKind(DifferenceKind.DELETE), hasState(DifferenceState.MERGED)));
+ assertEquals(3, size(rightDelete));
+ // 3 Left Add differences merged
+ leftAdd = filter(differencesAfter, and(fromSide(DifferenceSource.LEFT), ofKind(DifferenceKind.ADD),
+ hasState(DifferenceState.MERGED)));
+ assertEquals(3, size(leftAdd));
+ // 3 Right Add differences merged
+ rightAdd = filter(differencesAfter, and(fromSide(DifferenceSource.RIGHT), ofKind(DifferenceKind.ADD),
+ hasState(DifferenceState.MERGED)));
+ assertEquals(3, size(rightAdd));
+
+ command.dispose();
+ editingDomain.dispose();
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/command/data/MergeAllCommandInputData.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/command/data/MergeAllCommandInputData.java
new file mode 100644
index 000000000..880a11ce1
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/command/data/MergeAllCommandInputData.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Obeo.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.ide.ui.tests.command.data;
+
+import java.io.IOException;
+
+import org.eclipse.emf.compare.tests.framework.AbstractInputData;
+import org.eclipse.emf.ecore.resource.Resource;
+
+@SuppressWarnings("nls")
+public class MergeAllCommandInputData extends AbstractInputData {
+ public Resource getLeftScope() throws IOException {
+ return loadFromClassLoader("modelLeft.ecore");
+ }
+
+ public Resource getOriginScope() throws IOException {
+ return loadFromClassLoader("modelOrigin.ecore");
+ }
+
+ public Resource getRightScope() throws IOException {
+ return loadFromClassLoader("modelRight.ecore");
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/command/data/modelLeft.ecore b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/command/data/modelLeft.ecore
new file mode 100644
index 000000000..9923417f8
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/command/data/modelLeft.ecore
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmi:id="_packageRoot" name="MergeAllActions" nsURI="http:///org/eclipse/emf/examples/library/extlibrary.ecore/1.0.0"
+ nsPrefix="emfc">
+ <eClassifiers xsi:type="ecore:EClass" xmi:id="_RightDelete1" name="RightDelete1"/>
+ <eClassifiers xsi:type="ecore:EClass" xmi:id="_RightDelete2" name="RightDelete2"/>
+ <eClassifiers xsi:type="ecore:EClass" xmi:id="_RightDelete3" name="RightDelete3"/>
+ <eClassifiers xsi:type="ecore:EClass" xmi:id="_LeftAdd1" name="LeftAdd1"/>
+ <eClassifiers xsi:type="ecore:EClass" xmi:id="_LeftAdd2" name="LeftAdd2"/>
+ <eClassifiers xsi:type="ecore:EClass" xmi:id="_LeftAdd3" name="LeftAdd3"/>
+</ecore:EPackage>
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/command/data/modelOrigin.ecore b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/command/data/modelOrigin.ecore
new file mode 100644
index 000000000..27f6eeebb
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/command/data/modelOrigin.ecore
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmi:id="_packageRoot" name="MergeAllActions" nsURI="http:///org/eclipse/emf/examples/library/extlibrary.ecore/1.0.0"
+ nsPrefix="emfc">
+ <eClassifiers xsi:type="ecore:EClass" xmi:id="_LeftDelete1" name="LeftDelete1"/>
+ <eClassifiers xsi:type="ecore:EClass" xmi:id="_LeftDelete2" name="LeftDelete2"/>
+ <eClassifiers xsi:type="ecore:EClass" xmi:id="_LeftDelete3" name="LeftDelete3"/>
+ <eClassifiers xsi:type="ecore:EClass" xmi:id="_RightDelete1" name="RightDelete1"/>
+ <eClassifiers xsi:type="ecore:EClass" xmi:id="_RightDelete2" name="RightDelete2"/>
+ <eClassifiers xsi:type="ecore:EClass" xmi:id="_RightDelete3" name="RightDelete3"/>
+</ecore:EPackage>
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/command/data/modelRight.ecore b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/command/data/modelRight.ecore
new file mode 100644
index 000000000..f4df68c1f
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/command/data/modelRight.ecore
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmi:id="_packageRoot" name="MergeAllActions" nsURI="http:///org/eclipse/emf/examples/library/extlibrary.ecore/1.0.0"
+ nsPrefix="emfc">
+ <eClassifiers xsi:type="ecore:EClass" xmi:id="_LeftDelete1" name="LeftDelete1"/>
+ <eClassifiers xsi:type="ecore:EClass" xmi:id="_LeftDelete2" name="LeftDelete2"/>
+ <eClassifiers xsi:type="ecore:EClass" xmi:id="_LeftDelete3" name="LeftDelete3"/>
+ <eClassifiers xsi:type="ecore:EClass" xmi:id="_RightAdd1" name="RightAdd1"/>
+ <eClassifiers xsi:type="ecore:EClass" xmi:id="_RightAdd2" name="RightAdd2"/>
+ <eClassifiers xsi:type="ecore:EClass" xmi:id="_RightAdd3" name="RightAdd3"/>
+</ecore:EPackage>
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/suite/AllTests.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/suite/AllTests.java
index d8c01aea8..3015d2abb 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/suite/AllTests.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/suite/AllTests.java
@@ -17,6 +17,7 @@ import junit.framework.Test;
import junit.textui.TestRunner;
import org.eclipse.emf.compare.ComparePackage;
+import org.eclipse.emf.compare.ide.ui.tests.command.MergeAllCommandTests;
import org.eclipse.emf.compare.ide.ui.tests.compareconfiguration.EMFCompareConfigurationTest;
import org.eclipse.emf.compare.ide.ui.tests.contentmergeviewer.notloadedfragment.NotLoadedFragmentItemTest;
import org.eclipse.emf.compare.ide.ui.tests.logical.modelprovider.EMFModelProviderTest;
@@ -46,7 +47,7 @@ import org.junit.runners.Suite.SuiteClasses;
NotLoadedFragmentNodeTest.class, NotLoadedFragmentItemTest.class, ResolutionEventsTest.class,
ResourceComputationSchedulerTest.class, ThreadedModelResolverGraphTest.class,
ThreadedModelResolverWithCustomDependencyProviderTest.class, DependencyGraphUpdaterTest.class,
- GraphResolutionTest.class, EMFModelProviderTest.class })
+ GraphResolutionTest.class, EMFModelProviderTest.class, MergeAllCommandTests.class })
public class AllTests {
/**
* Launches the test with the given arguments.
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/EMFResourceMappingMerger.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/EMFResourceMappingMerger.java
index a3ec6b59f..21e9ad595 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/EMFResourceMappingMerger.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/EMFResourceMappingMerger.java
@@ -236,7 +236,7 @@ public class EMFResourceMappingMerger implements IResourceMappingMerger {
if (hasRealConflict(comparison)) {
// pre-merge what can be
final Graph<Diff> differencesGraph = MergeDependenciesUtil.mapDifferences(comparison,
- mergerRegistry, true);
+ mergerRegistry, true, null);
final PruningIterator<Diff> iterator = differencesGraph.breadthFirstIterator();
final Monitor emfMonitor = BasicMonitor.toMonitor(subMonitor.newChild(5)); // 100%
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AbstractMergeRunnable.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AbstractMergeRunnable.java
index 63273b848..7ffa31d9f 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AbstractMergeRunnable.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AbstractMergeRunnable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2014 Obeo.
+ * Copyright (c) 2014, 2015 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -95,7 +95,7 @@ public abstract class AbstractMergeRunnable {
* @param mergerRegistry
* Current registry of mergers.
*/
- private void markAsMerged(Diff diff, MergeMode mode, boolean mergeRightToLeft, Registry mergerRegistry) {
+ protected void markAsMerged(Diff diff, MergeMode mode, boolean mergeRightToLeft, Registry mergerRegistry) {
if (diff.getState() == DifferenceState.MERGED) {
return;
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeAllNonConflictingRunnable.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeAllNonConflictingRunnable.java
index 6cc1af3af..4be0e162f 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeAllNonConflictingRunnable.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeAllNonConflictingRunnable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2014 Obeo.
+ * Copyright (c) 2014, 2015 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions;
+import static com.google.common.collect.Lists.newArrayList;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.hasConflict;
@@ -18,7 +19,10 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
import java.util.List;
+import java.util.Set;
import org.eclipse.emf.common.util.BasicMonitor;
import org.eclipse.emf.common.util.Monitor;
@@ -31,12 +35,14 @@ import org.eclipse.emf.compare.DifferenceState;
import org.eclipse.emf.compare.internal.domain.IMergeAllNonConflictingRunnable;
import org.eclipse.emf.compare.internal.merge.MergeDependenciesUtil;
import org.eclipse.emf.compare.internal.merge.MergeMode;
+import org.eclipse.emf.compare.internal.merge.MergeOperation;
import org.eclipse.emf.compare.internal.utils.Graph;
import org.eclipse.emf.compare.internal.utils.PruningIterator;
import org.eclipse.emf.compare.merge.BatchMerger;
import org.eclipse.emf.compare.merge.IBatchMerger;
import org.eclipse.emf.compare.merge.IMerger;
import org.eclipse.emf.compare.merge.IMerger.Registry;
+import org.eclipse.emf.compare.merge.IMerger2;
/**
* Implements the "merge all non-conflicting" action.
@@ -64,52 +70,135 @@ public class MergeAllNonConflictingRunnable extends AbstractMergeRunnable implem
public Iterable<Diff> merge(Comparison comparison, boolean leftToRight, Registry mergerRegistry) {
Preconditions
.checkState(getMergeMode().isLeftToRight(isLeftEditable(), isRightEditable()) == leftToRight);
+ Iterable<Diff> affectedChanges;
+ if (hasRealConflict(comparison)) {
+ // This is a 3-way comparison.
+ // pre-merge what can be.
+ affectedChanges = mergeWithConflicts(comparison, leftToRight, mergerRegistry);
+ } else {
+ // There are no conflicts here.
+ affectedChanges = mergeWithoutConflicts(comparison, leftToRight, mergerRegistry);
+ }
+ return affectedChanges;
+ }
+ /**
+ * Handles the merge of all non-conflicting differences in case of a comparison without conflicts.
+ *
+ * @param comparison
+ * The comparison object.
+ * @param leftToRight
+ * The direction in which {@code differences} should be merged.
+ * @param mergerRegistry
+ * The registry of mergers.
+ * @return an iterable over the differences that have actually been merged by this operation.
+ */
+ private Iterable<Diff> mergeWithoutConflicts(Comparison comparison, boolean leftToRight,
+ Registry mergerRegistry) {
final List<Diff> affectedDiffs;
final Monitor emfMonitor = new BasicMonitor();
- if (hasRealConflict(comparison)) {
- // pre-merge what can be
- final Graph<Diff> differencesGraph = MergeDependenciesUtil.mapDifferences(comparison,
- mergerRegistry, !leftToRight);
- final PruningIterator<Diff> iterator = differencesGraph.breadthFirstIterator();
-
- affectedDiffs = new ArrayList<Diff>();
- while (iterator.hasNext()) {
- final Diff next = iterator.next();
- if (hasConflict(ConflictKind.REAL).apply(next)) {
- iterator.prune();
+ final IBatchMerger merger = new BatchMerger(mergerRegistry);
+ final boolean threeWay = comparison.isThreeWay();
+ if (threeWay && getMergeMode() == MergeMode.LEFT_TO_RIGHT) {
+ affectedDiffs = Lists.newArrayList(Iterables.filter(comparison.getDifferences(),
+ fromSide(DifferenceSource.LEFT)));
+ merger.copyAllLeftToRight(affectedDiffs, emfMonitor);
+ addOrUpdateMergeData(affectedDiffs, getMergeMode());
+ } else if (threeWay && getMergeMode() == MergeMode.RIGHT_TO_LEFT) {
+ affectedDiffs = Lists.newArrayList(Iterables.filter(comparison.getDifferences(),
+ fromSide(DifferenceSource.RIGHT)));
+ merger.copyAllRightToLeft(affectedDiffs, emfMonitor);
+ addOrUpdateMergeData(affectedDiffs, getMergeMode());
+ } else if (getMergeMode() == MergeMode.ACCEPT || getMergeMode() == MergeMode.REJECT) {
+ List<Diff> diffsToMarkAsMerged = newArrayList();
+ List<Diff> diffsToAccept = newArrayList();
+ List<Diff> diffsToReject = newArrayList();
+ for (Diff diff : comparison.getDifferences()) {
+ MergeOperation mergeAction = getMergeMode().getMergeAction(diff, isLeftEditable(),
+ isRightEditable());
+ if (mergeAction == MergeOperation.MARK_AS_MERGE) {
+ diffsToMarkAsMerged.add(diff);
} else {
- if (next.getState() != DifferenceState.MERGED) {
- affectedDiffs.add(next);
- final IMerger merger = mergerRegistry.getHighestRankingMerger(next);
- if (leftToRight) {
- merger.copyLeftToRight(next, emfMonitor);
- } else {
- merger.copyRightToLeft(next, emfMonitor);
- }
+ if (isLeftEditable() && leftToRight) {
+ diffsToReject.add(diff);
+ } else {
+ diffsToAccept.add(diff);
}
}
}
+ mergeAll(diffsToAccept, leftToRight, merger, mergerRegistry, emfMonitor);
+ mergeAll(diffsToReject, !leftToRight, merger, mergerRegistry, emfMonitor);
+ markAllAsMerged(diffsToMarkAsMerged, getMergeMode(), mergerRegistry);
+ affectedDiffs = Lists.newArrayList(diffsToAccept);
+ affectedDiffs.addAll(diffsToReject);
+ affectedDiffs.addAll(diffsToMarkAsMerged);
+ } else if (getMergeMode() == MergeMode.LEFT_TO_RIGHT) {
+ // We're in a 2way-comparison, so all differences come from left side.
+ affectedDiffs = Lists.newArrayList(Iterables.filter(comparison.getDifferences(),
+ fromSide(DifferenceSource.LEFT)));
+ merger.copyAllLeftToRight(affectedDiffs, emfMonitor);
+ addOrUpdateMergeData(affectedDiffs, getMergeMode());
+ } else if (getMergeMode() == MergeMode.RIGHT_TO_LEFT) {
+ // We're in a 2way-comparison, so all differences come from left side.
+ affectedDiffs = Lists.newArrayList(Iterables.filter(comparison.getDifferences(),
+ fromSide(DifferenceSource.LEFT)));
+ merger.copyAllRightToLeft(affectedDiffs, emfMonitor);
+ addOrUpdateMergeData(affectedDiffs, getMergeMode());
} else {
- final IBatchMerger merger = new BatchMerger(mergerRegistry);
- final boolean threeWay = comparison.isThreeWay();
- if (threeWay && leftToRight) {
- affectedDiffs = Lists.newArrayList(Iterables.filter(comparison.getDifferences(),
- fromSide(DifferenceSource.LEFT)));
- merger.copyAllLeftToRight(affectedDiffs, emfMonitor);
- } else if (threeWay) {
- affectedDiffs = Lists.newArrayList(Iterables.filter(comparison.getDifferences(),
- fromSide(DifferenceSource.RIGHT)));
- merger.copyAllRightToLeft(affectedDiffs, emfMonitor);
- } else if (leftToRight) {
- affectedDiffs = Lists.newArrayList(Iterables.filter(comparison.getDifferences(),
- fromSide(DifferenceSource.LEFT)));
- merger.copyAllLeftToRight(affectedDiffs, emfMonitor);
+ throw new IllegalStateException();
+ }
+
+ return affectedDiffs;
+ }
+
+ /**
+ * Handles the merge of all non-conflicting differences in case of a comparison with conflicts.
+ *
+ * @param comparison
+ * The comparison object.
+ * @param leftToRight
+ * The direction in which {@code differences} should be merged.
+ * @param mergerRegistry
+ * The registry of mergers.
+ * @return an iterable over the differences that have actually been merged by this operation.
+ */
+ private Iterable<Diff> mergeWithConflicts(Comparison comparison, boolean leftToRight,
+ Registry mergerRegistry) {
+ final List<Diff> affectedDiffs;
+ final Monitor emfMonitor = new BasicMonitor();
+ final Graph<Diff> differencesGraph = MergeDependenciesUtil.mapDifferences(comparison, mergerRegistry,
+ !leftToRight, getMergeMode());
+ final PruningIterator<Diff> iterator = differencesGraph.breadthFirstIterator();
+
+ affectedDiffs = new ArrayList<Diff>();
+ while (iterator.hasNext()) {
+ final Diff next = iterator.next();
+ if (hasConflict(ConflictKind.REAL).apply(next)) {
+ iterator.prune();
} else {
- // We're in a 2way-comparison, so all differences come from left side.
- affectedDiffs = Lists.newArrayList(Iterables.filter(comparison.getDifferences(),
- fromSide(DifferenceSource.LEFT)));
- merger.copyAllRightToLeft(affectedDiffs, emfMonitor);
+ if (next.getState() != DifferenceState.MERGED) {
+ affectedDiffs.add(next);
+ final IMerger merger = mergerRegistry.getHighestRankingMerger(next);
+ if (getMergeMode() == MergeMode.LEFT_TO_RIGHT) {
+ merger.copyLeftToRight(next, emfMonitor);
+ } else if (getMergeMode() == MergeMode.RIGHT_TO_LEFT) {
+ merger.copyRightToLeft(next, emfMonitor);
+ } else if (getMergeMode() == MergeMode.ACCEPT || getMergeMode() == MergeMode.REJECT) {
+ MergeOperation mergeAction = getMergeMode().getMergeAction(next, isLeftEditable(),
+ isRightEditable());
+ if (mergeAction == MergeOperation.MARK_AS_MERGE) {
+ markAsMerged(next, getMergeMode(), leftToRight, mergerRegistry);
+ } else {
+ if (isLeftEditable() && !leftToRight) {
+ merger.copyRightToLeft(next, emfMonitor);
+ } else if (isRightEditable() && leftToRight) {
+ merger.copyLeftToRight(next, emfMonitor);
+ }
+ }
+ } else {
+ throw new IllegalStateException();
+ }
+ }
}
}
addOrUpdateMergeData(affectedDiffs, getMergeMode());
@@ -132,4 +221,42 @@ public class MergeAllNonConflictingRunnable extends AbstractMergeRunnable implem
}
return false;
}
+
+ /**
+ * Merge all given differences in case of an ACCEPT or REJECT MergeMode.
+ *
+ * @param differences
+ * The differences to merge.
+ * @param leftToRight
+ * The direction in which {@code differences} should be merged.
+ * @param merger
+ * The current merger.
+ * @param mergerRegistry
+ * The registry of mergers.
+ * @param emfMonitor
+ * To monitor the process.
+ */
+ private void mergeAll(Collection<? extends Diff> differences, boolean leftToRight, IBatchMerger merger,
+ Registry mergerRegistry, Monitor emfMonitor) {
+ if (leftToRight) {
+ merger.copyAllLeftToRight(differences, emfMonitor);
+ } else {
+ merger.copyAllRightToLeft(differences, emfMonitor);
+ }
+
+ for (Diff difference : differences) {
+ final IMerger diffMerger = mergerRegistry.getHighestRankingMerger(difference);
+ if (diffMerger instanceof IMerger2) {
+ final Set<Diff> resultingMerges = MergeDependenciesUtil.getAllResultingMerges(difference,
+ mergerRegistry, !leftToRight);
+ addOrUpdateMergeData(resultingMerges, getMergeMode());
+
+ final Set<Diff> resultingRejections = MergeDependenciesUtil.getAllResultingRejections(
+ difference, mergerRegistry, !leftToRight);
+ addOrUpdateMergeData(resultingRejections, getMergeMode().inverse());
+ } else {
+ addOrUpdateMergeData(Collections.singleton(difference), getMergeMode());
+ }
+ }
+ }
}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/util/MergeViewerUtil.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/util/MergeViewerUtil.java
index 8bd30c068..b4a02af70 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/util/MergeViewerUtil.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/util/MergeViewerUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2014 Obeo.
+ * Copyright (c) 2012, 2015 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -375,12 +375,16 @@ public final class MergeViewerUtil {
final boolean markAsMerged;
if (diff.getState() == DifferenceState.MERGED) {
IMergeData mergeData = (IMergeData)EcoreUtil.getExistingAdapter(diff, IMergeData.class);
- boolean leftEditable = compareConfiguration.isLeftEditable();
- boolean rightEditable = compareConfiguration.isRightEditable();
- MergeMode mergeMode = mergeData.getMergeMode();
- MergeOperation mergeAction = mergeMode.getMergeAction(diff, leftEditable, rightEditable);
- if (mergeAction == MergeOperation.MARK_AS_MERGE) {
- markAsMerged = true;
+ if (mergeData != null) {
+ boolean leftEditable = compareConfiguration.isLeftEditable();
+ boolean rightEditable = compareConfiguration.isRightEditable();
+ MergeMode mergeMode = mergeData.getMergeMode();
+ MergeOperation mergeAction = mergeMode.getMergeAction(diff, leftEditable, rightEditable);
+ if (mergeAction == MergeOperation.MARK_AS_MERGE) {
+ markAsMerged = true;
+ } else {
+ markAsMerged = false;
+ }
} else {
markAsMerged = false;
}
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/MergeDependenciesUtil.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/MergeDependenciesUtil.java
index a290f67f3..26d0dcb10 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/MergeDependenciesUtil.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/MergeDependenciesUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2014 Obeo.
+ * Copyright (c) 2014, 2015 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -13,6 +13,7 @@ package org.eclipse.emf.compare.internal.merge;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide;
import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
@@ -56,16 +57,20 @@ public final class MergeDependenciesUtil {
* The {@link IMerger.Registry merger registry} currently in use.
* @param mergeRightToLeft
* The direction in which we're preparing a merge.
+ * @param mergeMode
+ * The merge mode. If MergeMode is null, then no differences will be filtered.
* @return The dependency graph of this comparison's differences.
*/
public static Graph<Diff> mapDifferences(Comparison comparison, IMerger.Registry mergerRegistry,
- boolean mergeRightToLeft) {
+ boolean mergeRightToLeft, MergeMode mergeMode) {
Graph<Diff> differencesGraph = new Graph<Diff>();
final Predicate<? super Diff> filter;
- if (mergeRightToLeft) {
+ if (mergeMode == MergeMode.RIGHT_TO_LEFT) {
filter = fromSide(DifferenceSource.RIGHT);
- } else {
+ } else if (mergeMode == MergeMode.LEFT_TO_RIGHT) {
filter = fromSide(DifferenceSource.LEFT);
+ } else {
+ filter = Predicates.alwaysTrue();
}
for (Diff diff : Iterables.filter(comparison.getDifferences(), filter)) {
final IMerger merger = mergerRegistry.getHighestRankingMerger(diff);

Back to the top