Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Goubet2013-06-20 10:33:57 -0400
committerGerrit Code Review @ Eclipse.org2013-06-21 07:29:01 -0400
commite8c43e5d86be0e8b40b0b89b9f09f7442f0f205f (patch)
tree3ab30094c0474f13ee55819e780c7a04cc743ae8
parent4a8ef93f5473bca8faa7dadd6dc6a123542ce0c6 (diff)
downloadorg.eclipse.emf.compare-e8c43e5d86be0e8b40b0b89b9f09f7442f0f205f.tar.gz
org.eclipse.emf.compare-e8c43e5d86be0e8b40b0b89b9f09f7442f0f205f.tar.xz
org.eclipse.emf.compare-e8c43e5d86be0e8b40b0b89b9f09f7442f0f205f.zip
Bypass EGit's "repository relative paths".
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/ComparisonScopeBuilder.java14
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/ProjectModelResolver.java33
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/ResourceVariantStorageProvider.java94
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/StreamAccessorStorage.java25
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/SubscriberStorageAccessor.java27
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/logical/IStorageProviderAccessor.java12
6 files changed, 188 insertions, 17 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 8e620649c..da6bc1211 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
@@ -152,11 +152,19 @@ public final class ComparisonScopeBuilder {
ITypedElement left, ITypedElement right, ITypedElement origin, IProgressMonitor monitor) {
SubMonitor progress = SubMonitor.convert(monitor, EMFCompareIDEUIMessages
.getString("EMFSynchronizationModel.resolving"), 100); //$NON-NLS-1$
- final IStorage leftStorage = StreamAccessorStorage.fromTypedElement(left);
- final IStorage rightStorage = StreamAccessorStorage.fromTypedElement(right);
+
+ // Can we find a local file to associate a proper path to our storages?
+ final IFile localFile = findFile(left);
+ String path = null;
+ if (localFile != null) {
+ path = localFile.getFullPath().toString();
+ }
+
+ final IStorage leftStorage = StreamAccessorStorage.fromTypedElement(path, left);
+ final IStorage rightStorage = StreamAccessorStorage.fromTypedElement(path, right);
final IStorage originStorage;
if (origin != null) {
- originStorage = StreamAccessorStorage.fromTypedElement(origin);
+ originStorage = StreamAccessorStorage.fromTypedElement(path, origin);
} else {
originStorage = null;
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/ProjectModelResolver.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/ProjectModelResolver.java
index 4abc3ab84..14afddb6b 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/ProjectModelResolver.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/ProjectModelResolver.java
@@ -221,7 +221,7 @@ public class ProjectModelResolver extends LogicalModelResolver {
updateChangedDependencies(monitor);
updateDependencies(leftFile, storageAccessor, monitor);
- final Set<IStorage> leftTraversal = resolveTraversal(leftFile, monitor);
+ final Set<IStorage> leftTraversal = resolveLocalTraversal(storageAccessor, leftFile, monitor);
final Set<IStorage> rightTraversal = resolveTraversal(storageAccessor, DiffSide.REMOTE,
leftTraversal, monitor);
final Set<IStorage> originTraversal;
@@ -373,6 +373,37 @@ public class ProjectModelResolver extends LogicalModelResolver {
}
/**
+ * This will be used in case of remote comparisons to resolve the local side's traversal (if there is a
+ * local side).
+ *
+ * @param storageAccessor
+ * The accessor that can be used to retrieve synchronization information between our resources.
+ * @param resource
+ * The resource for which we need the full logical model.
+ * @param monitor
+ * Monitor on which to report progress to the user.
+ * @return The set of all storages that compose the logical model of <code>resource</code>.
+ */
+ private Set<IStorage> resolveLocalTraversal(IStorageProviderAccessor storageAccessor, IFile resource,
+ IProgressMonitor monitor) {
+ final Set<IStorage> traversal = new LinkedHashSet<IStorage>();
+ final URI startURI = createURIFor(resource);
+
+ final Iterable<URI> uris = dependencyGraph.getSubgraphOf(startURI);
+ for (URI uri : uris) {
+ final IFile file = getFileAt(uri);
+ try {
+ if (!storageAccessor.isInSync(file)) {
+ traversal.add(file);
+ }
+ } catch (CoreException e) {
+ // swallow
+ }
+ }
+ return traversal;
+ }
+
+ /**
* This will be used to resolve the traversal of a file's logical model, according to
* {@link #dependencyGraph}.
*
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/ResourceVariantStorageProvider.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/ResourceVariantStorageProvider.java
index 216f918e9..79c06e331 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/ResourceVariantStorageProvider.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/ResourceVariantStorageProvider.java
@@ -10,9 +10,15 @@
*******************************************************************************/
package org.eclipse.emf.compare.ide.ui.internal.logical;
+import java.io.InputStream;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
import org.eclipse.emf.compare.ide.ui.logical.IStorageProvider;
import org.eclipse.team.core.variants.IResourceVariant;
@@ -22,16 +28,22 @@ import org.eclipse.team.core.variants.IResourceVariant;
* @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
*/
public class ResourceVariantStorageProvider implements IStorageProvider {
+ /** Path to the wrapped variant. */
+ private final String path;
+
/** Wrapped variant. */
private final IResourceVariant variant;
/**
* Wraps a resource variant as a storage provider.
*
+ * @param path
+ * Path to the wrapped variant.
* @param variant
* The wrapped resource variant.
*/
- public ResourceVariantStorageProvider(IResourceVariant variant) {
+ public ResourceVariantStorageProvider(String path, IResourceVariant variant) {
+ this.path = path;
this.variant = variant;
}
@@ -41,6 +53,84 @@ public class ResourceVariantStorageProvider implements IStorageProvider {
* @see org.eclipse.emf.compare.ide.ui.logical.IStorageProvider#getStorage(org.eclipse.core.runtime.IProgressMonitor)
*/
public IStorage getStorage(IProgressMonitor monitor) throws CoreException {
- return variant.getStorage(monitor);
+ return new StorageWrapper(path, variant.getStorage(monitor));
+ }
+
+ /**
+ * Wraps an IStorage, but override its path to something useable.
+ * <p>
+ * Egit uses its own kind of Paths, which cannot be resolved in an Eclipse context without knowledge of
+ * EGit's internals.
+ * </p>
+ *
+ * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
+ */
+ private static class StorageWrapper implements IStorage {
+ /** Path to the wrapped storage. */
+ private final String fullPath;
+
+ /** Wrapped storage. */
+ private final IStorage storage;
+
+ /**
+ * Wraps an IStorage with the accurate path.
+ *
+ * @param fullPath
+ * Path of that storage.
+ * @param storage
+ * The wrapped storage.
+ */
+ public StorageWrapper(String fullPath, IStorage storage) {
+ this.fullPath = fullPath;
+ this.storage = storage;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+ */
+ public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
+ if (IResource.class.isAssignableFrom(adapter) && storage instanceof IFile) {
+ return storage;
+ }
+ return storage.getAdapter(adapter);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.resources.IStorage#getContents()
+ */
+ public InputStream getContents() throws CoreException {
+ return storage.getContents();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.resources.IStorage#getFullPath()
+ */
+ public IPath getFullPath() {
+ return new Path(fullPath);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.resources.IStorage#getName()
+ */
+ public String getName() {
+ return storage.getName();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.resources.IStorage#isReadOnly()
+ */
+ public boolean isReadOnly() {
+ return storage.isReadOnly();
+ }
}
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/StreamAccessorStorage.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/StreamAccessorStorage.java
index 8e499dcdf..e3e548c95 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/StreamAccessorStorage.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/StreamAccessorStorage.java
@@ -58,26 +58,41 @@ public class StreamAccessorStorage implements IStorage {
}
/**
+ * This is a short-hand for {@link #fromTypedElement(String, ITypedElement)}. This second one should be
+ * preferred in case the given element is remote and we need a proper path for it.
+ *
+ * @param element
+ * The typed element for which we need to create a wrapper.
+ * @return The wrapped typed element.
+ * @throws IllegalArgumentException
+ * If the given element does not implement {@link IStreamContentAccessor}.
+ */
+ public static StreamAccessorStorage fromTypedElement(ITypedElement element)
+ throws IllegalArgumentException {
+ return fromTypedElement(null, element);
+ }
+
+ /**
* Creates a StreamAccessorStorage given the input typed element. Note that the given typed element -must-
* implement {@link IStreamContentAccessor} as well.
*
+ * @param storagePath
+ * The full path to this storage, can be <code>null</code>.
* @param element
* The typed element for which we need to create a wrapper.
* @return The wrapped typed element.
* @throws IllegalArgumentException
* If the given element does not implement {@link IStreamContentAccessor}.
*/
- public static StreamAccessorStorage fromTypedElement(ITypedElement element)
+ public static StreamAccessorStorage fromTypedElement(String storagePath, ITypedElement element)
throws IllegalArgumentException {
if (!(element instanceof IStreamContentAccessor)) {
throw new IllegalArgumentException();
}
final String fullPath;
- final IFile file = findFile(element);
-
- if (file != null) {
- fullPath = file.getFullPath().toString();
+ if (storagePath != null) {
+ fullPath = storagePath;
} else {
final IFileRevision revision = findFileRevision(element);
String tmp = null;
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/SubscriberStorageAccessor.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/SubscriberStorageAccessor.java
index f250eda44..3ab81d637 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/SubscriberStorageAccessor.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/SubscriberStorageAccessor.java
@@ -85,6 +85,15 @@ public final class SubscriberStorageAccessor implements IStorageProviderAccessor
}
/**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.ide.ui.logical.IStorageProviderAccessor#isInSync(org.eclipse.core.resources.IResource)
+ */
+ public boolean isInSync(IResource resource) throws CoreException {
+ return subscriber.getDiff(resource) == null;
+ }
+
+ /**
* Finds and returns the "origin" variant of the given IResource as provided by the underlying subscriber.
*
* @param resource
@@ -94,7 +103,8 @@ public final class SubscriberStorageAccessor implements IStorageProviderAccessor
*/
private IStorageProvider getOriginVariant(IResource resource) throws CoreException {
if (originTree != null) {
- return wrapStorageProvider(originTree.getResourceVariant(resource));
+ return wrapStorageProvider(resource.getFullPath().toString(), originTree
+ .getResourceVariant(resource));
}
final IDiff diff = subscriber.getDiff(resource);
@@ -111,7 +121,8 @@ public final class SubscriberStorageAccessor implements IStorageProviderAccessor
*/
private IStorageProvider getSourceVariant(IResource resource) throws CoreException {
if (sourceTree != null) {
- return wrapStorageProvider(sourceTree.getResourceVariant(resource));
+ return wrapStorageProvider(resource.getFullPath().toString(), sourceTree
+ .getResourceVariant(resource));
}
final IDiff diff = subscriber.getDiff(resource);
@@ -126,9 +137,10 @@ public final class SubscriberStorageAccessor implements IStorageProviderAccessor
* @return The "remote" variant of the given IResource.
* @throws CoreException
*/
- public IStorageProvider getRemoteVariant(IResource resource) throws CoreException {
+ private IStorageProvider getRemoteVariant(IResource resource) throws CoreException {
if (remoteTree != null) {
- return wrapStorageProvider(remoteTree.getResourceVariant(resource));
+ return wrapStorageProvider(resource.getFullPath().toString(), remoteTree
+ .getResourceVariant(resource));
}
final IDiff diff = subscriber.getDiff(resource);
@@ -152,13 +164,15 @@ public final class SubscriberStorageAccessor implements IStorageProviderAccessor
/**
* Wraps the given resource variant as an {@link IStorageProvider}.
*
+ * @param path
+ * Path of that storage.
* @param revision
* The wrapped resource variant.
* @return The wrapping storage provider.
*/
- private static IStorageProvider wrapStorageProvider(IResourceVariant variant) {
+ private static IStorageProvider wrapStorageProvider(String path, IResourceVariant variant) {
if (variant != null) {
- return new ResourceVariantStorageProvider(variant);
+ return new ResourceVariantStorageProvider(path, variant);
}
return null;
}
@@ -254,6 +268,7 @@ public final class SubscriberStorageAccessor implements IStorageProviderAccessor
try {
final Method method;
if (methodName.contains("Source")) { //$NON-NLS-1$
+ // Only available on git, only from 3.0
method = teamSubscriber.getClass().getDeclaredMethod(methodName);
} else {
method = ResourceVariantTreeSubscriber.class.getDeclaredMethod(methodName);
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/logical/IStorageProviderAccessor.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/logical/IStorageProviderAccessor.java
index de02ac513..f3796c3ea 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/logical/IStorageProviderAccessor.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/logical/IStorageProviderAccessor.java
@@ -38,6 +38,18 @@ public interface IStorageProviderAccessor {
*/
IStorageProvider getStorageProvider(IResource resource, DiffSide side) throws CoreException;
+ /**
+ * Checks whether the given resource is considered "in sync".
+ *
+ * @param resource
+ * The resource to check.
+ * @return <code>true</code> if this resource is in sync with its remote variant, <code>false</code>
+ * otherwise.
+ * @throws CoreException
+ * Thrown if we cannot get the diff for this resource.
+ */
+ boolean isInSync(IResource resource) throws CoreException;
+
/** Used by the resolution process to determine the side of the revision to fetch. */
public static enum DiffSide {
/** Source side. Usually denotes "left" or "local" content. */

Back to the top