Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2003-09-03 19:02:19 +0000
committerMichael Valenta2003-09-03 19:02:19 +0000
commit66e2e4b6162d5409a86a6e27936318720a5c81de (patch)
treebf36a5314f5dbd3cf344803bdc348e4c5aa32820
parenta6035294bc57409e2a0686bd13c342517c332060 (diff)
downloadeclipse.platform.team-66e2e4b6162d5409a86a6e27936318720a5c81de.tar.gz
eclipse.platform.team-66e2e4b6162d5409a86a6e27936318720a5c81de.tar.xz
eclipse.platform.team-66e2e4b6162d5409a86a6e27936318720a5c81de.zip
36637: [CVS EXT] cvs with ext access froze eclipse
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/connection/ExtConnection.java6
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/messages.properties1
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/Util.java73
3 files changed, 75 insertions, 5 deletions
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/connection/ExtConnection.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/connection/ExtConnection.java
index b45b8da64..a7f8d085c 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/connection/ExtConnection.java
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/connection/ExtConnection.java
@@ -18,7 +18,7 @@ import java.io.OutputStream;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
import org.eclipse.team.internal.ccvs.core.IServerConnection;
-import org.eclipse.team.internal.ccvs.core.Policy;
+import org.eclipse.team.internal.ccvs.core.util.Util;
import org.eclipse.team.internal.core.streams.PollingInputStream;
import org.eclipse.team.internal.core.streams.PollingOutputStream;
import org.eclipse.team.internal.core.streams.TimeoutInputStream;
@@ -95,7 +95,7 @@ public class ExtConnection implements IServerConnection {
String[] command = ((CVSRepositoryLocation)location).getExtCommand(password);
boolean connected = false;
try {
- process = Runtime.getRuntime().exec(command);
+ process = Util.createProcess(command, monitor);
inputStream = new PollingInputStream(new TimeoutInputStream(process.getInputStream(),
8192 /*bufferSize*/, 1000 /*readTimeout*/, -1 /*closeTimeout*/), location.getTimeout(), monitor);
@@ -111,7 +111,7 @@ public class ExtConnection implements IServerConnection {
try {
close();
} finally {
- throw new IOException(Policy.bind("EXTServerConnection.ioError", command[0])); //$NON-NLS-1$
+ // Ignore any exceptions during close
}
}
}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/messages.properties b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/messages.properties
index 10748d5bf..3e08ef595 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/messages.properties
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/messages.properties
@@ -232,6 +232,7 @@ ProjectDescriptionContentHandler.xml=Error parsing project description file
Util.invalidResource=Resource {1} is not relative to root {0}
Util.timeout=A timeout occurred connecting to host {0}
+Util.processTimeout=A timeout occurred executing command ''{0}''
Util.truncatedPath=...{0}
Synchronizer.reload=Examining {0}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/Util.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/Util.java
index 0fbda031b..3d90f555f 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/Util.java
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/Util.java
@@ -168,8 +168,7 @@ public class Util {
/**
* Helper method that will time out when making a socket connection.
- * This i
- * s required because there is no way to provide a timeout value
+ * This is required because there is no way to provide a timeout value
* when creating a socket and in some instances, they don't seem to
* timeout at all.
*/
@@ -242,6 +241,76 @@ public class Util {
return socket[0];
}
+ /**
+ * Helper method that will time out when running an external command.
+ * This is required because there is no way to provide a timeout value
+ * when executing an external command and in some instances, they don't seem to
+ * timeout at all.
+ */
+ public static Process createProcess(final String[] command, IProgressMonitor monitor) throws IOException {
+
+ // Start a thread to execute the command and get a handle to the process
+ final Process[] process = new Process[] { null };
+ final Exception[] exception = new Exception[] {null };
+ final Thread thread = new Thread(new Runnable() {
+ public void run() {
+ try {
+ Process newProcess = Runtime.getRuntime().exec(command);
+ synchronized (process) {
+ if (Thread.interrupted()) {
+ // we we're either cancelled or timed out so just destroy the process
+ newProcess.destroy();
+ } else {
+ process[0] = newProcess;
+ }
+ }
+ } catch (IOException e) {
+ exception[0] = e;
+ }
+ }
+ });
+ thread.start();
+
+ // Wait the appropriate number of seconds
+ int timeout = CVSProviderPlugin.getPlugin().getTimeout();
+ if (timeout == 0) timeout = CVSProviderPlugin.DEFAULT_TIMEOUT;
+ for (int i = 0; i < timeout; i++) {
+ try {
+ // wait for the thread to complete or 1 second, which ever comes first
+ thread.join(1000);
+ } catch (InterruptedException e) {
+ // I think this means the thread was interupted but not necessarily timed out
+ // so we don't need to do anything
+ }
+ synchronized (process) {
+ // if the user cancelled, clean up before preempting the operation
+ if (monitor.isCanceled()) {
+ if (thread.isAlive()) {
+ thread.interrupt();
+ }
+ if (process[0] != null) {
+ process[0].destroy();
+ }
+ // this method will throw the proper exception
+ Policy.checkCanceled(monitor);
+ }
+ }
+ }
+ // If the thread is still running (i.e. we timed out) signal that it is too late
+ synchronized (process) {
+ if (thread.isAlive()) {
+ thread.interrupt();
+ }
+ }
+ if (exception[0] != null) {
+ throw (IOException)exception[0];
+ }
+ if (process[0] == null) {
+ throw new InterruptedIOException(Policy.bind("Util.processTimeout", command[0])); //$NON-NLS-1$
+ }
+ return process[0];
+ }
+
public static String[] parseIntoSubstrings(String string, String delimiter) {
List result = new ArrayList();
int start = 0;

Back to the top