Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Daussy2014-09-26 08:14:59 +0000
committerLaurent Goubet2014-10-14 07:28:57 +0000
commit68573aa05bb2d1ad30511030ba55fb99926f4a65 (patch)
tree3a8ed6928e308101bb245514a0631799946910a9
parent0cbed3380c41e8ae1a46f5c7ad201b946f48d1b8 (diff)
downloadorg.eclipse.emf.compare-68573aa05bb2d1ad30511030ba55fb99926f4a65.tar.gz
org.eclipse.emf.compare-68573aa05bb2d1ad30511030ba55fb99926f4a65.tar.xz
org.eclipse.emf.compare-68573aa05bb2d1ad30511030ba55fb99926f4a65.zip
Adds ResourceSetHook extension point.
This extension point aims to provide a way for external client to hook some behavior into the ResourceSet used by EMF Compare (for example register new factories). Change-Id: I9273648a9bcbca8da6e1a7dbb41870c94f20ac07
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/ComparisonScopeBuilder.java12
-rw-r--r--plugins/org.eclipse.emf.compare.ide/META-INF/MANIFEST.MF2
-rw-r--r--plugins/org.eclipse.emf.compare.ide/build.properties3
-rw-r--r--plugins/org.eclipse.emf.compare.ide/plugin.xml17
-rw-r--r--plugins/org.eclipse.emf.compare.ide/schema/resourceSetHook.exsd78
-rw-r--r--plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/EMFCompareIDEPlugin.java65
-rw-r--r--plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/hook/IResourceSetHook.java59
-rw-r--r--plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/internal/hook/ResourceSetHookDescriptor.java77
-rw-r--r--plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/internal/hook/ResourceSetHookRegistry.java79
-rw-r--r--plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/internal/hook/ResourceSetHookRegistryListener.java93
-rw-r--r--plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/internal/ide_messages.properties1
-rw-r--r--plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/internal/utils/NotLoadingResourceSet.java61
-rw-r--r--plugins/org.eclipse.emf.compare.uml2.ide.tests/src/org/eclipse/emf/compare/uml2/ide/tests/profile/ProfileLoadingTest.java2
13 files changed, 538 insertions, 11 deletions
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/ComparisonScopeBuilder.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/ComparisonScopeBuilder.java
index 1bbc37832..08ad057c8 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/ComparisonScopeBuilder.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/ComparisonScopeBuilder.java
@@ -35,6 +35,8 @@ import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.compare.DifferenceSource;
+import org.eclipse.emf.compare.ide.EMFCompareIDEPlugin;
+import org.eclipse.emf.compare.ide.internal.hook.ResourceSetHookRegistry;
import org.eclipse.emf.compare.ide.internal.utils.NotLoadingResourceSet;
import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIMessages;
import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin;
@@ -446,15 +448,19 @@ public final class ComparisonScopeBuilder {
final StorageTraversal originTraversal = syncModel.getOriginTraversal();
final ResourceSet originResourceSet;
+ ResourceSetHookRegistry resourceSetHookRegistry = EMFCompareIDEPlugin.getDefault()
+ .getResourceSetHookRegistry();
if (originTraversal == null || originTraversal.getStorages().isEmpty()) {
originResourceSet = null;
progress.setWorkRemaining(2);
} else {
- originResourceSet = NotLoadingResourceSet.create(originTraversal, progress.newChild(1));
+ originResourceSet = NotLoadingResourceSet.create(originTraversal, progress.newChild(1),
+ resourceSetHookRegistry);
}
- final ResourceSet leftResourceSet = NotLoadingResourceSet.create(leftTraversal, progress.newChild(1));
+ final ResourceSet leftResourceSet = NotLoadingResourceSet.create(leftTraversal, progress.newChild(1),
+ resourceSetHookRegistry);
final ResourceSet rightResourceSet = NotLoadingResourceSet.create(rightTraversal, progress
- .newChild(1));
+ .newChild(1), resourceSetHookRegistry);
final Set<URI> urisInScope = Sets.newLinkedHashSet();
for (IStorage left : leftTraversal.getStorages()) {
diff --git a/plugins/org.eclipse.emf.compare.ide/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.compare.ide/META-INF/MANIFEST.MF
index 76aed8e52..fd3a1c645 100644
--- a/plugins/org.eclipse.emf.compare.ide/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.compare.ide/META-INF/MANIFEST.MF
@@ -21,4 +21,6 @@ Import-Package: com.google.common.annotations;version="[11.0.0,16.0.0)",
com.google.common.util.concurrent;version="[11.0.0,16.0.0)"
Export-Package: org.eclipse.emf.compare.ide,
org.eclipse.emf.compare.ide.internal.utils;x-friends:="org.eclipse.emf.compare.ide.ui,org.eclipse.emf.compare.uml2.ide.tests",
+ org.eclipse.emf.compare.ide.internal.hook;x-friends:="org.eclipse.emf.compare.ide.ui",
+ org.eclipse.emf.compare.ide.hook,
org.eclipse.emf.compare.ide.utils
diff --git a/plugins/org.eclipse.emf.compare.ide/build.properties b/plugins/org.eclipse.emf.compare.ide/build.properties
index 86cda4414..e42969aea 100644
--- a/plugins/org.eclipse.emf.compare.ide/build.properties
+++ b/plugins/org.eclipse.emf.compare.ide/build.properties
@@ -3,5 +3,6 @@ output.. = bin/
bin.includes = META-INF/,\
plugin.properties,\
.,\
- about.html
+ about.html,\
+ plugin.xml
src.includes = about.html
diff --git a/plugins/org.eclipse.emf.compare.ide/plugin.xml b/plugins/org.eclipse.emf.compare.ide/plugin.xml
new file mode 100644
index 000000000..52622d754
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide/plugin.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+
+<!--
+ Copyright (c) 2014 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
+-->
+
+<plugin>
+ <extension-point id="resourceSetHook" name="Resource Set Hook" schema="schema/resourceSetHook.exsd"/>
+</plugin>
diff --git a/plugins/org.eclipse.emf.compare.ide/schema/resourceSetHook.exsd b/plugins/org.eclipse.emf.compare.ide/schema/resourceSetHook.exsd
new file mode 100644
index 000000000..23c42f8b9
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide/schema/resourceSetHook.exsd
@@ -0,0 +1,78 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.emf.compare.rcp" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.emf.compare.rcp" id="resourceSetHook" name="Resource Set Hook"/>
+ </appinfo>
+ <documentation>
+ The ResourceSet hook extension point aims to offer a mean to hook external behaviors on the EMF Compare resource set. A hook has access to the ResourceSet before loading any resource and after loading all the resources. Those hooks will worked only if the input of the comparison are not already loaded items (that is to say neither an EObject,a Resource or ResourceSet).
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence minOccurs="1" maxOccurs="unbounded">
+ <element ref="resourceSetHook"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="resourceSetHook">
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+ Implementation of the IResourceSetHook.
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.emf.compare.rcp.internal.hook.IResourceSetHook"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ 3.2.0
+ </documentation>
+ </annotation>
+
+
+
+
+
+</schema>
diff --git a/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/EMFCompareIDEPlugin.java b/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/EMFCompareIDEPlugin.java
index b06ae3da6..1a246afd0 100644
--- a/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/EMFCompareIDEPlugin.java
+++ b/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/EMFCompareIDEPlugin.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2013 Obeo.
+ * Copyright (c) 2011, 2014 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
@@ -10,9 +10,13 @@
*******************************************************************************/
package org.eclipse.emf.compare.ide;
+import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.compare.ide.internal.hook.ResourceSetHookRegistry;
+import org.eclipse.emf.compare.ide.internal.hook.ResourceSetHookRegistryListener;
import org.osgi.framework.BundleContext;
/**
@@ -27,6 +31,12 @@ public class EMFCompareIDEPlugin extends Plugin {
/** This plugin's shared instance. */
private static EMFCompareIDEPlugin plugin;
+ /** Registry of {@link org.eclipse.emf.compare.rcp.internal.hook.IResourceSetHook}. */
+ private ResourceSetHookRegistry resourceSetHookRegistry;
+
+ /** The registry listener that will fill the {@link ResourceSetHookRegistry}. */
+ private ResourceSetHookRegistryListener resourceSetHookRegistryListener;
+
/**
* {@inheritDoc}
*
@@ -37,6 +47,10 @@ public class EMFCompareIDEPlugin extends Plugin {
plugin = this;
super.start(context);
+ final IExtensionRegistry registry = Platform.getExtensionRegistry();
+
+ setUpResourceSetHookRegistry(registry);
+
}
/**
@@ -47,6 +61,11 @@ public class EMFCompareIDEPlugin extends Plugin {
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
+
+ final IExtensionRegistry registry = Platform.getExtensionRegistry();
+
+ discardResourceSetHookRegistry(registry);
+
super.stop(context);
}
@@ -80,4 +99,48 @@ public class EMFCompareIDEPlugin extends Plugin {
public static EMFCompareIDEPlugin getDefault() {
return plugin;
}
+
+ /**
+ * Returns the {@link ResourceSetHookRegistry}.
+ * <p>
+ * It contains all hooks registered against the ResourceSetHook extension point.
+ * </p>
+ *
+ * @return {@link ResourceSetHookRegistry}.
+ * @since 3.1
+ */
+ public ResourceSetHookRegistry getResourceSetHookRegistry() {
+ return resourceSetHookRegistry;
+ }
+
+ /**
+ * Sets up the {@link ResourceSetHookRegistry}.
+ *
+ * @param registry
+ * {@link IExtensionRegistry} to listen in order to fill the registry
+ */
+ private void setUpResourceSetHookRegistry(IExtensionRegistry registry) {
+ // Sets up the resource set hook registry
+ resourceSetHookRegistry = new ResourceSetHookRegistry();
+ resourceSetHookRegistryListener = new ResourceSetHookRegistryListener(getLog(),
+ resourceSetHookRegistry);
+ registry.addListener(resourceSetHookRegistryListener, PLUGIN_ID + '.'
+ + ResourceSetHookRegistryListener.EXT_ID);
+ resourceSetHookRegistryListener.readRegistry(registry);
+
+ }
+
+ /**
+ * Discards the resource set hook registry.
+ *
+ * @param registry
+ * IExtensionRegistry to remove listener
+ */
+ private void discardResourceSetHookRegistry(IExtensionRegistry registry) {
+ // Unregisters the resource set hook registry
+ registry.removeListener(resourceSetHookRegistryListener);
+ resourceSetHookRegistryListener = null;
+ resourceSetHookRegistry = null;
+ }
+
}
diff --git a/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/hook/IResourceSetHook.java b/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/hook/IResourceSetHook.java
new file mode 100644
index 000000000..6a4d7c930
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/hook/IResourceSetHook.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2014 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.ide.hook;
+
+import java.util.Collection;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+
+/**
+ * Interface used to hook some behavior into the {@link ResourceSet} used by EMF Compare when using logical
+ * model.
+ *
+ * @author <a href="mailto:arthur.daussy@obeo.fr">Arthur Daussy</a>
+ */
+public interface IResourceSetHook {
+
+ /**
+ * Returns true if this hook should be used.
+ *
+ * @param uris
+ * list of {@link URI}s about to be loaded in the {@link ResourceSet}.
+ * @return <code>true</code> if this hook should be used, <code>false</code> otherwise.
+ */
+ boolean isHookFor(Collection<? extends URI> uris);
+
+ /**
+ * This will be called before the final resource set is populated, in unspecified order. Resource set
+ * hooks can load resource in this resource set and thus an individual hook is not guaranteed to be
+ * provided an empty resource set here.
+ *
+ * @param resourceSet
+ * about to be filled.
+ * @param uris
+ * {@link URI}s that the resource set has been requested to load. The {@link Collection} of
+ * {@link URI} is not modifiable.
+ */
+ void preLoadingHook(ResourceSet resourceSet, Collection<? extends URI> uris);
+
+ /**
+ * This will be called after the resource set is populated in an unspecified order.
+ *
+ * @param resourceSet
+ * that has been filled with {@link org.eclipse.emf.ecore.resource.Resource}s.
+ * @param uris
+ * {@link URI}s that the resource set has been requested to load.The {@link Collection} of
+ * {@link URI} is not modifiable.
+ */
+ void postLoadingHook(ResourceSet resourceSet, Collection<? extends URI> uris);
+
+}
diff --git a/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/internal/hook/ResourceSetHookDescriptor.java b/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/internal/hook/ResourceSetHookDescriptor.java
new file mode 100644
index 000000000..8a4980d62
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/internal/hook/ResourceSetHookDescriptor.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2014 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.ide.internal.hook;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.compare.ide.hook.IResourceSetHook;
+import org.eclipse.emf.compare.ide.internal.EMFCompareIDEMessages;
+import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin;
+
+/**
+ * Descriptor of {@link IResourceSetHook}.
+ * <p>
+ * It prevents greedy instantiation of {@link IResourceSetHook} if not needed
+ * </p>
+ *
+ * @author <a href="mailto:arthur.daussy@obeo.fr">Arthur Daussy</a>
+ */
+class ResourceSetHookDescriptor {
+
+ /**
+ * {@link IConfigurationElement} used to instantiate the hook.
+ */
+ private final IConfigurationElement element;
+
+ /**
+ * Prevents logging several time the same error.
+ */
+ private boolean error;
+
+ /**
+ * Constructor.
+ *
+ * @param element
+ * {@link #element}
+ */
+ public ResourceSetHookDescriptor(IConfigurationElement element) {
+ super();
+ this.element = element;
+ }
+
+ /**
+ * Lazy instantiation of the hook.
+ *
+ * @return a {@link IResourceSetHook} instance or <code>null</code> is something went wrong during the
+ * instantiation.
+ */
+ public IResourceSetHook getHook() {
+ // Prevents creating a new object if we know that it can not be created.
+ if (!error) {
+ try {
+ return (IResourceSetHook)element
+ .createExecutableExtension(ResourceSetHookRegistryListener.CLASS_ATTR);
+ } catch (CoreException e) {
+ error = true;
+ String contributorName = element.getDeclaringExtension().getContributor().getName();
+ String message = EMFCompareIDEMessages.getString(
+ "ResourceSetHookRegistry.hookInstanceError", contributorName); //$NON-NLS-1$
+ final IStatus status = new Status(IStatus.ERROR, contributorName, message
+ + element.getDeclaringExtension().getContributor().getName(), e);
+ EMFCompareRCPPlugin.getDefault().getLog().log(status);
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/internal/hook/ResourceSetHookRegistry.java b/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/internal/hook/ResourceSetHookRegistry.java
new file mode 100644
index 000000000..f303f17c9
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/internal/hook/ResourceSetHookRegistry.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2014 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.ide.internal.hook;
+
+import com.google.common.base.Function;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.eclipse.emf.compare.ide.hook.IResourceSetHook;
+
+/**
+ * Resgistry of {@link IResourceSetHook}.
+ *
+ * @author <a href="mailto:arthur.daussy@obeo.fr">Arthur Daussy</a>
+ */
+public class ResourceSetHookRegistry {
+
+ /**
+ * Transforms a {@link ResourceSetHookDescriptor} into a {@link IResourceSetHook}.
+ */
+ private static final Function<ResourceSetHookDescriptor, IResourceSetHook> TO_HOOK = new Function<ResourceSetHookDescriptor, IResourceSetHook>() {
+
+ public IResourceSetHook apply(ResourceSetHookDescriptor input) {
+ return input.getHook();
+ }
+ };
+
+ /**
+ * Registry of {@link IResourceSetHook}.
+ */
+ private final Map<String, ResourceSetHookDescriptor> registry = new ConcurrentHashMap<String, ResourceSetHookDescriptor>();
+
+ /**
+ * Gets the registered {@link IResourceSetHook}s.
+ *
+ * @return unmodifiable {@link Collection} of {@link IResourceSetHook}.
+ */
+ public Collection<IResourceSetHook> getResourceSetHooks() {
+ return Collections.unmodifiableCollection(Collections2.filter(Collections2.transform(registry
+ .values(), TO_HOOK), Predicates.notNull()));
+ }
+
+ /**
+ * Adds a new {@link ResourceSetHookDescriptor}.
+ *
+ * @param id
+ * of the descriptor.
+ * @param resourceSetHookDescriptor
+ * {@link ResourceSetHookDescriptor}.
+ */
+ void add(String id, ResourceSetHookDescriptor resourceSetHookDescriptor) {
+ registry.put(id, resourceSetHookDescriptor);
+ }
+
+ /**
+ * Removes the {@link ResourceSetHookDescriptor} that was registered against this id.
+ *
+ * @param id
+ * of the descriptor to remove.
+ * @return <code>true</code> if te descriptor as been removed, <code>false</code> otherwise.
+ */
+ boolean remove(String id) {
+ return registry.remove(id) != null;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/internal/hook/ResourceSetHookRegistryListener.java b/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/internal/hook/ResourceSetHookRegistryListener.java
new file mode 100644
index 000000000..1b5ef8cec
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/internal/hook/ResourceSetHookRegistryListener.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2014 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.ide.internal.hook;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.ILog;
+import org.eclipse.emf.compare.ide.EMFCompareIDEPlugin;
+import org.eclipse.emf.compare.rcp.extension.AbstractRegistryEventListener;
+
+/**
+ * Listener that fill a {@link ResourceSetHookRegistry}.
+ *
+ * @author <a href="mailto:arthur.daussy@obeo.fr">Arthur Daussy</a>
+ */
+public class ResourceSetHookRegistryListener extends AbstractRegistryEventListener {
+
+ /**
+ * Extension point id.
+ */
+ public static final String EXT_ID = "resourceSetHook"; //$NON-NLS-1$
+
+ /**
+ * Attribute referencing the implementation class of the
+ * {@link org.eclipse.emf.compare.ide.hook.IResourceSetHook}.
+ */
+ static final String CLASS_ATTR = "class"; //$NON-NLS-1$
+
+ /**
+ * {@link ResourceSetHookRegistry}.
+ */
+ private final ResourceSetHookRegistry registry;
+
+ /**
+ * Constructor.
+ *
+ * @param log
+ * {@link ILog}.
+ * @param registry
+ * Registry to fill.
+ */
+ public ResourceSetHookRegistryListener(ILog log, ResourceSetHookRegistry registry) {
+ super(EMFCompareIDEPlugin.PLUGIN_ID, ResourceSetHookRegistryListener.EXT_ID, 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) {
+ if (element.getAttribute(CLASS_ATTR) == null) {
+ logMissingAttribute(element, CLASS_ATTR);
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.extension.AbstractRegistryEventListener#addedValid(org.eclipse.core.runtime.IConfigurationElement)
+ */
+ @Override
+ protected boolean addedValid(IConfigurationElement element) {
+ registry.add(element.getAttribute(CLASS_ATTR), new ResourceSetHookDescriptor(element));
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.extension.AbstractRegistryEventListener#removedValid(org.eclipse.core.runtime.IConfigurationElement)
+ */
+ @Override
+ protected boolean removedValid(IConfigurationElement element) {
+ String key = element.getAttribute(CLASS_ATTR);
+ if (key != null) {
+ return registry.remove(key);
+ }
+ return false;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/internal/ide_messages.properties b/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/internal/ide_messages.properties
index ae9299e02..d9dd35af7 100644
--- a/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/internal/ide_messages.properties
+++ b/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/internal/ide_messages.properties
@@ -13,3 +13,4 @@ NotLoadingResourceSet.monitor.resolve = Create and resolve resource set
StorageResourceWrapper.failToLoad = Unable to load the resource with the uri {0} from the storage {1}
+ResourceSetHookRegistry.hookInstanceError = Unable to instantiate hook from {0}
diff --git a/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/internal/utils/NotLoadingResourceSet.java b/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/internal/utils/NotLoadingResourceSet.java
index 4d3d08eb7..36907e987 100644
--- a/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/internal/utils/NotLoadingResourceSet.java
+++ b/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/internal/utils/NotLoadingResourceSet.java
@@ -10,15 +10,20 @@
*******************************************************************************/
package org.eclipse.emf.compare.ide.internal.utils;
+import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Lists.newArrayList;
import static org.eclipse.emf.compare.ide.utils.ResourceUtil.createURIFor;
import com.google.common.annotations.Beta;
import com.google.common.base.Function;
-import com.google.common.collect.Iterables;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.ImmutableList;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -36,7 +41,9 @@ import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.emf.compare.ide.EMFCompareIDEPlugin;
+import org.eclipse.emf.compare.ide.hook.IResourceSetHook;
import org.eclipse.emf.compare.ide.internal.EMFCompareIDEMessages;
+import org.eclipse.emf.compare.ide.internal.hook.ResourceSetHookRegistry;
import org.eclipse.emf.compare.ide.utils.StorageTraversal;
import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin;
import org.eclipse.emf.compare.rcp.policy.ILoadOnDemandPolicy;
@@ -94,21 +101,35 @@ public final class NotLoadingResourceSet extends ResourceSetImpl {
* All traversals we are to load.
* @param monitor
* the monitor to which progress will be reported.
+ * @param resourceSetHookRegistry
+ * A registry of {@link IResourceSetHook}s that potentialy can hook on the new
+ * {@link org.eclipse.emf.ecore.resource.ResourceSet} (can be <code>null</code> if none).
* @return resource set containing the resources described by the given traversals.
*/
- public static NotLoadingResourceSet create(final StorageTraversal traversals, IProgressMonitor monitor) {
+ public static NotLoadingResourceSet create(final StorageTraversal traversals, IProgressMonitor monitor,
+ ResourceSetHookRegistry resourceSetHookRegistry) {
SubMonitor progress = SubMonitor.convert(monitor, 100);
progress.subTask(EMFCompareIDEMessages.getString("NotLoadingResourceSet.monitor.resolve")); //$NON-NLS-1$
final NotLoadingResourceSet resourceSet = new NotLoadingResourceSet(traversals);
- resourceSet.setURIResourceMap(new HashMap<URI, Resource>(traversals.getStorages().size() << 1));
final Set<? extends IStorage> storages = traversals.getStorages();
+ resourceSet.setURIResourceMap(new HashMap<URI, Resource>(storages.size() << 1));
+
+ final Collection<URI> urisToLoad = ImmutableList.copyOf(transform(storages, TO_URI));
+
+ final Collection<IResourceSetHook> hooks = getMatchingHooks(resourceSetHookRegistry, urisToLoad);
+
+ for (IResourceSetHook hook : hooks) {
+ hook.preLoadingHook(resourceSet, urisToLoad);
+ }
+
// loading is 60% of the total work?
final int loadWorkPercentage = 60;
SubMonitor subMonitor = progress.newChild(loadWorkPercentage).setWorkRemaining(
traversals.getStorages().size());
- for (URI uri : Iterables.transform(storages, TO_URI)) {
+
+ for (URI uri : urisToLoad) {
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
@@ -117,6 +138,10 @@ public final class NotLoadingResourceSet extends ResourceSetImpl {
subMonitor.worked(1);
}
+ for (IResourceSetHook hook : hooks) {
+ hook.postLoadingHook(resourceSet, urisToLoad);
+ }
+
final int resolveWorkPercentage = 40;
subMonitor = progress.newChild(resolveWorkPercentage).setWorkRemaining(
resourceSet.getResources().size());
@@ -135,7 +160,33 @@ public final class NotLoadingResourceSet extends ResourceSetImpl {
}
/**
- * {@inheritDoc}
+ * Retrieves the hooks that need to be hooked on this resource set.
+ *
+ * @param resourceSetHookRegistry
+ * Registry holding the hooks.
+ * @param urisToLoad
+ * The collection of uris that will be loaded.
+ * @return {@link Collection} of {@link IResourceSetHook}s that need to be hocked.
+ */
+ private static Collection<IResourceSetHook> getMatchingHooks(
+ ResourceSetHookRegistry resourceSetHookRegistry, final Collection<URI> urisToLoad) {
+ final Collection<IResourceSetHook> hooks;
+ if (resourceSetHookRegistry == null) {
+ hooks = Collections.emptyList();
+ } else {
+ hooks = Collections2.filter(resourceSetHookRegistry.getResourceSetHooks(),
+ new Predicate<IResourceSetHook>() {
+
+ public boolean apply(IResourceSetHook input) {
+ return input.isHookFor(urisToLoad);
+ }
+ });
+ }
+ return hooks;
+ }
+
+ /**
+ * Adds ResourceSetHook extension point. {@inheritDoc}
*
* @see org.eclipse.emf.ecore.resource.impl.ResourceSetImpl#demandLoadHelper(org.eclipse.emf.ecore.resource.Resource)
*/
diff --git a/plugins/org.eclipse.emf.compare.uml2.ide.tests/src/org/eclipse/emf/compare/uml2/ide/tests/profile/ProfileLoadingTest.java b/plugins/org.eclipse.emf.compare.uml2.ide.tests/src/org/eclipse/emf/compare/uml2/ide/tests/profile/ProfileLoadingTest.java
index 438a39548..42782b2b5 100644
--- a/plugins/org.eclipse.emf.compare.uml2.ide.tests/src/org/eclipse/emf/compare/uml2/ide/tests/profile/ProfileLoadingTest.java
+++ b/plugins/org.eclipse.emf.compare.uml2.ide.tests/src/org/eclipse/emf/compare/uml2/ide/tests/profile/ProfileLoadingTest.java
@@ -260,7 +260,7 @@ public class ProfileLoadingTest {
toStorage(new ExtensibleURIConverterImpl()));
StorageTraversal storageTraversal = new StorageTraversal(Sets.newHashSet(storages));
NotLoadingResourceSet newResourceSet = NotLoadingResourceSet.create(storageTraversal,
- new NullProgressMonitor());
+ new NullProgressMonitor(), null);
return newResourceSet;

Back to the top