diff options
author | Mikaël Barbero | 2013-03-11 22:21:49 +0000 |
---|---|---|
committer | Mikaël Barbero | 2013-03-11 23:02:40 +0000 |
commit | 1f9b238aeecef07e2133434cba00559d1dd2add5 (patch) | |
tree | f7894592b325741c7e776dc975859ed327f6616b | |
parent | 9ff2e9b23f43b850f5385854f66536cda5d62c63 (diff) | |
download | org.eclipse.emf.compare-1f9b238aeecef07e2133434cba00559d1dd2add5.tar.gz org.eclipse.emf.compare-1f9b238aeecef07e2133434cba00559d1dd2add5.tar.xz org.eclipse.emf.compare-1f9b238aeecef07e2133434cba00559d1dd2add5.zip |
refactored IPostProcessor to move nsURI and resourceURI to Descriptor
20 files changed, 253 insertions, 353 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 7f6474e6d..c73ec3548 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 @@ -18,7 +18,8 @@ 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.PostProcessorRegistryImpl;
+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;
@@ -32,13 +33,13 @@ public abstract class AbstractTest { private EMFCompare emfCompare;
- private PostProcessorRegistryImpl postProcessorRegistry;
+ private PostProcessorDescriptorRegistryImpl<String> postProcessorRegistry;
@Before
public void before() {
- postProcessorRegistry = new PostProcessorRegistryImpl();
- postProcessorRegistry.addPostProcessor(new CompareDiagramPostProcessor(
- Pattern.compile("http://www.eclipse.org/gmf/runtime/\\d.\\d.\\d/notation"), null));
+ 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();
}
@@ -49,7 +50,7 @@ public abstract class AbstractTest { /**
* @return the postProcessorRegistry
*/
- protected IPostProcessor.Registry getPostProcessorRegistry() {
+ protected IPostProcessor.Descriptor.Registry<?> getPostProcessorRegistry() {
return postProcessorRegistry;
}
diff --git a/plugins/org.eclipse.emf.compare.diagram.ide.ecoretools.tests/src/org/eclipse/emf/compare/diagram/ide/ecoretools/tests/nodechanges/NodechangesTest.java b/plugins/org.eclipse.emf.compare.diagram.ide.ecoretools.tests/src/org/eclipse/emf/compare/diagram/ide/ecoretools/tests/nodechanges/NodechangesTest.java index 1849f8efd..8d628896a 100644 --- a/plugins/org.eclipse.emf.compare.diagram.ide.ecoretools.tests/src/org/eclipse/emf/compare/diagram/ide/ecoretools/tests/nodechanges/NodechangesTest.java +++ b/plugins/org.eclipse.emf.compare.diagram.ide.ecoretools.tests/src/org/eclipse/emf/compare/diagram/ide/ecoretools/tests/nodechanges/NodechangesTest.java @@ -54,7 +54,7 @@ public class NodechangesTest extends AbstractTest { }
@Override
- protected IPostProcessor.Registry getPostProcessorRegistry() {
+ protected IPostProcessor.Descriptor.Registry<?> getPostProcessorRegistry() {
throw new UnsupportedOperationException("do not call this in IDE context");
}
diff --git a/plugins/org.eclipse.emf.compare.diagram.ide.ui/src/org/eclipse/emf/compare/diagram/ide/ui/internal/CompareDiagramIDEUIPlugin.java b/plugins/org.eclipse.emf.compare.diagram.ide.ui/src/org/eclipse/emf/compare/diagram/ide/ui/internal/CompareDiagramIDEUIPlugin.java index 1e493429e..aa18bc078 100644 --- a/plugins/org.eclipse.emf.compare.diagram.ide.ui/src/org/eclipse/emf/compare/diagram/ide/ui/internal/CompareDiagramIDEUIPlugin.java +++ b/plugins/org.eclipse.emf.compare.diagram.ide.ui/src/org/eclipse/emf/compare/diagram/ide/ui/internal/CompareDiagramIDEUIPlugin.java @@ -68,15 +68,11 @@ public class CompareDiagramIDEUIPlugin extends AbstractUIPlugin { configuration.setMoveThreshold(getPreferenceStore().getInt( CompareDiagramConstants.PREFERENCES_KEY_MOVE_THRESHOLD)); - IPostProcessor.Registry postProcessorRegistry = EMFCompareRCPPlugin.getDefault() + IPostProcessor.Descriptor.Registry<?> registry = EMFCompareRCPPlugin.getDefault() .getPostProcessorRegistry(); - for (IPostProcessor postprocessor : postProcessorRegistry.getPostProcessors()) { - if (postprocessor instanceof CompareDiagramPostProcessor) { - ((CompareDiagramPostProcessor)postprocessor).setConfiguration(configuration); - } else if (postprocessor instanceof IPostProcessor.Descriptor - && ((IPostProcessor.Descriptor)postprocessor).getPostProcessor() instanceof CompareDiagramPostProcessor) { - ((CompareDiagramPostProcessor)((IPostProcessor.Descriptor)postprocessor).getPostProcessor()) - .setConfiguration(configuration); + for (IPostProcessor.Descriptor descriptor : registry.getDescriptors()) { + if (CompareDiagramPostProcessor.class.getName().equals(descriptor.getInstanceClassName())) { + ((CompareDiagramPostProcessor)descriptor.getPostProcessor()).setConfiguration(configuration); } } } diff --git a/plugins/org.eclipse.emf.compare.diagram/src/org/eclipse/emf/compare/diagram/internal/CompareDiagramPostProcessor.java b/plugins/org.eclipse.emf.compare.diagram/src/org/eclipse/emf/compare/diagram/internal/CompareDiagramPostProcessor.java index 4bc7ce269..b4cd873d9 100644 --- a/plugins/org.eclipse.emf.compare.diagram/src/org/eclipse/emf/compare/diagram/internal/CompareDiagramPostProcessor.java +++ b/plugins/org.eclipse.emf.compare.diagram/src/org/eclipse/emf/compare/diagram/internal/CompareDiagramPostProcessor.java @@ -13,7 +13,6 @@ package org.eclipse.emf.compare.diagram.internal; import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import java.util.regex.Pattern;
import org.eclipse.emf.common.util.Monitor;
import org.eclipse.emf.compare.Comparison;
@@ -22,14 +21,14 @@ import org.eclipse.emf.compare.Match; import org.eclipse.emf.compare.diagram.internal.extensions.DiagramDiff;
import org.eclipse.emf.compare.diagram.internal.factories.DiagramExtensionFactoryRegistry;
import org.eclipse.emf.compare.diagram.internal.factories.IDiagramExtensionFactory;
-import org.eclipse.emf.compare.postprocessor.AbstractPostProcessor;
+import org.eclipse.emf.compare.postprocessor.IPostProcessor;
/**
* Post-processor to create the diagram difference extensions.
*
* @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a>
*/
-public class CompareDiagramPostProcessor extends AbstractPostProcessor {
+public class CompareDiagramPostProcessor implements IPostProcessor {
/** Registry of diagram difference extension factories. */
private Set<IDiagramExtensionFactory> diagramExtensionFactories;
@@ -38,23 +37,6 @@ public class CompareDiagramPostProcessor extends AbstractPostProcessor { private CompareDiagramConfiguration configuration;
/**
- * Constructor.
- */
- public CompareDiagramPostProcessor() {
- super(Pattern.compile("http://www.eclipse.org/gmf/runtime/\\d.\\d.\\d/notation"), null); //$NON-NLS-1$
- }
-
- /**
- * Constructor.
- *
- * @param configuration
- * The diagram comparison configuration.
- */
- public CompareDiagramPostProcessor(Pattern nsURI, Pattern resourceURI) {
- super(nsURI, resourceURI);
- }
-
- /**
* Set the diagram comparison configuration.
*
* @param configuration
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/EMFCompareIDEUIPlugin.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/EMFCompareIDEUIPlugin.java index b291a6fbb..1dbe26417 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/EMFCompareIDEUIPlugin.java +++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/EMFCompareIDEUIPlugin.java @@ -36,7 +36,7 @@ public class EMFCompareIDEUIPlugin extends AbstractUIPlugin { /** The plugin ID. */ public static final String PLUGIN_ID = "org.eclipse.emf.compare.ide.ui"; //$NON-NLS-1$ - public static final String ACCESSOR_FACTORY_PPID = "accessor_factory"; //$NON-NLS-1$ + public static final String ACCESSOR_FACTORY_PPID = "accessorFactory"; //$NON-NLS-1$ /** Plug-in's shared instance. */ private static EMFCompareIDEUIPlugin plugin; diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/accessor/IAccessorFactory.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/accessor/IAccessorFactory.java index 70f2f4f1a..0f4c37dd1 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/accessor/IAccessorFactory.java +++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/accessor/IAccessorFactory.java @@ -95,7 +95,6 @@ public interface IAccessorFactory { *
* @see org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.accessor.IAccessorFactory.Registry#getFactories(java.lang.Object)
*/
- @SuppressWarnings("unchecked")
// safe thanks to the isFactoryFor filter
public List<IAccessorFactory> getFactories(Object target) {
Iterable<IAccessorFactory> factories = filter(map.values(), isFactoryFor(target));
diff --git a/plugins/org.eclipse.emf.compare.rcp/schema/loadOnDemandPolicy.exsd b/plugins/org.eclipse.emf.compare.rcp/schema/loadOnDemandPolicy.exsd index ab55b4274..59b1fde42 100644 --- a/plugins/org.eclipse.emf.compare.rcp/schema/loadOnDemandPolicy.exsd +++ b/plugins/org.eclipse.emf.compare.rcp/schema/loadOnDemandPolicy.exsd @@ -55,7 +55,7 @@ </documentation> <appinfo> - <meta.attribute kind="java" basedOn=":org.eclipse.emf.compare.ide.policy.ILoadOnDemandPolicy"/> + <meta.attribute kind="java" basedOn=":org.eclipse.emf.compare.rcp.policy.ILoadOnDemandPolicy"/> </appinfo> </annotation> </attribute> diff --git a/plugins/org.eclipse.emf.compare.rcp/schema/postProcessor.exsd b/plugins/org.eclipse.emf.compare.rcp/schema/postProcessor.exsd index 162217ce8..90f4f6ed1 100644 --- a/plugins/org.eclipse.emf.compare.rcp/schema/postProcessor.exsd +++ b/plugins/org.eclipse.emf.compare.rcp/schema/postProcessor.exsd @@ -64,7 +64,7 @@ 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.extension.IPostProcessor"/> + <meta.attribute kind="java" basedOn=":org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor"/> </appinfo> </annotation> </attribute> diff --git a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/EMFCompareRCPPlugin.java b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/EMFCompareRCPPlugin.java index 655d844d2..b18adbf6f 100644 --- a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/EMFCompareRCPPlugin.java +++ b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/EMFCompareRCPPlugin.java @@ -15,12 +15,13 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Status; import org.eclipse.emf.compare.merge.IMerger; -import org.eclipse.emf.compare.postprocessor.PostProcessorRegistryImpl; +import org.eclipse.emf.compare.postprocessor.IPostProcessor; +import org.eclipse.emf.compare.postprocessor.PostProcessorDescriptorRegistryImpl; import org.eclipse.emf.compare.rcp.extension.AbstractRegistryEventListener; import org.eclipse.emf.compare.rcp.internal.merger.MergerExtensionRegistryListener; import org.eclipse.emf.compare.rcp.internal.policy.LoadOnDemandPolicyRegistryImpl; import org.eclipse.emf.compare.rcp.internal.policy.LoadOnDemandPolicyRegistryListener; -import org.eclipse.emf.compare.rcp.internal.postprocessor.PostProcessorRegistryListener; +import org.eclipse.emf.compare.rcp.internal.postprocessor.PostProcessorFactoryRegistryListener; import org.eclipse.emf.compare.rcp.policy.ILoadOnDemandPolicy; import org.osgi.framework.BundleContext; @@ -51,15 +52,15 @@ public class EMFCompareRCPPlugin extends Plugin { private ILoadOnDemandPolicy.Registry loadOnDemandRegistry; /** The registry listener that will be used to react to load on demand policy changes. */ - private LoadOnDemandPolicyRegistryListener loadOnDemandRegistryListener; + private AbstractRegistryEventListener loadOnDemandRegistryListener; /** * The registry that will hold references to all post processors. */ - private PostProcessorRegistryImpl postProcessorRegistry; + private IPostProcessor.Descriptor.Registry<String> postProcessorDescriptorsRegistry; /** The registry listener that will be used to react to post processor changes. */ - private PostProcessorRegistryListener postProcessorRegistryListener; + private AbstractRegistryEventListener postProcessorFactoryRegistryListener; /* * (non-Javadoc) @@ -77,11 +78,11 @@ public class EMFCompareRCPPlugin extends Plugin { registry.addListener(mergerRegistryListener, PLUGIN_ID + '.' + MERGER_PPID); mergerRegistryListener.readRegistry(registry); - postProcessorRegistry = new PostProcessorRegistryImpl(); - postProcessorRegistryListener = new PostProcessorRegistryListener(PLUGIN_ID, POST_PROCESSOR_PPID, - getLog(), postProcessorRegistry); - registry.addListener(postProcessorRegistryListener, PLUGIN_ID + '.' + POST_PROCESSOR_PPID); - postProcessorRegistryListener.readRegistry(registry); + postProcessorDescriptorsRegistry = new PostProcessorDescriptorRegistryImpl<String>(); + postProcessorFactoryRegistryListener = new PostProcessorFactoryRegistryListener(PLUGIN_ID, + POST_PROCESSOR_PPID, getLog(), postProcessorDescriptorsRegistry); + registry.addListener(postProcessorFactoryRegistryListener, PLUGIN_ID + '.' + POST_PROCESSOR_PPID); + postProcessorFactoryRegistryListener.readRegistry(registry); loadOnDemandRegistry = new LoadOnDemandPolicyRegistryImpl(); loadOnDemandRegistryListener = new LoadOnDemandPolicyRegistryListener(loadOnDemandRegistry, @@ -104,9 +105,9 @@ public class EMFCompareRCPPlugin extends Plugin { loadOnDemandRegistryListener = null; loadOnDemandRegistry = null; - registry.removeListener(postProcessorRegistryListener); - postProcessorRegistryListener = null; - postProcessorRegistry = null; + registry.removeListener(postProcessorFactoryRegistryListener); + postProcessorFactoryRegistryListener = null; + postProcessorDescriptorsRegistry = null; registry.removeListener(mergerRegistryListener); mergerRegistryListener = null; @@ -128,8 +129,8 @@ public class EMFCompareRCPPlugin extends Plugin { * * @return the post processor registry to which extension will be registered */ - public PostProcessorRegistryImpl getPostProcessorRegistry() { - return postProcessorRegistry; + public IPostProcessor.Descriptor.Registry<String> getPostProcessorRegistry() { + return postProcessorDescriptorsRegistry; } /** 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 b803151e4..203d314b5 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 @@ -13,24 +13,22 @@ package org.eclipse.emf.compare.rcp.internal.postprocessor; import java.util.regex.Pattern;
import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.emf.common.util.Monitor;
-import org.eclipse.emf.compare.Comparison;
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.post_processor" extension point.
+ * 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 IPostProcessor delegate;
-
private final Pattern nsURI;
private final Pattern resourceURI;
+ private IPostProcessor instance;
+
/**
* Creates a descriptor corresponding to the information of the given <em>element</em>.
*
@@ -38,99 +36,48 @@ public class PostProcessorDescriptor extends PluginClassDescriptor<IPostProcesso * Configuration element from which to create this descriptor.
*/
public PostProcessorDescriptor(IConfigurationElement element, Pattern nsURI, Pattern resourceURI) {
- super(element, PostProcessorRegistryListener.ATT_CLASS);
+ super(element, PostProcessorFactoryRegistryListener.ATT_CLASS);
this.nsURI = nsURI;
this.resourceURI = resourceURI;
}
/**
- * Creates an instance of this descriptor's post processor if needed, then return it.
- *
- * @return An instance of this descriptor's post processor.
- */
- public IPostProcessor getPostProcessor() {
- if (delegate == null) {
- delegate = createInstance();
- }
- return delegate;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor#postMatch(org.eclipse.emf.compare.Comparison,
- * org.eclipse.emf.common.util.Monitor)
- */
- public void postMatch(Comparison comparison, Monitor monitor) {
- getPostProcessor().postMatch(comparison, monitor);
- }
-
- /**
- * {@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) {
- getPostProcessor().postDiff(comparison, monitor);
- }
-
- /**
* {@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) {
- getPostProcessor().postRequirements(comparison, monitor);
- }
-
- /**
- * {@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) {
- getPostProcessor().postEquivalences(comparison, monitor);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor#postConflicts(org.eclipse.emf.compare.Comparison,
- * org.eclipse.emf.common.util.Monitor)
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor#getNsURI()
*/
- public void postConflicts(Comparison comparison, Monitor monitor) {
- getPostProcessor().postConflicts(comparison, monitor);
+ public Pattern getNsURI() {
+ return nsURI;
}
/**
* {@inheritDoc}
*
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor#postComparison(org.eclipse.emf.compare.Comparison,
- * org.eclipse.emf.common.util.Monitor)
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor#getResourceURI()
*/
- public void postComparison(Comparison comparison, Monitor monitor) {
- getPostProcessor().postComparison(comparison, monitor);
+ public Pattern getResourceURI() {
+ return resourceURI;
}
/**
* {@inheritDoc}
*
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor#getNsURI()
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#getPostProcessor()
*/
- public Pattern getNsURI() {
- return nsURI;
+ public IPostProcessor getPostProcessor() {
+ if (instance == null) {
+ instance = createInstance();
+ }
+ return instance;
}
/**
* {@inheritDoc}
*
- * @see org.eclipse.emf.compare.postprocessor.IPostProcessor#getResourceURI()
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor#getInstanceClassName()
*/
- public Pattern getResourceURI() {
- return resourceURI;
+ public String getInstanceClassName() {
+ return element.getAttribute(attributeName);
}
}
diff --git a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/postprocessor/PostProcessorRegistryListener.java b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/postprocessor/PostProcessorFactoryRegistryListener.java index c6923e995..b2a5123c5 100644 --- a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/postprocessor/PostProcessorRegistryListener.java +++ b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/postprocessor/PostProcessorFactoryRegistryListener.java @@ -24,7 +24,7 @@ import org.eclipse.emf.compare.rcp.extension.AbstractRegistryEventListener; *
* @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a>
*/
-public class PostProcessorRegistryListener extends AbstractRegistryEventListener {
+public class PostProcessorFactoryRegistryListener extends AbstractRegistryEventListener {
static final String TAG_PROCESSOR = "processor"; //$NON-NLS-1$
@@ -37,7 +37,7 @@ public class PostProcessorRegistryListener extends AbstractRegistryEventListener static final String ATT_CLASS = "class"; //$NON-NLS-1$
/** The post processor registry to which extension will be registered. */
- private final IPostProcessor.Registry registry;
+ private final IPostProcessor.Descriptor.Registry<String> registry;
/**
* Creates a new registry listener with the given post processor registry to which extension will be
@@ -49,8 +49,8 @@ public class PostProcessorRegistryListener extends AbstractRegistryEventListener * @param extensionPointID
* @param log
*/
- public PostProcessorRegistryListener(String pluginID, String extensionPointID, ILog log,
- IPostProcessor.Registry registry) {
+ public PostProcessorFactoryRegistryListener(String pluginID, String extensionPointID, ILog log,
+ IPostProcessor.Descriptor.Registry<String> registry) {
super(pluginID, extensionPointID, log);
this.registry = registry;
}
@@ -111,12 +111,13 @@ public class PostProcessorRegistryListener extends AbstractRegistryEventListener if (resourceURIChildren.length > 0) {
resourceURI = Pattern.compile(resourceURIChildren[0].getAttribute(ATT_VALUE));
}
+ String className = element.getAttribute(ATT_CLASS);
- IPostProcessor processor = new PostProcessorDescriptor(element, nsURI, resourceURI);
- IPostProcessor previous = registry.addPostProcessor(processor);
+ 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 '" + element.getAttribute(ATT_CLASS) + "' is registered twice.");
+ "The post processor factory '" + className + "' is registered twice.");
}
return true;
}
@@ -128,7 +129,8 @@ public class PostProcessorRegistryListener extends AbstractRegistryEventListener */
@Override
protected boolean removedValid(IConfigurationElement element) {
- registry.removePostProcessor(element.getAttribute(ATT_CLASS));
+ String className = element.getAttribute(ATT_CLASS);
+ registry.remove(className);
return true;
}
}
diff --git a/plugins/org.eclipse.emf.compare.tests/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.compare.tests/META-INF/MANIFEST.MF index 1399506f8..ccf501267 100644 --- a/plugins/org.eclipse.emf.compare.tests/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.emf.compare.tests/META-INF/MANIFEST.MF @@ -24,6 +24,8 @@ Export-Package: org.eclipse.emf.compare.tests.framework, org.eclipse.emf.compare.tests.nodes, org.eclipse.emf.compare.tests.nodes.impl, org.eclipse.emf.compare.tests.nodes.util, + org.eclipse.emf.compare.tests.postprocess, + org.eclipse.emf.compare.tests.postprocess.data, org.eclipse.emf.compare.tests.suite Import-Package: com.google.common.base;version="[11.0.0,15.0.0)", com.google.common.cache;version="[11.0.0,15.0.0)", 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 7dd7531f7..2122c888f 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 @@ -13,14 +13,16 @@ 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.PostProcessorRegistryImpl;
+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;
@@ -53,11 +55,11 @@ public class PostProcessorTest { final Resource left = input.getLeft();
final Resource right = input.getRight();
- PostProcessorRegistryImpl registry = new PostProcessorRegistryImpl();
+ 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.addPostProcessor(new TestPostProcessor("http://www.eclipse.org/emf/compare/tests/nodes",
- null));
+ 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()
@@ -72,10 +74,11 @@ public class PostProcessorTest { final Resource left = input.getLeft();
final Resource right = input.getRight();
- PostProcessorRegistryImpl registry = new PostProcessorRegistryImpl();
+ 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.addPostProcessor(new TestPostProcessor(".*/nodes", null));
+ 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()
@@ -90,9 +93,10 @@ public class PostProcessorTest { final Resource left = input.getLeft();
final Resource right = input.getRight();
- PostProcessorRegistryImpl registry = new PostProcessorRegistryImpl();
+ PostProcessorDescriptorRegistryImpl registry = new PostProcessorDescriptorRegistryImpl();
// No post processes if the regex matches no scanned namespace URIs.
- registry.addPostProcessor(new TestPostProcessor(".*/nides", null));
+ 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()
@@ -107,9 +111,10 @@ public class PostProcessorTest { final Resource left = input.getLeft();
final Resource right = input.getRight();
- PostProcessorRegistryImpl registry = new PostProcessorRegistryImpl();
+ PostProcessorDescriptorRegistryImpl registry = new PostProcessorDescriptorRegistryImpl();
// No post processes if the regex matches no scanned namespace URIs (null value case)
- registry.addPostProcessor(new TestPostProcessor(null, null));
+ 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()
@@ -124,9 +129,10 @@ public class PostProcessorTest { final Resource left = input.getLeft();
final Resource right = input.getRight();
- PostProcessorRegistryImpl registry = new PostProcessorRegistryImpl();
+ PostProcessorDescriptorRegistryImpl registry = new PostProcessorDescriptorRegistryImpl();
// No post processes if the regex matches no scanned namespace URIs (empty value case)
- registry.addPostProcessor(new TestPostProcessor("", null));
+ 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()
@@ -141,9 +147,10 @@ public class PostProcessorTest { final Resource left = input.getLeft();
final Resource right = input.getRight();
- PostProcessorRegistryImpl registry = new PostProcessorRegistryImpl();
+ PostProcessorDescriptorRegistryImpl registry = new PostProcessorDescriptorRegistryImpl();
// No post processes if the regex matches no scanned namespace URIs (blank value case)
- registry.addPostProcessor(new TestPostProcessor(" ", null));
+ 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()
@@ -158,10 +165,11 @@ public class PostProcessorTest { final Resource left = input.getLeft();
final Resource right = input.getRight();
- PostProcessorRegistryImpl registry = new PostProcessorRegistryImpl();
+ 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.addPostProcessor(new TestPostProcessor(null, left.getURI().toString()));
+ 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()
@@ -176,10 +184,11 @@ public class PostProcessorTest { final Resource left = input.getLeft();
final Resource right = input.getRight();
- PostProcessorRegistryImpl registry = new PostProcessorRegistryImpl();
+ 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.addPostProcessor(new TestPostProcessor(null, ".*.nodes"));
+ 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()
@@ -194,9 +203,10 @@ public class PostProcessorTest { final Resource left = input.getLeft();
final Resource right = input.getRight();
- PostProcessorRegistryImpl registry = new PostProcessorRegistryImpl();
+ PostProcessorDescriptorRegistryImpl registry = new PostProcessorDescriptorRegistryImpl();
// No post processes if the regex matches no scanned resource URIs
- registry.addPostProcessor(new TestPostProcessor(null, ".*.nides"));
+ 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()
@@ -211,9 +221,10 @@ public class PostProcessorTest { final Resource left = input.getLeft();
final Resource right = input.getRight();
- PostProcessorRegistryImpl registry = new PostProcessorRegistryImpl();
+ PostProcessorDescriptorRegistryImpl registry = new PostProcessorDescriptorRegistryImpl();
// No post processes if the regex matches no scanned resource URIs (empty value)
- registry.addPostProcessor(new TestPostProcessor(null, ""));
+ 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()
@@ -228,9 +239,10 @@ public class PostProcessorTest { final Resource left = input.getLeft();
final Resource right = input.getRight();
- PostProcessorRegistryImpl registry = new PostProcessorRegistryImpl();
+ PostProcessorDescriptorRegistryImpl registry = new PostProcessorDescriptorRegistryImpl();
// No post processes if the regex matches no scanned resource URIs (blank value)
- registry.addPostProcessor(new TestPostProcessor(null, " "));
+ 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()
@@ -239,5 +251,4 @@ public class PostProcessorTest { assertSame(Integer.valueOf(1), Integer.valueOf(comparison.getMatches().size()));
}
-
}
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 0497b0659..46818489e 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 @@ -27,18 +27,6 @@ import org.eclipse.emf.compare.postprocessor.IPostProcessor; */
public class TestPostProcessor implements IPostProcessor {
- private Pattern nsURI;
-
- private Pattern resourceURI;
-
- /**
- *
- */
- public TestPostProcessor(String nsURI, String resourceURI) {
- this.nsURI = nsURI == null ? null : Pattern.compile(nsURI);
- this.resourceURI = resourceURI == null ? null : Pattern.compile(resourceURI);
- }
-
public void postMatch(Comparison comparison, Monitor monitor) {
final List<Match> matches = comparison.getMatches();
final Match lastMatch = matches.get(matches.size() - 1);
@@ -96,24 +84,6 @@ public class TestPostProcessor implements IPostProcessor { /**
* {@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#postComparison(org.eclipse.emf.compare.Comparison,
* org.eclipse.emf.common.util.Monitor)
*/
@@ -122,4 +92,56 @@ public class TestPostProcessor implements IPostProcessor { }
+ 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();
+ }
+
+ }
+
}
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 04e1bba85..b8997894f 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 @@ -31,9 +31,10 @@ 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.PostProcessorRegistryImpl;
+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;
@@ -67,9 +68,9 @@ public abstract class AbstractTest { @Before
public void before() {
- PostProcessorRegistryImpl registry = new PostProcessorRegistryImpl();
- registry.addPostProcessor(new UMLPostProcessor(Pattern
- .compile("http://www.eclipse.org/uml2/\\d\\.0\\.0/UML"), null));
+ 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();
}
diff --git a/plugins/org.eclipse.emf.compare.uml2/src/org/eclipse/emf/compare/uml2/internal/postprocessor/UMLPostProcessor.java b/plugins/org.eclipse.emf.compare.uml2/src/org/eclipse/emf/compare/uml2/internal/postprocessor/UMLPostProcessor.java index 2e18a33a5..e7dce814a 100644 --- a/plugins/org.eclipse.emf.compare.uml2/src/org/eclipse/emf/compare/uml2/internal/postprocessor/UMLPostProcessor.java +++ b/plugins/org.eclipse.emf.compare.uml2/src/org/eclipse/emf/compare/uml2/internal/postprocessor/UMLPostProcessor.java @@ -21,7 +21,6 @@ import java.util.HashSet; import java.util.Iterator;
import java.util.Map;
import java.util.Set;
-import java.util.regex.Pattern;
import org.eclipse.emf.common.util.Monitor;
import org.eclipse.emf.compare.Comparison;
@@ -30,7 +29,7 @@ import org.eclipse.emf.compare.DifferenceKind; import org.eclipse.emf.compare.DifferenceSource;
import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.ReferenceChange;
-import org.eclipse.emf.compare.postprocessor.AbstractPostProcessor;
+import org.eclipse.emf.compare.postprocessor.IPostProcessor;
import org.eclipse.emf.compare.uml2.internal.UMLDiff;
import org.eclipse.emf.compare.uml2.internal.postprocessor.extension.DiffExtensionFactoryRegistry;
import org.eclipse.emf.compare.uml2.internal.postprocessor.extension.IDiffExtensionFactory;
@@ -40,7 +39,7 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.uml2.common.util.SubsetSupersetEObjectEList;
-public class UMLPostProcessor extends AbstractPostProcessor {
+public class UMLPostProcessor implements IPostProcessor {
/** UML2 extensions factories. */
private Set<IDiffExtensionFactory> uml2ExtensionFactories;
@@ -72,18 +71,6 @@ public class UMLPostProcessor extends AbstractPostProcessor { */
private static final Field SUBSET_FEATURES_FIELD = getSubsetField();
- public UMLPostProcessor() {
- super(Pattern.compile("http://www.eclipse.org/uml2/\\d.\\d.\\d/UML"), null);
- }
-
- /**
- * @param nsURI
- * @param resourceURI
- */
- public UMLPostProcessor(Pattern nsURI, Pattern resourceURI) {
- super(nsURI, resourceURI);
- }
-
/**
* {@inheritDoc}
*
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/EMFCompare.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/EMFCompare.java index f3082f470..f0163a4cf 100644 --- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/EMFCompare.java +++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/EMFCompare.java @@ -27,7 +27,7 @@ import org.eclipse.emf.compare.equi.IEquiEngine; import org.eclipse.emf.compare.match.DefaultMatchEngine;
import org.eclipse.emf.compare.match.IMatchEngine;
import org.eclipse.emf.compare.postprocessor.IPostProcessor;
-import org.eclipse.emf.compare.postprocessor.PostProcessorRegistryImpl;
+import org.eclipse.emf.compare.postprocessor.PostProcessorDescriptorRegistryImpl;
import org.eclipse.emf.compare.req.DefaultReqEngine;
import org.eclipse.emf.compare.req.IReqEngine;
import org.eclipse.emf.compare.scope.DefaultComparisonScope;
@@ -66,7 +66,7 @@ public class EMFCompare { private final IConflictDetector conflictDetector;
/** The PostProcessorRegistry to use to find an IPostProcessor. */
- private final IPostProcessor.Registry postProcessorRegistry;
+ private final IPostProcessor.Descriptor.Registry<?> postProcessorDescriptorRegistry;
/**
* Creates a new EMFCompare object able to compare Notifier with the help of given engines.
@@ -81,18 +81,18 @@ public class EMFCompare { * IEquiEngine to use to compute comparison
* @param conflictDetector
* IConflictDetector to use to compute comparison
- * @param postProcessorRegistry
+ * @param postProcessorFactoryRegistry
* PostProcessorRegistry to use to find an IPostProcessor
*/
protected EMFCompare(IMatchEngine matchEngine, IDiffEngine diffEngine, IReqEngine reqEngine,
IEquiEngine equiEngine, IConflictDetector conflictDetector,
- IPostProcessor.Registry postProcessorRegistry) {
+ IPostProcessor.Descriptor.Registry<?> postProcessorFactoryRegistry) {
this.matchEngine = checkNotNull(matchEngine);
this.diffEngine = checkNotNull(diffEngine);
this.reqEngine = checkNotNull(reqEngine);
this.equiEngine = checkNotNull(equiEngine);
this.conflictDetector = conflictDetector;
- this.postProcessorRegistry = checkNotNull(postProcessorRegistry);
+ this.postProcessorDescriptorRegistry = checkNotNull(postProcessorFactoryRegistry);
}
/**
@@ -161,7 +161,7 @@ public class EMFCompare { final Comparison comparison = matchEngine.match(scope, monitor);
- List<IPostProcessor> postProcessors = postProcessorRegistry.getPostProcessors(scope);
+ List<IPostProcessor> postProcessors = postProcessorDescriptorRegistry.getPostProcessors(scope);
for (IPostProcessor iPostProcessor : postProcessors) {
iPostProcessor.postMatch(comparison, monitor);
@@ -232,7 +232,7 @@ public class EMFCompare { protected IConflictDetector conflictDetector;
/** The PostProcessorRegistry to use to find an IPostProcessor. */
- protected IPostProcessor.Registry registry;
+ protected IPostProcessor.Descriptor.Registry<?> registry;
/**
* Creates a new builder object.
@@ -307,7 +307,7 @@ public class EMFCompare { * the PostProcessor to be used to find the post processor of each comparison steps.
* @return this same builder to allow chained call.
*/
- public Builder setPostProcessorRegistry(IPostProcessor.Registry r) {
+ public Builder setPostProcessorRegistry(IPostProcessor.Descriptor.Registry<?> r) {
this.registry = checkNotNull(r);
return this;
}
@@ -331,7 +331,7 @@ public class EMFCompare { equiEngine = new DefaultEquiEngine();
}
if (registry == null) {
- registry = new PostProcessorRegistryImpl();
+ registry = new PostProcessorDescriptorRegistryImpl();
}
if (conflictDetector == null) {
conflictDetector = new DefaultConflictDetector();
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/postprocessor/AbstractPostProcessor.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/postprocessor/AbstractPostProcessor.java deleted file mode 100644 index c32d266b9..000000000 --- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/postprocessor/AbstractPostProcessor.java +++ /dev/null @@ -1,54 +0,0 @@ -/*******************************************************************************
- * 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 java.util.regex.Pattern;
-
-/**
- * Abstract implementation of a post processor. It handles nsURI and resourceURI patterns as final fields.
- *
- * @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a>
- */
-public abstract class AbstractPostProcessor implements IPostProcessor {
-
- /** Namespace URIs (regex) this processor applies to. */
- private final Pattern nsUri;
-
- /** Resource URIs (regex) this processor applies to. */
- private final Pattern resourceUri;
-
- /**
- * Constructor.
- */
- public AbstractPostProcessor(Pattern nsURI, Pattern resourceURI) {
- nsUri = nsURI;
- resourceUri = resourceURI;
- }
-
- /**
- * Returns the namespace URI.
- *
- * @return The namespace URI.
- */
- public Pattern getNsURI() {
- return nsUri;
- }
-
- /**
- * Returns the resource URI.
- *
- * @return The resource URI.
- */
- public Pattern getResourceURI() {
- return resourceUri;
- }
-
-}
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 545301572..aa977a336 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 @@ -99,81 +99,88 @@ public interface IPostProcessor { void postComparison(Comparison comparison, Monitor monitor);
/**
- * 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();
-
- /**
- * Registry of post processor.
+ * Wrapper describing the given post processor
*
* @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
*/
- public interface Registry {
-
- /**
- * Adds a post processor to the registry.
- *
- * @param postProcessor
- * Post Processor that is to be added to this registry.
- */
- IPostProcessor addPostProcessor(IPostProcessor postProcessor);
-
+ interface Descriptor {
/**
- * Removes all extensions from this registry.
+ * Returns the wrapped post processor
*
- * @noreference This method is not intended to be referenced by clients.
+ * @return the wrapped post processor
*/
- void clear();
+ IPostProcessor getPostProcessor();
/**
- * This will return a copy of the registered post processors list.
+ * Returns the pattern of namespace URI on which this post processor can be applied.
*
- * @return A copy of the registered post processors list.
+ * @return The namespace URI pattern.
*/
- ImmutableList<IPostProcessor> getPostProcessors();
+ Pattern getNsURI();
/**
- * Removes a post processor from this registry.
+ * Returns the pattern of resource URI on which this post processor can be applied.
*
- * @param postProcessorClassName
- * Qualified class name of the post processor 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>.
+ * @return The resource URI.
*/
- IPostProcessor removePostProcessor(String postProcessorClassName);
+ Pattern getResourceURI();
/**
- * 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.
+ * Returns the class name of the instance that will be returned by {@link #getPostProcessor()}.
*
- * @param scope
- * The given scope.
- * @return The associated post processors if any.
+ * @return
*/
- ImmutableList<IPostProcessor> getPostProcessors(IComparisonScope scope);
- }
+ String getInstanceClassName();
- /**
- * Wrapper describing the given post processor
- *
- * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
- */
- interface Descriptor extends IPostProcessor {
/**
- * Returns the wrapped post processor
+ * Registry of post processor.
*
- * @return the wrapped post processor
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
*/
- IPostProcessor getPostProcessor();
+ public interface Registry<K> {
+
+ /**
+ * Adds a post processor to the registry.
+ *
+ * @param descriptor
+ * Post Processor that is to be added to this registry.
+ */
+ 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 postProcessorFactoryClassName
+ * Qualified class name of the post processor 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);
+ }
}
}
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/postprocessor/PostProcessorRegistryImpl.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/postprocessor/PostProcessorDescriptorRegistryImpl.java index ca7731c37..5b96a4b2f 100644 --- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/postprocessor/PostProcessorRegistryImpl.java +++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/postprocessor/PostProcessorDescriptorRegistryImpl.java @@ -16,6 +16,7 @@ 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;
/**
@@ -23,83 +24,78 @@ import org.eclipse.emf.compare.scope.IComparisonScope; *
* @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a>
*/
-public class PostProcessorRegistryImpl implements IPostProcessor.Registry {
+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<String, IPostProcessor> postProcessors;
+ private final Map<K, IPostProcessor.Descriptor> postProcessorFactories;
/**
* Creates a new extension registry.
*/
- public PostProcessorRegistryImpl() {
- postProcessors = new ConcurrentHashMap<String, IPostProcessor>();
+ public PostProcessorDescriptorRegistryImpl() {
+ postProcessorFactories = new ConcurrentHashMap<K, IPostProcessor.Descriptor>();
}
/**
* {@inheritDoc}
*
- * @see org.eclipse.emf.compare.extension.Registry#addPostProcessor(org.eclipse.emf.compare.extension.PostProcessorDescriptor)
+ * @see org.eclipse.emf.compare.extension.Registry#clearRegistry()
*/
- public IPostProcessor addPostProcessor(IPostProcessor postProcessor) {
- if (postProcessor instanceof IPostProcessor.Descriptor) {
- return postProcessors.put(((IPostProcessor.Descriptor)postProcessor).getPostProcessor()
- .getClass().getName(), postProcessor);
- } else {
- return postProcessors.put(postProcessor.getClass().getName(), postProcessor);
- }
+ public void clear() {
+ postProcessorFactories.clear();
}
/**
* {@inheritDoc}
*
- * @see org.eclipse.emf.compare.extension.Registry#clearRegistry()
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor.Registry#put(java.lang.Object,
+ * org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor)
*/
- public void clear() {
- postProcessors.clear();
+ public Descriptor put(K key, Descriptor postProcessor) {
+ return postProcessorFactories.put(key, postProcessor);
}
/**
* {@inheritDoc}
*
- * @see org.eclipse.emf.compare.extension.Registry#getRegisteredPostProcessors()
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor.Registry#getDescriptors()
*/
- public ImmutableList<IPostProcessor> getPostProcessors() {
- return ImmutableList.copyOf(postProcessors.values());
+ public ImmutableList<Descriptor> getDescriptors() {
+ return ImmutableList.copyOf(postProcessorFactories.values());
}
/**
* {@inheritDoc}
*
- * @return
- * @see org.eclipse.emf.compare.extension.Registry#removePostProcessor(java.lang.String)
+ * @see org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor.Registry#remove(java.lang.Object)
*/
- public IPostProcessor removePostProcessor(String postProcessorClassName) {
- return postProcessors.remove(postProcessorClassName);
+ public Descriptor remove(K key) {
+ return postProcessorFactories.remove(key);
}
/**
* {@inheritDoc}
*
- * @see org.eclipse.emf.compare.extension.Registry#getPostProcessors(org.eclipse.emf.compare.scope.IComparisonScope)
+ * @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 postProcessor : getPostProcessors()) {
- Pattern nsURIPattern = postProcessor.getNsURI();
+ for (IPostProcessor.Descriptor factory : getDescriptors()) {
+ Pattern nsURIPattern = factory.getNsURI();
if (nsURIPattern != null) {
for (String nsURI : scope.getNsURIs()) {
if (nsURIPattern.matcher(nsURI).matches()) {
- processors.add(postProcessor);
+ processors.add(factory.getPostProcessor());
break;
}
}
}
// Should probably use two loops here to prioritize NsURI matching
- Pattern resourceURIPattern = postProcessor.getResourceURI();
+ Pattern resourceURIPattern = factory.getResourceURI();
if (resourceURIPattern != null) {
for (String resourceURI : scope.getResourceURIs()) {
if (resourceURIPattern.matcher(resourceURI).matches()) {
- processors.add(postProcessor);
+ processors.add(factory.getPostProcessor());
break;
}
}
|