Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Fleck2017-05-02 11:59:50 -0400
committerLaurent Goubet2017-09-07 12:18:01 -0400
commita69366cc0e1c0f7f3a66911216dd13935b3615ba (patch)
tree891b473244abba6d21f8c4b9dbcc58ff48053736
parent591ce92e5689695a3ae3a5d49db6fc0ff93d5c33 (diff)
downloadorg.eclipse.emf.compare-a69366cc0e1c0f7f3a66911216dd13935b3615ba.tar.gz
org.eclipse.emf.compare-a69366cc0e1c0f7f3a66911216dd13935b3615ba.tar.xz
org.eclipse.emf.compare-a69366cc0e1c0f7f3a66911216dd13935b3615ba.zip
[516060] Opaque Action Body conflict resolution results in wrong body
Ensure that the text merge is not executed for REAL conflicts; instead just take the selected side. Includes tests. Bug: 516060 Change-Id: Ib150b2e70b4f0da20d1b2b09ae1e4353d9cbf34e Signed-off-by: Martin Fleck <mfleck@eclipsesource.com>
-rw-r--r--plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/opaque/OpaqueElementBodyChangeMergeTest.java97
-rw-r--r--plugins/org.eclipse.emf.compare.uml2/src/org/eclipse/emf/compare/uml2/internal/merge/OpaqueElementBodyChangeMerger.java8
2 files changed, 85 insertions, 20 deletions
diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/opaque/OpaqueElementBodyChangeMergeTest.java b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/opaque/OpaqueElementBodyChangeMergeTest.java
index 2a94bc23a..3b0d0ec7b 100644
--- a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/opaque/OpaqueElementBodyChangeMergeTest.java
+++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/opaque/OpaqueElementBodyChangeMergeTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2014, 2015 EclipseSource Muenchen GmbH and others.
+ * Copyright (c) 2014, 2017 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
@@ -7,6 +7,7 @@
*
* Contributors:
* Philip Langer - initial API and implementation
+ * Martin Fleck - bug 516060
*******************************************************************************/
package org.eclipse.emf.compare.uml2.tests.opaque;
@@ -30,7 +31,8 @@ import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Conflict;
import org.eclipse.emf.compare.ConflictKind;
import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.merge.IMerger;
+import org.eclipse.emf.compare.merge.BatchMerger;
+import org.eclipse.emf.compare.merge.IBatchMerger;
import org.eclipse.emf.compare.uml2.internal.OpaqueElementBodyChange;
import org.eclipse.emf.compare.uml2.tests.AbstractUMLInputData;
import org.eclipse.emf.compare.uml2.tests.AbstractUMLTest;
@@ -102,6 +104,24 @@ public class OpaqueElementBodyChangeMergeTest extends AbstractUMLTest {
+ "and concurrent changes" + NL //
+ "of them.";
+ private static final String A2_ORIGIN = "This is a" + NL //
+ + "test with multi-line" + NL //
+ + "String attribute" + NL //
+ + "and concurrent changes" + NL //
+ + "of them.";
+
+ private static final String A2_LEFT = "This is a" + NL //
+ + "test with multi-line (changed)" + NL //
+ + "String attribute" + NL //
+ + "and concurrent changes" + NL //
+ + "of them.";
+
+ private static final String A2_RIGHT = "This is a" + NL //
+ + "(changed)test with multi-line" + NL //
+ + "String attribute" + NL //
+ + "and concurrent changes" + NL //
+ + "of them.";
+
private static final Predicate<Diff> IS_OPAQUE_ELEMENT_CHANGE = new Predicate<Diff>() {
public boolean apply(Diff diff) {
return diff instanceof OpaqueElementBodyChange;
@@ -237,6 +257,55 @@ public class OpaqueElementBodyChangeMergeTest extends AbstractUMLTest {
}
@Test
+ public void testA2UseCaseLtoR() throws IOException {
+ Resource origin = input.getA2Origin();
+ Resource left = input.getA2Left();
+ Resource right = input.getA2Right();
+
+ Comparison comparison = compare(left, right, origin);
+ assertOneRealConflictOnOpaqueElementBodyChange(comparison);
+ assertA2UseCaseBody(origin.getEObject(OPAQUE_ACTION1_ID), A2_ORIGIN);
+ assertA2UseCaseBody(left.getEObject(OPAQUE_ACTION1_ID), A2_LEFT);
+ assertA2UseCaseBody(right.getEObject(OPAQUE_ACTION1_ID), A2_RIGHT);
+
+ // real conflict, apply left side
+ applyLeftOpaqueElementBodyChangesToRight(comparison);
+
+ assertA2UseCaseBody(origin.getEObject(OPAQUE_ACTION1_ID), A2_ORIGIN);
+ assertA2UseCaseBody(left.getEObject(OPAQUE_ACTION1_ID), A2_LEFT);
+ assertA2UseCaseBody(right.getEObject(OPAQUE_ACTION1_ID), A2_LEFT);
+ }
+
+ @Test
+ public void testA2UseCaseRtoL() throws IOException {
+ Resource origin = input.getA2Origin();
+ Resource left = input.getA2Left();
+ Resource right = input.getA2Right();
+
+ Comparison comparison = compare(left, right, origin);
+ assertOneRealConflictOnOpaqueElementBodyChange(comparison);
+ assertA2UseCaseBody(origin.getEObject(OPAQUE_ACTION1_ID), A2_ORIGIN);
+ assertA2UseCaseBody(left.getEObject(OPAQUE_ACTION1_ID), A2_LEFT);
+ assertA2UseCaseBody(right.getEObject(OPAQUE_ACTION1_ID), A2_RIGHT);
+
+ // real conflict, apply right side
+ applyRightOpaqueElementBodyChangesToLeft(comparison);
+
+ assertA2UseCaseBody(origin.getEObject(OPAQUE_ACTION1_ID), A2_ORIGIN);
+ assertA2UseCaseBody(left.getEObject(OPAQUE_ACTION1_ID), A2_RIGHT);
+ assertA2UseCaseBody(right.getEObject(OPAQUE_ACTION1_ID), A2_RIGHT);
+ }
+
+ private void assertA2UseCaseBody(EObject eObject, String expectedBody) {
+ assertTrue(eObject instanceof OpaqueAction);
+ OpaqueAction opaqueAction = (OpaqueAction)eObject;
+ assertEquals(1, opaqueAction.getBodies().size());
+ assertEquals(1, opaqueAction.getLanguages().size());
+ assertEquals(JAVA, opaqueAction.getLanguages().get(0));
+ assertEquals(expectedBody, opaqueAction.getBodies().get(0));
+ }
+
+ @Test
public void testA3UseCase() throws IOException {
Resource origin = input.getA3Origin();
Resource left = input.getA3Left();
@@ -670,40 +739,32 @@ public class OpaqueElementBodyChangeMergeTest extends AbstractUMLTest {
final EList<Diff> allDifferences = comparison.getDifferences();
final Iterable<Diff> rightOpaqueElementBodyChanges = filter(allDifferences,
and(IS_OPAQUE_ELEMENT_CHANGE, fromSide(RIGHT)));
- for (Diff diff : rightOpaqueElementBodyChanges) {
- IMerger merger = getMergerRegistry().getHighestRankingMerger(diff);
- merger.copyRightToLeft(diff, new BasicMonitor());
- }
+ final IBatchMerger merger = new BatchMerger(getMergerRegistry());
+ merger.copyAllRightToLeft(rightOpaqueElementBodyChanges, new BasicMonitor());
}
private void revertLeftOpaqueElementBodyChanges(Comparison comparison) {
final EList<Diff> allDifferences = comparison.getDifferences();
final Iterable<Diff> leftOpaqueElementBodyChanges = filter(allDifferences,
and(IS_OPAQUE_ELEMENT_CHANGE, fromSide(LEFT)));
- for (Diff diff : leftOpaqueElementBodyChanges) {
- IMerger merger = getMergerRegistry().getHighestRankingMerger(diff);
- merger.copyRightToLeft(diff, new BasicMonitor());
- }
+ final IBatchMerger merger = new BatchMerger(getMergerRegistry());
+ merger.copyAllRightToLeft(leftOpaqueElementBodyChanges, new BasicMonitor());
}
private void revertRightOpaqueElementBodyChanges(Comparison comparison) {
final EList<Diff> allDifferences = comparison.getDifferences();
final Iterable<Diff> rightOpaqueElementBodyChanges = filter(allDifferences,
and(IS_OPAQUE_ELEMENT_CHANGE, fromSide(RIGHT)));
- for (Diff diff : rightOpaqueElementBodyChanges) {
- IMerger merger = getMergerRegistry().getHighestRankingMerger(diff);
- merger.copyLeftToRight(diff, new BasicMonitor());
- }
+ final IBatchMerger merger = new BatchMerger(getMergerRegistry());
+ merger.copyAllLeftToRight(rightOpaqueElementBodyChanges, new BasicMonitor());
}
private void applyLeftOpaqueElementBodyChangesToRight(Comparison comparison) {
final EList<Diff> allDifferences = comparison.getDifferences();
final Iterable<Diff> leftOpaqueElementBodyChanges = filter(allDifferences,
and(IS_OPAQUE_ELEMENT_CHANGE, fromSide(LEFT)));
- for (Diff diff : leftOpaqueElementBodyChanges) {
- IMerger merger = getMergerRegistry().getHighestRankingMerger(diff);
- merger.copyLeftToRight(diff, new BasicMonitor());
- }
+ final IBatchMerger merger = new BatchMerger(getMergerRegistry());
+ merger.copyAllLeftToRight(leftOpaqueElementBodyChanges, new BasicMonitor());
}
private void assertNoRealConflict(Comparison comparison) {
diff --git a/plugins/org.eclipse.emf.compare.uml2/src/org/eclipse/emf/compare/uml2/internal/merge/OpaqueElementBodyChangeMerger.java b/plugins/org.eclipse.emf.compare.uml2/src/org/eclipse/emf/compare/uml2/internal/merge/OpaqueElementBodyChangeMerger.java
index d042d1340..b1231bc8e 100644
--- a/plugins/org.eclipse.emf.compare.uml2/src/org/eclipse/emf/compare/uml2/internal/merge/OpaqueElementBodyChangeMerger.java
+++ b/plugins/org.eclipse.emf.compare.uml2/src/org/eclipse/emf/compare/uml2/internal/merge/OpaqueElementBodyChangeMerger.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2014, 2016 EclipseSource Muenchen GmbH and others.
+ * Copyright (c) 2014, 2017 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
@@ -8,12 +8,15 @@
* Contributors:
* Philip Langer - initial API and implementation
* Martin Fleck - bug 507177: consider refinement behavior
+ * Martin Fleck - bug 516060
*******************************************************************************/
package org.eclipse.emf.compare.uml2.internal.merge;
+import static org.eclipse.emf.compare.ConflictKind.REAL;
import static org.eclipse.emf.compare.uml2.internal.postprocessor.util.UMLCompareUtil.getOpaqueElementLanguages;
import static org.eclipse.emf.compare.uml2.internal.postprocessor.util.UMLCompareUtil.isChangeOfOpaqueElementBodyAttribute;
import static org.eclipse.emf.compare.uml2.internal.postprocessor.util.UMLCompareUtil.isChangeOfOpaqueElementLanguageAttribute;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.hasConflict;
import com.google.common.base.Optional;
@@ -328,7 +331,8 @@ public class OpaqueElementBodyChangeMerger extends AttributeChangeMerger {
*/
private String getTargetBodyValue(OpaqueElementBodyChange bodyChange, boolean rightToLeft) {
final String newBody;
- if (bodyChange.getMatch().getComparison().isThreeWay()) {
+ boolean hasRealConflict = hasConflict(REAL).apply(bodyChange);
+ if (bodyChange.getMatch().getComparison().isThreeWay() && !hasRealConflict) {
newBody = performThreeWayTextMerge(bodyChange, rightToLeft);
} else if (rightToLeft) {
newBody = getRightBodyValue(bodyChange);

Back to the top