Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.compare/compare')
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/EditionSelectionDialog.java4
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/IStreamMerger.java70
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java89
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/IStructureCreatorDescriptor.java33
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/StreamMergerDescriptor.java55
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/StructureCreatorDescriptor.java57
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/LineComparator.java68
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/MergeMessages.java32
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/MergeMessages.properties15
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/TextMerger.java87
10 files changed, 445 insertions, 65 deletions
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/EditionSelectionDialog.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/EditionSelectionDialog.java
index 2eb990a18..09f477f55 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/EditionSelectionDialog.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/EditionSelectionDialog.java
@@ -274,7 +274,7 @@ public class EditionSelectionDialog extends ResizableDialog {
IStructureCreator structureCreator= null;
if (ppath != null) {
String type= target.getType();
- IStructureCreatorDescriptor scd= CompareUIPlugin.getStructureCreator(type);
+ StructureCreatorDescriptor scd= CompareUIPlugin.getStructureCreator(type);
if (scd != null)
structureCreator= scd.createStructureCreator();
}
@@ -345,7 +345,7 @@ public class EditionSelectionDialog extends ResizableDialog {
IStructureCreator structureCreator= null;
if (ppath != null) {
String type= target.getType();
- IStructureCreatorDescriptor scd= CompareUIPlugin.getStructureCreator(type);
+ StructureCreatorDescriptor scd= CompareUIPlugin.getStructureCreator(type);
if (scd != null)
structureCreator= scd.createStructureCreator();
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/IStreamMerger.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/IStreamMerger.java
new file mode 100644
index 000000000..49414b1b0
--- /dev/null
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/IStreamMerger.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.compare;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+
+/**
+ * This interface defines a single operation for performing a three-way merge on three
+ * input streams. The merged result is written to an output stream.
+ * <p>
+ * Clients must implement this interface when contributing new mergers to the
+ * <code>org.eclipse.compare.streamMergers</code> extension point.
+ * </p>
+ *
+ * @see org.eclipse.compare.internal.merge.TextMerger
+ *
+ * @since 3.0
+ */
+public interface IStreamMerger {
+
+ /**
+ * Indicates the successful completion of the merge operation (value <code>IStatus.OK</code>)
+ */
+ public static final int OK= IStatus.OK;
+
+ /**
+ * Indicates that a change conflict prevented the merge from successful completion (value <code>1</code>)
+ */
+ public static final int CONFLICT= 1;
+
+ /**
+ * Status code describing an internal error (value <code>2</code>)
+ */
+ public static final int INTERNAL_ERROR= 2;
+
+ /**
+ * Performs a merge operation on the given input streams and writes the merge result to the output stream.
+ * On success a status <code>IStatus.OK</code> is returned, on error a status <code>IStatus.ERROR</code>.
+ * If the merge operation cannot deal with conflicts, the code of the error status has the value <code>IStreamMerger.CONFLICT</code>.
+ * For text oriented mergers the encoding for the input and output streams is honored.
+ *
+ * @param output the byte stream to which the merge result is written; the merger will not close the stream
+ * @param outputEncoding the encoding to use when writing to the output stream
+ * @param ancestor the byte stream from which the common ancestor is read
+ * @param ancestorEncoding the encoding of the ancestor input byte stream
+ * @param target the byte stream containing the target of the merge
+ * @param targetEncoding the encoding of the target input byte stream
+ * @param other the byte stream containing the target of the merge
+ * @param otherEncoding the encoding of the other input byte stream
+ * @param monitor reports progress of the merge operation
+ * @return returns an ISta
+ */
+ IStatus merge(OutputStream output, String outputEncoding,
+ InputStream ancestor, String ancestorEncoding,
+ InputStream target, String targetEncoding,
+ InputStream other, String otherEncoding,
+ IProgressMonitor monitor);
+}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java
index d5e95ee70..ba585496e 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java
@@ -70,6 +70,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
public static final String PLUGIN_ID= "org.eclipse.compare"; //$NON-NLS-1$
+ private static final String STREAM_MERGER_EXTENSION_POINT= "streamMergers"; //$NON-NLS-1$
private static final String STRUCTURE_CREATOR_EXTENSION_POINT= "structureCreators"; //$NON-NLS-1$
private static final String STRUCTURE_MERGEVIEWER_EXTENSION_POINT= "structureMergeViewers"; //$NON-NLS-1$
private static final String CONTENT_MERGEVIEWER_EXTENSION_POINT= "contentMergeViewers"; //$NON-NLS-1$
@@ -86,6 +87,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
/** Maps ImageDescriptors to Images */
private static Map fgImages2= new Hashtable(10);
+ private static Map fgStreamMergers= new Hashtable(10);
private static Map fgStructureCreators= new Hashtable(10);
private static Map fgStructureViewerDescriptors= new Hashtable(10);
private static Map fgStructureViewerAliases= new Hashtable(10);
@@ -134,56 +136,55 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
}
/**
- * Registers all structure creators, content merge viewers, and structure merge viewers
+ * Registers all stream mergers, structure creators, content merge viewers, and structure merge viewers
* that are found in the XML plugin files.
*/
private void registerExtensions() {
IPluginRegistry registry= Platform.getPluginRegistry();
+ // collect all IStreamMergers
+ IConfigurationElement[] elements= registry.getConfigurationElementsFor(PLUGIN_ID, STREAM_MERGER_EXTENSION_POINT);
+ for (int i= 0; i < elements.length; i++) {
+ StreamMergerDescriptor desc= new StreamMergerDescriptor(elements[i]);
+ String extensions= desc.getExtension();
+ if (extensions != null)
+ registerStreamMerger(extensions, desc);
+ }
+
// collect all IStructureCreators
- IConfigurationElement[] elements= registry.getConfigurationElementsFor(PLUGIN_ID, STRUCTURE_CREATOR_EXTENSION_POINT);
+ elements= registry.getConfigurationElementsFor(PLUGIN_ID, STRUCTURE_CREATOR_EXTENSION_POINT);
for (int i= 0; i < elements.length; i++) {
- final IConfigurationElement conf= elements[i];
- String extensions= conf.getAttribute(EXTENSIONS_ATTRIBUTE);
- registerStructureCreator(extensions,
- new IStructureCreatorDescriptor() {
- public IStructureCreator createStructureCreator() {
- try {
- return (IStructureCreator) conf.createExecutableExtension(CLASS_ATTRIBUTE);
- } catch (CoreException ex) {
- log(ex.getStatus());
- }
- return null;
- }
- }
- );
+ StructureCreatorDescriptor desc= new StructureCreatorDescriptor(elements[i]);
+ String extensions= desc.getExtension();
+ if (extensions != null)
+ registerStructureCreator(extensions, desc);
}
// collect all viewers which define the structure mergeviewer extension point
elements= registry.getConfigurationElementsFor(PLUGIN_ID, STRUCTURE_MERGEVIEWER_EXTENSION_POINT);
for (int i= 0; i < elements.length; i++) {
ViewerDescriptor desc= new ViewerDescriptor(elements[i]);
- String ext= desc.getExtension();
- if (ext != null)
- registerStructureViewerDescriptor(desc.getExtension(), desc);
+ String extensions= desc.getExtension();
+ if (extensions != null)
+ registerStructureViewerDescriptor(extensions, desc);
}
// collect all viewers which define the content mergeviewer extension point
elements= registry.getConfigurationElementsFor(PLUGIN_ID, CONTENT_MERGEVIEWER_EXTENSION_POINT);
for (int i= 0; i < elements.length; i++) {
ViewerDescriptor desc= new ViewerDescriptor(elements[i]);
- String ext= desc.getExtension();
- if (ext != null)
- registerContentMergeViewerDescriptor(desc.getExtension(), desc);
+ String extensions= desc.getExtension();
+ if (extensions != null)
+ registerContentMergeViewerDescriptor(extensions, desc);
}
// collect all viewers which define the content viewer extension point
elements= registry.getConfigurationElementsFor(PLUGIN_ID, CONTENT_VIEWER_EXTENSION_POINT);
for (int i= 0; i < elements.length; i++) {
ViewerDescriptor desc= new ViewerDescriptor(elements[i]);
- String ext= desc.getExtension();
- if (ext != null)
- registerContentViewerDescriptor(desc.getExtension(), desc);
+ String extensions= desc.getExtension();
+ if (extensions != null)
+ registerContentViewerDescriptor(extensions, desc);
}
}
@@ -518,7 +519,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
* @param types one or more types separated by commas and whitespace
* @param descriptor the descriptor to register
*/
- public static void registerStructureCreator(String types, IStructureCreatorDescriptor descriptor) {
+ public static void registerStructureCreator(String types, StructureCreatorDescriptor descriptor) {
if (types != null) {
StringTokenizer tokenizer= new StringTokenizer(types, ","); //$NON-NLS-1$
while (tokenizer.hasMoreElements()) {
@@ -535,8 +536,8 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
* @return a descriptor for the given type, or <code>null</code> if no
* descriptor has been registered
*/
- public static IStructureCreatorDescriptor getStructureCreator(String type) {
- return (IStructureCreatorDescriptor) fgStructureCreators.get(normalizeCase(type));
+ public static StructureCreatorDescriptor getStructureCreator(String type) {
+ return (StructureCreatorDescriptor) fgStructureCreators.get(normalizeCase(type));
}
/**
@@ -580,7 +581,35 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
fgContentViewerDescriptors.put(normalizeCase(extension), descriptor);
}
}
-
+
+ /**
+ * Registers the given stream merger descriptor for one or more types.
+ *
+ * @param types one or more types separated by commas and whitespace
+ * @param descriptor the descriptor to register
+ */
+ public static void registerStreamMerger(String types, StreamMergerDescriptor descriptor) {
+ StringTokenizer tokenizer= new StringTokenizer(types, ","); //$NON-NLS-1$
+ while (tokenizer.hasMoreElements()) {
+ String extension= tokenizer.nextToken().trim();
+ fgStreamMergers.put(normalizeCase(extension), descriptor);
+ }
+ }
+
+ /**
+ * Returns a stream merger for the given type.
+ *
+ * @param type the type for which to find a stream merger
+ * @return a stream merger for the given type, or <code>null</code> if no
+ * stream merger has been registered
+ */
+ public static IStreamMerger createStreamMerger(String type) {
+ StreamMergerDescriptor descriptor= (StreamMergerDescriptor) fgStreamMergers.get(type);
+ if (descriptor != null)
+ return descriptor.createStreamMerger();
+ return null;
+ }
+
/**
* Returns a structure compare viewer based on an old viewer and an input object.
* If the old viewer is suitable for showing the input, the old viewer
@@ -616,7 +645,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
if (vd != null)
return vd.createViewer(oldViewer, parent, configuration);
- IStructureCreatorDescriptor scc= getStructureCreator(type);
+ StructureCreatorDescriptor scc= getStructureCreator(type);
if (scc != null) {
IStructureCreator sc= scc.createStructureCreator();
if (sc != null) {
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/IStructureCreatorDescriptor.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/IStructureCreatorDescriptor.java
deleted file mode 100644
index f5a845e80..000000000
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/IStructureCreatorDescriptor.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.internal;
-
-import org.eclipse.compare.structuremergeviewer.IStructureCreator;
-
-/**
- * A factory object for creating <code>IStructureCreator</code>s from a descriptor.
- * <p>
- * It is used when registering <code>IStructureCreator</code> for types
- * in <code>CompareUIPlugin.registerStructureCreator</code>.
- * </p>
- *
- * @see IStructureCreator
- * @see CompareUIPlugin
- */
-public interface IStructureCreatorDescriptor {
-
- /**
- * Creates a new structure creator.
- *
- * @return a newly created structure creator
- */
- IStructureCreator createStructureCreator();
-}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/StreamMergerDescriptor.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/StreamMergerDescriptor.java
new file mode 100644
index 000000000..bebd4f177
--- /dev/null
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/StreamMergerDescriptor.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.compare.internal;
+
+import org.eclipse.compare.IStreamMerger;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+
+/**
+ * A factory proxy for creating a StructureCreator.
+ */
+class StreamMergerDescriptor {
+
+ private final static String CLASS_ATTRIBUTE= "class"; //$NON-NLS-1$
+ private final static String EXTENSIONS_ATTRIBUTE= "extensions"; //$NON-NLS-1$
+
+ private IConfigurationElement fElement;
+
+ /**
+ * Creates a new sorter node with the given configuration element.
+ */
+ public StreamMergerDescriptor(IConfigurationElement element) {
+ fElement= element;
+ }
+
+ /**
+ * Creates a new stream merger from this node.
+ */
+ public IStreamMerger createStreamMerger() {
+ try {
+ return (IStreamMerger)fElement.createExecutableExtension(CLASS_ATTRIBUTE);
+ } catch (CoreException ex) {
+ //ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.createSorter.title"), SearchMessages.getString("Search.Error.createSorter.message")); //$NON-NLS-2$ //$NON-NLS-1$
+ return null;
+ } catch (ClassCastException ex) {
+ //ExceptionHandler.displayMessageDialog(ex, SearchMessages.getString("Search.Error.createSorter.title"), SearchMessages.getString("Search.Error.createSorter.message")); //$NON-NLS-2$ //$NON-NLS-1$
+ return null;
+ }
+ }
+
+ /**
+ * Returns the streammergers's extensions.
+ */
+ public String getExtension() {
+ return fElement.getAttribute(EXTENSIONS_ATTRIBUTE);
+ }
+}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/StructureCreatorDescriptor.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/StructureCreatorDescriptor.java
new file mode 100644
index 000000000..8d0bc78ad
--- /dev/null
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/StructureCreatorDescriptor.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.compare.internal;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+
+import org.eclipse.compare.structuremergeviewer.IStructureCreator;
+
+/**
+ * A factory proxy for creating a StructureCreator.
+ */
+public class StructureCreatorDescriptor {
+
+ private final static String CLASS_ATTRIBUTE= "class"; //$NON-NLS-1$
+ private final static String EXTENSIONS_ATTRIBUTE= "extensions"; //$NON-NLS-1$
+
+ private IConfigurationElement fElement;
+
+ /**
+ * Creates a new sorter node with the given configuration element.
+ */
+ public StructureCreatorDescriptor(IConfigurationElement element) {
+ fElement= element;
+ }
+
+ /**
+ * Creates a new sorter from this node.
+ */
+ public IStructureCreator createStructureCreator() {
+ try {
+ return (IStructureCreator)fElement.createExecutableExtension(CLASS_ATTRIBUTE);
+ } catch (CoreException ex) {
+ CompareUIPlugin.log(ex.getStatus());
+ //ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.createSorter.title"), SearchMessages.getString("Search.Error.createSorter.message")); //$NON-NLS-2$ //$NON-NLS-1$
+ return null;
+ } catch (ClassCastException ex) {
+ //ExceptionHandler.displayMessageDialog(ex, SearchMessages.getString("Search.Error.createSorter.title"), SearchMessages.getString("Search.Error.createSorter.message")); //$NON-NLS-2$ //$NON-NLS-1$
+ return null;
+ }
+ }
+
+ /**
+ * Returns the structure creator's extensions.
+ */
+ public String getExtension() {
+ return fElement.getAttribute(EXTENSIONS_ATTRIBUTE);
+ }
+}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/LineComparator.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/LineComparator.java
new file mode 100644
index 000000000..6cda1f25e
--- /dev/null
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/LineComparator.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.compare.internal.merge;
+
+import java.io.*;
+import java.util.ArrayList;
+import org.eclipse.compare.rangedifferencer.IRangeComparator;
+
+/**
+ * This implementation of IRangeComparator breaks an input stream into lines.
+ */
+class LineComparator implements IRangeComparator {
+
+ private String[] fLines;
+
+ public LineComparator(InputStream is, String encoding) throws UnsupportedEncodingException {
+
+ BufferedReader br = new BufferedReader(new InputStreamReader(is, encoding));
+ String line;
+ ArrayList ar = new ArrayList();
+ try {
+ while ((line = br.readLine()) != null)
+ ar.add(line);
+ } catch (IOException e) {
+ }
+ try {
+ is.close();
+ } catch (IOException e1) {
+ }
+ fLines = (String[]) ar.toArray(new String[ar.size()]);
+ }
+
+ String getLine(int ix) {
+ return fLines[ix];
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.compare.rangedifferencer.IRangeComparator#getRangeCount()
+ */
+ public int getRangeCount() {
+ return fLines.length;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.compare.rangedifferencer.IRangeComparator#rangesEqual(int, org.eclipse.compare.rangedifferencer.IRangeComparator, int)
+ */
+ public boolean rangesEqual(int thisIndex, IRangeComparator other,
+ int otherIndex) {
+ String s1 = fLines[thisIndex];
+ String s2 = ((LineComparator) other).fLines[otherIndex];
+ return s1.equals(s2);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.compare.rangedifferencer.IRangeComparator#skipRangeComparison(int, int, org.eclipse.compare.rangedifferencer.IRangeComparator)
+ */
+ public boolean skipRangeComparison(int length, int maxLength, IRangeComparator other) {
+ return false;
+ }
+}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/MergeMessages.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/MergeMessages.java
new file mode 100644
index 000000000..e72825d2a
--- /dev/null
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/MergeMessages.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.compare.internal.merge;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+class MergeMessages {
+
+ private static final String RESOURCE_BUNDLE= "org.eclipse.compare.internal.merge.MergeMessages";//$NON-NLS-1$
+
+ private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
+
+ private MergeMessages() {
+ }
+
+ public static String getString(String key) {
+ try {
+ return fgResourceBundle.getString(key);
+ } catch (MissingResourceException e) {
+ return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
+ }
+ }
+}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/MergeMessages.properties b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/MergeMessages.properties
new file mode 100644
index 000000000..8b55acb6c
--- /dev/null
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/MergeMessages.properties
@@ -0,0 +1,15 @@
+###############################################################################
+# Copyright (c) 2004 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Common Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/cpl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+
+TextAutoMerge.inputEncodingError= Unsupported encoding for input streams
+TextAutoMerge.outputEncodingError= Unsupported encoding for output streams
+TextAutoMerge.outputIOError= IO error on writing
+TextAutoMerge.conflict= Conflict: cannot auto merge \ No newline at end of file
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/TextMerger.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/TextMerger.java
new file mode 100644
index 000000000..93caa32bf
--- /dev/null
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/TextMerger.java
@@ -0,0 +1,87 @@
+package org.eclipse.compare.internal.merge;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+
+import org.eclipse.compare.*;
+import org.eclipse.compare.rangedifferencer.RangeDifference;
+import org.eclipse.compare.rangedifferencer.RangeDifferencer;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+
+/**
+ * A simple merger for streams containing text lines.
+ */
+public class TextMerger implements IStreamMerger {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.compare.internal.merge.IAutoMerger#automerge(java.io.OutputStream,
+ * org.eclipse.core.resources.IEncodedStorage,
+ * org.eclipse.core.resources.IEncodedStorage,
+ * org.eclipse.core.resources.IEncodedStorage,
+ * org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public IStatus merge(OutputStream output, String outputEncoding,
+ InputStream ancestor, String ancestorEncoding,
+ InputStream target, String targetEncoding,
+ InputStream other, String otherEncoding,
+ IProgressMonitor monitor) {
+
+ LineComparator a, t, o;
+
+ try {
+ a= new LineComparator(ancestor, ancestorEncoding);
+ t= new LineComparator(target, targetEncoding);
+ o= new LineComparator(other, otherEncoding);
+ } catch (UnsupportedEncodingException e) {
+ return new Status(Status.ERROR, CompareUI.PLUGIN_ID, 1, MergeMessages.getString("TextAutoMerge.inputEncodingError"), e); //$NON-NLS-1$
+ }
+
+ try {
+ char lineSeparator= '\n';
+
+ RangeDifference[] diffs = RangeDifferencer.findRanges(monitor, a, t, o);
+
+ for (int i = 0; i < diffs.length; i++) {
+ RangeDifference rd = diffs[i];
+ switch (rd.kind()) {
+ case RangeDifference.ANCESTOR: // pseudo conflict
+ case RangeDifference.NOCHANGE:
+ case RangeDifference.RIGHT:
+ for (int j = rd.rightStart(); j < rd.rightEnd(); j++) {
+ String s= o.getLine(j);
+ output.write(s.getBytes(outputEncoding));
+ output.write(lineSeparator);
+ }
+ break;
+
+ case RangeDifference.LEFT:
+ for (int j = rd.leftStart(); j < rd.leftEnd(); j++) {
+ String s= t.getLine(j);
+ output.write(s.getBytes(outputEncoding));
+ output.write(lineSeparator);
+ }
+ break;
+
+ case RangeDifference.CONFLICT:
+ return new Status(Status.ERROR, CompareUI.PLUGIN_ID, CONFLICT, MergeMessages.getString("TextAutoMerge.conflict"), null); //$NON-NLS-1$
+
+ default:
+ break;
+ }
+ }
+
+ } catch (UnsupportedEncodingException e) {
+ return new Status(Status.ERROR, CompareUI.PLUGIN_ID, 1, MergeMessages.getString("TextAutoMerge.outputEncodingError"), e); //$NON-NLS-1$
+ } catch (IOException e) {
+ return new Status(Status.ERROR, CompareUI.PLUGIN_ID, 1, MergeMessages.getString("TextAutoMerge.outputIOError"), e); //$NON-NLS-1$
+ }
+
+ return Status.OK_STATUS;
+ }
+} \ No newline at end of file

Back to the top