Update of /cvsroot/jcommander/incubator/matthias_kue/org.jcommander.eclipsepatch.compare/compare/org/eclipse/compare/internal/merge In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8063/compare/org/eclipse/compare/internal/merge Added Files: MergeMessages.properties MergeMessages.java TextStreamMerger.java LineComparator.java Log Message: Patched version of org.eclipse.compare --- NEW FILE: MergeMessages.java --- /******************************************************************************* * Copyright (c) 2000, 2005 IBM Corporation and others. * 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: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.compare.internal.merge; import org.eclipse.osgi.util.NLS; public final class MergeMessages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.compare.internal.merge.MergeMessages";//$NON-NLS-1$ private MergeMessages() { // Do not instantiate } public static String TextAutoMerge_inputEncodingError; public static String TextAutoMerge_outputEncodingError; public static String TextAutoMerge_outputIOError; public static String TextAutoMerge_conflict; static { NLS.initializeMessages(BUNDLE_NAME, MergeMessages.class); } } --- NEW FILE: MergeMessages.properties --- ############################################################################### # Copyright (c) 2004 IBM Corporation and others. # 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: # 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 --- NEW FILE: TextStreamMerger.java --- /******************************************************************************* * Copyright (c) 2003, 2004 IBM Corporation and others. * 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: * IBM Corporation - initial API and implementation *******************************************************************************/ 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 TextStreamMerger 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(IStatus.ERROR, CompareUI.PLUGIN_ID, 1, MergeMessages.TextAutoMerge_inputEncodingError, e); } try { String lineSeparator= System.getProperty("line.separator"); //$NON-NLS-1$ if (lineSeparator == null) lineSeparator= "\n"; //$NON-NLS-1$ 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.getBytes(outputEncoding)); } 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.getBytes(outputEncoding)); } break; case RangeDifference.CONFLICT: return new Status(IStatus.ERROR, CompareUI.PLUGIN_ID, CONFLICT, MergeMessages.TextAutoMerge_conflict, null); default: break; } } } catch (UnsupportedEncodingException e) { return new Status(IStatus.ERROR, CompareUI.PLUGIN_ID, 1, MergeMessages.TextAutoMerge_outputEncodingError, e); } catch (IOException e) { return new Status(IStatus.ERROR, CompareUI.PLUGIN_ID, 1, MergeMessages.TextAutoMerge_outputIOError, e); } return Status.OK_STATUS; } } --- NEW FILE: LineComparator.java --- /******************************************************************************* * Copyright (c) 2004 IBM Corporation and others. * 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: * 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) { // silently ignored } // 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; } } |