1 11 package org.eclipse.team.internal.ui.mapping; 12 13 import java.io.*; 14 15 import org.eclipse.compare.CompareUI; 16 import org.eclipse.compare.rangedifferencer.RangeDifference; 17 import org.eclipse.compare.rangedifferencer.RangeDifferencer; 18 import org.eclipse.core.resources.IStorage; 19 import org.eclipse.core.runtime.*; 20 import org.eclipse.team.core.mapping.IStorageMerger; 21 import org.eclipse.team.internal.ui.TeamUIMessages; 22 23 public class TextStorageMerger implements IStorageMerger { 24 25 public IStatus merge(OutputStream output, String outputEncoding, 26 IStorage ancestor, IStorage target, IStorage other, 27 IProgressMonitor monitor) throws CoreException { 28 29 LineComparator a, t, o; 30 31 try { 32 a= LineComparator.create(ancestor, outputEncoding); 33 t= LineComparator.create(target, outputEncoding); 34 o= LineComparator.create(other,outputEncoding); 35 } catch (UnsupportedEncodingException e) { 36 throw new CoreException (new Status(IStatus.ERROR, CompareUI.PLUGIN_ID, UNSUPPORTED_ENCODING, TeamUIMessages.TextAutoMerge_inputEncodingError, e)); 37 } 38 39 try { 40 boolean firstLine = true; 41 String lineSeparator= System.getProperty("line.separator"); if (lineSeparator == null) 43 lineSeparator= "\n"; 45 RangeDifference[] diffs= RangeDifferencer.findRanges(monitor, a, t, o); 46 47 for (int i= 0; i < diffs.length; i++) { 48 RangeDifference rd= diffs[i]; 49 switch (rd.kind()) { 50 case RangeDifference.ANCESTOR: case RangeDifference.NOCHANGE: 52 case RangeDifference.RIGHT: 53 for (int j= rd.rightStart(); j < rd.rightEnd(); j++) { 54 String s= o.getLine(j); 55 if (!firstLine) 56 output.write(lineSeparator.getBytes(outputEncoding)); 57 output.write(s.getBytes(outputEncoding)); 58 firstLine = false; 59 } 60 break; 61 62 case RangeDifference.LEFT: 63 for (int j= rd.leftStart(); j < rd.leftEnd(); j++) { 64 String s= t.getLine(j); 65 if (!firstLine) 66 output.write(lineSeparator.getBytes(outputEncoding)); 67 output.write(s.getBytes(outputEncoding)); 68 firstLine = false; 69 } 70 break; 71 72 case RangeDifference.CONFLICT: 73 return new Status(IStatus.WARNING, CompareUI.PLUGIN_ID, CONFLICT, TeamUIMessages.TextAutoMerge_conflict, null); 74 75 default: 76 break; 77 } 78 } 79 80 } catch (UnsupportedEncodingException e) { 81 throw new CoreException (new Status(IStatus.ERROR, CompareUI.PLUGIN_ID, UNSUPPORTED_ENCODING, TeamUIMessages.TextAutoMerge_outputEncodingError, e)); 82 } catch (IOException e) { 83 return new Status(IStatus.ERROR, CompareUI.PLUGIN_ID, INTERNAL_ERROR, TeamUIMessages.TextAutoMerge_outputIOError, e); 84 } 85 86 return Status.OK_STATUS; 87 } 88 89 92 public boolean canMergeWithoutAncestor() { 93 return false; 94 } 95 96 } 97 | Popular Tags |