git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277906 13f79535-47bb-0310-9956-ffa450edef68master
@@ -83,6 +83,12 @@ public class RExecTask extends Task { | |||
*/ | |||
public class RExecSubTask { | |||
protected String taskString = ""; | |||
/** | |||
* Execute the subtask. | |||
* @param rexec the client | |||
* @throws BuildException always as it is not allowed to instantiate this object | |||
*/ | |||
public void execute(AntRExecClient rexec) | |||
throws BuildException { | |||
throw new BuildException("Shouldn't be able instantiate a SubTask directly"); | |||
@@ -90,6 +96,7 @@ public class RExecTask extends Task { | |||
/** | |||
* the message as nested text | |||
* @param s the nested text | |||
*/ | |||
public void addText(String s) { | |||
setString(getProject().replaceProperties(s)); | |||
@@ -97,6 +104,7 @@ public class RExecTask extends Task { | |||
/** | |||
* the message as an attribute | |||
* @param s a <code>String</code> value | |||
*/ | |||
public void setString(String s) { | |||
taskString += s; | |||
@@ -108,6 +116,11 @@ public class RExecTask extends Task { | |||
*/ | |||
public class RExecWrite extends RExecSubTask { | |||
private boolean echoString = true; | |||
/** | |||
* Execute the write exec task. | |||
* @param rexec the task to use | |||
* @throws BuildException on error | |||
*/ | |||
public void execute(AntRExecClient rexec) | |||
throws BuildException { | |||
rexec.sendString(taskString, echoString); | |||
@@ -116,6 +129,7 @@ public class RExecTask extends Task { | |||
/** | |||
* Whether or not the message should be echoed to the log. | |||
* Defaults to <code>true</code>. | |||
* @param b a <code>boolean</code> value | |||
*/ | |||
public void setEcho(boolean b) { | |||
echoString = b; | |||
@@ -128,12 +142,18 @@ public class RExecTask extends Task { | |||
*/ | |||
public class RExecRead extends RExecSubTask { | |||
private Integer timeout = null; | |||
/** | |||
* Execute the read exec task. | |||
* @param rexec the task to use | |||
* @throws BuildException on error | |||
*/ | |||
public void execute(AntRExecClient rexec) | |||
throws BuildException { | |||
rexec.waitForString(taskString, timeout); | |||
} | |||
/** | |||
* a timeout value that overrides any task wide timeout. | |||
* @param i an <code>Integer</code> value | |||
*/ | |||
public void setTimeout(Integer i) { | |||
this.timeout = i; | |||
@@ -141,6 +161,7 @@ public class RExecTask extends Task { | |||
/** | |||
* Sets the default timeout if none has been set already | |||
* @param defaultTimeout an <code>Integer</code> value | |||
* @ant.attribute ignore="true" | |||
*/ | |||
public void setDefaultTimeout(Integer defaultTimeout) { | |||
@@ -206,7 +227,8 @@ public class RExecTask extends Task { | |||
/** | |||
* Write this string to the rexec session. | |||
* @param echoString Logs string sent | |||
* @param s the string to write | |||
* @param echoString if true log the string sent | |||
*/ | |||
public void sendString(String s, boolean echoString) { | |||
OutputStream os = this.getOutputStream(); | |||
@@ -279,6 +301,7 @@ public class RExecTask extends Task { | |||
* A string to wait for from the server. | |||
* A subTask <read> tag was found. Create the object, | |||
* Save it in our list, and return it. | |||
* @return a read sub task | |||
*/ | |||
public RExecSubTask createRead() { | |||
@@ -290,6 +313,7 @@ public class RExecTask extends Task { | |||
* Add text to send to the server | |||
* A subTask <write> tag was found. Create the object, | |||
* Save it in our list, and return it. | |||
* @return a write sub task | |||
*/ | |||
public RExecSubTask createWrite() { | |||
RExecSubTask task = (RExecSubTask) new RExecWrite(); | |||
@@ -298,8 +322,9 @@ public class RExecTask extends Task { | |||
} | |||
/** | |||
* Verify that all parameters are included. | |||
* Connect and possibly login | |||
* Iterate through the list of Reads and writes | |||
* Connect and possibly login. | |||
* Iterate through the list of Reads and writes. | |||
* @throws BuildException on error | |||
*/ | |||
public void execute() throws BuildException { | |||
/** A server name is required to continue */ | |||
@@ -367,10 +392,15 @@ public class RExecTask extends Task { | |||
} | |||
/** | |||
* Set the the comand to execute on the server; | |||
* @param c a <code>String</code> value | |||
*/ | |||
public void setCommand(String c) { this.command = c; } | |||
public void setCommand(String c) { | |||
this.command = c; | |||
} | |||
/** | |||
* send a carriage return after connecting; optional, defaults to false. | |||
* @param b a <code>boolean</code> value | |||
*/ | |||
public void setInitialCR(boolean b) { | |||
this.addCarriageReturn = b; | |||
@@ -378,19 +408,32 @@ public class RExecTask extends Task { | |||
/** | |||
* Set the the login password to use | |||
* required if <tt>userid</tt> is set. | |||
* @param p a <code>String</code> value | |||
*/ | |||
public void setPassword(String p) { this.password = p; } | |||
public void setPassword(String p) { | |||
this.password = p; | |||
} | |||
/** | |||
* Set the tcp port to connect to; default is 23. | |||
* @param p an <code>int</code> value | |||
*/ | |||
public void setPort(int p) { this.port = p; } | |||
public void setPort(int p) { | |||
this.port = p; | |||
} | |||
/** | |||
* Set the hostname or address of the remote server. | |||
* @param m a <code>String</code> value | |||
*/ | |||
public void setServer(String m) { this.server = m; } | |||
public void setServer(String m) { | |||
this.server = m; | |||
} | |||
/** | |||
* set a default timeout in seconds to wait for a response, | |||
* zero means forever (the default) | |||
* @param i an <code>Integer</code> value | |||
*/ | |||
public void setTimeout(Integer i) { | |||
this.defaultTimeout = i; | |||
@@ -398,6 +441,9 @@ public class RExecTask extends Task { | |||
/** | |||
* Set the the login id to use on the server; | |||
* required if <tt>password</tt> is set. | |||
* @param u a <code>String</code> value | |||
*/ | |||
public void setUserid(String u) { this.userid = u; } | |||
public void setUserid(String u) { | |||
this.userid = u; | |||
} | |||
} |
@@ -1,5 +1,5 @@ | |||
/* | |||
* Copyright 2000-2004 The Apache Software Foundation | |||
* Copyright 2000-2005 The Apache Software Foundation | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
@@ -16,15 +16,12 @@ | |||
*/ | |||
package org.apache.tools.ant.taskdefs.optional.net; | |||
import java.lang.reflect.InvocationTargetException; | |||
import java.lang.reflect.Method; | |||
import java.net.Authenticator; | |||
import java.net.PasswordAuthentication; | |||
import java.util.Properties; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.Project; | |||
import org.apache.tools.ant.Task; | |||
import org.apache.tools.ant.util.JavaEnvUtils; | |||
/** | |||
* Sets Java's web proxy properties, so that tasks and code run in | |||
@@ -74,6 +74,7 @@ public class TelnetTask extends Task { | |||
* Verify that all parameters are included. | |||
* Connect and possibly login | |||
* Iterate through the list of Reads and writes | |||
* @throws BuildException on error | |||
*/ | |||
public void execute() throws BuildException { | |||
/** A server name is required to continue */ | |||
@@ -141,27 +142,40 @@ public class TelnetTask extends Task { | |||
/** | |||
* Set the the login id to use on the server; | |||
* required if <tt>password</tt> is set. | |||
* @param u a <code>String</code> value | |||
*/ | |||
public void setUserid(String u) { this.userid = u; } | |||
public void setUserid(String u) { | |||
this.userid = u; | |||
} | |||
/** | |||
* Set the the login password to use | |||
* required if <tt>userid</tt> is set. | |||
* @param p a <code>String</code> value | |||
*/ | |||
public void setPassword(String p) { this.password = p; } | |||
public void setPassword(String p) { | |||
this.password = p; | |||
} | |||
/** | |||
* Set the hostname or address of the remote server. | |||
* @param m a <code>String</code> value | |||
*/ | |||
public void setServer(String m) { this.server = m; } | |||
public void setServer(String m) { | |||
this.server = m; | |||
} | |||
/** | |||
* Set the tcp port to connect to; default is 23. | |||
* @param p an <code>int</code> value | |||
*/ | |||
public void setPort(int p) { this.port = p; } | |||
public void setPort(int p) { | |||
this.port = p; | |||
} | |||
/** | |||
* send a carriage return after connecting; optional, defaults to false. | |||
* @param b a <code>boolean</code> value | |||
*/ | |||
public void setInitialCR(boolean b) { | |||
this.addCarriageReturn = b; | |||
@@ -170,6 +184,7 @@ public class TelnetTask extends Task { | |||
/** | |||
* set a default timeout in seconds to wait for a response, | |||
* zero means forever (the default) | |||
* @param i an <code>Integer</code> value | |||
*/ | |||
public void setTimeout(Integer i) { | |||
this.defaultTimeout = i; | |||
@@ -179,6 +194,7 @@ public class TelnetTask extends Task { | |||
* A string to wait for from the server. | |||
* A subTask <read> tag was found. Create the object, | |||
* Save it in our list, and return it. | |||
* @return a read telnet sub task | |||
*/ | |||
public TelnetSubTask createRead() { | |||
@@ -191,6 +207,7 @@ public class TelnetTask extends Task { | |||
* Add text to send to the server | |||
* A subTask <write> tag was found. Create the object, | |||
* Save it in our list, and return it. | |||
* @return a write telnet sub task | |||
*/ | |||
public TelnetSubTask createWrite() { | |||
TelnetSubTask task = (TelnetSubTask) new TelnetWrite(); | |||
@@ -204,6 +221,11 @@ public class TelnetTask extends Task { | |||
*/ | |||
public class TelnetSubTask { | |||
protected String taskString = ""; | |||
/** | |||
* Execute the subtask. | |||
* @param telnet the client | |||
* @throws BuildException always as it is not allowed to instantiate this object | |||
*/ | |||
public void execute(AntTelnetClient telnet) | |||
throws BuildException { | |||
throw new BuildException("Shouldn't be able instantiate a SubTask directly"); | |||
@@ -211,6 +233,7 @@ public class TelnetTask extends Task { | |||
/** | |||
* the message as nested text | |||
* @param s the nested text | |||
*/ | |||
public void addText(String s) { | |||
setString(getProject().replaceProperties(s)); | |||
@@ -218,6 +241,7 @@ public class TelnetTask extends Task { | |||
/** | |||
* the message as an attribute | |||
* @param s a <code>String</code> value | |||
*/ | |||
public void setString(String s) { | |||
taskString += s; | |||
@@ -229,6 +253,11 @@ public class TelnetTask extends Task { | |||
*/ | |||
public class TelnetWrite extends TelnetSubTask { | |||
private boolean echoString = true; | |||
/** | |||
* Execute the write task. | |||
* @param telnet the task to use | |||
* @throws BuildException on error | |||
*/ | |||
public void execute(AntTelnetClient telnet) | |||
throws BuildException { | |||
telnet.sendString(taskString, echoString); | |||
@@ -237,6 +266,7 @@ public class TelnetTask extends Task { | |||
/** | |||
* Whether or not the message should be echoed to the log. | |||
* Defaults to <code>true</code>. | |||
* @param b a <code>boolean</code> value | |||
*/ | |||
public void setEcho(boolean b) { | |||
echoString = b; | |||
@@ -249,12 +279,18 @@ public class TelnetTask extends Task { | |||
*/ | |||
public class TelnetRead extends TelnetSubTask { | |||
private Integer timeout = null; | |||
/** | |||
* Execute the read task. | |||
* @param telnet the task to use | |||
* @throws BuildException on error | |||
*/ | |||
public void execute(AntTelnetClient telnet) | |||
throws BuildException { | |||
telnet.waitForString(taskString, timeout); | |||
} | |||
/** | |||
* a timeout value that overrides any task wide timeout. | |||
* @param i an <code>Integer</code> value | |||
*/ | |||
public void setTimeout(Integer i) { | |||
this.timeout = i; | |||
@@ -262,6 +298,7 @@ public class TelnetTask extends Task { | |||
/** | |||
* Sets the default timeout if none has been set already | |||
* @param defaultTimeout an <code>Integer</code> value | |||
* @ant.attribute ignore="true" | |||
*/ | |||
public void setDefaultTimeout(Integer defaultTimeout) { | |||
@@ -328,9 +365,10 @@ public class TelnetTask extends Task { | |||
} | |||
/** | |||
* Write this string to the telnet session. | |||
* @param echoString Logs string sent | |||
*/ | |||
* Write this string to the telnet session. | |||
* @param s the string to write | |||
* @param echoString if true log the string sent | |||
*/ | |||
public void sendString(String s, boolean echoString) { | |||
OutputStream os = this.getOutputStream(); | |||
try { | |||