From e19a2de440045f14fa2da7a112b8d237bf2abf0f Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Fri, 24 Oct 2003 08:49:11 +0000 Subject: [PATCH] Catch insanely small timeouts (i.e. it occurs before we even start to execute the command), PR 23992 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275563 13f79535-47bb-0310-9956-ffa450edef68 --- .../ant/taskdefs/optional/ssh/SSHExec.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java index 41529abcd..8489cd03e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java @@ -65,6 +65,7 @@ import java.io.IOException; import java.io.StringReader; import com.jcraft.jsch.ChannelExec; +import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; /** @@ -93,6 +94,9 @@ public class SSHExec extends SSHBase { private File outputFile = null; // like private boolean append = false; // like + private static final String TIMEOUT_MESSAGE = + "Timeout period exceeded, connection dropped."; + /** * Constructor for SSHExecTask. */ @@ -205,7 +209,7 @@ public class SSHExec extends SSHBase { if (thread.isAlive()) { // ran out of time thread = null; - log("Timeout period exceeded, connection dropped."); + log(TIMEOUT_MESSAGE, Project.MSG_ERR); } else { // completed successfully if (outputProperty != null) { @@ -227,9 +231,19 @@ public class SSHExec extends SSHBase { } } } - } catch (BuildException e) { throw e; + } catch (JSchException e) { + if (e.getMessage().indexOf("session is down") >= 0) { + log(TIMEOUT_MESSAGE, Project.MSG_ERR); + } else { + if (getFailonerror()) { + throw new BuildException(e); + } else { + log("Caught exception: " + e.getMessage(), + Project.MSG_ERR); + } + } } catch (Exception e) { if (getFailonerror()) { throw new BuildException(e);