Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/FeatureMapMoveDiffTest.java90
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/data/FeatureMapMoveDiffInputData.java27
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/data/featuremapmove/left.nodes13
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/data/featuremapmove/right.nodes13
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java7
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/diff/DefaultDiffEngine.java31
6 files changed, 177 insertions, 4 deletions
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/FeatureMapMoveDiffTest.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/FeatureMapMoveDiffTest.java
new file mode 100644
index 000000000..08b428a29
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/FeatureMapMoveDiffTest.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2014 EclipseSource Muenchen GmbH and others.
+ * 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:
+ * Stefan Dirix - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.tests.diff;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.DifferenceKind;
+import org.eclipse.emf.compare.EMFCompare;
+import org.eclipse.emf.compare.FeatureMapChange;
+import org.eclipse.emf.compare.ReferenceChange;
+import org.eclipse.emf.compare.scope.DefaultComparisonScope;
+import org.eclipse.emf.compare.scope.IComparisonScope;
+import org.eclipse.emf.compare.tests.diff.data.FeatureMapMoveDiffInputData;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.junit.Test;
+
+/**
+ * Tests the DiffEngine for its handling of FeatureMap Changes.
+ *
+ * @author Stefan Dirix <sdirix@eclipsesource.com>
+ */
+@SuppressWarnings("nls")
+public class FeatureMapMoveDiffTest {
+
+ private FeatureMapMoveDiffInputData input = new FeatureMapMoveDiffInputData();
+
+ /**
+ * Tests a scenario in which an element is moved from one FeatureMap to another whereby the Nodes
+ * containing the FeatureMaps are also added / removed. For this case the DiffEngine must calculate
+ * additional FeatureMapChanges to keep the order of the elements during merging.
+ *
+ * @throws IOException
+ * if {@link FeatureMapMoveDiffInputData} fails to load the test models.
+ */
+ @Test
+ public void testFeatureMapMoveDiffs() throws IOException {
+ final Resource left = input.getFeatureMapMoveLeft();
+ final Resource right = input.getFeatureMapMoveRight();
+
+ final IComparisonScope scope = new DefaultComparisonScope(right, left, null);
+ Comparison comparison = EMFCompare.builder().build().compare(scope);
+
+ // should detect 6 differences when diffengine does not cut off featuremap changes
+ final List<Diff> differences = comparison.getDifferences();
+ assertEquals(6, differences.size());
+
+ // 2 of them should be move reference changes
+ final List<Diff> moveDifferences = new ArrayList<Diff>(2);
+ for (Diff diff : differences) {
+ if (diff instanceof ReferenceChange && diff.getKind() == DifferenceKind.MOVE) {
+ moveDifferences.add(diff);
+ }
+ }
+ assertEquals(2, moveDifferences.size());
+
+ // check if move reference changes are accompanied with featuremap changes
+ for (Diff mdiff : moveDifferences) {
+ // moveDiff itself + featuremap change
+ assertEquals(2, mdiff.getEquivalence().getDifferences().size());
+
+ boolean foundFeatureMapChange = false;
+ for (Diff equivalent : mdiff.getEquivalence().getDifferences()) {
+ if (equivalent != mdiff) {
+ assertTrue(equivalent instanceof FeatureMapChange);
+ foundFeatureMapChange = true;
+ }
+ }
+ if (!foundFeatureMapChange) {
+ fail("ReferenceChange should have FeatureMapChange as equivalent");
+ }
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/data/FeatureMapMoveDiffInputData.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/data/FeatureMapMoveDiffInputData.java
new file mode 100644
index 000000000..6f88c9521
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/data/FeatureMapMoveDiffInputData.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2014 EclipseSource Muenchen GmbH and others.
+ * 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:
+ * Stefan Dirix - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.tests.diff.data;
+
+import java.io.IOException;
+
+import org.eclipse.emf.compare.tests.framework.AbstractInputData;
+import org.eclipse.emf.ecore.resource.Resource;
+
+@SuppressWarnings("nls")
+public class FeatureMapMoveDiffInputData extends AbstractInputData {
+ public Resource getFeatureMapMoveLeft() throws IOException {
+ return loadFromClassLoader("featuremapmove/left.nodes");
+ }
+
+ public Resource getFeatureMapMoveRight() throws IOException {
+ return loadFromClassLoader("featuremapmove/right.nodes");
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/data/featuremapmove/left.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/data/featuremapmove/left.nodes
new file mode 100644
index 000000000..ec5f2a5ac
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/data/featuremapmove/left.nodes
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<nodes:Node
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes"
+ xmi:id="_root"
+ name="Root">
+ <containmentRef1 xsi:type="nodes:NodeFeatureMapContainment2" name="n1">
+ <single name="a"/>
+ <multiple name="b"/>
+ </containmentRef1>
+</nodes:Node> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/data/featuremapmove/right.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/data/featuremapmove/right.nodes
new file mode 100644
index 000000000..54602874f
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/data/featuremapmove/right.nodes
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<nodes:Node
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes"
+ xmi:id="_root"
+ name="Root">
+ <containmentRef1 xsi:type="nodes:NodeFeatureMapContainment2" name="n2">
+ <multiple name="b"/>
+ <single name="a"/>
+ </containmentRef1>
+</nodes:Node> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java
index 2ba7be843..3ffa48368 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java
@@ -20,6 +20,7 @@ import org.eclipse.emf.compare.tests.command.CommandStackTestSuite;
import org.eclipse.emf.compare.tests.conflict.ConflictDetectionTest;
import org.eclipse.emf.compare.tests.conflict.MultiLineAttributeConflictDetectionTest;
import org.eclipse.emf.compare.tests.diff.ComparisonUtilTest;
+import org.eclipse.emf.compare.tests.diff.FeatureMapMoveDiffTest;
import org.eclipse.emf.compare.tests.diff.DiffUtilTest;
import org.eclipse.emf.compare.tests.diff.FeatureFilterTest;
import org.eclipse.emf.compare.tests.diff.LCSPerformanceTest;
@@ -69,9 +70,9 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({CompareTestSuite.class, DefaultComparisonScopeTest.class, IdentifierComparisonTest.class,
ExtLibraryTest.class, ConflictDetectionTest.class, ReqComputingTest.class, EquiComputingTest.class,
- DiffUtilTest.class, ComparisonUtilTest.class, LCSPerformanceTest.class, MultipleMergeTest.class,
- PostProcessorTest.class, IndividualMergeTest.class, ExtensionMergeTest.class,
- IndividualMergeOutOfScopeValuesTest.class, ProximityComparisonTest.class,
+ DiffUtilTest.class, FeatureMapMoveDiffTest.class, ComparisonUtilTest.class, LCSPerformanceTest.class,
+ MultipleMergeTest.class, PostProcessorTest.class, IndividualMergeTest.class,
+ ExtensionMergeTest.class, IndividualMergeOutOfScopeValuesTest.class, ProximityComparisonTest.class,
DynamicInstanceComparisonTest.class, URIDistanceTest.class, FragmentationTest.class,
AllEditTests.class, CommandStackTestSuite.class, MatchEngineFactoryRegistryTest.class,
ConflictMergeTest.class, PseudoConflictMergeTest.class, ProximityIndexTest.class, AllRCPTests.class,
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/diff/DefaultDiffEngine.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/diff/DefaultDiffEngine.java
index ac426f067..adddf4f4c 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/diff/DefaultDiffEngine.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/diff/DefaultDiffEngine.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2014 Obeo.
+ * Copyright (c) 2012, 2014 Obeo and others.
* 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
@@ -7,6 +7,7 @@
*
* Contributors:
* Obeo - initial API and implementation
+ * Stefan Dirix - bug 450949
*******************************************************************************/
package org.eclipse.emf.compare.diff;
@@ -492,6 +493,15 @@ public class DefaultDiffEngine implements IDiffEngine {
} else {
shortcut = match.getLeft() == null || match.getRight() == null;
}
+
+ // Do not shortcut when manyvalued FeatureMaps are affected to keep their ordering intact
+ if (shortcut && FeatureMapUtil.isFeatureMap(attribute)) {
+ final EObject owner = getOwner(match);
+ if (owner != null && FeatureMapUtil.isMany(owner, attribute)) {
+ shortcut = false;
+ }
+ }
+
if (shortcut) {
return;
}
@@ -508,6 +518,25 @@ public class DefaultDiffEngine implements IDiffEngine {
}
/**
+ * Returns one side of the match if any exist. The order of the checked sides is Origin, Left and Right.
+ *
+ * @param match
+ * The match whose sides are checked.
+ * @return Either Origin, Left or Right if one of them exists, {@code null} otherwise.
+ */
+ private EObject getOwner(Match match) {
+ EObject owner = null;
+ if (match.getOrigin() != null) {
+ owner = match.getOrigin();
+ } else if (match.getLeft() != null) {
+ owner = match.getLeft();
+ } else if (match.getRight() != null) {
+ owner = match.getRight();
+ }
+ return owner;
+ }
+
+ /**
* Computes the difference between the sides of the given <code>match</code> for the given
* <code>reference</code>.
*

Back to the top