Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndre Weinand2002-02-08 19:15:10 +0000
committerAndre Weinand2002-02-08 19:15:10 +0000
commit25a43f5b4fcaf5a8987733bd500dd558f183bec9 (patch)
treef22b57c86517b4485fabb234a60746f20c36ce6d /bundles/org.eclipse.compare
parent6e3dcf6ca6b671c0f802dd6183d7461a8aee2124 (diff)
downloadeclipse.platform.team-25a43f5b4fcaf5a8987733bd500dd558f183bec9.tar.gz
eclipse.platform.team-25a43f5b4fcaf5a8987733bd500dd558f183bec9.tar.xz
eclipse.platform.team-25a43f5b4fcaf5a8987733bd500dd558f183bec9.zip
patch improvements
Diffstat (limited to 'bundles/org.eclipse.compare')
-rw-r--r--bundles/org.eclipse.compare/buildnotes_compare.html1
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareUI.java12
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java12
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/Diff.java17
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/Hunk.java25
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/InputPatchPage.java9
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/LineReader.java3
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/PatchWizard.java50
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/Patcher.java177
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/PreviewPatchPage.java29
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/buildnotes_compare.html1
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareUI.java12
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java12
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/Diff.java17
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/Hunk.java25
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/InputPatchPage.java9
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/LineReader.java3
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/PatchWizard.java50
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/Patcher.java177
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/PreviewPatchPage.java29
20 files changed, 546 insertions, 124 deletions
diff --git a/bundles/org.eclipse.compare/buildnotes_compare.html b/bundles/org.eclipse.compare/buildnotes_compare.html
index 3aa7c29c3..7440921f7 100644
--- a/bundles/org.eclipse.compare/buildnotes_compare.html
+++ b/bundles/org.eclipse.compare/buildnotes_compare.html
@@ -15,6 +15,7 @@ Eclipse Build Input February ??th 2002
<h2>
What's new in this drop</h2>
+No more basic icons.
<h3>
API changes</h3>
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareUI.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareUI.java
index 301e06e80..5a39d9dc2 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareUI.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareUI.java
@@ -34,6 +34,16 @@ import org.eclipse.compare.structuremergeviewer.IStructureCreator;
*/
public final class CompareUI {
+ /** Image descriptors for the 'Next' tool bar button. */
+ public static final ImageDescriptor DESC_DTOOL_NEXT= CompareUIPlugin.getImageDescriptor(CompareUIPlugin.DTOOL_NEXT);
+ public static final ImageDescriptor DESC_CTOOL_NEXT= CompareUIPlugin.getImageDescriptor(CompareUIPlugin.CTOOL_NEXT);
+ public static final ImageDescriptor DESC_ETOOL_NEXT= CompareUIPlugin.getImageDescriptor(CompareUIPlugin.ETOOL_NEXT);
+
+ /** Image descriptors for the 'Previous' tool bar button. */
+ public static final ImageDescriptor DESC_DTOOL_PREV= CompareUIPlugin.getImageDescriptor(CompareUIPlugin.DTOOL_PREV);
+ public static final ImageDescriptor DESC_CTOOL_PREV= CompareUIPlugin.getImageDescriptor(CompareUIPlugin.CTOOL_PREV);
+ public static final ImageDescriptor DESC_ETOOL_PREV= CompareUIPlugin.getImageDescriptor(CompareUIPlugin.ETOOL_PREV);
+
/**
* Name of the title property of a compare viewer.
* If a property with this name is set
@@ -110,7 +120,7 @@ public final class CompareUI {
public static Image getImage(String type) {
return CompareUIPlugin.getImage(type);
}
-
+
/**
* Registers the given image for being disposed when this plug-in is shutdown.
*
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 30ad36cc7..4c56ee5e5 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
@@ -48,7 +48,15 @@ import org.eclipse.ui.plugin.AbstractUIPlugin;
* </p>
*/
public final class CompareUIPlugin extends AbstractUIPlugin {
-
+
+ public static final String DTOOL_NEXT= "dlcl16/next_nav.gif"; //$NON-NLS-1$
+ public static final String CTOOL_NEXT= "clcl16/next_nav.gif"; //$NON-NLS-1$
+ public static final String ETOOL_NEXT= "elcl16/next_nav.gif"; //$NON-NLS-1$
+
+ public static final String DTOOL_PREV= "dlcl16/prev_nav.gif"; //$NON-NLS-1$
+ public static final String CTOOL_PREV= "clcl16/prev_nav.gif"; //$NON-NLS-1$
+ public static final String ETOOL_PREV= "elcl16/prev_nav.gif"; //$NON-NLS-1$
+
private static boolean NORMALIZE_CASE= true;
private final static String CLASS_ATTRIBUTE= "class"; //$NON-NLS-1$
@@ -347,7 +355,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
}
public static ImageDescriptor getImageDescriptor(String relativePath) {
-
+
URL installURL= null;
if (fgComparePlugin != null)
installURL= fgComparePlugin.getDescriptor().getInstallURL();
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/Diff.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/Diff.java
index 17d06f4b5..77dc42e28 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/Diff.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/Diff.java
@@ -18,6 +18,7 @@ import org.eclipse.compare.structuremergeviewer.Differencer;
List fHunks= new ArrayList();
boolean fIsEnabled= true;
String fRejected;
+
/* package */ Diff(IPath oldPath, long oldDate, IPath newPath, long newDate) {
fOldPath= oldPath;
@@ -26,6 +27,22 @@ import org.eclipse.compare.structuremergeviewer.Differencer;
fNewDate= newPath == null ? 0 : newDate;
}
+ void reverse() {
+ IPath tp= fOldPath;
+ fOldPath= fNewPath;
+ fNewPath= tp;
+
+ long t= fOldDate;
+ fOldDate= fNewDate;
+ fNewDate= t;
+
+ Iterator iter= fHunks.iterator();
+ while (iter.hasNext()) {
+ Hunk hunk= (Hunk) iter.next();
+ hunk.reverse();
+ }
+ }
+
Hunk[] getHunks() {
return (Hunk[]) fHunks.toArray((Hunk[]) new Hunk[fHunks.size()]);
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/Hunk.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/Hunk.java
index e72586fb9..6620af3a5 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/Hunk.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/Hunk.java
@@ -41,6 +41,31 @@ import org.eclipse.jface.util.Assert;
fLines= (String[]) lines.toArray(new String[lines.size()]);
}
+ void reverse() {
+ int t= fOldStart;
+ fOldStart= fNewStart;
+ fNewStart= t;
+
+ t= fOldLength;
+ fOldLength= fNewLength;
+ fNewLength= t;
+
+ for (int i= 0; i < fLines.length; i++) {
+ String line= fLines[i];
+ char c= line.charAt(0);
+ switch (c) {
+ case '+':
+ fLines[i]= '-' + line.substring(1);
+ break;
+ case '-':
+ fLines[i]= '+' + line.substring(1);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
/**
* Returns the contents of this hunk.
* Each line starts with a control character. Their meaning is as follows:
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/InputPatchPage.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/InputPatchPage.java
index e43ed752e..c0535baf3 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/InputPatchPage.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/InputPatchPage.java
@@ -165,16 +165,17 @@ import org.eclipse.compare.internal.Utilities;
// guess prefix count
for (int i= 0; i < diffs.length; i++) {
IPath p= diffs[i].fOldPath;
- int matches= match(p, list);
- if (matches > 0) {
- return p.segmentCount() - matches;
+ if (p != null) {
+ int matches= match(p, list);
+ if (matches > 0) {
+ return p.segmentCount() - matches;
+ }
}
}
return 0;
}
private int match(IPath path, ArrayList list) {
- System.out.println("match: " + path);
Iterator iter= list.iterator();
while (iter.hasNext()) {
IPath filePath= (IPath) iter.next();
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/LineReader.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/LineReader.java
index 69c15509e..4306e63ea 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/LineReader.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/LineReader.java
@@ -7,6 +7,8 @@ package org.eclipse.compare.patch;
import java.io.*;
import java.util.*;
+import org.eclipse.jface.util.Assert;
+
/* package */ class LineReader {
private boolean fHaveChar= false;
@@ -16,6 +18,7 @@ import java.util.*;
/* package */ LineReader(BufferedReader reader) {
fReader= reader;
+ Assert.isNotNull(reader);
}
/**
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/PatchWizard.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/PatchWizard.java
index 808535a49..8fc93f312 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/PatchWizard.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/PatchWizard.java
@@ -11,6 +11,7 @@ import org.eclipse.jface.viewers.*;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.compare.*;
import org.eclipse.compare.internal.*;
@@ -86,28 +87,33 @@ import org.eclipse.compare.structuremergeviewer.Differencer;
*/
public boolean performFinish() {
- CompareConfiguration cc= new CompareConfiguration() {
- public Image getImage(int kind) {
- if (kind == Differencer.ADDITION)
- kind= Differencer.DELETION;
- else if (kind == Differencer.DELETION)
- kind= Differencer.ADDITION;
- return super.getImage(kind);
- }
- public Image getImage(Image base, int kind) {
- if (kind == Differencer.ADDITION)
- kind= Differencer.DELETION;
- else if (kind == Differencer.DELETION)
- kind= Differencer.ADDITION;
- return super.getImage(base, kind);
- }
- };
- cc.setProperty(CompareEditor.CONFIRM_SAVE_PROPERTY, new Boolean(false));
-
- fPatcher.setName(fPatchWizardPage.getPatchName());
-
- CompareUI.openCompareEditor(new PatchCompareInput(cc, fPatcher, new StructuredSelection(fTarget)));
-
+ if (false) {
+ CompareConfiguration cc= new CompareConfiguration() {
+ public Image getImage(int kind) {
+ if (kind == Differencer.ADDITION)
+ kind= Differencer.DELETION;
+ else if (kind == Differencer.DELETION)
+ kind= Differencer.ADDITION;
+ return super.getImage(kind);
+ }
+ public Image getImage(Image base, int kind) {
+ if (kind == Differencer.ADDITION)
+ kind= Differencer.DELETION;
+ else if (kind == Differencer.DELETION)
+ kind= Differencer.ADDITION;
+ return super.getImage(base, kind);
+ }
+ };
+ cc.setProperty(CompareEditor.CONFIRM_SAVE_PROPERTY, new Boolean(false));
+
+ fPatcher.setName(fPatchWizardPage.getPatchName());
+
+ CompareUI.openCompareEditor(new PatchCompareInput(cc, fPatcher, new StructuredSelection(fTarget)));
+ } else {
+ fPatcher.setName(fPatchWizardPage.getPatchName());
+ fPatcher.applyAll(getTarget(), new NullProgressMonitor());
+ }
+
// Save the dialog settings
if (fHasNewDialogSettings) {
IDialogSettings workbenchSettings= CompareUIPlugin.getDefault().getDialogSettings();
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/Patcher.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/Patcher.java
index 81bf4f276..36f8ac677 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/Patcher.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/Patcher.java
@@ -7,6 +7,10 @@ import java.util.*;
import org.eclipse.jface.util.Assert;
import org.eclipse.core.runtime.*;
+import org.eclipse.core.resources.*;
+
+import org.eclipse.compare.structuremergeviewer.Differencer;
+
/**
* A Patcher
@@ -16,6 +20,8 @@ import org.eclipse.core.runtime.*;
*/
public class Patcher {
+ private static final boolean DEBUG= false;
+
private static final String DEV_NULL= "/dev/null"; //$NON-NLS-1$
// diff formats
@@ -100,6 +106,10 @@ public class Patcher {
boolean setReversed(boolean reverse) {
if (fReverse != reverse) {
fReverse= reverse;
+
+ for (int i= 0; i < fDiffs.length; i++)
+ fDiffs[i].reverse();
+
return true;
}
return false;
@@ -243,7 +253,7 @@ public class Patcher {
int a1= c, a2= 0;
if (line.length() > 1)
a2= line.charAt(1);
- System.out.println("char: " + a1 + " " + a2);
+ if (DEBUG) System.out.println("char: " + a1 + " " + a2);
break;
}
return line;
@@ -513,7 +523,7 @@ public class Patcher {
if (pos >= 0)
path= path.substring(0, pos);
if (path2 != null && !path2.equals(path)) {
- // System.out.println("path mismatch: " + path2);
+ if (DEBUG) System.out.println("path mismatch: " + path2);
path= path2;
}
return new Path(path);
@@ -534,13 +544,13 @@ public class Patcher {
pair[0]= pair[1]= -1;
int startPos= line.indexOf(start);
if (startPos < 0) {
- System.out.println("parsing error in extractPair: couldn't find \'" + start + "\'");
+ if (DEBUG) System.out.println("parsing error in extractPair: couldn't find \'" + start + "\'");
return;
}
line= line.substring(startPos+1);
int endPos= line.indexOf(' ');
if (endPos < 0) {
- System.out.println("parsing error in extractPair: couldn't find end blank");
+ if (DEBUG) System.out.println("parsing error in extractPair: couldn't find end blank");
return;
}
line= line.substring(0, endPos);
@@ -621,11 +631,11 @@ public class Patcher {
}
if (found) {
- System.out.println("patched hunk at offset: " + (shift-oldShift));
+ if (DEBUG) System.out.println("patched hunk at offset: " + (shift-oldShift));
shift+= doPatch(hunk, lines, shift);
} else {
if (failedHunks != null) {
- System.out.println("failed hunk");
+ if (DEBUG) System.out.println("failed hunk");
failedHunks.add(hunk);
}
}
@@ -655,7 +665,7 @@ public class Patcher {
return false;
pos++;
}
- } else if ((!fReverse && controlChar == '-') || (fReverse && controlChar == '+')) {
+ } else if (controlChar == '-') {
// deleted lines
while (true) {
if (pos < 0 || pos >= lines.size())
@@ -669,7 +679,7 @@ public class Patcher {
return false;
pos++;
}
- } else if ((!fReverse && controlChar == '+') || (fReverse && controlChar == '-')) {
+ } else if (controlChar == '+') {
// added lines
// we don't have to do anything for a 'try'
} else
@@ -694,7 +704,7 @@ public class Patcher {
}
pos++;
}
- } else if ((!fReverse && controlChar == '-') || (fReverse && controlChar == '+')) {
+ } else if (controlChar == '-') {
// deleted lines
while (true) {
Assert.isTrue(pos < lines.size(), "doPatch: inconsistency in deleted lines"); //$NON-NLS-1$
@@ -704,7 +714,7 @@ public class Patcher {
pos++;
}
lines.remove(pos);
- } else if ((!fReverse && controlChar == '+') || (fReverse && controlChar == '-')) {
+ } else if (controlChar == '+') {
// added lines
lines.add(pos, line);
pos++;
@@ -714,6 +724,153 @@ public class Patcher {
return hunk.fNewLength - hunk.fOldLength;
}
+ public void applyAll(IResource target, IProgressMonitor pm) {
+
+ if (DEBUG) System.out.println("applyAll: start");
+
+ IContainer container= null;
+ if (target instanceof IContainer)
+ container= (IContainer) target;
+ else {
+ if (DEBUG) System.out.println("applyAll: not yet implemented");
+ return;
+ }
+
+ for (int i= 0; i < fDiffs.length; i++) {
+ Diff diff= fDiffs[i];
+ if (diff.fIsEnabled) {
+
+ IPath path= getPath(diff);
+ IFile file= createPath(container, path);
+
+ int type= diff.getType();
+ switch (type) {
+ case Differencer.ADDITION:
+ if (DEBUG) System.out.println(" add: " + path);
+ updateFile(diff, file, true, pm);
+ break;
+ case Differencer.DELETION:
+ if (DEBUG) System.out.println(" del: " + path);
+ deleteFile(file, pm);
+ break;
+ case Differencer.CHANGE:
+ if (DEBUG) System.out.println(" chg: " + path);
+ updateFile(diff, file, false, pm);
+ break;
+ }
+
+ /*
+ String rej= diff.fRejected;
+ if (rej != null) {
+ IPath pp= path.removeLastSegments(1);
+ pp= pp.append(path.lastSegment() + ".rej");
+ createPath(fRoot, rootFolder, pp, diff, true);
+ }
+ */
+ }
+ if (pm != null)
+ pm.worked(1);
+ }
+
+ try {
+ target.refreshLocal(IResource.DEPTH_INFINITE, pm);
+ } catch (CoreException ex) {
+ if (DEBUG) System.out.println("refreshLocal: exception " + ex);
+ }
+ if (DEBUG) System.out.println("applyAll: end");
+ }
+
+ List apply(Diff diff, IFile file, boolean create, List failedHunks) {
+
+ if (file == null)
+ if (DEBUG) System.out.println(" file == null");
+
+ List lines= null;
+ if (!create) {
+ // read current contents
+ InputStream is= null;
+ try {
+ is= file.getContents();
+ BufferedReader reader= new BufferedReader(new InputStreamReader(is));
+ lines= new LineReader(reader).readLines();
+ if (DEBUG) System.out.println(" creating reader successful");
+ } catch(CoreException ex) {
+ if (DEBUG) System.out.println(" reading contents: " + ex);
+ } finally {
+ if (is != null)
+ try {
+ is.close();
+ } catch(IOException ex) {
+ }
+ }
+ }
+
+ if (lines == null)
+ lines= new ArrayList();
+
+ patch(diff, lines, failedHunks);
+
+ return lines;
+ }
+
+ private void deleteFile(IFile file, IProgressMonitor pm) {
+ try {
+ file.delete(true, true, pm);
+ } catch (CoreException ex) {
+ System.out.println("deleteFile: exception: " + ex);
+ }
+ }
+
+ private void updateFile(Diff diff, IFile file, boolean create, IProgressMonitor pm) {
+
+ if (DEBUG) System.out.println(" updateFile: start");
+
+ // patch it and collect rejected hunks
+ List failed= new ArrayList();
+
+ if (DEBUG) System.out.println(" patching: start");
+ List lines= apply(diff, file, create, failed);
+ if (DEBUG) System.out.println(" patching: end");
+
+ // convert the result into a String
+ StringBuffer sb= new StringBuffer();
+ Iterator iter= lines.iterator();
+ while (iter.hasNext())
+ sb.append((String)iter.next());
+ String contents= sb.toString();
+
+ // and save it
+ InputStream is= new ByteArrayInputStream(contents.getBytes());
+ try {
+ if (file.exists()) {
+ file.setContents(is, false, true, pm);
+ if (DEBUG) System.out.println(" setContents: successfull");
+ } else {
+ file.create(is, false, pm);
+ if (DEBUG) System.out.println(" create: successfull");
+ }
+ } catch (CoreException ex) {
+ if (DEBUG) System.out.println(" exception: " + ex);
+ } finally {
+ if (is != null)
+ try {
+ is.close();
+ } catch(IOException ex) {
+ }
+ }
+ if (DEBUG) System.out.println(" updateFile: end");
+ }
+
+ private IFile createPath(IContainer folder, IPath path) {
+ if (path.segmentCount() > 1) {
+ IFolder f= folder.getFolder(path.uptoSegment(1));
+ //System.out.println("createPath: " + f + " " + f.exists());
+ return createPath(f, path.removeFirstSegments(1));
+ }
+ // a leaf
+ return folder.getFile(path);
+ }
+
private static String stripWhiteSpace(String s) {
StringBuffer sb= new StringBuffer();
int l= s.length();
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/PreviewPatchPage.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/PreviewPatchPage.java
index 83977bd17..952c5615f 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/PreviewPatchPage.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/PreviewPatchPage.java
@@ -371,7 +371,8 @@ import org.eclipse.compare.structuremergeviewer.*;
TreeItem item= children[i];
Diff diff= (Diff) item.getData();
String error= null;
-
+
+ boolean create= false;
IFile file= null;
if (diff.getType() == Differencer.ADDITION) {
IPath p= diff.fNewPath;
@@ -385,6 +386,7 @@ import org.eclipse.compare.structuremergeviewer.*;
diff.fIsEnabled= false;
error= "(file already exists)";
}
+ create= true;
} else {
IPath p= diff.fOldPath;
if (strip > 0 && strip < p.segmentCount())
@@ -404,28 +406,8 @@ import org.eclipse.compare.structuremergeviewer.*;
ArrayList failedHunks= new ArrayList(); // collect rejected hunks here
- java.util.List lines= null;
- InputStream is= null;
- try {
- if (file != null) {
- is= file.getContents();
- BufferedReader reader= new BufferedReader(new InputStreamReader(is));
- lines= new LineReader(reader).readLines();
- }
- } catch(CoreException ex) {
- System.out.println("CoreException: " + ex);
- } finally {
- if (is != null)
- try {
- is.close();
- } catch(IOException ex) {
- }
- }
-
- if (lines == null)
- lines= new ArrayList();
- fPatchWizard.getPatcher().patch(diff, lines, failedHunks);
-
+ fPatchWizard.getPatcher().apply(diff, file, create, failedHunks);
+
if (! failedHunks.isEmpty()) {
StringBuffer sb= new StringBuffer();
Iterator iter= failedHunks.iterator();
@@ -462,6 +444,7 @@ import org.eclipse.compare.structuremergeviewer.*;
if (error != null)
label+= " " + error;
item.setText(label);
+ item.setImage(getImage(diff));
item.setChecked(checked);
boolean gray= (checkedSubs > 0 && checkedSubs < hunkItems.length);
item.setGrayed(gray);
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/buildnotes_compare.html b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/buildnotes_compare.html
index 3aa7c29c3..7440921f7 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/buildnotes_compare.html
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/buildnotes_compare.html
@@ -15,6 +15,7 @@ Eclipse Build Input February ??th 2002
<h2>
What's new in this drop</h2>
+No more basic icons.
<h3>
API changes</h3>
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareUI.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareUI.java
index 301e06e80..5a39d9dc2 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareUI.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareUI.java
@@ -34,6 +34,16 @@ import org.eclipse.compare.structuremergeviewer.IStructureCreator;
*/
public final class CompareUI {
+ /** Image descriptors for the 'Next' tool bar button. */
+ public static final ImageDescriptor DESC_DTOOL_NEXT= CompareUIPlugin.getImageDescriptor(CompareUIPlugin.DTOOL_NEXT);
+ public static final ImageDescriptor DESC_CTOOL_NEXT= CompareUIPlugin.getImageDescriptor(CompareUIPlugin.CTOOL_NEXT);
+ public static final ImageDescriptor DESC_ETOOL_NEXT= CompareUIPlugin.getImageDescriptor(CompareUIPlugin.ETOOL_NEXT);
+
+ /** Image descriptors for the 'Previous' tool bar button. */
+ public static final ImageDescriptor DESC_DTOOL_PREV= CompareUIPlugin.getImageDescriptor(CompareUIPlugin.DTOOL_PREV);
+ public static final ImageDescriptor DESC_CTOOL_PREV= CompareUIPlugin.getImageDescriptor(CompareUIPlugin.CTOOL_PREV);
+ public static final ImageDescriptor DESC_ETOOL_PREV= CompareUIPlugin.getImageDescriptor(CompareUIPlugin.ETOOL_PREV);
+
/**
* Name of the title property of a compare viewer.
* If a property with this name is set
@@ -110,7 +120,7 @@ public final class CompareUI {
public static Image getImage(String type) {
return CompareUIPlugin.getImage(type);
}
-
+
/**
* Registers the given image for being disposed when this plug-in is shutdown.
*
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java
index 30ad36cc7..4c56ee5e5 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java
@@ -48,7 +48,15 @@ import org.eclipse.ui.plugin.AbstractUIPlugin;
* </p>
*/
public final class CompareUIPlugin extends AbstractUIPlugin {
-
+
+ public static final String DTOOL_NEXT= "dlcl16/next_nav.gif"; //$NON-NLS-1$
+ public static final String CTOOL_NEXT= "clcl16/next_nav.gif"; //$NON-NLS-1$
+ public static final String ETOOL_NEXT= "elcl16/next_nav.gif"; //$NON-NLS-1$
+
+ public static final String DTOOL_PREV= "dlcl16/prev_nav.gif"; //$NON-NLS-1$
+ public static final String CTOOL_PREV= "clcl16/prev_nav.gif"; //$NON-NLS-1$
+ public static final String ETOOL_PREV= "elcl16/prev_nav.gif"; //$NON-NLS-1$
+
private static boolean NORMALIZE_CASE= true;
private final static String CLASS_ATTRIBUTE= "class"; //$NON-NLS-1$
@@ -347,7 +355,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
}
public static ImageDescriptor getImageDescriptor(String relativePath) {
-
+
URL installURL= null;
if (fgComparePlugin != null)
installURL= fgComparePlugin.getDescriptor().getInstallURL();
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/Diff.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/Diff.java
index 17d06f4b5..77dc42e28 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/Diff.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/Diff.java
@@ -18,6 +18,7 @@ import org.eclipse.compare.structuremergeviewer.Differencer;
List fHunks= new ArrayList();
boolean fIsEnabled= true;
String fRejected;
+
/* package */ Diff(IPath oldPath, long oldDate, IPath newPath, long newDate) {
fOldPath= oldPath;
@@ -26,6 +27,22 @@ import org.eclipse.compare.structuremergeviewer.Differencer;
fNewDate= newPath == null ? 0 : newDate;
}
+ void reverse() {
+ IPath tp= fOldPath;
+ fOldPath= fNewPath;
+ fNewPath= tp;
+
+ long t= fOldDate;
+ fOldDate= fNewDate;
+ fNewDate= t;
+
+ Iterator iter= fHunks.iterator();
+ while (iter.hasNext()) {
+ Hunk hunk= (Hunk) iter.next();
+ hunk.reverse();
+ }
+ }
+
Hunk[] getHunks() {
return (Hunk[]) fHunks.toArray((Hunk[]) new Hunk[fHunks.size()]);
}
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/Hunk.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/Hunk.java
index e72586fb9..6620af3a5 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/Hunk.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/Hunk.java
@@ -41,6 +41,31 @@ import org.eclipse.jface.util.Assert;
fLines= (String[]) lines.toArray(new String[lines.size()]);
}
+ void reverse() {
+ int t= fOldStart;
+ fOldStart= fNewStart;
+ fNewStart= t;
+
+ t= fOldLength;
+ fOldLength= fNewLength;
+ fNewLength= t;
+
+ for (int i= 0; i < fLines.length; i++) {
+ String line= fLines[i];
+ char c= line.charAt(0);
+ switch (c) {
+ case '+':
+ fLines[i]= '-' + line.substring(1);
+ break;
+ case '-':
+ fLines[i]= '+' + line.substring(1);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
/**
* Returns the contents of this hunk.
* Each line starts with a control character. Their meaning is as follows:
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/InputPatchPage.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/InputPatchPage.java
index e43ed752e..c0535baf3 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/InputPatchPage.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/InputPatchPage.java
@@ -165,16 +165,17 @@ import org.eclipse.compare.internal.Utilities;
// guess prefix count
for (int i= 0; i < diffs.length; i++) {
IPath p= diffs[i].fOldPath;
- int matches= match(p, list);
- if (matches > 0) {
- return p.segmentCount() - matches;
+ if (p != null) {
+ int matches= match(p, list);
+ if (matches > 0) {
+ return p.segmentCount() - matches;
+ }
}
}
return 0;
}
private int match(IPath path, ArrayList list) {
- System.out.println("match: " + path);
Iterator iter= list.iterator();
while (iter.hasNext()) {
IPath filePath= (IPath) iter.next();
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/LineReader.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/LineReader.java
index 69c15509e..4306e63ea 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/LineReader.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/LineReader.java
@@ -7,6 +7,8 @@ package org.eclipse.compare.patch;
import java.io.*;
import java.util.*;
+import org.eclipse.jface.util.Assert;
+
/* package */ class LineReader {
private boolean fHaveChar= false;
@@ -16,6 +18,7 @@ import java.util.*;
/* package */ LineReader(BufferedReader reader) {
fReader= reader;
+ Assert.isNotNull(reader);
}
/**
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/PatchWizard.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/PatchWizard.java
index 808535a49..8fc93f312 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/PatchWizard.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/PatchWizard.java
@@ -11,6 +11,7 @@ import org.eclipse.jface.viewers.*;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.compare.*;
import org.eclipse.compare.internal.*;
@@ -86,28 +87,33 @@ import org.eclipse.compare.structuremergeviewer.Differencer;
*/
public boolean performFinish() {
- CompareConfiguration cc= new CompareConfiguration() {
- public Image getImage(int kind) {
- if (kind == Differencer.ADDITION)
- kind= Differencer.DELETION;
- else if (kind == Differencer.DELETION)
- kind= Differencer.ADDITION;
- return super.getImage(kind);
- }
- public Image getImage(Image base, int kind) {
- if (kind == Differencer.ADDITION)
- kind= Differencer.DELETION;
- else if (kind == Differencer.DELETION)
- kind= Differencer.ADDITION;
- return super.getImage(base, kind);
- }
- };
- cc.setProperty(CompareEditor.CONFIRM_SAVE_PROPERTY, new Boolean(false));
-
- fPatcher.setName(fPatchWizardPage.getPatchName());
-
- CompareUI.openCompareEditor(new PatchCompareInput(cc, fPatcher, new StructuredSelection(fTarget)));
-
+ if (false) {
+ CompareConfiguration cc= new CompareConfiguration() {
+ public Image getImage(int kind) {
+ if (kind == Differencer.ADDITION)
+ kind= Differencer.DELETION;
+ else if (kind == Differencer.DELETION)
+ kind= Differencer.ADDITION;
+ return super.getImage(kind);
+ }
+ public Image getImage(Image base, int kind) {
+ if (kind == Differencer.ADDITION)
+ kind= Differencer.DELETION;
+ else if (kind == Differencer.DELETION)
+ kind= Differencer.ADDITION;
+ return super.getImage(base, kind);
+ }
+ };
+ cc.setProperty(CompareEditor.CONFIRM_SAVE_PROPERTY, new Boolean(false));
+
+ fPatcher.setName(fPatchWizardPage.getPatchName());
+
+ CompareUI.openCompareEditor(new PatchCompareInput(cc, fPatcher, new StructuredSelection(fTarget)));
+ } else {
+ fPatcher.setName(fPatchWizardPage.getPatchName());
+ fPatcher.applyAll(getTarget(), new NullProgressMonitor());
+ }
+
// Save the dialog settings
if (fHasNewDialogSettings) {
IDialogSettings workbenchSettings= CompareUIPlugin.getDefault().getDialogSettings();
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/Patcher.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/Patcher.java
index 81bf4f276..36f8ac677 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/Patcher.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/Patcher.java
@@ -7,6 +7,10 @@ import java.util.*;
import org.eclipse.jface.util.Assert;
import org.eclipse.core.runtime.*;
+import org.eclipse.core.resources.*;
+
+import org.eclipse.compare.structuremergeviewer.Differencer;
+
/**
* A Patcher
@@ -16,6 +20,8 @@ import org.eclipse.core.runtime.*;
*/
public class Patcher {
+ private static final boolean DEBUG= false;
+
private static final String DEV_NULL= "/dev/null"; //$NON-NLS-1$
// diff formats
@@ -100,6 +106,10 @@ public class Patcher {
boolean setReversed(boolean reverse) {
if (fReverse != reverse) {
fReverse= reverse;
+
+ for (int i= 0; i < fDiffs.length; i++)
+ fDiffs[i].reverse();
+
return true;
}
return false;
@@ -243,7 +253,7 @@ public class Patcher {
int a1= c, a2= 0;
if (line.length() > 1)
a2= line.charAt(1);
- System.out.println("char: " + a1 + " " + a2);
+ if (DEBUG) System.out.println("char: " + a1 + " " + a2);
break;
}
return line;
@@ -513,7 +523,7 @@ public class Patcher {
if (pos >= 0)
path= path.substring(0, pos);
if (path2 != null && !path2.equals(path)) {
- // System.out.println("path mismatch: " + path2);
+ if (DEBUG) System.out.println("path mismatch: " + path2);
path= path2;
}
return new Path(path);
@@ -534,13 +544,13 @@ public class Patcher {
pair[0]= pair[1]= -1;
int startPos= line.indexOf(start);
if (startPos < 0) {
- System.out.println("parsing error in extractPair: couldn't find \'" + start + "\'");
+ if (DEBUG) System.out.println("parsing error in extractPair: couldn't find \'" + start + "\'");
return;
}
line= line.substring(startPos+1);
int endPos= line.indexOf(' ');
if (endPos < 0) {
- System.out.println("parsing error in extractPair: couldn't find end blank");
+ if (DEBUG) System.out.println("parsing error in extractPair: couldn't find end blank");
return;
}
line= line.substring(0, endPos);
@@ -621,11 +631,11 @@ public class Patcher {
}
if (found) {
- System.out.println("patched hunk at offset: " + (shift-oldShift));
+ if (DEBUG) System.out.println("patched hunk at offset: " + (shift-oldShift));
shift+= doPatch(hunk, lines, shift);
} else {
if (failedHunks != null) {
- System.out.println("failed hunk");
+ if (DEBUG) System.out.println("failed hunk");
failedHunks.add(hunk);
}
}
@@ -655,7 +665,7 @@ public class Patcher {
return false;
pos++;
}
- } else if ((!fReverse && controlChar == '-') || (fReverse && controlChar == '+')) {
+ } else if (controlChar == '-') {
// deleted lines
while (true) {
if (pos < 0 || pos >= lines.size())
@@ -669,7 +679,7 @@ public class Patcher {
return false;
pos++;
}
- } else if ((!fReverse && controlChar == '+') || (fReverse && controlChar == '-')) {
+ } else if (controlChar == '+') {
// added lines
// we don't have to do anything for a 'try'
} else
@@ -694,7 +704,7 @@ public class Patcher {
}
pos++;
}
- } else if ((!fReverse && controlChar == '-') || (fReverse && controlChar == '+')) {
+ } else if (controlChar == '-') {
// deleted lines
while (true) {
Assert.isTrue(pos < lines.size(), "doPatch: inconsistency in deleted lines"); //$NON-NLS-1$
@@ -704,7 +714,7 @@ public class Patcher {
pos++;
}
lines.remove(pos);
- } else if ((!fReverse && controlChar == '+') || (fReverse && controlChar == '-')) {
+ } else if (controlChar == '+') {
// added lines
lines.add(pos, line);
pos++;
@@ -714,6 +724,153 @@ public class Patcher {
return hunk.fNewLength - hunk.fOldLength;
}
+ public void applyAll(IResource target, IProgressMonitor pm) {
+
+ if (DEBUG) System.out.println("applyAll: start");
+
+ IContainer container= null;
+ if (target instanceof IContainer)
+ container= (IContainer) target;
+ else {
+ if (DEBUG) System.out.println("applyAll: not yet implemented");
+ return;
+ }
+
+ for (int i= 0; i < fDiffs.length; i++) {
+ Diff diff= fDiffs[i];
+ if (diff.fIsEnabled) {
+
+ IPath path= getPath(diff);
+ IFile file= createPath(container, path);
+
+ int type= diff.getType();
+ switch (type) {
+ case Differencer.ADDITION:
+ if (DEBUG) System.out.println(" add: " + path);
+ updateFile(diff, file, true, pm);
+ break;
+ case Differencer.DELETION:
+ if (DEBUG) System.out.println(" del: " + path);
+ deleteFile(file, pm);
+ break;
+ case Differencer.CHANGE:
+ if (DEBUG) System.out.println(" chg: " + path);
+ updateFile(diff, file, false, pm);
+ break;
+ }
+
+ /*
+ String rej= diff.fRejected;
+ if (rej != null) {
+ IPath pp= path.removeLastSegments(1);
+ pp= pp.append(path.lastSegment() + ".rej");
+ createPath(fRoot, rootFolder, pp, diff, true);
+ }
+ */
+ }
+ if (pm != null)
+ pm.worked(1);
+ }
+
+ try {
+ target.refreshLocal(IResource.DEPTH_INFINITE, pm);
+ } catch (CoreException ex) {
+ if (DEBUG) System.out.println("refreshLocal: exception " + ex);
+ }
+ if (DEBUG) System.out.println("applyAll: end");
+ }
+
+ List apply(Diff diff, IFile file, boolean create, List failedHunks) {
+
+ if (file == null)
+ if (DEBUG) System.out.println(" file == null");
+
+ List lines= null;
+ if (!create) {
+ // read current contents
+ InputStream is= null;
+ try {
+ is= file.getContents();
+ BufferedReader reader= new BufferedReader(new InputStreamReader(is));
+ lines= new LineReader(reader).readLines();
+ if (DEBUG) System.out.println(" creating reader successful");
+ } catch(CoreException ex) {
+ if (DEBUG) System.out.println(" reading contents: " + ex);
+ } finally {
+ if (is != null)
+ try {
+ is.close();
+ } catch(IOException ex) {
+ }
+ }
+ }
+
+ if (lines == null)
+ lines= new ArrayList();
+
+ patch(diff, lines, failedHunks);
+
+ return lines;
+ }
+
+ private void deleteFile(IFile file, IProgressMonitor pm) {
+ try {
+ file.delete(true, true, pm);
+ } catch (CoreException ex) {
+ System.out.println("deleteFile: exception: " + ex);
+ }
+ }
+
+ private void updateFile(Diff diff, IFile file, boolean create, IProgressMonitor pm) {
+
+ if (DEBUG) System.out.println(" updateFile: start");
+
+ // patch it and collect rejected hunks
+ List failed= new ArrayList();
+
+ if (DEBUG) System.out.println(" patching: start");
+ List lines= apply(diff, file, create, failed);
+ if (DEBUG) System.out.println(" patching: end");
+
+ // convert the result into a String
+ StringBuffer sb= new StringBuffer();
+ Iterator iter= lines.iterator();
+ while (iter.hasNext())
+ sb.append((String)iter.next());
+ String contents= sb.toString();
+
+ // and save it
+ InputStream is= new ByteArrayInputStream(contents.getBytes());
+ try {
+ if (file.exists()) {
+ file.setContents(is, false, true, pm);
+ if (DEBUG) System.out.println(" setContents: successfull");
+ } else {
+ file.create(is, false, pm);
+ if (DEBUG) System.out.println(" create: successfull");
+ }
+ } catch (CoreException ex) {
+ if (DEBUG) System.out.println(" exception: " + ex);
+ } finally {
+ if (is != null)
+ try {
+ is.close();
+ } catch(IOException ex) {
+ }
+ }
+ if (DEBUG) System.out.println(" updateFile: end");
+ }
+
+ private IFile createPath(IContainer folder, IPath path) {
+ if (path.segmentCount() > 1) {
+ IFolder f= folder.getFolder(path.uptoSegment(1));
+ //System.out.println("createPath: " + f + " " + f.exists());
+ return createPath(f, path.removeFirstSegments(1));
+ }
+ // a leaf
+ return folder.getFile(path);
+ }
+
private static String stripWhiteSpace(String s) {
StringBuffer sb= new StringBuffer();
int l= s.length();
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/PreviewPatchPage.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/PreviewPatchPage.java
index 83977bd17..952c5615f 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/PreviewPatchPage.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/PreviewPatchPage.java
@@ -371,7 +371,8 @@ import org.eclipse.compare.structuremergeviewer.*;
TreeItem item= children[i];
Diff diff= (Diff) item.getData();
String error= null;
-
+
+ boolean create= false;
IFile file= null;
if (diff.getType() == Differencer.ADDITION) {
IPath p= diff.fNewPath;
@@ -385,6 +386,7 @@ import org.eclipse.compare.structuremergeviewer.*;
diff.fIsEnabled= false;
error= "(file already exists)";
}
+ create= true;
} else {
IPath p= diff.fOldPath;
if (strip > 0 && strip < p.segmentCount())
@@ -404,28 +406,8 @@ import org.eclipse.compare.structuremergeviewer.*;
ArrayList failedHunks= new ArrayList(); // collect rejected hunks here
- java.util.List lines= null;
- InputStream is= null;
- try {
- if (file != null) {
- is= file.getContents();
- BufferedReader reader= new BufferedReader(new InputStreamReader(is));
- lines= new LineReader(reader).readLines();
- }
- } catch(CoreException ex) {
- System.out.println("CoreException: " + ex);
- } finally {
- if (is != null)
- try {
- is.close();
- } catch(IOException ex) {
- }
- }
-
- if (lines == null)
- lines= new ArrayList();
- fPatchWizard.getPatcher().patch(diff, lines, failedHunks);
-
+ fPatchWizard.getPatcher().apply(diff, file, create, failedHunks);
+
if (! failedHunks.isEmpty()) {
StringBuffer sb= new StringBuffer();
Iterator iter= failedHunks.iterator();
@@ -462,6 +444,7 @@ import org.eclipse.compare.structuremergeviewer.*;
if (error != null)
label+= " " + error;
item.setText(label);
+ item.setImage(getImage(diff));
item.setChecked(checked);
boolean gray= (checkedSubs > 0 && checkedSubs < hunkItems.length);
item.setGrayed(gray);

Back to the top