Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-03-16 07:53:42 -0400
committerEike Stepper2013-03-16 08:01:59 -0400
commit5991889c5ff1a0745f52d23255bb6904c18cdf33 (patch)
treefd34eefd6f12735b61bd97dfe182dd993ae0dcc5
parent14f00f443494295a5fde8000ec05959eba0262cd (diff)
downloadcdo-5991889c5ff1a0745f52d23255bb6904c18cdf33.tar.gz
cdo-5991889c5ff1a0745f52d23255bb6904c18cdf33.tar.xz
cdo-5991889c5ff1a0745f52d23255bb6904c18cdf33.zip
[403125] Support FeatureFilter in CDOCompareUtil
https://bugs.eclipse.org/bugs/show_bug.cgi?id=403125
-rw-r--r--plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOCompare.java224
-rw-r--r--plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOCompareUtil.java139
-rw-r--r--plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOComparisonScope.java91
-rw-r--r--plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOIDFunction.java38
-rw-r--r--plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/ComparisonScopeAdapter.java38
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EMFCompareTest.java57
-rw-r--r--plugins/org.eclipse.emf.cdo.ui.compare/src/org/eclipse/emf/cdo/ui/compare/CDOCompareEditorUtil.java5
7 files changed, 384 insertions, 208 deletions
diff --git a/plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOCompare.java b/plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOCompare.java
new file mode 100644
index 0000000000..5441b55a0d
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOCompare.java
@@ -0,0 +1,224 @@
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.compare;
+
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.id.CDOIDUtil;
+import org.eclipse.emf.cdo.common.model.EMFUtil;
+import org.eclipse.emf.cdo.util.CDOUtil;
+
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
+import org.eclipse.emf.common.util.Monitor;
+import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.EMFCompare;
+import org.eclipse.emf.compare.EMFCompare.Builder;
+import org.eclipse.emf.compare.conflict.IConflictDetector;
+import org.eclipse.emf.compare.diff.IDiffEngine;
+import org.eclipse.emf.compare.equi.IEquiEngine;
+import org.eclipse.emf.compare.extension.PostProcessorRegistry;
+import org.eclipse.emf.compare.match.DefaultComparisonFactory;
+import org.eclipse.emf.compare.match.DefaultEqualityHelperFactory;
+import org.eclipse.emf.compare.match.DefaultMatchEngine;
+import org.eclipse.emf.compare.match.IComparisonFactory;
+import org.eclipse.emf.compare.match.IEqualityHelperFactory;
+import org.eclipse.emf.compare.match.IMatchEngine;
+import org.eclipse.emf.compare.match.eobject.IEObjectMatcher;
+import org.eclipse.emf.compare.match.eobject.IdentifierEObjectMatcher;
+import org.eclipse.emf.compare.req.IReqEngine;
+import org.eclipse.emf.compare.scope.IComparisonScope;
+import org.eclipse.emf.ecore.EObject;
+
+import com.google.common.base.Function;
+
+/**
+ * @author Eike Stepper
+ */
+public class CDOCompare
+{
+ public Comparison compare(IComparisonScope scope)
+ {
+ Function<EObject, String> idFunction = createIDFunction();
+ IEObjectMatcher matcher = createMatcher(idFunction);
+ IEqualityHelperFactory equalityHelperFactory = createEqualityHelperFactory();
+ IComparisonFactory comparisonFactory = createComparisonFactory(equalityHelperFactory);
+ EMFCompare comparator = createComparator(matcher, comparisonFactory);
+
+ Comparison comparison = comparator.compare(scope);
+ comparison.eAdapters().add(new ComparisonScopeAdapter(scope));
+ return comparison;
+ }
+
+ protected CDOIDFunction createIDFunction()
+ {
+ return new CDOIDFunction();
+ }
+
+ protected IdentifierEObjectMatcher createMatcher(Function<EObject, String> idFunction)
+ {
+ return new IdentifierEObjectMatcher(idFunction);
+ }
+
+ protected IEqualityHelperFactory createEqualityHelperFactory()
+ {
+ return new DefaultEqualityHelperFactory();
+ }
+
+ protected IComparisonFactory createComparisonFactory(IEqualityHelperFactory equalityHelperFactory)
+ {
+ return new DefaultComparisonFactory(equalityHelperFactory);
+ }
+
+ protected EMFCompare createComparator(IEObjectMatcher matcher, IComparisonFactory comparisonFactory)
+ {
+ Builder builder = EMFCompare.builder();
+
+ IMatchEngine matchEngine = createMatchEngine(matcher, comparisonFactory);
+ if (matchEngine != null)
+ {
+ builder.setMatchEngine(matchEngine);
+ }
+
+ IDiffEngine diffEngine = createDiffEngine();
+ if (diffEngine != null)
+ {
+ builder.setDiffEngine(diffEngine);
+ }
+
+ IReqEngine reqEngine = createRequirementEngine();
+ if (reqEngine != null)
+ {
+ builder.setRequirementEngine(reqEngine);
+ }
+
+ IEquiEngine equiEngine = createEquivalenceEngine();
+ if (equiEngine != null)
+ {
+ builder.setEquivalenceEngine(equiEngine);
+ }
+
+ PostProcessorRegistry registry = createPostProcessorRegistry();
+ if (registry != null)
+ {
+ builder.setPostProcessorRegistry(registry);
+ }
+
+ IConflictDetector conflictDetector = createConflictDetector();
+ if (conflictDetector != null)
+ {
+ builder.setConflictDetector(conflictDetector);
+ }
+
+ return builder.build();
+ }
+
+ protected CDOMatchEngine createMatchEngine(IEObjectMatcher matcher, IComparisonFactory comparisonFactory)
+ {
+ return new CDOMatchEngine(matcher, comparisonFactory);
+ }
+
+ protected IDiffEngine createDiffEngine()
+ {
+ return null;
+ }
+
+ protected IReqEngine createRequirementEngine()
+ {
+ return null;
+ }
+
+ protected IEquiEngine createEquivalenceEngine()
+ {
+ return null;
+ }
+
+ protected PostProcessorRegistry createPostProcessorRegistry()
+ {
+ return null;
+ }
+
+ protected IConflictDetector createConflictDetector()
+ {
+ return null;
+ }
+
+ public static IComparisonScope getScope(Comparison comparison)
+ {
+ ComparisonScopeAdapter adapter = EMFUtil.getAdapter(comparison, ComparisonScopeAdapter.class);
+ if (adapter == null)
+ {
+ return null;
+ }
+
+ return adapter.getScope();
+ }
+
+ /**
+ * An {@link CDOIDFunction ID function} that considers the {@link CDOID}s of {@link CDOObject objects}.
+ *
+ * @author Eike Stepper
+ */
+ public static class CDOIDFunction implements Function<EObject, String>
+ {
+ public String apply(EObject o)
+ {
+ CDOObject object = CDOUtil.getCDOObject(o);
+ CDOID id = object.cdoID();
+
+ StringBuilder builder = new StringBuilder();
+ CDOIDUtil.write(builder, id);
+ return builder.toString();
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class CDOMatchEngine extends DefaultMatchEngine
+ {
+ CDOMatchEngine(IEObjectMatcher matcher, IComparisonFactory comparisonFactory)
+ {
+ super(matcher, comparisonFactory);
+ }
+
+ @Override
+ protected void match(Comparison comparison, IComparisonScope scope, final Notifier left, final Notifier right,
+ final Notifier origin, Monitor monitor)
+ {
+ match(comparison, scope, (EObject)left, (EObject)right, (EObject)origin, monitor);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private static final class ComparisonScopeAdapter extends AdapterImpl
+ {
+ private IComparisonScope scope;
+
+ public ComparisonScopeAdapter(IComparisonScope scope)
+ {
+ this.scope = scope;
+ }
+
+ public final IComparisonScope getScope()
+ {
+ return scope;
+ }
+
+ @Override
+ public boolean isAdapterForType(Object type)
+ {
+ return type == ComparisonScopeAdapter.class;
+ }
+ }
+}
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 0d7e7bceb3..fea269b545 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
@@ -13,39 +13,23 @@ package org.eclipse.emf.cdo.compare;
import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.common.branch.CDOBranch;
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.compare.CDOCompare.CDOIDFunction;
import org.eclipse.emf.cdo.compare.CDOComparisonScope.AllContents;
import org.eclipse.emf.cdo.compare.CDOComparisonScope.Minimal;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
import org.eclipse.emf.cdo.eresource.CDOResourceNode;
-import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.spi.common.branch.CDOBranchUtil;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
-import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.view.CDOView;
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.common.util.Monitor;
import org.eclipse.emf.compare.Comparison;
-import org.eclipse.emf.compare.EMFCompare;
import org.eclipse.emf.compare.Match;
-import org.eclipse.emf.compare.match.DefaultComparisonFactory;
-import org.eclipse.emf.compare.match.DefaultEqualityHelperFactory;
-import org.eclipse.emf.compare.match.DefaultMatchEngine;
-import org.eclipse.emf.compare.match.IComparisonFactory;
-import org.eclipse.emf.compare.match.IMatchEngine;
import org.eclipse.emf.compare.match.eobject.IEObjectMatcher;
-import org.eclipse.emf.compare.match.eobject.IdentifierEObjectMatcher;
import org.eclipse.emf.compare.scope.IComparisonScope;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.spi.cdo.InternalCDOSession;
-import org.eclipse.emf.spi.cdo.InternalCDOSession.MergeData;
-import com.google.common.base.Function;
-
-import java.util.HashSet;
import java.util.Set;
/**
@@ -84,6 +68,11 @@ public final class CDOCompareUtil
{
}
+ public static Comparison compare(IComparisonScope scope)
+ {
+ return new CDOCompare().compare(scope);
+ }
+
/**
* Takes an arbitrary {@link CDOObject object} (including {@link CDOResourceNode resource nodes}) and returns {@link Match matches} for <b>all</b> elements of its {@link EObject#eAllContents() content tree}. This scope has the advantage that the comparison can
* be rooted at specific objects that are different from (below of) the root resource. The disadvantage is that all the transitive children of this specific object are
@@ -91,16 +80,7 @@ public final class CDOCompareUtil
*/
public static Comparison compare(CDOObject left, CDOView rightView, CDOView[] originView)
{
- CDOView leftView = left.cdoView();
- assertSameSession(leftView, rightView);
-
- CDOView view = openOriginView(leftView, rightView, originView);
-
- CDOObject right = CDOUtil.getCDOObject(rightView.getObject(left));
- CDOObject origin = view == null ? null : CDOUtil.getCDOObject(view.getObject(left));
-
- IComparisonScope scope = new CDOComparisonScope.AllContents(left, right, origin);
- return createComparison(scope);
+ return compare(CDOComparisonScope.AllContents.create(left, rightView, originView));
}
/**
@@ -111,115 +91,16 @@ public final class CDOCompareUtil
*/
public static Comparison compare(CDOView leftView, CDOView rightView, CDOView[] originView)
{
- assertSameSession(leftView, rightView);
-
- CDOView view = openOriginView(leftView, rightView, originView);
- Set<CDOID> ids = getAffectedIDs(leftView, rightView, view);
- return createComparison(leftView, rightView, view, ids);
+ return compare(CDOComparisonScope.Minimal.create(leftView, rightView, originView));
}
public static Comparison compare(CDOView leftView, CDOView rightView, CDOView[] originView, Set<CDOID> ids)
{
- assertSameSession(leftView, rightView);
-
- CDOView view = openOriginView(leftView, rightView, originView);
- return createComparison(leftView, rightView, view, ids);
+ return compare(CDOComparisonScope.Minimal.create(leftView, rightView, originView, ids));
}
public static Comparison compareUncommittedChanges(CDOTransaction transaction)
{
- CDOSession session = transaction.getSession();
- CDOView lastView = session.openView(transaction.getLastUpdateTime());
-
- Set<CDOID> ids = new HashSet<CDOID>();
- ids.addAll(transaction.getNewObjects().keySet());
- ids.addAll(transaction.getDirtyObjects().keySet());
- ids.addAll(transaction.getDetachedObjects().keySet());
-
- return createComparison(transaction, lastView, null, ids);
- }
-
- private static void assertSameSession(CDOView view1, CDOView view2)
- {
- if (view1.getSession() != view2.getSession())
- {
- throw new IllegalArgumentException("Sessions are different");
- }
- }
-
- private static CDOView openOriginView(CDOView leftView, CDOView rightView, CDOView[] originView)
- {
- if (originView != null)
- {
- if (originView.length != 1)
- {
- throw new IllegalArgumentException("originView.length != 1");
- }
-
- if (originView[0] != null)
- {
- throw new IllegalArgumentException("originView[0] != null");
- }
-
- CDOBranchPoint ancestor = CDOBranchUtil.getAncestor(leftView, rightView);
- if (!ancestor.equals(leftView) && !ancestor.equals(rightView))
- {
- originView[0] = leftView.getSession().openView(ancestor);
- return originView[0];
- }
- }
-
- return null;
- }
-
- private static Set<CDOID> getAffectedIDs(CDOView leftView, CDOView rightView, CDOView originView)
- {
- if (originView != null)
- {
- InternalCDOSession session = (InternalCDOSession)leftView.getSession();
- MergeData mergeData = session.getMergeData(leftView, rightView, originView, false);
- return mergeData.getIDs();
- }
-
- CDOChangeSetData changeSetData = leftView.compareRevisions(rightView);
- return new HashSet<CDOID>(changeSetData.getChangeKinds().keySet());
- }
-
- private static Comparison createComparison(CDOView leftView, CDOView rightView, CDOView originView, Set<CDOID> ids)
- {
- IComparisonScope scope = new CDOComparisonScope.Minimal(leftView, rightView, originView, ids);
- return createComparison(scope);
- }
-
- private static Comparison createComparison(IComparisonScope scope)
- {
- Function<EObject, String> idFunction = new CDOIDFunction();
- IEObjectMatcher matcher = new IdentifierEObjectMatcher(idFunction);
-
- IComparisonFactory comparisonFactory = new DefaultComparisonFactory(new DefaultEqualityHelperFactory());
- IMatchEngine matchEngine = new CDOMatchEngine(matcher, comparisonFactory);
- EMFCompare comparator = EMFCompare.builder().setMatchEngine(matchEngine).build();
-
- Comparison comparison = comparator.compare(scope);
- comparison.eAdapters().add(new ComparisonScopeAdapter(scope));
- return comparison;
- }
-
- /**
- * @author Eike Stepper
- */
- private static final class CDOMatchEngine extends DefaultMatchEngine
- {
- private CDOMatchEngine(IEObjectMatcher matcher, IComparisonFactory comparisonFactory)
- {
- super(matcher, comparisonFactory);
- }
-
- @Override
- protected void match(Comparison comparison, IComparisonScope scope, final Notifier left, final Notifier right,
- final Notifier origin, Monitor monitor)
- {
- match(comparison, scope, (EObject)left, (EObject)right, (EObject)origin, monitor);
- }
+ return compare(CDOComparisonScope.Minimal.create(transaction));
}
}
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 7586650ce8..4350fa6783 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
@@ -12,11 +12,15 @@ package org.eclipse.emf.cdo.compare;
import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.CDOState;
+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.CDORevisionData;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.eresource.CDOResourceNode;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.spi.common.branch.CDOBranchUtil;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.util.ObjectNotFoundException;
@@ -30,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.spi.cdo.InternalCDOSession;
+import org.eclipse.emf.spi.cdo.InternalCDOSession.MergeData;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterators;
@@ -60,6 +66,36 @@ public abstract class CDOComparisonScope extends AbstractComparisonScope
return Iterators.emptyIterator();
}
+ private static CDOView openOriginView(CDOView leftView, CDOView rightView, CDOView[] originView)
+ {
+ if (leftView.getSession() != rightView.getSession())
+ {
+ throw new IllegalArgumentException("Sessions are different");
+ }
+
+ if (originView != null)
+ {
+ if (originView.length != 1)
+ {
+ throw new IllegalArgumentException("originView.length != 1");
+ }
+
+ if (originView[0] != null)
+ {
+ throw new IllegalArgumentException("originView[0] != null");
+ }
+
+ CDOBranchPoint ancestor = CDOBranchUtil.getAncestor(leftView, rightView);
+ if (!ancestor.equals(leftView) && !ancestor.equals(rightView))
+ {
+ originView[0] = leftView.getSession().openView(ancestor);
+ return originView[0];
+ }
+ }
+
+ return null;
+ }
+
/**
* Takes an arbitrary {@link CDOObject object} (including {@link CDOResourceNode resource nodes})
* and returns {@link Match matches} for <b>all</b> elements of its {@link EObject#eAllContents() content tree}. This scope has the advantage that the comparison can
@@ -83,6 +119,22 @@ public abstract class CDOComparisonScope extends AbstractComparisonScope
{
return eObject.eAllContents();
}
+
+ /**
+ * Takes an arbitrary {@link CDOObject object} (including {@link CDOResourceNode resource nodes}) and returns {@link Match matches} for <b>all</b> elements of its {@link EObject#eAllContents() content tree}. This scope has the advantage that the comparison can
+ * be rooted at specific objects that are different from (below of) the root resource. The disadvantage is that all the transitive children of this specific object are
+ * matched, whether they differ or not. Major parts of huge repositories can be loaded to the client side easily, if no attention is paid.
+ */
+ public static AllContents create(CDOObject left, CDOView rightView, CDOView[] originView)
+ {
+ CDOView leftView = left.cdoView();
+ CDOView view = openOriginView(leftView, rightView, originView);
+
+ CDOObject right = CDOUtil.getCDOObject(rightView.getObject(left));
+ CDOObject origin = view == null ? null : CDOUtil.getCDOObject(view.getObject(left));
+
+ return new CDOComparisonScope.AllContents(left, right, origin);
+ }
}
/**
@@ -191,6 +243,45 @@ public abstract class CDOComparisonScope extends AbstractComparisonScope
}
}
+ public static IComparisonScope create(CDOView leftView, CDOView rightView, CDOView[] originView)
+ {
+ CDOView view = openOriginView(leftView, rightView, originView);
+ Set<CDOID> ids = getAffectedIDs(leftView, rightView, view);
+ return new CDOComparisonScope.Minimal(leftView, rightView, view, ids);
+ }
+
+ public static IComparisonScope create(CDOView leftView, CDOView rightView, CDOView[] originView, Set<CDOID> ids)
+ {
+ CDOView view = openOriginView(leftView, rightView, originView);
+ return new CDOComparisonScope.Minimal(leftView, rightView, view, ids);
+ }
+
+ public static IComparisonScope create(CDOTransaction transaction)
+ {
+ CDOSession session = transaction.getSession();
+ CDOView lastView = session.openView(transaction.getLastUpdateTime());
+
+ Set<CDOID> ids = new HashSet<CDOID>();
+ ids.addAll(transaction.getNewObjects().keySet());
+ ids.addAll(transaction.getDirtyObjects().keySet());
+ ids.addAll(transaction.getDetachedObjects().keySet());
+
+ return new CDOComparisonScope.Minimal(transaction, lastView, null, ids);
+ }
+
+ private static Set<CDOID> getAffectedIDs(CDOView leftView, CDOView rightView, CDOView originView)
+ {
+ if (originView != null)
+ {
+ InternalCDOSession session = (InternalCDOSession)leftView.getSession();
+ MergeData mergeData = session.getMergeData(leftView, rightView, originView, false);
+ return mergeData.getIDs();
+ }
+
+ CDOChangeSetData changeSetData = leftView.compareRevisions(rightView);
+ return new HashSet<CDOID>(changeSetData.getChangeKinds().keySet());
+ }
+
private static CDOResource getRoot(CDOView view)
{
if (view == null)
diff --git a/plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOIDFunction.java b/plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOIDFunction.java
deleted file mode 100644
index cca2e5d4a9..0000000000
--- a/plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOIDFunction.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.emf.cdo.compare;
-
-import org.eclipse.emf.cdo.CDOObject;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.id.CDOIDUtil;
-import org.eclipse.emf.cdo.util.CDOUtil;
-
-import org.eclipse.emf.ecore.EObject;
-
-import com.google.common.base.Function;
-
-/**
- * An {@link CDOIDFunction ID function} that considers the {@link CDOID}s of {@link CDOObject objects}.
- *
- * @author Eike Stepper
- */
-public class CDOIDFunction implements Function<EObject, String>
-{
- public String apply(EObject o)
- {
- CDOObject object = CDOUtil.getCDOObject(o);
- CDOID id = object.cdoID();
-
- StringBuilder builder = new StringBuilder();
- CDOIDUtil.write(builder, id);
- return builder.toString();
- }
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/ComparisonScopeAdapter.java b/plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/ComparisonScopeAdapter.java
deleted file mode 100644
index c8b1cdbf7f..0000000000
--- a/plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/ComparisonScopeAdapter.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.emf.cdo.compare;
-
-import org.eclipse.emf.common.notify.impl.AdapterImpl;
-import org.eclipse.emf.compare.scope.IComparisonScope;
-
-/**
- * @author Eike Stepper
- */
-public final class ComparisonScopeAdapter extends AdapterImpl
-{
- private IComparisonScope scope;
-
- public ComparisonScopeAdapter(IComparisonScope scope)
- {
- this.scope = scope;
- }
-
- public final IComparisonScope getScope()
- {
- return scope;
- }
-
- @Override
- public boolean isAdapterForType(Object type)
- {
- return type == ComparisonScopeAdapter.class;
- }
-}
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 89f8444b52..09d91481be 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
@@ -13,7 +13,9 @@ package org.eclipse.emf.cdo.tests;
import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.common.commit.CDOCommitInfo;
import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.compare.CDOCompare;
import org.eclipse.emf.cdo.compare.CDOCompareUtil;
+import org.eclipse.emf.cdo.compare.CDOComparisonScope;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.tests.config.IRepositoryConfig;
@@ -31,6 +33,10 @@ import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.EMFCompare;
import org.eclipse.emf.compare.Match;
+import org.eclipse.emf.compare.diff.DefaultDiffEngine;
+import org.eclipse.emf.compare.diff.DiffBuilder;
+import org.eclipse.emf.compare.diff.FeatureFilter;
+import org.eclipse.emf.compare.diff.IDiffEngine;
import org.eclipse.emf.compare.match.DefaultComparisonFactory;
import org.eclipse.emf.compare.match.DefaultEqualityHelperFactory;
import org.eclipse.emf.compare.match.DefaultMatchEngine;
@@ -39,12 +45,17 @@ import org.eclipse.emf.compare.match.IMatchEngine;
import org.eclipse.emf.compare.match.eobject.IEObjectMatcher;
import org.eclipse.emf.compare.scope.IComparisonScope;
import org.eclipse.emf.compare.utils.UseIdentifiers;
+import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
+import java.util.Collections;
+import java.util.Set;
+
/**
* @author Eike Stepper
*/
@@ -278,6 +289,52 @@ public class EMFCompareTest extends AbstractCDOTest
assertEquals(1, comparison.getMatch(company).getDifferences().size());
}
+ public void testFeatureFilter() throws Exception
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource(getResourcePath("/res1"));
+
+ Company company = createCompany();
+ company.setName("ESC");
+ company.setCity("Berlin");
+ resource.getContents().add(company);
+ CDOCommitInfo commit1 = transaction.commit();
+
+ company.setName("Eclipse");
+ company.setCity("Ottawa");
+ transaction.commit();
+
+ IComparisonScope scope = CDOComparisonScope.Minimal.create(transaction, session.openView(commit1), null);
+ Comparison comparison = new CDOCompare()
+ {
+ @Override
+ protected IDiffEngine createDiffEngine()
+ {
+ return new DefaultDiffEngine(new DiffBuilder())
+ {
+ @Override
+ protected FeatureFilter createFeatureFilter()
+ {
+ return new FeatureFilter()
+ {
+ Set<? extends EStructuralFeature> ignored = Collections.singleton(getModel1Package().getAddress_City());
+
+ @Override
+ protected boolean isIgnoredAttribute(EAttribute attribute)
+ {
+ return ignored.contains(attribute);
+ }
+ };
+ }
+ };
+ }
+ }.compare(scope);
+
+ dump(comparison);
+ assertEquals(1, comparison.getMatch(company).getDifferences().size());
+ }
+
private Company createCompany()
{
Company company = getModel1Factory().createCompany();
diff --git a/plugins/org.eclipse.emf.cdo.ui.compare/src/org/eclipse/emf/cdo/ui/compare/CDOCompareEditorUtil.java b/plugins/org.eclipse.emf.cdo.ui.compare/src/org/eclipse/emf/cdo/ui/compare/CDOCompareEditorUtil.java
index 307d07c568..03c2149dc1 100644
--- a/plugins/org.eclipse.emf.cdo.ui.compare/src/org/eclipse/emf/cdo/ui/compare/CDOCompareEditorUtil.java
+++ b/plugins/org.eclipse.emf.cdo.ui.compare/src/org/eclipse/emf/cdo/ui/compare/CDOCompareEditorUtil.java
@@ -10,9 +10,8 @@
*/
package org.eclipse.emf.cdo.ui.compare;
-import org.eclipse.emf.cdo.common.model.EMFUtil;
+import org.eclipse.emf.cdo.compare.CDOCompare;
import org.eclipse.emf.cdo.compare.CDOCompareUtil;
-import org.eclipse.emf.cdo.compare.ComparisonScopeAdapter;
import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.emf.common.notify.AdapterFactory;
@@ -38,7 +37,7 @@ public class CDOCompareEditorUtil
{
Comparison comparison = CDOCompareUtil.compare(leftView, rightView, originView);
- IComparisonScope scope = EMFUtil.getAdapter(comparison, ComparisonScopeAdapter.class).getScope();
+ IComparisonScope scope = CDOCompare.getScope(comparison);
ICompareEditingDomain editingDomain = EMFCompareEditingDomain.create(scope.getLeft(), scope.getRight(),
scope.getOrigin());

Back to the top