Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOCompareUtil.java107
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EMFCompareTest.java71
2 files changed, 159 insertions, 19 deletions
diff --git a/plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOCompareUtil.java b/plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOCompareUtil.java
index 3fcffc08db..5fbd17baf8 100644
--- a/plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOCompareUtil.java
+++ b/plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOCompareUtil.java
@@ -12,8 +12,10 @@ package org.eclipse.emf.cdo.compare;
import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
+import org.eclipse.emf.cdo.common.commit.CDOChangeSetData;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDUtil;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.spi.common.branch.CDOBranchUtil;
import org.eclipse.emf.cdo.util.CDOUtil;
@@ -33,11 +35,16 @@ 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.spi.cdo.InternalCDOSession;
+import org.eclipse.emf.spi.cdo.InternalCDOSession.MergeData;
import com.google.common.base.Function;
+import com.google.common.base.Predicate;
import com.google.common.collect.Iterators;
+import java.util.HashSet;
import java.util.Iterator;
+import java.util.Set;
/**
* Various static methods that may help EMF Compare in a CDO scope.
@@ -73,34 +80,29 @@ public final class CDOCompareUtil
rightView = session.openView(right);
}
- CDOObject leftObject = leftView.getRootResource();
- Notifier rightObject = rightView.getRootResource();
-
CDOView originView = null;
- Notifier originObject = null;
if (threeWay)
{
CDOBranchPoint ancestor = CDOBranchUtil.getAncestor(leftView, rightView);
if (!ancestor.equals(leftView) && !ancestor.equals(rightView))
{
originView = session.openView(ancestor);
- originObject = originView.getRootResource();
}
}
- // Set<CDOID> ids;
- // if (originView != null)
- // {
- // MergeData mergeData = ((InternalCDOSession)session).getMergeData(leftView, rightView, null);
- // ids = mergeData.getIDs();
- // }
- // else
- // {
- // CDOChangeSetData changeSetData = leftView.compareRevisions(right);
- // ids = changeSetData.getChangeKinds().keySet();
- // }
+ Set<CDOID> ids;
+ if (originView != null)
+ {
+ MergeData mergeData = ((InternalCDOSession)session).getMergeData(leftView, rightView, null);
+ ids = mergeData.getIDs();
+ }
+ else
+ {
+ CDOChangeSetData changeSetData = leftView.compareRevisions(right);
+ ids = new HashSet<CDOID>(changeSetData.getChangeKinds().keySet());
+ }
- IComparisonScope scope = new CDOComparisonScope.AllContents(leftObject, rightObject, originObject);
+ IComparisonScope scope = new CDOComparisonScope.Minimal(leftView, rightView, originView, ids);
return createComparison(scope, leftView, rightView, originView);
}
@@ -271,6 +273,77 @@ public final class CDOCompareUtil
return eObject.eAllContents();
}
}
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class Minimal extends CDOComparisonScope implements Predicate<EObject>
+ {
+ private Set<CDOID> ids;
+
+ public Minimal(CDOView leftView, CDOView rightView, CDOView originView, Set<CDOID> ids)
+ {
+ super(leftView.getRootResource(), rightView.getRootResource(), originView != null ? originView
+ .getRootResource() : null);
+ this.ids = ids;
+
+ Set<CDOID> requiredParentIDs = new HashSet<CDOID>();
+ for (CDOID id : ids)
+ {
+ CDOObject leftObject = leftView.getObject(id);
+ collectRequiredParentIDs(leftObject, requiredParentIDs);
+
+ CDOObject rightObject = rightView.getObject(id);
+ collectRequiredParentIDs(rightObject, requiredParentIDs);
+
+ if (originView != null)
+ {
+ CDOObject originObject = originView.getObject(id);
+ collectRequiredParentIDs(originObject, requiredParentIDs);
+ }
+ }
+
+ ids.addAll(requiredParentIDs);
+ }
+
+ public Iterator<? extends EObject> getChildren(EObject eObject)
+ {
+ return Iterators.filter(eObject.eAllContents(), this);
+ }
+
+ public boolean apply(EObject input)
+ {
+ CDOObject object = CDOUtil.getCDOObject(input);
+ CDOID id = object.cdoID();
+ return ids.contains(id);
+ }
+
+ private void collectRequiredParentIDs(CDOObject object, Set<CDOID> requiredParentIDs)
+ {
+ CDOView view = object.cdoView();
+ CDORevision revision = object.cdoRevision();
+
+ CDOID containerID = (CDOID)revision.data().getContainerID();
+ collectRequiredParentIDs(view, containerID, requiredParentIDs);
+
+ CDOID resourceID = revision.data().getResourceID();
+ collectRequiredParentIDs(view, resourceID, requiredParentIDs);
+ }
+
+ private void collectRequiredParentIDs(CDOView view, CDOID id, Set<CDOID> requiredParentIDs)
+ {
+ if (!CDOIDUtil.isNull(id))
+ {
+ if (!ids.contains(id) && !requiredParentIDs.contains(id))
+ {
+ requiredParentIDs.add(id);
+
+ CDOObject object = view.getObject(id);
+ collectRequiredParentIDs(object, 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 3edee66546..ae5303508d 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
@@ -34,15 +34,45 @@ import org.eclipse.emf.ecore.EObject;
public class EMFCompareTest extends AbstractCDOTest
{
@SuppressWarnings("unused")
- public void testNewAudit() throws Exception
+ public void testAllContentsOfRoot() throws Exception
{
CDOSession session = openSession();
CDOTransaction transaction = session.openTransaction();
CDOResource resource = transaction.createResource(getResourcePath("/res1"));
- Company company = getModel1Factory().createCompany();
+ Company company = createCompany();
company.setName("ESC");
+
resource.getContents().add(company);
+ resource.getContents().add(createCompany());
+ resource.getContents().add(createCompany());
+ CDOCommitInfo commit1 = transaction.commit();
+
+ company.setName("Sympedia");
+ CDOCommitInfo commit2 = transaction.commit();
+
+ company.setName("Eclipse");
+ CDOCommitInfo commit3 = transaction.commit();
+
+ // CloseableComparison comparison = CDOCompareUtil.compare(session.openView(commit2).getObject(company), commit3);
+ CDOComparison comparison = CDOCompareUtil.compare(transaction.getRootResource(), commit2);
+ dump(comparison.getMatches(), "");
+ comparison.close();
+ }
+
+ @SuppressWarnings("unused")
+ public void testAllContentsOfCompany() throws Exception
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource(getResourcePath("/res1"));
+
+ Company company = createCompany();
+ company.setName("ESC");
+
+ resource.getContents().add(company);
+ resource.getContents().add(createCompany());
+ resource.getContents().add(createCompany());
CDOCommitInfo commit1 = transaction.commit();
company.setName("Sympedia");
@@ -57,6 +87,43 @@ public class EMFCompareTest extends AbstractCDOTest
comparison.close();
}
+ @SuppressWarnings("unused")
+ public void testMinimal() throws Exception
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource(getResourcePath("/res1"));
+
+ Company company = createCompany();
+
+ resource.getContents().add(company);
+ resource.getContents().add(createCompany());
+ resource.getContents().add(createCompany());
+ CDOCommitInfo commit1 = transaction.commit();
+
+ company.setName("Sympedia");
+ CDOCommitInfo commit2 = transaction.commit();
+
+ company.setName("Eclipse");
+ CDOCommitInfo commit3 = transaction.commit();
+
+ // CloseableComparison comparison = CDOCompareUtil.compare(session.openView(commit2).getObject(company), commit3);
+ CDOComparison comparison = CDOCompareUtil.compare(transaction, commit2);
+ dump(comparison.getMatches(), "");
+ comparison.close();
+ }
+
+ private Company createCompany()
+ {
+ Company company = getModel1Factory().createCompany();
+ company.getCategories().add(getModel1Factory().createCategory());
+ company.getCategories().add(getModel1Factory().createCategory());
+ company.getCategories().add(getModel1Factory().createCategory());
+ company.getCategories().add(getModel1Factory().createCategory());
+ company.getCategories().add(getModel1Factory().createCategory());
+ return company;
+ }
+
private static void dump(EList<Match> matches, String indent)
{
for (Match match : matches)

Back to the top