Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2007-09-12 16:52:03 +0000
committerMichael Valenta2007-09-12 16:52:03 +0000
commit07c0dacadd1ebf8776b1bf194f39f3a19a12fa42 (patch)
treeb24eb50cbdcd7867756512034d9633629c5a87ee /bundles
parenta4e65977a1a019aa1eb70074410bb09b3f392030 (diff)
downloadeclipse.platform.team-07c0dacadd1ebf8776b1bf194f39f3a19a12fa42.tar.gz
eclipse.platform.team-07c0dacadd1ebf8776b1bf194f39f3a19a12fa42.tar.xz
eclipse.platform.team-07c0dacadd1ebf8776b1bf194f39f3a19a12fa42.zip
Bug 136330 [API] DelegatingStorageMerger should be API
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/DelegatingStorageMerger.java (renamed from bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/DelegatingStorageMerger.java)113
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/MergeContext.java1
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/TeamPlugin.java30
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/IStreamMergerDelegate.java1
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/CVSSubscriberMergeContext.java7
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/StreamMergerDelegate.java5
6 files changed, 95 insertions, 62 deletions
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/DelegatingStorageMerger.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/DelegatingStorageMerger.java
index 08dbf163e..4eb8e5311 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/DelegatingStorageMerger.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/DelegatingStorageMerger.java
@@ -8,7 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.team.internal.core.mapping;
+package org.eclipse.team.core.mapping;
import java.io.IOException;
import java.io.OutputStream;
@@ -18,65 +18,64 @@ import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.content.*;
import org.eclipse.osgi.util.NLS;
-import org.eclipse.team.core.Team;
-import org.eclipse.team.core.TeamException;
-import org.eclipse.team.core.mapping.IStorageMerger;
+import org.eclipse.team.core.*;
import org.eclipse.team.internal.core.*;
+import org.eclipse.team.internal.core.mapping.IStreamMergerDelegate;
/**
* This storage merger delegates to the appropriate merger or returns a conflict
- * if no merger is available.
+ * if no merger is available or if a merge was not possible.
* <p>
* The target storage is used to look for an appropriate merger. If the target
* is an {@link IFile}, the content type of the file is used. Otherwise, the
- * {@link IContentTypeManager} is used to find an appropriate content type.If an
+ * {@link IContentTypeManager} is used to find an appropriate content type. If an
* appropriate merger is not found, a status containing the
* <code>CONFLICT</code> is returned.
+ * <p>
+ * Clients may use this class directly or subclass it.
+ * @since 3.4
*
*/
public class DelegatingStorageMerger implements IStorageMerger {
- private static IStreamMergerDelegate mergerDelegate;
private static DelegatingStorageMerger instance;
- private final IContentType contentType;
- public DelegatingStorageMerger() {
- contentType = null;
+ /**
+ * Return the storage merger associated with the <code>IContentTypeManager.CT_TEXT</code>
+ * content type.
+ * @return the storage merger associated with the <code>IContentTypeManager.CT_TEXT</code>
+ * content type
+ */
+ public static IStorageMerger createTextMerger() {
+ return Team.createMerger(Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT));
}
- public DelegatingStorageMerger(IContentType contentType) {
- this.contentType = contentType;
- }
-
/**
- * Set the file merger that is used by the {@link #merge(OutputStream, String, IStorage, IStorage, IStorage, IProgressMonitor)}
- * method. It is the responsibility of subclasses to provide a merger.
- * If a merger is not provided, subclasses must override <code>performThreeWayMerge</code>.
- * @param merger the merger used to merge files
+ * Default no-arg constructor.
*/
- public static void setMergerDelegate(IStreamMergerDelegate merger) {
- mergerDelegate = merger;
+ public DelegatingStorageMerger() {
+ // Nothing to do
}
+ /**
+ * Helper method that returns a singleton instance that can be used to merge
+ * two {@link IStorage} instances.
+ * @return a storage merger that delegates the merge based on the type
+ * of the target storage.
+ */
public static IStorageMerger getInstance() {
if (instance == null)
instance = new DelegatingStorageMerger();
return instance;
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.team.core.mapping.IStorageMerger#merge(java.io.OutputStream,
- * java.lang.String, org.eclipse.core.resources.IStorage,
- * org.eclipse.core.resources.IStorage,
- * org.eclipse.core.resources.IStorage,
- * org.eclipse.core.runtime.IProgressMonitor)
+ /* (non-Javadoc)
+ * @see org.eclipse.team.core.mapping.IStorageMerger#merge(java.io.OutputStream, java.lang.String, org.eclipse.core.resources.IStorage, org.eclipse.core.resources.IStorage, org.eclipse.core.resources.IStorage, org.eclipse.core.runtime.IProgressMonitor)
*/
public IStatus merge(OutputStream output, String outputEncoding,
IStorage ancestor, IStorage target, IStorage other,
IProgressMonitor monitor) throws CoreException {
- IStorageMerger merger = findMerger(target);
+ IStorageMerger merger = createDelegateMerger(target);
if (merger == null)
return new Status(IStatus.WARNING, TeamPlugin.ID, CONFLICT,
Messages.DelegatingStorageMerger_0, null);
@@ -87,18 +86,17 @@ public class DelegatingStorageMerger implements IStorageMerger {
return merger.merge(output, outputEncoding, ancestor, target, other, monitor);
}
- protected IStorageMerger findMerger(IStorage target) throws CoreException {
+ /**
+ * Create a merger for the given storage or return <code>null</code>
+ * if an appropriate merger could not be created. This method is called
+ * by {@link #merge(OutputStream, String, IStorage, IStorage, IStorage, IProgressMonitor)}
+ * to create the merger to which the merge should be delegated.
+ * @param target the storage that contains the target contents of the merge.
+ * @return a merger for the given storage or <code>null</code>
+ * @throws CoreException
+ */
+ protected IStorageMerger createDelegateMerger(IStorage target) throws CoreException {
IStorageMerger merger = null;
- if (contentType != null) {
- // A particular merger has been requested
- merger = getMerger(contentType);
- if (merger != null) {
- return merger;
- } else {
- // The requested merger is not available but still try and find another
- TeamPlugin.log(IStatus.ERROR, NLS.bind("Storage merger for {0} not available", contentType.getId()), null); //$NON-NLS-1$
- }
- }
CoreException exception = null;
try {
IContentType type = getContentType(target);
@@ -115,7 +113,7 @@ public class DelegatingStorageMerger implements IStorageMerger {
// If team thinks the file is text, try to get a text merger for the file
int type = getType(target);
if (type == Team.TEXT)
- merger = getTextMerger();
+ merger = createTextMerger();
if (merger == null) {
// As a last resort, look for a stream merger
merger = findAndWrapStreamMerger(target);
@@ -134,11 +132,21 @@ public class DelegatingStorageMerger implements IStorageMerger {
return merger;
}
+ /**
+ * Return the Team content type associated with the given
+ * target.
+ * @param target the storage that contains the target contents for the merge.
+ * @return the Team content type associated with the given
+ * target
+ * @see Team#getFileContentManager()
+ * @see IFileContentManager#getType(IStorage)
+ */
protected int getType(IStorage target) {
return Team.getFileContentManager().getType(target);
}
private IStorageMerger findAndWrapStreamMerger(IStorage target) {
+ IStreamMergerDelegate mergerDelegate = TeamPlugin.getPlugin().getMergerDelegate();
if (mergerDelegate != null) {
IStorageMerger merger = mergerDelegate.findMerger(target);
return merger;
@@ -146,10 +154,6 @@ public class DelegatingStorageMerger implements IStorageMerger {
return null;
}
- protected IStorageMerger getTextMerger() {
- return new DelegatingStorageMerger(Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT));
- }
-
private IStorageMerger getMerger(String name) {
String extension = getExtension(name);
if (extension != null)
@@ -157,6 +161,12 @@ public class DelegatingStorageMerger implements IStorageMerger {
return null;
}
+ /**
+ * Helper method for returning the extension of a file name
+ * @param name the file name
+ * @return the extension of the file name or <code>null</code>
+ * if the file name does not have an extension
+ */
public static String getExtension(String name) {
int index = name.lastIndexOf('.');
if (index == -1) {
@@ -166,14 +176,17 @@ public class DelegatingStorageMerger implements IStorageMerger {
}
private IStorageMerger getMerger(IContentType type) {
- IStorageMerger merger = StorageMergerRegistry.getInstance().createStreamMerger(type);
- return merger;
+ return Team.createMerger(type);
}
- /*
- * Find the content type for the given storage and return null if a content
+ /**
+ * A helper method that finds the content type for the given storage or returns
+ * <code>null</code> if a content
* type cannot be found. Any exceptions that occur when trying to determine
- * the content type are propogated.
+ * the content type are propagated.
+ * @param target the storage that contains the target contents of the merge.
+ * @return the content type of the storage or <code>null</code>
+ * @throws CoreException if an exception occurs
*/
public static IContentType getContentType(IStorage target) throws CoreException {
if (target instanceof IFile) {
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/MergeContext.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/MergeContext.java
index 3c6953251..c39a79ba6 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/MergeContext.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/MergeContext.java
@@ -23,7 +23,6 @@ import org.eclipse.team.core.diff.IThreeWayDiff;
import org.eclipse.team.core.history.IFileRevision;
import org.eclipse.team.core.mapping.*;
import org.eclipse.team.internal.core.*;
-import org.eclipse.team.internal.core.mapping.DelegatingStorageMerger;
import org.eclipse.team.internal.core.mapping.SyncInfoToDiffConverter;
/**
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/TeamPlugin.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/TeamPlugin.java
index fabb76702..400cbe453 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/TeamPlugin.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/TeamPlugin.java
@@ -10,16 +10,16 @@
*******************************************************************************/
package org.eclipse.team.internal.core;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
import java.util.*;
-import java.util.ArrayList;
-import java.util.List;
+import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.content.IContentDescription;
import org.eclipse.core.runtime.content.IContentTypeManager;
import org.eclipse.team.core.*;
+import org.eclipse.team.core.mapping.DelegatingStorageMerger;
+import org.eclipse.team.internal.core.mapping.IStreamMergerDelegate;
import org.osgi.framework.BundleContext;
/**
@@ -58,6 +58,8 @@ final public class TeamPlugin extends Plugin {
// The one and only plug-in instance
private static TeamPlugin plugin;
+
+ private IStreamMergerDelegate mergerDelegate;
/**
* Constructs a plug-in runtime class.
@@ -97,7 +99,10 @@ final public class TeamPlugin extends Plugin {
}
/**
- * Log the given exception alloing with the provided message and severity indicator
+ * Log the given exception allowing with the provided message and severity indicator
+ * @param severity the severity
+ * @param message the message
+ * @param e the exception
*/
public static void log(int severity, String message, Throwable e) {
plugin.getLog().log(new Status(severity, ID, 0, message, e));
@@ -106,6 +111,7 @@ final public class TeamPlugin extends Plugin {
/**
* Log the given CoreException in a manner that will include the stacktrace of
* the exception in the log.
+ * @param e the exception
*/
public static void log(CoreException e) {
log(e.getStatus().getSeverity(), e.getMessage(), e);
@@ -188,5 +194,19 @@ final public class TeamPlugin extends Plugin {
}
return (IPath[]) result.toArray(new IPath[result.size()]);
}
+
+ /**
+ * Set the file merger that is used by the {@link DelegatingStorageMerger#merge(OutputStream, String, IStorage, IStorage, IStorage, IProgressMonitor)}
+ * method. It is the responsibility of subclasses to provide a merger.
+ * If a merger is not provided, subclasses must override <code>performThreeWayMerge</code>.
+ * @param merger the merger used to merge files
+ */
+ public void setMergerDelegate(IStreamMergerDelegate merger) {
+ mergerDelegate = merger;
+ }
+
+ public IStreamMergerDelegate getMergerDelegate() {
+ return mergerDelegate;
+ }
}
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/IStreamMergerDelegate.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/IStreamMergerDelegate.java
index 13078752c..c11734d73 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/IStreamMergerDelegate.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/IStreamMergerDelegate.java
@@ -11,6 +11,7 @@
package org.eclipse.team.internal.core.mapping;
import org.eclipse.core.resources.IStorage;
+import org.eclipse.team.core.mapping.DelegatingStorageMerger;
import org.eclipse.team.core.mapping.IStorageMerger;
/**
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/CVSSubscriberMergeContext.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/CVSSubscriberMergeContext.java
index 9b8fcfdfa..24cf938c1 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/CVSSubscriberMergeContext.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/CVSSubscriberMergeContext.java
@@ -29,18 +29,17 @@ import org.eclipse.team.internal.ccvs.core.resources.EclipseSynchronizer;
import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo;
import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
import org.eclipse.team.internal.ccvs.ui.Policy;
-import org.eclipse.team.internal.core.mapping.DelegatingStorageMerger;
public abstract class CVSSubscriberMergeContext extends SubscriberMergeContext {
private static final IStorageMerger MERGER = new DelegatingStorageMerger() {
- protected IStorageMerger findMerger(IStorage target) throws CoreException {
- IStorageMerger storageMerger = super.findMerger(target);
+ protected IStorageMerger createDelegateMerger(IStorage target) throws CoreException {
+ IStorageMerger storageMerger = super.createDelegateMerger(target);
if (storageMerger == null) {
if (target instanceof IFile) {
IFile file = (IFile) target;
if (isText(file))
- storageMerger = getTextMerger();
+ storageMerger = createTextMerger();
}
}
return storageMerger;
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/StreamMergerDelegate.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/StreamMergerDelegate.java
index 054f7527f..b1ad40e32 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/StreamMergerDelegate.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/StreamMergerDelegate.java
@@ -15,15 +15,16 @@ import org.eclipse.compare.IStreamMerger;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.team.core.mapping.DelegatingStorageMerger;
import org.eclipse.team.core.mapping.IStorageMerger;
-import org.eclipse.team.internal.core.mapping.DelegatingStorageMerger;
+import org.eclipse.team.internal.core.TeamPlugin;
import org.eclipse.team.internal.core.mapping.IStreamMergerDelegate;
import org.eclipse.team.internal.ui.TeamUIPlugin;
public class StreamMergerDelegate implements IStreamMergerDelegate {
public static void start() {
- DelegatingStorageMerger.setMergerDelegate(new StreamMergerDelegate());
+ TeamPlugin.getPlugin().setMergerDelegate(new StreamMergerDelegate());
}
public IStorageMerger findMerger(IStorage target) {

Back to the top