Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-03-18 07:24:32 -0400
committerEike Stepper2013-03-18 07:24:32 -0400
commitf8cbd61bb2875664281ab37f54ca58c02b1775ef (patch)
tree9e73632435350804edb72985b6021dfba66737f5
parent5991889c5ff1a0745f52d23255bb6904c18cdf33 (diff)
downloadcdo-f8cbd61bb2875664281ab37f54ca58c02b1775ef.tar.gz
cdo-f8cbd61bb2875664281ab37f54ca58c02b1775ef.tar.xz
cdo-f8cbd61bb2875664281ab37f54ca58c02b1775ef.zip
[402371] CDOCompareUtil.compare fails with models that use Containment
Proxies https://bugs.eclipse.org/bugs/show_bug.cgi?id=402371
-rw-r--r--plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOComparisonScope.java38
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EMFCompareTest.java24
2 files changed, 39 insertions, 23 deletions
diff --git a/plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOComparisonScope.java b/plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOComparisonScope.java
index 4350fa6783..e9b9b5f529 100644
--- a/plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOComparisonScope.java
+++ b/plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOComparisonScope.java
@@ -34,6 +34,8 @@ import org.eclipse.emf.compare.scope.IComparisonScope;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.ecore.util.EcoreUtil.ProperContentIterator;
import org.eclipse.emf.spi.cdo.InternalCDOSession;
import org.eclipse.emf.spi.cdo.InternalCDOSession.MergeData;
@@ -51,6 +53,8 @@ import java.util.Set;
*/
public abstract class CDOComparisonScope extends AbstractComparisonScope
{
+ private boolean resolveProxies = true;
+
public CDOComparisonScope(Notifier left, Notifier right, Notifier origin)
{
super(left, right, origin);
@@ -66,6 +70,16 @@ public abstract class CDOComparisonScope extends AbstractComparisonScope
return Iterators.emptyIterator();
}
+ public final boolean isResolveProxies()
+ {
+ return resolveProxies;
+ }
+
+ public final void setResolveProxies(boolean resolveProxies)
+ {
+ this.resolveProxies = resolveProxies;
+ }
+
private static CDOView openOriginView(CDOView leftView, CDOView rightView, CDOView[] originView)
{
if (leftView.getSession() != rightView.getSession())
@@ -117,7 +131,7 @@ public abstract class CDOComparisonScope extends AbstractComparisonScope
public Iterator<? extends EObject> getChildren(EObject eObject)
{
- return eObject.eAllContents();
+ return EcoreUtil.getAllProperContents(eObject, isResolveProxies());
}
/**
@@ -181,7 +195,14 @@ public abstract class CDOComparisonScope extends AbstractComparisonScope
@Override
public Iterator<EObject> getChildren(Object object)
{
- return Iterators.filter(((EObject)object).eContents().iterator(), Minimal.this);
+ if (object instanceof Resource)
+ {
+ Iterator<EObject> iterator = ((Resource)object).getContents().iterator();
+ return Iterators.filter(iterator, Minimal.this);
+ }
+
+ Iterator<EObject> iterator = new ProperContentIterator<EObject>((EObject)object, isResolveProxies());
+ return Iterators.filter(iterator, Minimal.this);
}
};
}
@@ -209,11 +230,16 @@ public abstract class CDOComparisonScope extends AbstractComparisonScope
CDORevisionData revisionData = object.cdoRevision().data();
- CDOID containerID = (CDOID)revisionData.getContainerID();
- collectRequiredParentIDs(view, containerID, requiredParentIDs);
-
CDOID resourceID = revisionData.getResourceID();
- collectRequiredParentIDs(view, resourceID, requiredParentIDs);
+ if (!CDOIDUtil.isNull(resourceID))
+ {
+ collectRequiredParentIDs(view, resourceID, requiredParentIDs);
+ }
+ else
+ {
+ CDOID containerID = (CDOID)revisionData.getContainerID();
+ collectRequiredParentIDs(view, containerID, requiredParentIDs);
+ }
}
private void collectRequiredParentIDs(CDOView view, CDOID id, Set<CDOID> requiredParentIDs)
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EMFCompareTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EMFCompareTest.java
index 09d91481be..6329c1f02e 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EMFCompareTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EMFCompareTest.java
@@ -165,12 +165,7 @@ public class EMFCompareTest extends AbstractCDOTest
Comparison comparison = CDOCompareUtil.compare(transaction, session.openView(commitInfo), null);
dump(comparison);
-
- Match match = comparison.getMatch(categoryCrossContained);
- EList<Diff> differences = match.getDifferences();
-
- int fails;
- assertEquals(0, differences.size());
+ assertEquals(0, comparison.getMatch(categoryCrossContained).getDifferences().size());
}
public void testContainmentProxyEMF() throws Exception
@@ -179,8 +174,8 @@ public class EMFCompareTest extends AbstractCDOTest
Category categoryCrossContained = populate(resourceSetA);
ResourceSet resourceSetB = createResourceSet();
- Product1 product0 = populate(resourceSetA).getProducts().get(0);
- product0.setName("CHANGED");
+ Product1 product0 = populate(resourceSetB).getProducts().get(0);
+ product0.setName("ProductB");
IComparisonScope scope = EMFCompare.createDefaultScope(resourceSetA, resourceSetB);
@@ -193,10 +188,8 @@ public class EMFCompareTest extends AbstractCDOTest
// Compare the two models
Comparison comparison = comparator.compare(scope);
dump(comparison);
-
- Match match = comparison.getMatch(categoryCrossContained);
- EList<Diff> differences = match.getDifferences();
- assertEquals(0, differences.size());
+ assertEquals(0, comparison.getMatch(categoryCrossContained).getDifferences().size());
+ assertEquals(1, comparison.getMatch(product0).getDifferences().size());
}
public void testNoContainmentProxy() throws Exception
@@ -228,9 +221,7 @@ public class EMFCompareTest extends AbstractCDOTest
Comparison comparison = CDOCompareUtil.compare(transaction, session.openView(commitInfo), null);
dump(comparison);
-
- Match match = comparison.getMatch(category);
- assertEquals(0, match.getDifferences().size());
+ assertEquals(0, comparison.getMatch(category).getDifferences().size());
}
public void testChanges() throws Exception
@@ -260,7 +251,6 @@ public class EMFCompareTest extends AbstractCDOTest
Comparison comparison = CDOCompareUtil.compareUncommittedChanges(transaction);
dump(comparison);
-
assertEquals(1, comparison.getMatch(category1).getDifferences().size());
assertEquals(1, comparison.getMatch(company).getDifferences().size());
}
@@ -285,7 +275,6 @@ public class EMFCompareTest extends AbstractCDOTest
Comparison comparison = CDOCompareUtil.compareUncommittedChanges(transaction);
dump(comparison);
-
assertEquals(1, comparison.getMatch(company).getDifferences().size());
}
@@ -372,6 +361,7 @@ public class EMFCompareTest extends AbstractCDOTest
for (int i = 0; i < 10; ++i)
{
Product1 product = factory.createProduct1();
+ product.setName("Product" + i);
categoryCrossContained.getProducts().add(product);
}

Back to the top