Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Richard2013-03-13 09:02:22 +0000
committerAxel Richard2013-03-18 14:01:13 +0000
commita65a3a35cc015367b6608de2cb1ea7043237033c (patch)
tree5cddbd2a9fb4e7b5751a36e3668a41c2d662b73a
parent0e5138aaf013f713b261699b137883265896d39d (diff)
downloadorg.eclipse.emf.compare-a65a3a35cc015367b6608de2cb1ea7043237033c.tar.gz
org.eclipse.emf.compare-a65a3a35cc015367b6608de2cb1ea7043237033c.tar.xz
org.eclipse.emf.compare-a65a3a35cc015367b6608de2cb1ea7043237033c.zip
[403187] Ordering post processors
Add an ordinal number attribute to the post processor extension point. The UML Post processor has now an ordinal number superior than the Compare Digaram Post processor. Bug: 403187 Change-Id: I985f5ae19bc1567908a024b5a438594b266cb1db
-rw-r--r--plugins/org.eclipse.emf.compare.diagram.ecoretools.tests/src/org/eclipse/emf/compare/diagram/ecoretools/tests/AbstractTest.java178
-rw-r--r--plugins/org.eclipse.emf.compare.diagram/plugin.xml3
-rw-r--r--plugins/org.eclipse.emf.compare.rcp/schema/postProcessor.exsd9
-rw-r--r--plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/postprocessor/PostProcessorDescriptor.java194
-rw-r--r--plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/postprocessor/PostProcessorFactoryRegistryListener.java299
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/postprocess/PostProcessorTest.java521
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/postprocess/data/TestPostProcessor.java316
-rw-r--r--plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/AbstractTest.java303
-rw-r--r--plugins/org.eclipse.emf.compare.uml2/plugin.xml3
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/emfcomparemessages.properties2
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/postprocessor/BasicPostProcessorDescriptorImpl.java195
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/postprocessor/IPostProcessor.java399
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/postprocessor/PostProcessorDescriptorRegistryImpl.java227
13 files changed, 1398 insertions, 1251 deletions
diff --git a/plugins/org.eclipse.emf.compare.diagram.ecoretools.tests/src/org/eclipse/emf/compare/diagram/ecoretools/tests/AbstractTest.java b/plugins/org.eclipse.emf.compare.diagram.ecoretools.tests/src/org/eclipse/emf/compare/diagram/ecoretools/tests/AbstractTest.java
index c73ec3548..43224f773 100644
--- a/plugins/org.eclipse.emf.compare.diagram.ecoretools.tests/src/org/eclipse/emf/compare/diagram/ecoretools/tests/AbstractTest.java
+++ b/plugins/org.eclipse.emf.compare.diagram.ecoretools.tests/src/org/eclipse/emf/compare/diagram/ecoretools/tests/AbstractTest.java
@@ -1,89 +1,89 @@
-/*******************************************************************************
- * Copyright (c) 2013 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.diagram.ecoretools.tests;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.regex.Pattern;
-
-import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.EMFCompare;
-import org.eclipse.emf.compare.diagram.internal.CompareDiagramPostProcessor;
-import org.eclipse.emf.compare.postprocessor.IPostProcessor;
-import org.eclipse.emf.compare.postprocessor.PostProcessorDescriptorRegistryImpl;
-import org.eclipse.emf.compare.tests.postprocess.data.TestPostProcessor;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.junit.After;
-import org.junit.Before;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterators;
-
-@SuppressWarnings("nls")
-public abstract class AbstractTest {
-
- private EMFCompare emfCompare;
-
- private PostProcessorDescriptorRegistryImpl<String> postProcessorRegistry;
-
- @Before
- public void before() {
- postProcessorRegistry = new PostProcessorDescriptorRegistryImpl<String>();
- postProcessorRegistry.put(CompareDiagramPostProcessor.class.getName(), new TestPostProcessor.TestPostProcessorDescriptor(
- Pattern.compile("http://www.eclipse.org/gmf/runtime/\\d.\\d.\\d/notation"), null, new CompareDiagramPostProcessor()));
- emfCompare = EMFCompare.builder().setPostProcessorRegistry(postProcessorRegistry).build();
- }
-
- protected EMFCompare getCompare() {
- return emfCompare;
- }
-
- /**
- * @return the postProcessorRegistry
- */
- protected IPostProcessor.Descriptor.Registry<?> getPostProcessorRegistry() {
- return postProcessorRegistry;
- }
-
- @After
- public void after() {
- if (getInput() != null && getInput().getSets() != null) {
- for (ResourceSet set : getInput().getSets()) {
- cleanup(set);
- }
- }
- }
-
- private void cleanup(ResourceSet resourceSet) {
- for (Resource res : resourceSet.getResources()) {
- res.unload();
- }
- resourceSet.getResources().clear();
- }
-
- protected enum TestKind {
- ADD, DELETE;
- }
-
- protected static Integer count(List<Diff> differences, Predicate<? super Diff> p) {
- int count = 0;
- final Iterator<Diff> result = Iterators.filter(differences.iterator(), p);
- while (result.hasNext()) {
- count++;
- result.next();
- }
- return Integer.valueOf(count);
- }
-
- protected abstract DiagramInputData getInput();
-
-}
+/*******************************************************************************
+ * Copyright (c) 2013 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.diagram.ecoretools.tests;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.EMFCompare;
+import org.eclipse.emf.compare.diagram.internal.CompareDiagramPostProcessor;
+import org.eclipse.emf.compare.postprocessor.IPostProcessor;
+import org.eclipse.emf.compare.postprocessor.PostProcessorDescriptorRegistryImpl;
+import org.eclipse.emf.compare.tests.postprocess.data.TestPostProcessor;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.junit.After;
+import org.junit.Before;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterators;
+
+@SuppressWarnings("nls")
+public abstract class AbstractTest {
+
+ private EMFCompare emfCompare;
+
+ private PostProcessorDescriptorRegistryImpl<String> postProcessorRegistry;
+
+ @Before
+ public void before() {
+ postProcessorRegistry = new PostProcessorDescriptorRegistryImpl<String>();
+ postProcessorRegistry.put(CompareDiagramPostProcessor.class.getName(), new TestPostProcessor.TestPostProcessorDescriptor(
+ Pattern.compile("http://www.eclipse.org/gmf/runtime/\\d.\\d.\\d/notation"), null, new CompareDiagramPostProcessor(), 30));
+ emfCompare = EMFCompare.builder().setPostProcessorRegistry(postProcessorRegistry).build();
+ }
+
+ protected EMFCompare getCompare() {
+ return emfCompare;
+ }
+
+ /**
+ * @return the postProcessorRegistry
+ */
+ protected IPostProcessor.Descriptor.Registry<?> getPostProcessorRegistry() {
+ return postProcessorRegistry;
+ }
+
+ @After
+ public void after() {
+ if (getInput() != null && getInput().getSets() != null) {
+ for (ResourceSet set : getInput().getSets()) {
+ cleanup(set);
+ }
+ }
+ }
+
+ private void cleanup(ResourceSet resourceSet) {
+ for (Resource res : resourceSet.getResources()) {
+ res.unload();
+ }
+ resourceSet.getResources().clear();
+ }
+
+ protected enum TestKind {
+ ADD, DELETE;
+ }
+
+ protected static Integer count(List<Diff> differences, Predicate<? super Diff> p) {
+ int count = 0;
+ final Iterator<Diff> result = Iterators.filter(differences.iterator(), p);
+ while (result.hasNext()) {
+ count++;
+ result.next();
+ }
+ return Integer.valueOf(count);
+ }
+
+ protected abstract DiagramInputData getInput();
+
+}
diff --git a/plugins/org.eclipse.emf.compare.diagram/plugin.xml b/plugins/org.eclipse.emf.compare.diagram/plugin.xml
index b8df17cae..948391d69 100644
--- a/plugins/org.eclipse.emf.compare.diagram/plugin.xml
+++ b/plugins/org.eclipse.emf.compare.diagram/plugin.xml
@@ -25,7 +25,8 @@
<extension
point="org.eclipse.emf.compare.rcp.postProcessor">
<processor
- class="org.eclipse.emf.compare.diagram.internal.CompareDiagramPostProcessor">
+ class="org.eclipse.emf.compare.diagram.internal.CompareDiagramPostProcessor"
+ ordinal="30">
<nsURI
value="http://www.eclipse.org/gmf/runtime/\d.\d.\d/notation">
</nsURI>
diff --git a/plugins/org.eclipse.emf.compare.rcp/schema/postProcessor.exsd b/plugins/org.eclipse.emf.compare.rcp/schema/postProcessor.exsd
index 90f4f6ed1..08b253c0d 100644
--- a/plugins/org.eclipse.emf.compare.rcp/schema/postProcessor.exsd
+++ b/plugins/org.eclipse.emf.compare.rcp/schema/postProcessor.exsd
@@ -64,10 +64,17 @@
Fully qualified name of a class that implements org.eclipse.emf.compare.postprocessor.IPostProcessor.
</documentation>
<appinfo>
- <meta.attribute kind="java" basedOn=":org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor"/>
+ <meta.attribute kind="java" basedOn=":org.eclipse.emf.compare.postprocessor.IPostProcessor"/>
</appinfo>
</annotation>
</attribute>
+ <attribute name="ordinal" type="string" use="required">
+ <annotation>
+ <documentation>
+ Denoting the specified position in the sequence of post processing. For example, if a post-processor P1 has an ordinal of 10 and another (P2) has an ordinal of 12, P1 will always be called before P2 if they are both applicable to the current comparison scope.
+ </documentation>
+ </annotation>
+ </attribute>
</complexType>
</element>
diff --git a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/postprocessor/PostProcessorDescriptor.java b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/postprocessor/PostProcessorDescriptor.java
index 203d314b5..3439941cb 100644
--- a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/postprocessor/PostProcessorDescriptor.java
+++ b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/postprocessor/PostProcessorDescriptor.java
@@ -1,83 +1,111 @@
-/*******************************************************************************
- * Copyright (c) 2012, 2013 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.rcp.internal.postprocessor;
-
-import java.util.regex.Pattern;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.emf.compare.postprocessor.IPostProcessor;
-import org.eclipse.emf.compare.rcp.extension.PluginClassDescriptor;
-
-/**
- * Describes an extension as contributed to the "org.eclipse.emf.compare.rcp.postProcessor" extension point.
- *
- * @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a>
- */
-public class PostProcessorDescriptor extends PluginClassDescriptor<IPostProcessor> implements IPostProcessor.Descriptor {
-
- private final Pattern nsURI;
-
- private final Pattern resourceURI;
-
- private IPostProcessor instance;
-
- /**
- * Creates a descriptor corresponding to the information of the given <em>element</em>.
- *
- * @param element
- * Configuration element from which to create this descriptor.
- */
- public PostProcessorDescriptor(IConfigurationElement element, Pattern nsURI, Pattern resourceURI) {
- super(element, PostProcessorFactoryRegistryListener.ATT_CLASS);
- this.nsURI = nsURI;
- this.resourceURI = resourceURI;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor#getNsURI()
- */
- public Pattern getNsURI() {
- return nsURI;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor#getResourceURI()
- */
- public Pattern getResourceURI() {
- return resourceURI;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#getPostProcessor()
- */
- public IPostProcessor getPostProcessor() {
- if (instance == null) {
- instance = createInstance();
- }
- return instance;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#getInstanceClassName()
- */
- public String getInstanceClassName() {
- return element.getAttribute(attributeName);
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.rcp.internal.postprocessor;
+
+import java.util.regex.Pattern;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.emf.compare.postprocessor.IPostProcessor;
+import org.eclipse.emf.compare.rcp.extension.PluginClassDescriptor;
+
+/**
+ * Describes an extension as contributed to the "org.eclipse.emf.compare.rcp.postProcessor" extension point.
+ *
+ * @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a>
+ */
+public class PostProcessorDescriptor extends PluginClassDescriptor<IPostProcessor> implements IPostProcessor.Descriptor {
+
+ /** The pattern of namespace URI on which this post processor can be applied. */
+ private final Pattern nsURI;
+
+ /** The pattern of resource URI on which this post processor can be applied. */
+ private final Pattern resourceURI;
+
+ /** The wrapped post processor. */
+ private IPostProcessor instance;
+
+ /** Ordinal of this post processor. */
+ private int ordinal;
+
+ /**
+ * Creates a descriptor corresponding to the information of the given <em>element</em>.
+ *
+ * @param element
+ * Configuration element from which to create this descriptor.
+ * @param nsURI
+ * The pattern of namespace URI on which this post processor can be applied.
+ * @param resourceURI
+ * The pattern of resource URI on which this post processor can be applied.
+ */
+ public PostProcessorDescriptor(IConfigurationElement element, Pattern nsURI, Pattern resourceURI) {
+ super(element, PostProcessorFactoryRegistryListener.ATT_CLASS);
+ this.nsURI = nsURI;
+ this.resourceURI = resourceURI;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor#getNsURI()
+ */
+ public Pattern getNsURI() {
+ return nsURI;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor#getResourceURI()
+ */
+ public Pattern getResourceURI() {
+ return resourceURI;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#getPostProcessor()
+ */
+ public IPostProcessor getPostProcessor() {
+ if (instance == null) {
+ instance = createInstance();
+ }
+ return instance;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#getInstanceClassName()
+ */
+ public String getInstanceClassName() {
+ return element.getAttribute(attributeName);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#getOrdinal()
+ */
+ public int getOrdinal() {
+ return ordinal;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#setOrdinal(int)
+ */
+ public void setOrdinal(int r) {
+ ordinal = r;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/postprocessor/PostProcessorFactoryRegistryListener.java b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/postprocessor/PostProcessorFactoryRegistryListener.java
index b2a5123c5..2c02b40a6 100644
--- a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/postprocessor/PostProcessorFactoryRegistryListener.java
+++ b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/postprocessor/PostProcessorFactoryRegistryListener.java
@@ -1,136 +1,163 @@
-/*******************************************************************************
- * Copyright (c) 2012, 2013 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.rcp.internal.postprocessor;
-
-import java.util.regex.Pattern;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.ILog;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.emf.compare.postprocessor.IPostProcessor;
-import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin;
-import org.eclipse.emf.compare.rcp.extension.AbstractRegistryEventListener;
-
-/**
- * This listener will allow us to be aware of contribution changes against the model resolver extension point.
- *
- * @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a>
- */
-public class PostProcessorFactoryRegistryListener extends AbstractRegistryEventListener {
-
- static final String TAG_PROCESSOR = "processor"; //$NON-NLS-1$
-
- static final String TAG_NS_URI = "nsURI"; //$NON-NLS-1$
-
- static final String TAG_RESOURCE_URI = "resourceURI"; //$NON-NLS-1$
-
- static final String ATT_VALUE = "value"; //$NON-NLS-1$
-
- static final String ATT_CLASS = "class"; //$NON-NLS-1$
-
- /** The post processor registry to which extension will be registered. */
- private final IPostProcessor.Descriptor.Registry<String> registry;
-
- /**
- * Creates a new registry listener with the given post processor registry to which extension will be
- * registered.
- *
- * @param registry
- * the post processor registry to which extension will be registered.
- * @param pluginID
- * @param extensionPointID
- * @param log
- */
- public PostProcessorFactoryRegistryListener(String pluginID, String extensionPointID, ILog log,
- IPostProcessor.Descriptor.Registry<String> registry) {
- super(pluginID, extensionPointID, log);
- this.registry = registry;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.extension.AbstractRegistryEventListener#validateExtensionElement(org.eclipse.core.runtime.IConfigurationElement)
- */
- @Override
- protected boolean validateExtensionElement(IConfigurationElement element) {
- final boolean valid;
- if (TAG_PROCESSOR.equals(element.getName())) {
- IConfigurationElement[] nsURIChildren = element.getChildren(TAG_NS_URI);
- IConfigurationElement[] resourceURIChildren = element.getChildren(TAG_RESOURCE_URI);
- if (element.getAttribute(ATT_CLASS) == null) {
- logMissingAttribute(element, ATT_CLASS);
- valid = false;
- } else if (nsURIChildren.length > 0) {
- if (nsURIChildren[0].getAttribute(ATT_VALUE) == null) {
- logMissingAttribute(nsURIChildren[0], ATT_VALUE);
- valid = false;
- } else {
- valid = true;
- }
- } else if (resourceURIChildren.length > 0) {
- if (resourceURIChildren[0].getAttribute(ATT_VALUE) == null) {
- logMissingAttribute(resourceURIChildren[0], ATT_VALUE);
- valid = false;
- } else {
- valid = true;
- }
- } else {
- log(IStatus.ERROR, element, "Post processor must have an nsURI or a resource URI");
- valid = false;
- }
- } else {
- valid = false;
- }
-
- return valid;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.extension.AbstractRegistryEventListener#addedValid(org.eclipse.core.runtime.IConfigurationElement)
- */
- @Override
- protected boolean addedValid(IConfigurationElement element) {
- IConfigurationElement[] nsURIChildren = element.getChildren(TAG_NS_URI);
- IConfigurationElement[] resourceURIChildren = element.getChildren(TAG_RESOURCE_URI);
- Pattern nsURI = null;
- if (nsURIChildren.length > 0) {
- nsURI = Pattern.compile(nsURIChildren[0].getAttribute(ATT_VALUE));
- }
- Pattern resourceURI = null;
- if (resourceURIChildren.length > 0) {
- resourceURI = Pattern.compile(resourceURIChildren[0].getAttribute(ATT_VALUE));
- }
- String className = element.getAttribute(ATT_CLASS);
-
- IPostProcessor.Descriptor descriptor = new PostProcessorDescriptor(element, nsURI, resourceURI);
- IPostProcessor.Descriptor previous = registry.put(className, descriptor);
- if (previous != null) {
- EMFCompareRCPPlugin.getDefault().log(IStatus.WARNING,
- "The post processor factory '" + className + "' is registered twice.");
- }
- return true;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.extension.AbstractRegistryEventListener#removedValid(org.eclipse.core.runtime.IConfigurationElement)
- */
- @Override
- protected boolean removedValid(IConfigurationElement element) {
- String className = element.getAttribute(ATT_CLASS);
- registry.remove(className);
- return true;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.rcp.internal.postprocessor;
+
+import java.util.regex.Pattern;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.ILog;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.emf.compare.postprocessor.IPostProcessor;
+import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin;
+import org.eclipse.emf.compare.rcp.extension.AbstractRegistryEventListener;
+import org.eclipse.emf.compare.rcp.internal.EMFCompareRCPMessages;
+
+/**
+ * This listener will allow us to be aware of contribution changes against the model resolver extension point.
+ *
+ * @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a>
+ */
+public class PostProcessorFactoryRegistryListener extends AbstractRegistryEventListener {
+
+ /** TAG_PROCESSOR. */
+ static final String TAG_PROCESSOR = "processor"; //$NON-NLS-1$
+
+ /** TAG_NS_URI. */
+ static final String TAG_NS_URI = "nsURI"; //$NON-NLS-1$
+
+ /** TAG_RESOURCE_URI. */
+ static final String TAG_RESOURCE_URI = "resourceURI"; //$NON-NLS-1$
+
+ /** ATT_VALUE. */
+ static final String ATT_VALUE = "value"; //$NON-NLS-1$
+
+ /** ATT_CLASS. */
+ static final String ATT_CLASS = "class"; //$NON-NLS-1$
+
+ /** ATT_ORDINAL. */
+ static final String ATT_ORDINAL = "ordinal"; //$NON-NLS-1$
+
+ /** The post processor registry to which extension will be registered. */
+ private final IPostProcessor.Descriptor.Registry<String> registry;
+
+ /**
+ * Creates a new registry listener with the given post processor registry to which extension will be
+ * registered.
+ *
+ * @param pluginID
+ * The pluginID of the extension point to be monitored.
+ * @param extensionPointID
+ * The extension point ID to be monitored
+ * @param log
+ * The log object to be used to log error and/or warning.
+ * @param registry
+ * the post processor registry to which extension will be registered.
+ */
+ public PostProcessorFactoryRegistryListener(String pluginID, String extensionPointID, ILog log,
+ IPostProcessor.Descriptor.Registry<String> registry) {
+ super(pluginID, extensionPointID, log);
+ this.registry = registry;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.extension.AbstractRegistryEventListener#validateExtensionElement(org.eclipse.core.runtime.IConfigurationElement)
+ */
+ @Override
+ protected boolean validateExtensionElement(IConfigurationElement element) {
+ final boolean valid;
+ if (TAG_PROCESSOR.equals(element.getName())) {
+ IConfigurationElement[] nsURIChildren = element.getChildren(TAG_NS_URI);
+ IConfigurationElement[] resourceURIChildren = element.getChildren(TAG_RESOURCE_URI);
+ if (element.getAttribute(ATT_CLASS) == null) {
+ logMissingAttribute(element, ATT_CLASS);
+ valid = false;
+ } else if (element.getAttribute(ATT_ORDINAL) == null) {
+ logMissingAttribute(element, ATT_ORDINAL);
+ valid = false;
+ } else if (element.getAttribute(ATT_ORDINAL) != null) {
+ String ordinalStr = element.getAttribute(ATT_ORDINAL);
+ try {
+ Integer.parseInt(ordinalStr);
+ } catch (NumberFormatException nfe) {
+ log(IStatus.ERROR, element, EMFCompareRCPMessages.getString(
+ "malformed.extension.attribute", //$NON-NLS-1$
+ ATT_ORDINAL));
+ return false;
+ }
+ valid = true;
+ } else if (nsURIChildren.length > 0) {
+ if (nsURIChildren[0].getAttribute(ATT_VALUE) == null) {
+ logMissingAttribute(nsURIChildren[0], ATT_VALUE);
+ valid = false;
+ } else {
+ valid = true;
+ }
+ } else if (resourceURIChildren.length > 0) {
+ if (resourceURIChildren[0].getAttribute(ATT_VALUE) == null) {
+ logMissingAttribute(resourceURIChildren[0], ATT_VALUE);
+ valid = false;
+ } else {
+ valid = true;
+ }
+ } else {
+ log(IStatus.ERROR, element, "Post processor must have an nsURI or a resource URI");
+ valid = false;
+ }
+ } else {
+ valid = false;
+ }
+
+ return valid;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.extension.AbstractRegistryEventListener#addedValid(org.eclipse.core.runtime.IConfigurationElement)
+ */
+ @Override
+ protected boolean addedValid(IConfigurationElement element) {
+ IConfigurationElement[] nsURIChildren = element.getChildren(TAG_NS_URI);
+ IConfigurationElement[] resourceURIChildren = element.getChildren(TAG_RESOURCE_URI);
+ Pattern nsURI = null;
+ if (nsURIChildren.length > 0) {
+ nsURI = Pattern.compile(nsURIChildren[0].getAttribute(ATT_VALUE));
+ }
+ Pattern resourceURI = null;
+ if (resourceURIChildren.length > 0) {
+ resourceURI = Pattern.compile(resourceURIChildren[0].getAttribute(ATT_VALUE));
+ }
+ String className = element.getAttribute(ATT_CLASS);
+
+ IPostProcessor.Descriptor descriptor = new PostProcessorDescriptor(element, nsURI, resourceURI);
+ descriptor.setOrdinal(Integer.parseInt(element.getAttribute(ATT_ORDINAL)));
+ IPostProcessor.Descriptor previous = registry.put(className, descriptor);
+ if (previous != null) {
+ EMFCompareRCPPlugin.getDefault().log(IStatus.WARNING,
+ "The post processor factory '" + className + "' is registered twice.");
+ }
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.extension.AbstractRegistryEventListener#removedValid(org.eclipse.core.runtime.IConfigurationElement)
+ */
+ @Override
+ protected boolean removedValid(IConfigurationElement element) {
+ String className = element.getAttribute(ATT_CLASS);
+ registry.remove(className);
+ return true;
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/postprocess/PostProcessorTest.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/postprocess/PostProcessorTest.java
index 2122c888f..b4b9608c3 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/postprocess/PostProcessorTest.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/postprocess/PostProcessorTest.java
@@ -1,254 +1,267 @@
-/*******************************************************************************
- * Copyright (c) 2012, 2013 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.tests.postprocess;
-
-import static junit.framework.Assert.assertSame;
-
-import java.io.IOException;
-import java.util.regex.Pattern;
-
-import org.eclipse.emf.compare.Comparison;
-import org.eclipse.emf.compare.EMFCompare;
-import org.eclipse.emf.compare.postprocessor.PostProcessorDescriptorRegistryImpl;
-import org.eclipse.emf.compare.scope.IComparisonScope;
-import org.eclipse.emf.compare.tests.nodes.NodesPackage;
-import org.eclipse.emf.compare.tests.postprocess.data.PostProcessInputData;
-import org.eclipse.emf.compare.tests.postprocess.data.TestPostProcessor;
-import org.eclipse.emf.compare.tests.postprocess.data.TestPostProcessor.TestPostProcessorDescriptor;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-@SuppressWarnings("nls")
-public class PostProcessorTest {
-
- private PostProcessInputData input = new PostProcessInputData();
-
- @BeforeClass
- public static void beforeClass() {
- EPackage.Registry.INSTANCE.put(NodesPackage.eNS_URI, NodesPackage.eINSTANCE);
- }
-
- @Test
- public void testNominalUseCase() throws IOException {
- // No post processes.
- final Resource left = input.getLeft();
- final Resource right = input.getRight();
-
- final IComparisonScope scope = EMFCompare.createDefaultScope(left, right);
- final Comparison comparison = EMFCompare.builder().build().compare(scope);
-
- assertSame(Integer.valueOf(1), Integer.valueOf(comparison.getMatches().size()));
- }
-
- @Test
- public void testA1UseCase() throws IOException {
- final Resource left = input.getLeft();
- final Resource right = input.getRight();
-
- PostProcessorDescriptorRegistryImpl registry = new PostProcessorDescriptorRegistryImpl();
- // Post processing (add a match element) if EMF Compare scans a model coming from the namespace URI
- // "http://www.eclipse.org/emf/compare/tests/nodes" at least.
- registry.put(TestPostProcessor.class.getName(), new TestPostProcessorDescriptor(Pattern
- .compile("http://www.eclipse.org/emf/compare/tests/nodes"), null, new TestPostProcessor()));
-
- final IComparisonScope scope = EMFCompare.createDefaultScope(left, right);
- final Comparison comparison = EMFCompare.builder().setPostProcessorRegistry(registry).build()
- .compare(scope);
-
- assertSame(Integer.valueOf(2), Integer.valueOf(comparison.getMatches().size()));
-
- }
-
- @Test
- public void testA2UseCase() throws IOException {
- final Resource left = input.getLeft();
- final Resource right = input.getRight();
-
- PostProcessorDescriptorRegistryImpl registry = new PostProcessorDescriptorRegistryImpl();
- // Post processing (add a match element) if EMF Compare scans a model from the namespace URI which
- // matches the regex ".*/nodes" at least.
- registry.put(TestPostProcessor.class.getName(), new TestPostProcessorDescriptor(Pattern
- .compile(".*/nodes"), null, new TestPostProcessor()));
-
- final IComparisonScope scope = EMFCompare.createDefaultScope(left, right);
- final Comparison comparison = EMFCompare.builder().setPostProcessorRegistry(registry).build()
- .compare(scope);
-
- assertSame(Integer.valueOf(2), Integer.valueOf(comparison.getMatches().size()));
-
- }
-
- @Test
- public void testA3UseCase() throws IOException {
- final Resource left = input.getLeft();
- final Resource right = input.getRight();
-
- PostProcessorDescriptorRegistryImpl registry = new PostProcessorDescriptorRegistryImpl();
- // No post processes if the regex matches no scanned namespace URIs.
- registry.put(TestPostProcessor.class.getName(), new TestPostProcessorDescriptor(Pattern
- .compile(".*/nides"), null, new TestPostProcessor()));
-
- final IComparisonScope scope = EMFCompare.createDefaultScope(left, right);
- final Comparison comparison = EMFCompare.builder().setPostProcessorRegistry(registry).build()
- .compare(scope);
-
- assertSame(Integer.valueOf(1), Integer.valueOf(comparison.getMatches().size()));
-
- }
-
- @Test
- public void testA4UseCase() throws IOException {
- final Resource left = input.getLeft();
- final Resource right = input.getRight();
-
- PostProcessorDescriptorRegistryImpl registry = new PostProcessorDescriptorRegistryImpl();
- // No post processes if the regex matches no scanned namespace URIs (null value case)
- registry.put(TestPostProcessor.class.getName(), new TestPostProcessorDescriptor(null, null,
- new TestPostProcessor()));
-
- final IComparisonScope scope = EMFCompare.createDefaultScope(left, right);
- final Comparison comparison = EMFCompare.builder().setPostProcessorRegistry(registry).build()
- .compare(scope);
-
- assertSame(Integer.valueOf(1), Integer.valueOf(comparison.getMatches().size()));
-
- }
-
- @Test
- public void testA5UseCase() throws IOException {
- final Resource left = input.getLeft();
- final Resource right = input.getRight();
-
- PostProcessorDescriptorRegistryImpl registry = new PostProcessorDescriptorRegistryImpl();
- // No post processes if the regex matches no scanned namespace URIs (empty value case)
- registry.put(TestPostProcessor.class.getName(), new TestPostProcessorDescriptor(Pattern.compile(""),
- null, new TestPostProcessor()));
-
- final IComparisonScope scope = EMFCompare.createDefaultScope(left, right);
- final Comparison comparison = EMFCompare.builder().setPostProcessorRegistry(registry).build()
- .compare(scope);
-
- assertSame(Integer.valueOf(1), Integer.valueOf(comparison.getMatches().size()));
-
- }
-
- @Test
- public void testA6UseCase() throws IOException {
- final Resource left = input.getLeft();
- final Resource right = input.getRight();
-
- PostProcessorDescriptorRegistryImpl registry = new PostProcessorDescriptorRegistryImpl();
- // No post processes if the regex matches no scanned namespace URIs (blank value case)
- registry.put(TestPostProcessor.class.getName(), new TestPostProcessorDescriptor(Pattern.compile(" "),
- null, new TestPostProcessor()));
-
- final IComparisonScope scope = EMFCompare.createDefaultScope(left, right);
- final Comparison comparison = EMFCompare.builder().setPostProcessorRegistry(registry).build()
- .compare(scope);
-
- assertSame(Integer.valueOf(1), Integer.valueOf(comparison.getMatches().size()));
-
- }
-
- @Test
- public void testB1UseCase() throws IOException {
- final Resource left = input.getLeft();
- final Resource right = input.getRight();
-
- PostProcessorDescriptorRegistryImpl registry = new PostProcessorDescriptorRegistryImpl();
- // Post processing (add a match element) if EMF Compare scans a resource where its URI is the same as
- // the specified one at least.
- registry.put(TestPostProcessor.class.getName(), new TestPostProcessorDescriptor(null, Pattern
- .compile(left.getURI().toString()), new TestPostProcessor()));
-
- final IComparisonScope scope = EMFCompare.createDefaultScope(left, right);
- final Comparison comparison = EMFCompare.builder().setPostProcessorRegistry(registry).build()
- .compare(scope);
-
- assertSame(Integer.valueOf(2), Integer.valueOf(comparison.getMatches().size()));
-
- }
-
- @Test
- public void testB2UseCase() throws IOException {
- final Resource left = input.getLeft();
- final Resource right = input.getRight();
-
- PostProcessorDescriptorRegistryImpl registry = new PostProcessorDescriptorRegistryImpl();
- // Post processing (add a match element) if EMF Compare scans a resource where its URI matches the
- // specified regex at least.
- registry.put(TestPostProcessor.class.getName(), new TestPostProcessorDescriptor(null, Pattern
- .compile(".*.nodes"), new TestPostProcessor()));
-
- final IComparisonScope scope = EMFCompare.createDefaultScope(left, right);
- final Comparison comparison = EMFCompare.builder().setPostProcessorRegistry(registry).build()
- .compare(scope);
-
- assertSame(Integer.valueOf(2), Integer.valueOf(comparison.getMatches().size()));
-
- }
-
- @Test
- public void testB3UseCase() throws IOException {
- final Resource left = input.getLeft();
- final Resource right = input.getRight();
-
- PostProcessorDescriptorRegistryImpl registry = new PostProcessorDescriptorRegistryImpl();
- // No post processes if the regex matches no scanned resource URIs
- registry.put(TestPostProcessor.class.getName(), new TestPostProcessorDescriptor(null, Pattern
- .compile(".*.nides"), new TestPostProcessor()));
-
- final IComparisonScope scope = EMFCompare.createDefaultScope(left, right);
- final Comparison comparison = EMFCompare.builder().setPostProcessorRegistry(registry).build()
- .compare(scope);
-
- assertSame(Integer.valueOf(1), Integer.valueOf(comparison.getMatches().size()));
-
- }
-
- @Test
- public void testB4UseCase() throws IOException {
- final Resource left = input.getLeft();
- final Resource right = input.getRight();
-
- PostProcessorDescriptorRegistryImpl registry = new PostProcessorDescriptorRegistryImpl();
- // No post processes if the regex matches no scanned resource URIs (empty value)
- registry.put(TestPostProcessor.class.getName(), new TestPostProcessorDescriptor(null, Pattern
- .compile(""), new TestPostProcessor()));
-
- final IComparisonScope scope = EMFCompare.createDefaultScope(left, right);
- final Comparison comparison = EMFCompare.builder().setPostProcessorRegistry(registry).build()
- .compare(scope);
-
- assertSame(Integer.valueOf(1), Integer.valueOf(comparison.getMatches().size()));
-
- }
-
- @Test
- public void testB5UseCase() throws IOException {
- final Resource left = input.getLeft();
- final Resource right = input.getRight();
-
- PostProcessorDescriptorRegistryImpl registry = new PostProcessorDescriptorRegistryImpl();
- // No post processes if the regex matches no scanned resource URIs (blank value)
- registry.put(TestPostProcessor.class.getName(), new TestPostProcessorDescriptor(null, Pattern
- .compile(" "), new TestPostProcessor()));
-
- final IComparisonScope scope = EMFCompare.createDefaultScope(left, right);
- final Comparison comparison = EMFCompare.builder().setPostProcessorRegistry(registry).build()
- .compare(scope);
-
- assertSame(Integer.valueOf(1), Integer.valueOf(comparison.getMatches().size()));
-
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.tests.postprocess;
+
+import static junit.framework.Assert.assertSame;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.EMFCompare;
+import org.eclipse.emf.compare.postprocessor.IPostProcessor;
+import org.eclipse.emf.compare.postprocessor.PostProcessorDescriptorRegistryImpl;
+import org.eclipse.emf.compare.scope.IComparisonScope;
+import org.eclipse.emf.compare.tests.nodes.NodesPackage;
+import org.eclipse.emf.compare.tests.postprocess.data.PostProcessInputData;
+import org.eclipse.emf.compare.tests.postprocess.data.TestPostProcessor;
+import org.eclipse.emf.compare.tests.postprocess.data.TestPostProcessor.TestPostProcessorDescriptor;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+@SuppressWarnings("nls")
+public class PostProcessorTest {
+
+ private PostProcessInputData input = new PostProcessInputData();
+
+ @BeforeClass
+ public static void beforeClass() {
+ EPackage.Registry.INSTANCE.put(NodesPackage.eNS_URI, NodesPackage.eINSTANCE);
+ }
+
+ @Test
+ public void testNominalUseCase() throws IOException {
+ // No post processes.
+ final Resource left = input.getLeft();
+ final Resource right = input.getRight();
+
+ final IComparisonScope scope = EMFCompare.createDefaultScope(left, right);
+ final Comparison comparison = EMFCompare.builder().build().compare(scope);
+
+ assertSame(Integer.valueOf(1), Integer.valueOf(comparison.getMatches().size()));
+ }
+
+ @Test
+ public void testA1UseCase() throws IOException {
+ final Resource left = input.getLeft();
+ final Resource right = input.getRight();
+
+ // Post processing (add a match element) if EMF Compare scans a model coming from the namespace URI
+ // "http://www.eclipse.org/emf/compare/tests/nodes" at least.
+ final Comparison comparison = compareWithPostProcessing(left, right, Pattern
+ .compile("http://www.eclipse.org/emf/compare/tests/nodes"), null);
+
+ assertSame(Integer.valueOf(2), Integer.valueOf(comparison.getMatches().size()));
+
+ }
+
+ @Test
+ public void testA2UseCase() throws IOException {
+ final Resource left = input.getLeft();
+ final Resource right = input.getRight();
+
+ // Post processing (add a match element) if EMF Compare scans a model from the names
+ // matches the regex ".*/nodes" at least.
+ final Comparison comparison = compareWithPostProcessing(left, right, Pattern.compile(".*/nodes"),
+ null);
+
+ assertSame(Integer.valueOf(2), Integer.valueOf(comparison.getMatches().size()));
+
+ }
+
+ @Test
+ public void testA3UseCase() throws IOException {
+ final Resource left = input.getLeft();
+ final Resource right = input.getRight();
+
+ // No post processes if the regex matches no scanned namespace URIs.
+ final Comparison comparison = compareWithPostProcessing(left, right, Pattern.compile(".*/nides"),
+ null);
+
+ assertSame(Integer.valueOf(1), Integer.valueOf(comparison.getMatches().size()));
+
+ }
+
+ @Test
+ public void testA4UseCase() throws IOException {
+ final Resource left = input.getLeft();
+ final Resource right = input.getRight();
+
+ // No post processes if the regex matches no scanned namespace URIs (null value case)
+ final Comparison comparison = compareWithPostProcessing(left, right, null, null);
+
+ assertSame(Integer.valueOf(1), Integer.valueOf(comparison.getMatches().size()));
+
+ }
+
+ @Test
+ public void testA5UseCase() throws IOException {
+ final Resource left = input.getLeft();
+ final Resource right = input.getRight();
+
+ // No post processes if the regex matches no scanned namespace URIs (empty value cas)
+ final Comparison comparison = compareWithPostProcessing(left, right, Pattern.compile(""), null);
+
+ assertSame(Integer.valueOf(1), Integer.valueOf(comparison.getMatches().size()));
+
+ }
+
+ @Test
+ public void testA6UseCase() throws IOException {
+ final Resource left = input.getLeft();
+ final Resource right = input.getRight();
+
+ // No post processes if the regex matches no scanned namespace URIs (blank value cas)
+ final Comparison comparison = compareWithPostProcessing(left, right, Pattern.compile(" "), null);
+
+ assertSame(Integer.valueOf(1), Integer.valueOf(comparison.getMatches().size()));
+
+ }
+
+ @Test
+ public void testB1UseCase() throws IOException {
+ final Resource left = input.getLeft();
+ final Resource right = input.getRight();
+
+ // Post processing (add a match element) if EMF Compare scans a resource where its U
+ // the specified one at least.
+ final Comparison comparison = compareWithPostProcessing(left, right, null, Pattern.compile(left
+ .getURI().toString()));
+
+ assertSame(Integer.valueOf(2), Integer.valueOf(comparison.getMatches().size()));
+
+ }
+
+ @Test
+ public void testB2UseCase() throws IOException {
+ final Resource left = input.getLeft();
+ final Resource right = input.getRight();
+
+ // Post processing (add a match element) if EMF Compare scans a resource where its U
+ // specified regex at least.
+ final Comparison comparison = compareWithPostProcessing(left, right, null, Pattern
+ .compile(".*.nodes"));
+
+ assertSame(Integer.valueOf(2), Integer.valueOf(comparison.getMatches().size()));
+
+ }
+
+ @Test
+ public void testB3UseCase() throws IOException {
+ final Resource left = input.getLeft();
+ final Resource right = input.getRight();
+
+ // No post processes if the regex matches no scanned resource URIs
+ final Comparison comparison = compareWithPostProcessing(left, right, null, Pattern
+ .compile(".*.nides"));
+
+ assertSame(Integer.valueOf(1), Integer.valueOf(comparison.getMatches().size()));
+
+ }
+
+ @Test
+ public void testB4UseCase() throws IOException {
+ final Resource left = input.getLeft();
+ final Resource right = input.getRight();
+
+ // No post processes if the regex matches no scanned resource URIs (empty value)
+ final Comparison comparison = compareWithPostProcessing(left, right, null, Pattern.compile(""));
+
+ assertSame(Integer.valueOf(1), Integer.valueOf(comparison.getMatches().size()));
+
+ }
+
+ @Test
+ public void testB5UseCase() throws IOException {
+ final Resource left = input.getLeft();
+ final Resource right = input.getRight();
+
+ // No post processes if the regex matches no scanned resource URIs (blank value)
+ final Comparison comparison = compareWithPostProcessing(left, right, null, Pattern.compile(" "));
+
+ assertSame(Integer.valueOf(1), Integer.valueOf(comparison.getMatches().size()));
+
+ }
+
+ @Test
+ public void testOrderingPostProcessors() throws IOException {
+ final Resource left = input.getLeft();
+ final Resource right = input.getRight();
+ final IComparisonScope scope = EMFCompare.createDefaultScope(left, right);
+
+ PostProcessorDescriptorRegistryImpl registry = new PostProcessorDescriptorRegistryImpl();
+ registry.put(TestPostProcessor1.class.getName(), new TestPostProcessorDescriptor(Pattern.compile(""),
+ null, new TestPostProcessor1(), 1));
+ registry.put(TestPostProcessor2.class.getName(), new TestPostProcessorDescriptor(Pattern
+ .compile("http://www.eclipse.org/emf/compare/tests/nodes"), null, new TestPostProcessor2(),
+ 10));
+ registry.put(TestPostProcessor3.class.getName(),
+ new TestPostProcessorDescriptor(Pattern
+ .compile("http://www.eclipse.org/emf/compare/tests/nodes"), null,
+ new TestPostProcessor3(), 9));
+ registry.put(TestPostProcessor4.class.getName(), new TestPostProcessorDescriptor(Pattern
+ .compile("http://www.eclipse.org/emf/compare/tests/nodes"), null, new TestPostProcessor4(),
+ 11));
+
+ // Populate nsURIs of the scope.
+ EMFCompare.builder().setPostProcessorRegistry(registry).build().compare(scope);
+
+ List<IPostProcessor> postProcessors = registry.getPostProcessors(scope);
+
+ assertEquals(3, postProcessors.size());
+ assertTrue(postProcessors.get(0) instanceof TestPostProcessor3);
+ assertTrue(postProcessors.get(1) instanceof TestPostProcessor2);
+ assertTrue(postProcessors.get(2) instanceof TestPostProcessor4);
+ }
+
+ private Comparison compareWithPostProcessing(Resource left, Resource right, Pattern nsURI,
+ Pattern resourceURI) {
+ PostProcessorDescriptorRegistryImpl registry = new PostProcessorDescriptorRegistryImpl();
+ registry.put(TestPostProcessor.class.getName(), new TestPostProcessorDescriptor(nsURI, resourceURI,
+ new TestPostProcessor(), 10));
+
+ final IComparisonScope scope = EMFCompare.createDefaultScope(left, right);
+ return EMFCompare.builder().setPostProcessorRegistry(registry).build().compare(scope);
+ }
+
+ /**
+ * Empty Implementation, used to test ordering
+ */
+ private class TestPostProcessor1 extends TestPostProcessor {
+
+ }
+
+ /**
+ * Empty Implementation, used to test ordering
+ */
+ private class TestPostProcessor2 extends TestPostProcessor {
+
+ }
+
+ /**
+ * Empty Implementation, used to test ordering
+ */
+ private class TestPostProcessor3 extends TestPostProcessor {
+
+ }
+
+ /**
+ * Empty Implementation, used to test ordering
+ */
+ private class TestPostProcessor4 extends TestPostProcessor {
+
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/postprocess/data/TestPostProcessor.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/postprocess/data/TestPostProcessor.java
index 46818489e..e4a87ab2d 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/postprocess/data/TestPostProcessor.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/postprocess/data/TestPostProcessor.java
@@ -1,147 +1,169 @@
-/*******************************************************************************
- * Copyright (c) 2012, 2013 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.tests.postprocess.data;
-
-import java.util.List;
-import java.util.regex.Pattern;
-
-import org.eclipse.emf.common.util.Monitor;
-import org.eclipse.emf.compare.CompareFactory;
-import org.eclipse.emf.compare.Comparison;
-import org.eclipse.emf.compare.Match;
-import org.eclipse.emf.compare.postprocessor.IPostProcessor;
-
-/**
- * This provides a post processor to add a copy of the first scanned match at the same level of the
- * comparison.
- *
- * @author <a href="cedric.notot@obeo.fr">Cedric Notot</a>
- */
-public class TestPostProcessor implements IPostProcessor {
-
- public void postMatch(Comparison comparison, Monitor monitor) {
- final List<Match> matches = comparison.getMatches();
- final Match lastMatch = matches.get(matches.size() - 1);
- final Match copyLastMatch = CompareFactory.eINSTANCE.createMatch();
- copyLastMatch.setLeft(lastMatch.getLeft());
- copyLastMatch.setRight(lastMatch.getRight());
- copyLastMatch.setOrigin(lastMatch.getOrigin());
- matches.add(copyLastMatch);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor#postConflicts(org.eclipse.emf.compare.Comparison,
- * org.eclipse.emf.common.util.Monitor)
- */
- public void postConflicts(Comparison comparison, Monitor monitor) {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor#postEquivalences(org.eclipse.emf.compare.Comparison,
- * org.eclipse.emf.common.util.Monitor)
- */
- public void postEquivalences(Comparison comparison, Monitor monitor) {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor#postRequirements(org.eclipse.emf.compare.Comparison,
- * org.eclipse.emf.common.util.Monitor)
- */
- public void postRequirements(Comparison comparison, Monitor monitor) {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor#postDiff(org.eclipse.emf.compare.Comparison,
- * org.eclipse.emf.common.util.Monitor)
- */
- public void postDiff(Comparison comparison, Monitor monitor) {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor#postComparison(org.eclipse.emf.compare.Comparison,
- * org.eclipse.emf.common.util.Monitor)
- */
- public void postComparison(Comparison comparison, Monitor monitor) {
- // TODO Auto-generated method stub
-
- }
-
- public static class TestPostProcessorDescriptor implements IPostProcessor.Descriptor {
-
- private final Pattern nsURI;
-
- private final Pattern resourceURI;
-
- private final IPostProcessor postProcessor;
-
- public TestPostProcessorDescriptor(Pattern nsURI, Pattern resourceURI, IPostProcessor postProcessor) {
- this.nsURI = nsURI;
- this.resourceURI = resourceURI;
- this.postProcessor = postProcessor;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#getPostProcessor()
- */
- public IPostProcessor getPostProcessor() {
- return postProcessor;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#getNsURI()
- */
- public Pattern getNsURI() {
- return nsURI;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#getResourceURI()
- */
- public Pattern getResourceURI() {
- return resourceURI;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#getInstanceClassName()
- */
- public String getInstanceClassName() {
- return postProcessor.getClass().getName();
- }
-
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.tests.postprocess.data;
+
+import java.util.List;
+import java.util.regex.Pattern;
+
+import org.eclipse.emf.common.util.Monitor;
+import org.eclipse.emf.compare.CompareFactory;
+import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.Match;
+import org.eclipse.emf.compare.postprocessor.IPostProcessor;
+
+/**
+ * This provides a post processor to add a copy of the first scanned match at the same level of the
+ * comparison.
+ *
+ * @author <a href="cedric.notot@obeo.fr">Cedric Notot</a>
+ */
+public class TestPostProcessor implements IPostProcessor {
+
+ public void postMatch(Comparison comparison, Monitor monitor) {
+ final List<Match> matches = comparison.getMatches();
+ final Match lastMatch = matches.get(matches.size() - 1);
+ final Match copyLastMatch = CompareFactory.eINSTANCE.createMatch();
+ copyLastMatch.setLeft(lastMatch.getLeft());
+ copyLastMatch.setRight(lastMatch.getRight());
+ copyLastMatch.setOrigin(lastMatch.getOrigin());
+ matches.add(copyLastMatch);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor#postConflicts(org.eclipse.emf.compare.Comparison,
+ * org.eclipse.emf.common.util.Monitor)
+ */
+ public void postConflicts(Comparison comparison, Monitor monitor) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor#postEquivalences(org.eclipse.emf.compare.Comparison,
+ * org.eclipse.emf.common.util.Monitor)
+ */
+ public void postEquivalences(Comparison comparison, Monitor monitor) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor#postRequirements(org.eclipse.emf.compare.Comparison,
+ * org.eclipse.emf.common.util.Monitor)
+ */
+ public void postRequirements(Comparison comparison, Monitor monitor) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor#postDiff(org.eclipse.emf.compare.Comparison,
+ * org.eclipse.emf.common.util.Monitor)
+ */
+ public void postDiff(Comparison comparison, Monitor monitor) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor#postComparison(org.eclipse.emf.compare.Comparison,
+ * org.eclipse.emf.common.util.Monitor)
+ */
+ public void postComparison(Comparison comparison, Monitor monitor) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public static class TestPostProcessorDescriptor implements IPostProcessor.Descriptor {
+
+ private final Pattern nsURI;
+
+ private final Pattern resourceURI;
+
+ private final IPostProcessor postProcessor;
+
+ private int ordinal;
+
+ public TestPostProcessorDescriptor(Pattern nsURI, Pattern resourceURI, IPostProcessor postProcessor,
+ int ordinal) {
+ this.nsURI = nsURI;
+ this.resourceURI = resourceURI;
+ this.postProcessor = postProcessor;
+ this.ordinal = ordinal;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#getPostProcessor()
+ */
+ public IPostProcessor getPostProcessor() {
+ return postProcessor;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#getNsURI()
+ */
+ public Pattern getNsURI() {
+ return nsURI;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#getResourceURI()
+ */
+ public Pattern getResourceURI() {
+ return resourceURI;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#getInstanceClassName()
+ */
+ public String getInstanceClassName() {
+ return postProcessor.getClass().getName();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#getOrdinal()
+ */
+ public int getOrdinal() {
+ return ordinal;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#setOrdinal(int)
+ */
+ public void setOrdinal(int parseInt) {
+ ordinal = parseInt;
+ }
+
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/AbstractTest.java b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/AbstractTest.java
index b8997894f..b8d70ce9d 100644
--- a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/AbstractTest.java
+++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/AbstractTest.java
@@ -1,151 +1,152 @@
-/**
- * Copyright (c) 2012, 2013 Obeo.
- * 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:
- * Obeo - initial API and implementation
- */
-package org.eclipse.emf.compare.uml2.tests;
-
-import static org.junit.Assert.assertTrue;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterators;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.regex.Pattern;
-
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.common.util.BasicMonitor;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.compare.AttributeChange;
-import org.eclipse.emf.compare.ComparePackage;
-import org.eclipse.emf.compare.Comparison;
-import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.EMFCompare;
-import org.eclipse.emf.compare.ReferenceChange;
-import org.eclipse.emf.compare.merge.BatchMerger;
-import org.eclipse.emf.compare.merge.IBatchMerger;
-import org.eclipse.emf.compare.merge.IMerger;
-import org.eclipse.emf.compare.postprocessor.PostProcessorDescriptorRegistryImpl;
-import org.eclipse.emf.compare.scope.IComparisonScope;
-import org.eclipse.emf.compare.tests.framework.AbstractInputData;
-import org.eclipse.emf.compare.tests.postprocess.data.TestPostProcessor;
-import org.eclipse.emf.compare.uml2.internal.merge.UMLMerger;
-import org.eclipse.emf.compare.uml2.internal.postprocessor.UMLPostProcessor;
-import org.eclipse.emf.compare.utils.ReferenceUtil;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.uml2.uml.UMLPackage;
-import org.eclipse.uml2.uml.internal.resource.UMLResourceFactoryImpl;
-import org.junit.Before;
-import org.junit.BeforeClass;
-
-@SuppressWarnings("nls")
-public abstract class AbstractTest {
-
- private EMFCompare emfCompare;
-
- private static final IMerger.Registry mergerRegistry = IMerger.RegistryImpl.createStandaloneInstance();
-
- @BeforeClass
- public static void fillRegistries() {
- EPackage.Registry.INSTANCE.put(ComparePackage.eNS_URI, ComparePackage.eINSTANCE);
- EPackage.Registry.INSTANCE.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
-
- Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("uml", //$NON-NLS-1$
- new UMLResourceFactoryImpl());
-
- final IMerger umlMerger = new UMLMerger();
- umlMerger.setRanking(11);
- mergerRegistry.add(umlMerger);
- }
-
- @Before
- public void before() {
- PostProcessorDescriptorRegistryImpl<String> registry = new PostProcessorDescriptorRegistryImpl<String>();
- registry.put(UMLPostProcessor.class.getName(), new TestPostProcessor.TestPostProcessorDescriptor(
- Pattern.compile("http://www.eclipse.org/uml2/\\d\\.0\\.0/UML"), null, new UMLPostProcessor()));
- emfCompare = EMFCompare.builder().setPostProcessorRegistry(registry).build();
- }
-
- protected EMFCompare getCompare() {
- return emfCompare;
- }
-
- protected enum TestKind {
- ADD, DELETE;
- }
-
- protected static Integer count(List<Diff> differences, Predicate<Object> p) {
- int count = 0;
- final Iterator<Diff> result = Iterators.filter(differences.iterator(), p);
- while (result.hasNext()) {
- count++;
- result.next();
- }
- return Integer.valueOf(count);
- }
-
- public static Predicate<? super Diff> onRealFeature(final EStructuralFeature feature) {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- final EStructuralFeature affectedFeature;
- if (input instanceof AttributeChange) {
- affectedFeature = ((AttributeChange)input).getAttribute();
- } else if (input instanceof ReferenceChange) {
- affectedFeature = ((ReferenceChange)input).getReference();
- } else {
- return false;
- }
- return feature == affectedFeature;
- }
- };
- }
-
- public static Predicate<? super Diff> isChangeAdd() {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- if (input instanceof ReferenceChange) {
- return ReferenceUtil.getAsList(input.getMatch().getLeft(),
- ((ReferenceChange)input).getReference()).contains(
- ((ReferenceChange)input).getValue());
- } else if (input instanceof AttributeChange) {
- return ReferenceUtil.getAsList(input.getMatch().getLeft(),
- ((AttributeChange)input).getAttribute()).contains(
- ((AttributeChange)input).getValue());
- }
- return false;
- }
- };
- }
-
- protected abstract AbstractInputData getInput();
-
- protected void testMergeLeftToRight(Notifier left, Notifier right, Notifier origin) {
- final IComparisonScope scope = EMFCompare.createDefaultScope(left, right, origin);
- final Comparison comparisonBefore = getCompare().compare(scope);
- EList<Diff> differences = comparisonBefore.getDifferences();
- final IBatchMerger merger = new BatchMerger(mergerRegistry);
- merger.copyAllLeftToRight(differences, new BasicMonitor());
- final Comparison comparisonAfter = getCompare().compare(scope);
- assertTrue("Comparison#getDifferences() must be empty after copyAllLeftToRight", comparisonAfter
- .getDifferences().isEmpty());
- }
-
- protected void testMergeRightToLeft(Notifier left, Notifier right, Notifier origin) {
- final IComparisonScope scope = EMFCompare.createDefaultScope(left, right, origin);
- final Comparison comparisonBefore = getCompare().compare(scope);
- EList<Diff> differences = comparisonBefore.getDifferences();
- final IBatchMerger merger = new BatchMerger(mergerRegistry);
- merger.copyAllRightToLeft(differences, new BasicMonitor());
- final Comparison comparisonAfter = getCompare().compare(scope);
- assertTrue("Comparison#getDifferences() must be empty after copyAllRightToLeft", comparisonAfter
- .getDifferences().isEmpty());
- }
-}
+/**
+ * Copyright (c) 2012, 2013 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ */
+package org.eclipse.emf.compare.uml2.tests;
+
+import static org.junit.Assert.assertTrue;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterators;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.common.util.BasicMonitor;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.compare.AttributeChange;
+import org.eclipse.emf.compare.ComparePackage;
+import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.EMFCompare;
+import org.eclipse.emf.compare.ReferenceChange;
+import org.eclipse.emf.compare.merge.BatchMerger;
+import org.eclipse.emf.compare.merge.IBatchMerger;
+import org.eclipse.emf.compare.merge.IMerger;
+import org.eclipse.emf.compare.postprocessor.PostProcessorDescriptorRegistryImpl;
+import org.eclipse.emf.compare.scope.IComparisonScope;
+import org.eclipse.emf.compare.tests.framework.AbstractInputData;
+import org.eclipse.emf.compare.tests.postprocess.data.TestPostProcessor;
+import org.eclipse.emf.compare.uml2.internal.merge.UMLMerger;
+import org.eclipse.emf.compare.uml2.internal.postprocessor.UMLPostProcessor;
+import org.eclipse.emf.compare.utils.ReferenceUtil;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.eclipse.uml2.uml.internal.resource.UMLResourceFactoryImpl;
+import org.junit.Before;
+import org.junit.BeforeClass;
+
+@SuppressWarnings("nls")
+public abstract class AbstractTest {
+
+ private EMFCompare emfCompare;
+
+ private static final IMerger.Registry mergerRegistry = IMerger.RegistryImpl.createStandaloneInstance();
+
+ @BeforeClass
+ public static void fillRegistries() {
+ EPackage.Registry.INSTANCE.put(ComparePackage.eNS_URI, ComparePackage.eINSTANCE);
+ EPackage.Registry.INSTANCE.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
+
+ Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("uml", //$NON-NLS-1$
+ new UMLResourceFactoryImpl());
+
+ final IMerger umlMerger = new UMLMerger();
+ umlMerger.setRanking(11);
+ mergerRegistry.add(umlMerger);
+ }
+
+ @Before
+ public void before() {
+ PostProcessorDescriptorRegistryImpl<String> registry = new PostProcessorDescriptorRegistryImpl<String>();
+ registry.put(UMLPostProcessor.class.getName(), new TestPostProcessor.TestPostProcessorDescriptor(
+ Pattern.compile("http://www.eclipse.org/uml2/\\d\\.0\\.0/UML"), null, new UMLPostProcessor(),
+ 20));
+ emfCompare = EMFCompare.builder().setPostProcessorRegistry(registry).build();
+ }
+
+ protected EMFCompare getCompare() {
+ return emfCompare;
+ }
+
+ protected enum TestKind {
+ ADD, DELETE;
+ }
+
+ protected static Integer count(List<Diff> differences, Predicate<Object> p) {
+ int count = 0;
+ final Iterator<Diff> result = Iterators.filter(differences.iterator(), p);
+ while (result.hasNext()) {
+ count++;
+ result.next();
+ }
+ return Integer.valueOf(count);
+ }
+
+ public static Predicate<? super Diff> onRealFeature(final EStructuralFeature feature) {
+ return new Predicate<Diff>() {
+ public boolean apply(Diff input) {
+ final EStructuralFeature affectedFeature;
+ if (input instanceof AttributeChange) {
+ affectedFeature = ((AttributeChange)input).getAttribute();
+ } else if (input instanceof ReferenceChange) {
+ affectedFeature = ((ReferenceChange)input).getReference();
+ } else {
+ return false;
+ }
+ return feature == affectedFeature;
+ }
+ };
+ }
+
+ public static Predicate<? super Diff> isChangeAdd() {
+ return new Predicate<Diff>() {
+ public boolean apply(Diff input) {
+ if (input instanceof ReferenceChange) {
+ return ReferenceUtil.getAsList(input.getMatch().getLeft(),
+ ((ReferenceChange)input).getReference()).contains(
+ ((ReferenceChange)input).getValue());
+ } else if (input instanceof AttributeChange) {
+ return ReferenceUtil.getAsList(input.getMatch().getLeft(),
+ ((AttributeChange)input).getAttribute()).contains(
+ ((AttributeChange)input).getValue());
+ }
+ return false;
+ }
+ };
+ }
+
+ protected abstract AbstractInputData getInput();
+
+ protected void testMergeLeftToRight(Notifier left, Notifier right, Notifier origin) {
+ final IComparisonScope scope = EMFCompare.createDefaultScope(left, right, origin);
+ final Comparison comparisonBefore = getCompare().compare(scope);
+ EList<Diff> differences = comparisonBefore.getDifferences();
+ final IBatchMerger merger = new BatchMerger(mergerRegistry);
+ merger.copyAllLeftToRight(differences, new BasicMonitor());
+ final Comparison comparisonAfter = getCompare().compare(scope);
+ assertTrue("Comparison#getDifferences() must be empty after copyAllLeftToRight", comparisonAfter
+ .getDifferences().isEmpty());
+ }
+
+ protected void testMergeRightToLeft(Notifier left, Notifier right, Notifier origin) {
+ final IComparisonScope scope = EMFCompare.createDefaultScope(left, right, origin);
+ final Comparison comparisonBefore = getCompare().compare(scope);
+ EList<Diff> differences = comparisonBefore.getDifferences();
+ final IBatchMerger merger = new BatchMerger(mergerRegistry);
+ merger.copyAllRightToLeft(differences, new BasicMonitor());
+ final Comparison comparisonAfter = getCompare().compare(scope);
+ assertTrue("Comparison#getDifferences() must be empty after copyAllRightToLeft", comparisonAfter
+ .getDifferences().isEmpty());
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.uml2/plugin.xml b/plugins/org.eclipse.emf.compare.uml2/plugin.xml
index 84a9a8ea5..5665ffeb6 100644
--- a/plugins/org.eclipse.emf.compare.uml2/plugin.xml
+++ b/plugins/org.eclipse.emf.compare.uml2/plugin.xml
@@ -23,7 +23,8 @@ Contributors:
<extension
point="org.eclipse.emf.compare.rcp.postProcessor">
<processor
- class="org.eclipse.emf.compare.uml2.internal.postprocessor.UMLPostProcessor">
+ class="org.eclipse.emf.compare.uml2.internal.postprocessor.UMLPostProcessor"
+ ordinal="20">
<nsURI
value="http://www.eclipse.org/uml2/\d.0.0/UML">
</nsURI>
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/emfcomparemessages.properties b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/emfcomparemessages.properties
index cd1784e52..21ed24891 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/emfcomparemessages.properties
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/emfcomparemessages.properties
@@ -23,4 +23,4 @@ DiffUtil.IllegalFeature=Feature {0} is not multi-valued.
ResourceAttachmentChangeSpec.MissingMatch = Could not locate resource match for {0}
ResourceAttachmentChangeSpec.MissingRS = Could not locate resource set to create {0}
-IMerger.MissingMerger = No merger found for diff {0} \ No newline at end of file
+IMerger.MissingMerger = No merger found for diff {0}
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/postprocessor/BasicPostProcessorDescriptorImpl.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/postprocessor/BasicPostProcessorDescriptorImpl.java
index 3af74d54d..c72eb50d9 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/postprocessor/BasicPostProcessorDescriptorImpl.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/postprocessor/BasicPostProcessorDescriptorImpl.java
@@ -1,87 +1,108 @@
-/*******************************************************************************
- * Copyright (c) 2012 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.postprocessor;
-
-import java.util.regex.Pattern;
-
-import org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor;
-
-/**
- * A simple implementation of {@link Descriptor} that will delegate its method implementation to values given
- * to its constructor.
- *
- * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
- */
-public class BasicPostProcessorDescriptorImpl implements Descriptor {
-
- /** The nsURI pattern on which the described post processor applied to. */
- private final Pattern nsURI;
-
- /** The resourceURI pattern on which the described post processor applied to. */
- private final Pattern resourceURI;
-
- /** The described post processor. */
- private final IPostProcessor postProcessor;
-
- /**
- * Constructs a new descriptor with the given value.
- *
- * @param postProcessor
- * the described post processor
- * @param nsURI
- * The nsURI pattern on which the described post processor applied to. May be <code>null</code>
- * .
- * @param resourceURI
- * The resourceURI pattern on which the described post processor applied to. May be
- * <code>null</code>
- */
- public BasicPostProcessorDescriptorImpl(IPostProcessor postProcessor, Pattern nsURI, Pattern resourceURI) {
- this.postProcessor = postProcessor;
- this.nsURI = nsURI;
- this.resourceURI = resourceURI;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#getNsURI()
- */
- public Pattern getNsURI() {
- return nsURI;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#getResourceURI()
- */
- public Pattern getResourceURI() {
- return resourceURI;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#getInstanceClassName()
- */
- public String getInstanceClassName() {
- return getPostProcessor().getClass().getName();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#getPostProcessor()
- */
- public IPostProcessor getPostProcessor() {
- return postProcessor;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.postprocessor;
+
+import java.util.regex.Pattern;
+
+import org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor;
+
+/**
+ * A simple implementation of {@link Descriptor} that will delegate its method implementation to values given
+ * to its constructor.
+ *
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public class BasicPostProcessorDescriptorImpl implements Descriptor {
+
+ /** The nsURI pattern on which the described post processor applied to. */
+ private final Pattern nsURI;
+
+ /** The resourceURI pattern on which the described post processor applied to. */
+ private final Pattern resourceURI;
+
+ /** The described post processor. */
+ private final IPostProcessor postProcessor;
+
+ /** The ordinal of this post processor. */
+ private int ordinal;
+
+ /**
+ * Constructs a new descriptor with the given value.
+ *
+ * @param postProcessor
+ * the described post processor
+ * @param nsURI
+ * The nsURI pattern on which the described post processor applied to. May be <code>null</code>
+ * .
+ * @param resourceURI
+ * The resourceURI pattern on which the described post processor applied to. May be
+ * <code>null</code>
+ */
+ public BasicPostProcessorDescriptorImpl(IPostProcessor postProcessor, Pattern nsURI, Pattern resourceURI) {
+ this.postProcessor = postProcessor;
+ this.nsURI = nsURI;
+ this.resourceURI = resourceURI;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#getNsURI()
+ */
+ public Pattern getNsURI() {
+ return nsURI;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#getResourceURI()
+ */
+ public Pattern getResourceURI() {
+ return resourceURI;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#getInstanceClassName()
+ */
+ public String getInstanceClassName() {
+ return getPostProcessor().getClass().getName();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#getPostProcessor()
+ */
+ public IPostProcessor getPostProcessor() {
+ return postProcessor;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#getOrdinal()
+ */
+ public int getOrdinal() {
+ return ordinal;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#setOrdinal(int)
+ */
+ public void setOrdinal(int parseInt) {
+ ordinal = parseInt;
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/postprocessor/IPostProcessor.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/postprocessor/IPostProcessor.java
index d336fd955..7da141c12 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/postprocessor/IPostProcessor.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/postprocessor/IPostProcessor.java
@@ -1,192 +1,207 @@
-/*******************************************************************************
- * Copyright (c) 2012, 2013 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.postprocessor;
-
-import com.google.common.collect.ImmutableList;
-
-import java.util.regex.Pattern;
-
-import org.eclipse.emf.common.util.Monitor;
-import org.eclipse.emf.compare.Comparison;
-import org.eclipse.emf.compare.scope.IComparisonScope;
-
-/**
- * Implementations of this interface can be used in order to tell EMF Compare how to make post treatments at
- * each step of the comparison.
- *
- * @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a>
- */
-public interface IPostProcessor {
-
- /**
- * This will be called by EMF Compare in order to execute the specified behavior after the match step,
- * from a <code>comparison</code>.
- *
- * @param comparison
- * The comparison after the match step.
- * @param monitor
- * The monitor to report progress or to check for cancellation
- * @since 3.0
- */
- void postMatch(Comparison comparison, Monitor monitor);
-
- /**
- * This will be called by EMF Compare in order to execute the specified behavior after the difference
- * step, from a <code>comparison</code>.
- *
- * @param comparison
- * The comparison after the difference step.
- * @param monitor
- * The monitor to report progress or to check for cancellation
- * @since 3.0
- */
- void postDiff(Comparison comparison, Monitor monitor);
-
- /**
- * This will be called by EMF Compare in order to execute the specified behavior after the requirements
- * step, from a <code>comparison</code>.
- *
- * @param comparison
- * The comparison after the requirements step.
- * @param monitor
- * The monitor to report progress or to check for cancellation
- * @since 3.0
- */
- void postRequirements(Comparison comparison, Monitor monitor);
-
- /**
- * This will be called by EMF Compare in order to execute the specified behavior after the equivalences
- * step, from a <code>comparison</code>.
- *
- * @param comparison
- * The comparison after the equivalences step.
- * @param monitor
- * The monitor to report progress or to check for cancellation
- * @since 3.0
- */
- void postEquivalences(Comparison comparison, Monitor monitor);
-
- /**
- * This will be called by EMF Compare in order to execute the specified behavior after the conflicts step,
- * from a <code>comparison</code>.
- *
- * @param comparison
- * The comparison after the conflicts step.
- * @param monitor
- * The monitor to report progress or to check for cancellation
- * @since 3.0
- */
- void postConflicts(Comparison comparison, Monitor monitor);
-
- /**
- * This will be called by EMF Compare in order to execute the specified behavior after a comparison, from
- * a <code>comparison</code>.
- *
- * @param comparison
- * The comparison after the all steps.
- * @param monitor
- * The monitor to report progress or to check for cancellation
- * @since 3.0
- */
- void postComparison(Comparison comparison, Monitor monitor);
-
- /**
- * Wrapper describing the given post processor.
- *
- * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
- */
- interface Descriptor {
- /**
- * Returns the wrapped post processor.
- *
- * @return the wrapped post processor
- */
- IPostProcessor getPostProcessor();
-
- /**
- * Returns the pattern of namespace URI on which this post processor can be applied.
- *
- * @return The namespace URI pattern.
- */
- Pattern getNsURI();
-
- /**
- * Returns the pattern of resource URI on which this post processor can be applied.
- *
- * @return The resource URI.
- */
- Pattern getResourceURI();
-
- /**
- * Returns the class name of the instance that will be returned by {@link #getPostProcessor()}.
- *
- * @return the class name of the instance that will be returned by {@link #getPostProcessor()}.
- */
- String getInstanceClassName();
-
- /**
- * Registry of post processor.
- *
- * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
- */
- public interface Registry<K> {
-
- /**
- * Adds a post processor to the registry.
- *
- * @param key
- * key with which the specified descriptor is to be associated
- * @param descriptor
- * Post Processor that is to be added to this registry.
- * @return the previous descriptor associated with <tt>key</tt>, or <tt>null</tt> if there was no
- * mapping for <tt>key</tt>. (A <tt>null</tt> return can also indicate that the map
- * previously associated <tt>null</tt> with <tt>key</tt>, if the implementation supports
- * <tt>null</tt> values.)
- */
- IPostProcessor.Descriptor put(K key, IPostProcessor.Descriptor descriptor);
-
- /**
- * Removes all extensions from this registry.
- *
- * @noreference This method is not intended to be referenced by clients.
- */
- void clear();
-
- /**
- * This will return a copy of the registered post processors list.
- *
- * @return A copy of the registered post processors list.
- */
- ImmutableList<IPostProcessor.Descriptor> getDescriptors();
-
- /**
- * Removes a post processor from this registry.
- *
- * @param key
- * key of the post processor descriptor that is to be removed from the registry.
- * @return the previous value associated with <tt>key</tt>, or <tt>null</tt> if there was no
- * mapping for <tt>key</tt>.
- */
- IPostProcessor.Descriptor remove(K key);
-
- /**
- * Retrieve the post processors from a given <code>scope</code>. The scope provides the set of
- * scanned namespaces and resource uris. If they match with the regex of some post processors,
- * then tey are returned.
- *
- * @param scope
- * The given scope.
- * @return The associated post processors if any.
- */
- ImmutableList<IPostProcessor> getPostProcessors(IComparisonScope scope);
- }
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.postprocessor;
+
+import com.google.common.collect.ImmutableList;
+
+import java.util.regex.Pattern;
+
+import org.eclipse.emf.common.util.Monitor;
+import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.scope.IComparisonScope;
+
+/**
+ * Implementations of this interface can be used in order to tell EMF Compare how to make post treatments at
+ * each step of the comparison.
+ *
+ * @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a>
+ */
+public interface IPostProcessor {
+
+ /**
+ * This will be called by EMF Compare in order to execute the specified behavior after the match step,
+ * from a <code>comparison</code>.
+ *
+ * @param comparison
+ * The comparison after the match step.
+ * @param monitor
+ * The monitor to report progress or to check for cancellation
+ * @since 3.0
+ */
+ void postMatch(Comparison comparison, Monitor monitor);
+
+ /**
+ * This will be called by EMF Compare in order to execute the specified behavior after the difference
+ * step, from a <code>comparison</code>.
+ *
+ * @param comparison
+ * The comparison after the difference step.
+ * @param monitor
+ * The monitor to report progress or to check for cancellation
+ * @since 3.0
+ */
+ void postDiff(Comparison comparison, Monitor monitor);
+
+ /**
+ * This will be called by EMF Compare in order to execute the specified behavior after the requirements
+ * step, from a <code>comparison</code>.
+ *
+ * @param comparison
+ * The comparison after the requirements step.
+ * @param monitor
+ * The monitor to report progress or to check for cancellation
+ * @since 3.0
+ */
+ void postRequirements(Comparison comparison, Monitor monitor);
+
+ /**
+ * This will be called by EMF Compare in order to execute the specified behavior after the equivalences
+ * step, from a <code>comparison</code>.
+ *
+ * @param comparison
+ * The comparison after the equivalences step.
+ * @param monitor
+ * The monitor to report progress or to check for cancellation
+ * @since 3.0
+ */
+ void postEquivalences(Comparison comparison, Monitor monitor);
+
+ /**
+ * This will be called by EMF Compare in order to execute the specified behavior after the conflicts step,
+ * from a <code>comparison</code>.
+ *
+ * @param comparison
+ * The comparison after the conflicts step.
+ * @param monitor
+ * The monitor to report progress or to check for cancellation
+ * @since 3.0
+ */
+ void postConflicts(Comparison comparison, Monitor monitor);
+
+ /**
+ * This will be called by EMF Compare in order to execute the specified behavior after a comparison, from
+ * a <code>comparison</code>.
+ *
+ * @param comparison
+ * The comparison after the all steps.
+ * @param monitor
+ * The monitor to report progress or to check for cancellation
+ * @since 3.0
+ */
+ void postComparison(Comparison comparison, Monitor monitor);
+
+ /**
+ * Wrapper describing the given post processor.
+ *
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+ interface Descriptor {
+ /**
+ * Returns the wrapped post processor.
+ *
+ * @return the wrapped post processor
+ */
+ IPostProcessor getPostProcessor();
+
+ /**
+ * Returns the ordinal of this post processor.
+ *
+ * @return The ordinal.
+ */
+ int getOrdinal();
+
+ /**
+ * Set the ordinal of this post processor.
+ *
+ * @param parseInt
+ * The ordinal.
+ */
+ void setOrdinal(int parseInt);
+
+ /**
+ * Returns the pattern of namespace URI on which this post processor can be applied.
+ *
+ * @return The namespace URI pattern.
+ */
+ Pattern getNsURI();
+
+ /**
+ * Returns the pattern of resource URI on which this post processor can be applied.
+ *
+ * @return The resource URI.
+ */
+ Pattern getResourceURI();
+
+ /**
+ * Returns the class name of the instance that will be returned by {@link #getPostProcessor()}.
+ *
+ * @return the class name of the instance that will be returned by {@link #getPostProcessor()}.
+ */
+ String getInstanceClassName();
+
+ /**
+ * Registry of post processor.
+ *
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+ public interface Registry<K> {
+
+ /**
+ * Adds a post processor to the registry.
+ *
+ * @param key
+ * key with which the specified descriptor is to be associated
+ * @param descriptor
+ * Post Processor that is to be added to this registry.
+ * @return the previous descriptor associated with <tt>key</tt>, or <tt>null</tt> if there was no
+ * mapping for <tt>key</tt>. (A <tt>null</tt> return can also indicate that the map
+ * previously associated <tt>null</tt> with <tt>key</tt>, if the implementation supports
+ * <tt>null</tt> values.)
+ */
+ IPostProcessor.Descriptor put(K key, IPostProcessor.Descriptor descriptor);
+
+ /**
+ * Removes all extensions from this registry.
+ *
+ * @noreference This method is not intended to be referenced by clients.
+ */
+ void clear();
+
+ /**
+ * This will return a copy of the registered post processors list.
+ *
+ * @return A copy of the registered post processors list.
+ */
+ ImmutableList<IPostProcessor.Descriptor> getDescriptors();
+
+ /**
+ * Removes a post processor from this registry.
+ *
+ * @param key
+ * key of the post processor descriptor that is to be removed from the registry.
+ * @return the previous value associated with <tt>key</tt>, or <tt>null</tt> if there was no
+ * mapping for <tt>key</tt>.
+ */
+ IPostProcessor.Descriptor remove(K key);
+
+ /**
+ * Retrieve the post processors from a given <code>scope</code>. The scope provides the set of
+ * scanned namespaces and resource uris. If they match with the regex of some post processors,
+ * then they are returned.
+ *
+ * @param scope
+ * The given scope.
+ * @return The associated post processors if any.
+ */
+ ImmutableList<IPostProcessor> getPostProcessors(IComparisonScope scope);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/postprocessor/PostProcessorDescriptorRegistryImpl.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/postprocessor/PostProcessorDescriptorRegistryImpl.java
index 2bb92dfa0..6cabdfa28 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/postprocessor/PostProcessorDescriptorRegistryImpl.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/postprocessor/PostProcessorDescriptorRegistryImpl.java
@@ -1,108 +1,119 @@
-/*******************************************************************************
- * Copyright (c) 2012, 2013 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.postprocessor;
-
-import com.google.common.collect.ImmutableList;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.regex.Pattern;
-
-import org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor;
-import org.eclipse.emf.compare.scope.IComparisonScope;
-
-/**
- * This will contain all of the EMF Compare extensions.
- *
- * @param <K>
- * the type of the key of this registry
- * @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a>
- */
-public class PostProcessorDescriptorRegistryImpl<K> implements IPostProcessor.Descriptor.Registry<K> {
-
- /** List of all the post processors contributed through "org.eclipse.emf.compare.postProcessor". */
- private final Map<K, IPostProcessor.Descriptor> postProcessorFactories;
-
- /**
- * Creates a new extension registry.
- */
- public PostProcessorDescriptorRegistryImpl() {
- postProcessorFactories = new ConcurrentHashMap<K, IPostProcessor.Descriptor>();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.extension.Registry#clearRegistry()
- */
- public void clear() {
- postProcessorFactories.clear();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor.Registry#put(java.lang.Object,
- * org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor)
- */
- public Descriptor put(K key, Descriptor postProcessor) {
- return postProcessorFactories.put(key, postProcessor);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor.Registry#getDescriptors()
- */
- public ImmutableList<Descriptor> getDescriptors() {
- return ImmutableList.copyOf(postProcessorFactories.values());
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor.Registry#remove(java.lang.Object)
- */
- public Descriptor remove(K key) {
- return postProcessorFactories.remove(key);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor.Registry#getFactories(org.eclipse.emf.compare.scope.IComparisonScope)
- */
- public ImmutableList<IPostProcessor> getPostProcessors(IComparisonScope scope) {
- final ImmutableList.Builder<IPostProcessor> processors = ImmutableList.builder();
- for (IPostProcessor.Descriptor factory : getDescriptors()) {
- Pattern nsURIPattern = factory.getNsURI();
- if (nsURIPattern != null) {
- for (String nsURI : scope.getNsURIs()) {
- if (nsURIPattern.matcher(nsURI).matches()) {
- processors.add(factory.getPostProcessor());
- break;
- }
- }
- }
- // Should probably use two loops here to prioritize NsURI matching
- Pattern resourceURIPattern = factory.getResourceURI();
- if (resourceURIPattern != null) {
- for (String resourceURI : scope.getResourceURIs()) {
- if (resourceURIPattern.matcher(resourceURI).matches()) {
- processors.add(factory.getPostProcessor());
- break;
- }
- }
- }
- }
- return processors.build();
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.postprocessor;
+
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Ordering;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.regex.Pattern;
+
+import org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor;
+import org.eclipse.emf.compare.scope.IComparisonScope;
+
+/**
+ * This will contain all of the EMF Compare extensions.
+ *
+ * @param <K>
+ * the type of the key of this registry
+ * @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a>
+ */
+public class PostProcessorDescriptorRegistryImpl<K> implements IPostProcessor.Descriptor.Registry<K> {
+
+ /**
+ * Function ordering descriptors by their ranking.
+ */
+ private static Function<IPostProcessor.Descriptor, Integer> ordinal = new Function<IPostProcessor.Descriptor, Integer>() {
+ public Integer apply(IPostProcessor.Descriptor from) {
+ return Integer.valueOf(from.getOrdinal());
+ }
+ };
+
+ /** List of all the post processors contributed through "org.eclipse.emf.compare.postProcessor". */
+ private final Map<K, IPostProcessor.Descriptor> postProcessorFactories;
+
+ /**
+ * Creates a new extension registry.
+ */
+ public PostProcessorDescriptorRegistryImpl() {
+ postProcessorFactories = new ConcurrentHashMap<K, IPostProcessor.Descriptor>();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.extension.Registry#clearRegistry()
+ */
+ public void clear() {
+ postProcessorFactories.clear();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor.Registry#put(java.lang.Object,
+ * org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor)
+ */
+ public Descriptor put(K key, Descriptor postProcessor) {
+ return postProcessorFactories.put(key, postProcessor);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor.Registry#getDescriptors()
+ */
+ public ImmutableList<Descriptor> getDescriptors() {
+ return Ordering.natural().onResultOf(ordinal).immutableSortedCopy(postProcessorFactories.values());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor.Registry#remove(java.lang.Object)
+ */
+ public Descriptor remove(K key) {
+ return postProcessorFactories.remove(key);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor.Registry#getPostProcessors(org.eclipse.emf.compare.scope.IComparisonScope)
+ */
+ public ImmutableList<IPostProcessor> getPostProcessors(IComparisonScope scope) {
+ final ImmutableList.Builder<IPostProcessor> processors = ImmutableList.builder();
+ for (IPostProcessor.Descriptor factory : getDescriptors()) {
+ Pattern nsURIPattern = factory.getNsURI();
+ if (nsURIPattern != null) {
+ for (String nsURI : scope.getNsURIs()) {
+ if (nsURIPattern.matcher(nsURI).matches()) {
+ processors.add(factory.getPostProcessor());
+ break;
+ }
+ }
+ }
+ // Should probably use two loops here to prioritize NsURI matching
+ Pattern resourceURIPattern = factory.getResourceURI();
+ if (resourceURIPattern != null) {
+ for (String resourceURI : scope.getResourceURIs()) {
+ if (resourceURIPattern.matcher(resourceURI).matches()) {
+ processors.add(factory.getPostProcessor());
+ break;
+ }
+ }
+ }
+ }
+ return processors.build();
+ }
+}

Back to the top