From fa99b4cc4482aeeaf7b19b2372078d5f16998138 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Mon, 14 Mar 2005 08:56:48 +0000 Subject: [PATCH] Make use the protocol directly, when possible. Also, did the command attribute actually work? PR: 26632 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277913 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 3 ++ docs/manual/OptionalTasks/rexec.html | 11 +++-- .../ant/taskdefs/optional/net/RExecTask.java | 45 +++++++++++++------ 3 files changed, 43 insertions(+), 16 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 57b8a9fab..4771b4229 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -257,6 +257,9 @@ Other changes: * Ant generated jar files should now be detected as jar files by Solaris. Bugzilla Report 32649. +* with a single command should now work with unusal login + dialogs without special read/write pairs. Bugzilla Report 26632. + Fixed bugs: ----------- diff --git a/docs/manual/OptionalTasks/rexec.html b/docs/manual/OptionalTasks/rexec.html index be680b840..9403fd7a3 100644 --- a/docs/manual/OptionalTasks/rexec.html +++ b/docs/manual/OptionalTasks/rexec.html @@ -17,6 +17,11 @@ it uses nested <read> to indicate strings to wait for, and

Note: This task depends on external libraries not included in the Ant distribution. See Library Dependencies for more information.

+

You can specify the commands you want to execute as nested elements +or via the command attribute, we recommend you use the command +attribute. If you use the command attribute, you must use the +username and password attributes as well.

+

Parameters

@@ -27,12 +32,12 @@ See Library Dependencies for m - + - + @@ -42,7 +47,7 @@ See Library Dependencies for m - + diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/net/RExecTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/net/RExecTask.java index d2668621a..5cc8b645a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/net/RExecTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/net/RExecTask.java @@ -350,23 +350,20 @@ public class RExecTask extends Task { } catch (IOException e) { throw new BuildException("Can't connect to " + server); } - /** Login if userid and password were specified */ - if (userid != null && password != null) { - login(rexec); - } - /** Process each sub command */ - Enumeration tasksToRun = rexecTasks.elements(); - while (tasksToRun != null && tasksToRun.hasMoreElements()) { - RExecSubTask task = (RExecSubTask) tasksToRun.nextElement(); - if (task instanceof RExecRead && defaultTimeout != null) { - ((RExecRead) task).setDefaultTimeout(defaultTimeout); - } - task.execute(rexec); + if (userid != null && password != null && command != null + && rexecTasks.size() == 0) { + // simple one-shot execution + rexec.rexec(userid, password, command); + } else { + // need nested read/write elements + handleMultipleTasks(rexec); } /** Keep reading input stream until end of it or time-out */ rexec.waitForEOF(defaultTimeout); - } finally { + } catch (IOException e) { + throw new BuildException("Error r-executing command", e); + } finally { if (rexec != null && rexec.isConnected()) { try { rexec.disconnect(); @@ -446,4 +443,26 @@ public class RExecTask extends Task { public void setUserid(String u) { this.userid = u; } + + /** + * Deals with multiple read/write calls. + * + * @since Ant 1.6.3 + */ + private void handleMultipleTasks(AntRExecClient rexec) { + + /** Login if userid and password were specified */ + if (userid != null && password != null) { + login(rexec); + } + /** Process each sub command */ + Enumeration tasksToRun = rexecTasks.elements(); + while (tasksToRun != null && tasksToRun.hasMoreElements()) { + RExecSubTask task = (RExecSubTask) tasksToRun.nextElement(); + if (task instanceof RExecRead && defaultTimeout != null) { + ((RExecRead) task).setDefaultTimeout(defaultTimeout); + } + task.execute(rexec); + } + } }
userid the login id to use on the remote server.YesNo
password the login password to use on the remote server.YesNo
server
command the command to execute on the remote server.YesNo
port