Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2007-01-18 17:13:46 +0000
committerMichael Valenta2007-01-18 17:13:46 +0000
commita73a586dc54c826ca6f580e3460f09abbfd4c1a6 (patch)
tree5987fb92276f3430a55d6886d92398327b2e3f37
parente920d4a87ef1ed8e3277bc110f940ada508cb715 (diff)
downloadeclipse.platform.team-a73a586dc54c826ca6f580e3460f09abbfd4c1a6.tar.gz
eclipse.platform.team-a73a586dc54c826ca6f580e3460f09abbfd4c1a6.tar.xz
eclipse.platform.team-a73a586dc54c826ca6f580e3460f09abbfd4c1a6.zip
Bug 170879 paste patch from clipboard into package explorer
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/CompareWithPatchAction.java22
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Patcher.java2
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/ApplyPatchOperation.java31
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/CompareWithPatchAction.java22
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Patcher.java2
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/ApplyPatchOperation.java31
6 files changed, 68 insertions, 42 deletions
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/CompareWithPatchAction.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/CompareWithPatchAction.java
index 85593d483..c723e8a40 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/CompareWithPatchAction.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/CompareWithPatchAction.java
@@ -10,11 +10,8 @@
*******************************************************************************/
package org.eclipse.compare.internal.patch;
-import java.io.IOException;
-
import org.eclipse.compare.CompareConfiguration;
-import org.eclipse.compare.internal.BaseCompareAction;
-import org.eclipse.compare.internal.Utilities;
+import org.eclipse.compare.internal.*;
import org.eclipse.compare.patch.ApplyPatchOperation;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
@@ -43,19 +40,10 @@ public class CompareWithPatchAction extends BaseCompareAction implements IObject
boolean isPatch = false;
if (firstResource instanceof IFile) {
- IFile file = (IFile)firstResource;
- if (file.exists()) {
- WorkspacePatcher patch = new WorkspacePatcher(null);
- try {
- patch.parse(file);
- if (patch.getDiffs().length > 0) {
- isPatch = true;
- }
- } catch (IOException e) {
- // Ignore
- } catch (CoreException e) {
- // Ignore
- }
+ try {
+ isPatch = ApplyPatchOperation.isPatch((IFile)firstResource);
+ } catch (CoreException e) {
+ CompareUIPlugin.log(e);
}
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Patcher.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Patcher.java
index 914dad1c3..6c9b55d6d 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Patcher.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Patcher.java
@@ -130,7 +130,7 @@ public class Patcher {
}
}
- private static BufferedReader createReader(IStorage storage) throws CoreException {
+ public static BufferedReader createReader(IStorage storage) throws CoreException {
return new BufferedReader(new InputStreamReader(storage.getContents()));
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/ApplyPatchOperation.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/ApplyPatchOperation.java
index c0d1eee65..535428e00 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/ApplyPatchOperation.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/ApplyPatchOperation.java
@@ -1,11 +1,14 @@
package org.eclipse.compare.patch;
+import java.io.BufferedReader;
+import java.io.IOException;
+
import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.internal.ComparePreferencePage;
-import org.eclipse.compare.internal.patch.PatchWizard;
-import org.eclipse.compare.internal.patch.PatchWizardDialog;
+import org.eclipse.compare.internal.CompareUIPlugin;
+import org.eclipse.compare.internal.patch.*;
import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.*;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.ide.IDE;
@@ -53,6 +56,28 @@ public class ApplyPatchOperation implements Runnable {
private String patchWizardTitle;
/**
+ * Return whether the given storage contains a patch.
+ * @param storage the storage
+ * @return whether the given storage contains a patch
+ * @throws CoreException if an error occurs reading the contents from the storage
+ */
+ public static boolean isPatch(IStorage storage) throws CoreException {
+ BufferedReader reader = Patcher.createReader(storage);
+ try {
+ PatchReader patchReader= new PatchReader();
+ patchReader.parse(reader);
+ return patchReader.getDiffs().length > 0;
+ } catch (IOException e) {
+ throw new CoreException(new Status(IStatus.ERROR, CompareUIPlugin.PLUGIN_ID, 0, e.getMessage(), e));
+ } finally {
+ try {
+ reader.close();
+ } catch (IOException e) { //ignored
+ }
+ }
+ }
+
+ /**
* Creates a new ApplyPatchOperation with the supplied compare configuration, patch and target.
* The behaviour of the Apply Patch wizard is controlled by the number of parameters supplied:
* <ul>
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/CompareWithPatchAction.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/CompareWithPatchAction.java
index 85593d483..c723e8a40 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/CompareWithPatchAction.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/CompareWithPatchAction.java
@@ -10,11 +10,8 @@
*******************************************************************************/
package org.eclipse.compare.internal.patch;
-import java.io.IOException;
-
import org.eclipse.compare.CompareConfiguration;
-import org.eclipse.compare.internal.BaseCompareAction;
-import org.eclipse.compare.internal.Utilities;
+import org.eclipse.compare.internal.*;
import org.eclipse.compare.patch.ApplyPatchOperation;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
@@ -43,19 +40,10 @@ public class CompareWithPatchAction extends BaseCompareAction implements IObject
boolean isPatch = false;
if (firstResource instanceof IFile) {
- IFile file = (IFile)firstResource;
- if (file.exists()) {
- WorkspacePatcher patch = new WorkspacePatcher(null);
- try {
- patch.parse(file);
- if (patch.getDiffs().length > 0) {
- isPatch = true;
- }
- } catch (IOException e) {
- // Ignore
- } catch (CoreException e) {
- // Ignore
- }
+ try {
+ isPatch = ApplyPatchOperation.isPatch((IFile)firstResource);
+ } catch (CoreException e) {
+ CompareUIPlugin.log(e);
}
}
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Patcher.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Patcher.java
index 914dad1c3..6c9b55d6d 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Patcher.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Patcher.java
@@ -130,7 +130,7 @@ public class Patcher {
}
}
- private static BufferedReader createReader(IStorage storage) throws CoreException {
+ public static BufferedReader createReader(IStorage storage) throws CoreException {
return new BufferedReader(new InputStreamReader(storage.getContents()));
}
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/ApplyPatchOperation.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/ApplyPatchOperation.java
index c0d1eee65..535428e00 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/ApplyPatchOperation.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/ApplyPatchOperation.java
@@ -1,11 +1,14 @@
package org.eclipse.compare.patch;
+import java.io.BufferedReader;
+import java.io.IOException;
+
import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.internal.ComparePreferencePage;
-import org.eclipse.compare.internal.patch.PatchWizard;
-import org.eclipse.compare.internal.patch.PatchWizardDialog;
+import org.eclipse.compare.internal.CompareUIPlugin;
+import org.eclipse.compare.internal.patch.*;
import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.*;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.ide.IDE;
@@ -53,6 +56,28 @@ public class ApplyPatchOperation implements Runnable {
private String patchWizardTitle;
/**
+ * Return whether the given storage contains a patch.
+ * @param storage the storage
+ * @return whether the given storage contains a patch
+ * @throws CoreException if an error occurs reading the contents from the storage
+ */
+ public static boolean isPatch(IStorage storage) throws CoreException {
+ BufferedReader reader = Patcher.createReader(storage);
+ try {
+ PatchReader patchReader= new PatchReader();
+ patchReader.parse(reader);
+ return patchReader.getDiffs().length > 0;
+ } catch (IOException e) {
+ throw new CoreException(new Status(IStatus.ERROR, CompareUIPlugin.PLUGIN_ID, 0, e.getMessage(), e));
+ } finally {
+ try {
+ reader.close();
+ } catch (IOException e) { //ignored
+ }
+ }
+ }
+
+ /**
* Creates a new ApplyPatchOperation with the supplied compare configuration, patch and target.
* The behaviour of the Apply Patch wizard is controlled by the number of parameters supplied:
* <ul>

Back to the top