Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlgoubet2011-05-11 15:30:20 +0000
committerlgoubet2011-05-11 15:30:20 +0000
commit3abfc343525840dbc5cca4086c1e81036d39bf8c (patch)
tree61860753b2efd019657f9d46ebc9e89811f1153e
parent312dab6231ca8e7d68b5ca6b70d266afa992a491 (diff)
downloadorg.eclipse.emf.compare-3abfc343525840dbc5cca4086c1e81036d39bf8c.tar.gz
org.eclipse.emf.compare-3abfc343525840dbc5cca4086c1e81036d39bf8c.tar.xz
org.eclipse.emf.compare-3abfc343525840dbc5cca4086c1e81036d39bf8c.zip
Make sure than EMF Compare uses the ModelProvider when called from the
synchronize view [345415] needs to be fixed in order to remove a workaround commited with this.
-rw-r--r--plugins/org.eclipse.emf.compare.logical/META-INF/MANIFEST.MF2
-rw-r--r--plugins/org.eclipse.emf.compare.logical/plugin.xml2
-rw-r--r--plugins/org.eclipse.emf.compare.logical/src/org/eclipse/emf/compare/logical/adapter/EMFCompareAdapterFactory.java20
-rw-r--r--plugins/org.eclipse.emf.compare.logical/src/org/eclipse/emf/compare/logical/model/EMFResourceMapping.java9
-rw-r--r--plugins/org.eclipse.emf.compare.logical/src/org/eclipse/emf/compare/logical/synchronization/EMFModelDelta.java10
-rw-r--r--plugins/org.eclipse.emf.compare.ui/src/org/eclipse/emf/compare/ui/internal/ModelComparator.java80
6 files changed, 111 insertions, 12 deletions
diff --git a/plugins/org.eclipse.emf.compare.logical/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.compare.logical/META-INF/MANIFEST.MF
index 66466b0fb..8ed3d3c27 100644
--- a/plugins/org.eclipse.emf.compare.logical/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.compare.logical/META-INF/MANIFEST.MF
@@ -10,8 +10,6 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.expressions;bundle-version="3.4.200",
org.eclipse.emf.compare;bundle-version="1.2.0",
org.eclipse.team.ui;bundle-version="3.5.200",
- org.eclipse.ui.workbench;bundle-version="3.7.0",
- org.eclipse.jface;bundle-version="3.7.0",
org.eclipse.compare;bundle-version="3.5.200",
org.eclipse.team.core;bundle-version="3.6.0",
org.eclipse.ui.navigator;bundle-version="3.5.0",
diff --git a/plugins/org.eclipse.emf.compare.logical/plugin.xml b/plugins/org.eclipse.emf.compare.logical/plugin.xml
index 1ea5c96fe..5105d7003 100644
--- a/plugins/org.eclipse.emf.compare.logical/plugin.xml
+++ b/plugins/org.eclipse.emf.compare.logical/plugin.xml
@@ -50,7 +50,7 @@
<adapter
type="org.eclipse.team.ui.mapping.ISynchronizationCompareAdapter">
</adapter>
- </factory>
+ </factory>
<!--FIXME Remove this factory once tested : this will have to be configured per project on their elements.-->
<factory
adaptableType="org.eclipse.emf.ecore.EObject"
diff --git a/plugins/org.eclipse.emf.compare.logical/src/org/eclipse/emf/compare/logical/adapter/EMFCompareAdapterFactory.java b/plugins/org.eclipse.emf.compare.logical/src/org/eclipse/emf/compare/logical/adapter/EMFCompareAdapterFactory.java
index 7fbf39228..fba6e7e8c 100644
--- a/plugins/org.eclipse.emf.compare.logical/src/org/eclipse/emf/compare/logical/adapter/EMFCompareAdapterFactory.java
+++ b/plugins/org.eclipse.emf.compare.logical/src/org/eclipse/emf/compare/logical/adapter/EMFCompareAdapterFactory.java
@@ -20,6 +20,7 @@ import org.eclipse.emf.compare.logical.model.EMFResourceMapping;
import org.eclipse.emf.compare.logical.synchronization.EMFCompareAdapter;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.team.ui.mapping.ISynchronizationCompareAdapter;
/**
@@ -46,6 +47,8 @@ public class EMFCompareAdapterFactory implements IAdapterFactory {
adapter = createResourceMapping((EObject)adaptableObject);
} else if (adaptableObject instanceof Resource) {
adapter = createResourceMapping((Resource)adaptableObject);
+ } else if (adaptableObject instanceof IFile) {
+ adapter = createResourceMapping((IFile)adaptableObject);
}
}
return adapter;
@@ -90,4 +93,21 @@ public class EMFCompareAdapterFactory implements IAdapterFactory {
}
return null;
}
+
+ /**
+ * This will try and create a resource mapping for the given IFile.
+ *
+ * @param iFile
+ * The IFile for which we need a resource mapping.
+ * @return The resource mapping if it could be created, <code>null</code> otherwise.
+ */
+ private ResourceMapping createResourceMapping(IFile iFile) {
+ if (iFile.exists() && iFile.isAccessible()) {
+ Resource eResource = EMFResourceUtil.getResource(iFile, new ResourceSetImpl());
+ if (eResource != null) {
+ return new EMFResourceMapping(iFile, eResource, EMFModelProvider.PROVIDER_ID);
+ }
+ }
+ return null;
+ }
}
diff --git a/plugins/org.eclipse.emf.compare.logical/src/org/eclipse/emf/compare/logical/model/EMFResourceMapping.java b/plugins/org.eclipse.emf.compare.logical/src/org/eclipse/emf/compare/logical/model/EMFResourceMapping.java
index b733f4953..e3e7c02ab 100644
--- a/plugins/org.eclipse.emf.compare.logical/src/org/eclipse/emf/compare/logical/model/EMFResourceMapping.java
+++ b/plugins/org.eclipse.emf.compare.logical/src/org/eclipse/emf/compare/logical/model/EMFResourceMapping.java
@@ -177,8 +177,13 @@ public class EMFResourceMapping extends ResourceMapping {
}
}
- EcoreUtil.resolveAll(remoteResourceSet);
- EcoreUtil.resolveAll(ancestorResourceSet);
+ // There is a chance that the resource did not exist on the repository
+ if (remoteResourceSet != null) {
+ EcoreUtil.resolveAll(remoteResourceSet);
+ }
+ if (ancestorResourceSet != null) {
+ EcoreUtil.resolveAll(ancestorResourceSet);
+ }
}
resolvePhysicalResources();
diff --git a/plugins/org.eclipse.emf.compare.logical/src/org/eclipse/emf/compare/logical/synchronization/EMFModelDelta.java b/plugins/org.eclipse.emf.compare.logical/src/org/eclipse/emf/compare/logical/synchronization/EMFModelDelta.java
index db5312db7..4b694228d 100644
--- a/plugins/org.eclipse.emf.compare.logical/src/org/eclipse/emf/compare/logical/synchronization/EMFModelDelta.java
+++ b/plugins/org.eclipse.emf.compare.logical/src/org/eclipse/emf/compare/logical/synchronization/EMFModelDelta.java
@@ -261,9 +261,13 @@ public class EMFModelDelta extends EMFDelta {
ResourceMapping[] mappings = context.getScope().getMappings();
for (ResourceMapping mapping : mappings) {
if (modelProviderId.equals(mapping.getModelProviderId()) && mapping instanceof EMFResourceMapping) {
- localResourceSet = ((EMFResourceMapping)mapping).getLocalResourceSet();
- remoteResourceSet = ((EMFResourceMapping)mapping).getRemoteResourceSet();
- ancestorResourceSet = ((EMFResourceMapping)mapping).getAncestorResourceSet();
+ EMFResourceMapping emfMapping = (EMFResourceMapping)mapping;
+ if (emfMapping.getLocalResourceSet() != null && emfMapping.getRemoteResourceSet() != null
+ && emfMapping.getAncestorResourceSet() != null) {
+ localResourceSet = emfMapping.getLocalResourceSet();
+ remoteResourceSet = emfMapping.getRemoteResourceSet();
+ ancestorResourceSet = emfMapping.getAncestorResourceSet();
+ }
}
}
diff --git a/plugins/org.eclipse.emf.compare.ui/src/org/eclipse/emf/compare/ui/internal/ModelComparator.java b/plugins/org.eclipse.emf.compare.ui/src/org/eclipse/emf/compare/ui/internal/ModelComparator.java
index dd74a0c39..7a73c3e13 100644
--- a/plugins/org.eclipse.emf.compare.ui/src/org/eclipse/emf/compare/ui/internal/ModelComparator.java
+++ b/plugins/org.eclipse.emf.compare.ui/src/org/eclipse/emf/compare/ui/internal/ModelComparator.java
@@ -11,6 +11,7 @@
package org.eclipse.emf.compare.ui.internal;
import java.io.IOException;
+import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.Calendar;
import java.util.Date;
@@ -24,10 +25,14 @@ import java.util.Set;
import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.CompareEditorInput;
import org.eclipse.compare.CompareUI;
+import org.eclipse.compare.IResourceProvider;
import org.eclipse.compare.IStreamContentAccessor;
import org.eclipse.compare.ITypedElement;
import org.eclipse.compare.ResourceNode;
import org.eclipse.compare.structuremergeviewer.ICompareInput;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.mapping.IModelProviderDescriptor;
+import org.eclipse.core.resources.mapping.ModelProvider;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
@@ -54,6 +59,7 @@ import org.eclipse.emf.compare.match.service.MatchService;
import org.eclipse.emf.compare.ui.EMFCompareUIMessages;
import org.eclipse.emf.compare.ui.EMFCompareUIPlugin;
import org.eclipse.emf.compare.ui.ICompareInputDetailsProvider;
+import org.eclipse.emf.compare.ui.ModelCompareInput;
import org.eclipse.emf.compare.ui.team.AbstractTeamHandler;
import org.eclipse.emf.compare.ui.util.EMFCompareConstants;
import org.eclipse.emf.compare.util.EMFCompareMap;
@@ -69,6 +75,8 @@ import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.team.core.mapping.ISynchronizationContext;
+import org.eclipse.team.ui.mapping.ISynchronizationCompareAdapter;
import org.eclipse.ui.PlatformUI;
/**
@@ -210,8 +218,8 @@ public final class ModelComparator implements ICompareInputDetailsProvider {
* This will parse {@link #TEAM_HANDLERS_EXTENSION_POINT} for team handlers.
*/
private static void parseExtensionMetaData() {
- final IExtension[] extensions = Platform.getExtensionRegistry().getExtensionPoint(
- TEAM_HANDLERS_EXTENSION_POINT).getExtensions();
+ final IExtension[] extensions = Platform.getExtensionRegistry()
+ .getExtensionPoint(TEAM_HANDLERS_EXTENSION_POINT).getExtensions();
// The RevisionComparisonHandler will be added last in the registry to allow clients override
TeamHandlerDescriptor revisionHandler = null;
for (final IExtension extension : extensions) {
@@ -265,8 +273,8 @@ public final class ModelComparator implements ICompareInputDetailsProvider {
configuration.setLeftEditable(configuration.isLeftEditable() && !isLeftRemote());
configuration.setRightEditable(configuration.isRightEditable() && !isRightRemote());
- configuration.setProperty(EMFCompareConstants.PROPERTY_COMPARISON_TIME, end.getTime()
- - start.getTime());
+ configuration.setProperty(EMFCompareConstants.PROPERTY_COMPARISON_TIME,
+ end.getTime() - start.getTime());
if (isLeftRemote()) {
if (doResourceMatchOnly) {
configuration.setLeftLabel(EMFCompareUIMessages.getString(EMFCompareUIMessages
@@ -472,6 +480,12 @@ public final class ModelComparator implements ICompareInputDetailsProvider {
rightElement = input.getRight();
ancestorElement = input.getAncestor();
+ // check whether this comparison hasn't already been played (workaround for #345415)
+ if (handleResourceMapping(input)) {
+ loadingSucceeded = true;
+ return loadingSucceeded;
+ }
+
try {
// This will be sufficient when comparing local resources
loadingSucceeded = handleLocalResources(leftElement, rightElement, ancestorElement);
@@ -531,6 +545,64 @@ public final class ModelComparator implements ICompareInputDetailsProvider {
}
/**
+ * This is a workaround for bug 345415 and needs to be removed ASAP when this bug is fixed. Basically,
+ * Platform/Compare does not call our ModelProvider when using the action
+ * "right-click > Open In Compare Editor". We then do the work ourselves here... but with insufficient
+ * information. We'll need to access non-API fields along the way.
+ *
+ * @param input
+ * The input we've been fed by Platform/Compare.
+ * @return <code>true</code> if we managed to find a ResourceMapping with a {@link ModelCompareInput}
+ * corresponding to <em>input</em>, <code>false</code> otherwise.
+ */
+ private boolean handleResourceMapping(ICompareInput input) {
+ final IResourceProvider resourceProvider = (IResourceProvider)Platform.getAdapterManager()
+ .getAdapter(leftElement, IResourceProvider.class);
+ if (resourceProvider != null) {
+ final IResource localResource = resourceProvider.getResource();
+ final IModelProviderDescriptor[] descriptors = ModelProvider.getModelProviderDescriptors();
+ for (int i = 0; i < descriptors.length; i++) {
+ final IModelProviderDescriptor descriptor = descriptors[i];
+ try {
+ final IResource[] resources = descriptor
+ .getMatchingResources(new IResource[] {localResource, });
+ if (resources.length > 0) {
+ final ModelProvider modelProvider = descriptor.getModelProvider();
+ final ISynchronizationCompareAdapter compareAdapter = (ISynchronizationCompareAdapter)Platform
+ .getAdapterManager().getAdapter(modelProvider,
+ ISynchronizationCompareAdapter.class);
+ // FIXME until 345415 is fixed, we need to find the proper model provider from here...
+ // ... which requires non-API things.
+ final Field contextField = input.getClass().getDeclaredField("context"); //$NON-NLS-1$
+ contextField.setAccessible(true);
+ final ISynchronizationContext context = (ISynchronizationContext)contextField
+ .get(input);
+ final ICompareInput actualInput = compareAdapter.asCompareInput(context,
+ localResource);
+
+ if (actualInput instanceof ModelCompareInput) {
+ comparisonResult = ((ModelCompareInput)actualInput).getComparisonSnapshot();
+ return true;
+ }
+ }
+ } catch (CoreException e) {
+ // FIXME log
+ } catch (SecurityException e) {
+ // FIXME remove when 345415 is fixed
+ } catch (NoSuchFieldException e) {
+ // FIXME remove when 345415 is fixed
+ } catch (IllegalArgumentException e) {
+ // FIXME remove when 345415 is fixed
+ } catch (IllegalAccessException e) {
+ // FIXME remove when 345415 is fixed
+ }
+ }
+ }
+
+ return false;
+ }
+
+ /**
* We might want to create an editor for an already compared configuration. This enables us to do so.
*
* @param snapshot

Back to the top