1 | class TelnetSubTask {↵ | | 1 | class RExecSubTask {↵
|
2 | // CheckStyle:VisibilityModifier OFF - bc↵ | | 2 | // CheckStyle:VisibilityModifier OFF - bc↵
|
3 | protected String taskString = "";↵ | | 3 | protected String taskString = "";↵
|
4 | // CheckStyle:VisibilityModifier ON↵ | | 4 | // CheckStyle:VisibilityModifier ON↵
|
|
5 | /**↵ | | 5 | /**↵
|
6 | * Execute the subtask.↵ | | 6 | * Execute the subtask.↵
|
7 | * @param telnet the client↵ | | 7 | * @param rexec the client↵
|
8 | * @throws BuildException always as it is not allowed to instantiate this object↵ | | 8 | * @throws BuildException always as it is not allowed to instantiate this object↵
|
9 | */↵ | | 9 | */↵
|
10 | public void execute(AntTelnetClient telnet)↵ | | 10 | public void execute(AntRExecClient rexec)↵
|
11 | throws BuildException {↵ | | 11 | throws BuildException {↵
|
12 | throw new BuildException("Shouldn't be able instantiate a SubTask directly");↵ | | 12 | throw new BuildException("Shouldn't be able instantiate a SubTask directly");↵
|
13 | }↵ | | 13 | }↵
|
|
14 | /**↵ | | 14 | /**↵
|
15 | * the message as nested text↵ | | 15 | * the message as nested text↵
|
16 | * @param s the nested text↵ | | 16 | * @param s the nested text↵
|
17 | */↵ | | 17 | */↵
|
18 | public void addText(String s) {↵ | | 18 | public void addText(String s) {↵
|
19 | setString(getProject().replaceProperties(s));↵ | | 19 | setString(getProject().replaceProperties(s));↵
|
20 | }↵ | | 20 | }↵
|
|
21 | /**↵ | | 21 | /**↵
|
22 | * the message as an attribute↵ | | 22 | * the message as an attribute↵
|
23 | * @param s a <code>String</code> value↵ | | 23 | * @param s a <code>String</code> value↵
|
24 | */↵ | | 24 | */↵
|
25 | public void setString(String s) {↵ | | 25 | public void setString(String s) {↵
|
26 | taskString += s;↵ | | 26 | taskString += s;↵
|
27 | }↵ | | 27 | }↵
|
28 | }↵ | | 28 | }↵
|
|
29 | /**↵ | | 29 | /**↵
|
30 | * Sends text to the connected server↵ | | 30 | * Sends text to the connected server↵
|
31 | */↵ | | 31 | */↵
|
32 | public class TelnetWrite extends TelnetSubTask {↵ | | 32 | public class RExecWrite extends RExecSubTask {↵
|
33 | private boolean echoString = true;↵ | | 33 | private boolean echoString = true;↵
|
34 | /**↵ | | 34 | /**↵
|
35 | * Execute the write task.↵ | | 35 | * Execute the write exec task.↵
|
36 | * @param telnet the task to use↵ | | 36 | * @param rexec the task to use↵
|
37 | * @throws BuildException on error↵ | | 37 | * @throws BuildException on error↵
|
38 | */↵ | | 38 | */↵
|
39 | public void execute(AntTelnetClient telnet)↵ | | 39 | public void execute(AntRExecClient rexec)↵
|
40 | throws BuildException {↵ | | 40 | throws BuildException {↵
|
41 | telnet.sendString(taskString, echoString);↵ | | 41 | rexec.sendString(taskString, echoString);↵
|
42 | }↵ | | 42 | }↵
|
|
43 | /**↵ | | 43 | /**↵
|
44 | * Whether or not the message should be echoed to the log.↵ | | 44 | * Whether or not the message should be echoed to the log.↵
|
45 | * Defaults to <code>true</code>.↵ | | 45 | * Defaults to <code>true</code>.↵
|
46 | * @param b a <code>boolean</code> value↵ | | 46 | * @param b a <code>boolean</code> value↵
|
47 | */↵ | | 47 | */↵
|
48 | public void setEcho(boolean b) {↵ | | 48 | public void setEcho(boolean b) {↵
|
49 | echoString = b;↵ | | 49 | echoString = b;↵
|
50 | }↵ | | 50 | }↵
|
51 | }↵ | | 51 | }↵
|
|
52 | /**↵ | | 52 | /**↵
|
53 | * Reads the output from the connected server↵ | | 53 | * Reads the output from the connected server↵
|
54 | * until the required string is found or we time out.↵ | | 54 | * until the required string is found or we time out.↵
|
55 | */↵ | | 55 | */↵
|
56 | public class TelnetRead extends TelnetSubTask {↵ | | 56 | public class RExecRead extends RExecSubTask {↵
|
57 | private Integer timeout = null;↵ | | 57 | private Integer timeout = null;↵
|
58 | /**↵ | | 58 | /**↵
|
59 | * Execute the read task.↵ | | 59 | * Execute the read exec task.↵
|
60 | * @param telnet the task to use↵ | | 60 | * @param rexec the task to use↵
|
61 | * @throws BuildException on error↵ | | 61 | * @throws BuildException on error↵
|
62 | */↵ | | 62 | */↵
|
63 | public void execute(AntTelnetClient telnet)↵ | | 63 | public void execute(AntRExecClient rexec)↵
|
64 | throws BuildException {↵ | | 64 | throws BuildException {↵
|
65 | telnet.waitForString(taskString, timeout);↵ | | 65 | rexec.waitForString(taskString, timeout);↵
|
66 | }↵ | | 66 | }↵
|
67 | /**↵ | | 67 | /**↵
|
68 | * a timeout value that overrides any task wide timeout.↵ | | 68 | * a timeout value that overrides any task wide timeout.↵
|
69 | * @param i an <code>Integer</code> value↵ | | 69 | * @param i an <code>Integer</code> value↵
|
70 | */↵ | | 70 | */↵
|
71 | public void setTimeout(Integer i) {↵ | | 71 | public void setTimeout(Integer i) {↵
|
72 | this.timeout = i;↵ | | 72 | this.timeout = i;↵
|
73 | }↵ | | 73 | }↵
|
|
74 | /**↵ | | 74 | /**↵
|
75 | * Sets the default timeout if none has been set already↵ | | 75 | * Sets the default timeout if none has been set already↵
|
76 | * @param defaultTimeout an <code>Integer</code> value↵ | | 76 | * @param defaultTimeout an <code>Integer</code> value↵
|
77 | * @ant.attribute ignore="true"↵ | | 77 | * @ant.attribute ignore="true"↵
|
78 | */↵ | | 78 | */↵
|
79 | public void setDefaultTimeout(Integer defaultTimeout) {↵ | | 79 | public void setDefaultTimeout(Integer defaultTimeout) {↵
|
80 | if (timeout == null) {↵ | | 80 | if (timeout == null) {↵
|
81 | timeout = defaultTimeout;↵ | | 81 | timeout = defaultTimeout;↵
|
82 | }↵ | | 82 | }↵
|
83 | }↵ | | 83 | }↵
|
84 | }↵ | | 84 | }↵
|
|
85 | /**↵ | | 85 | /**↵
|
86 | * This class handles the abstraction of the telnet protocol.↵ | | 86 | * This class handles the abstraction of the rexec protocol.↵
|
87 | * Currently it is a wrapper around <a↵ | | 87 | * Currently it is a wrapper around <a↵
|
88 | * href="http://jakarta.apache.org/commons/net/index.html">Jakarta↵ | | 88 | * href="http://jakarta.apache.org/commons/net/index.html">Jakarta↵
|
89 | * Commons Net</a>.↵ | | 89 | * Commons Net</a>.↵
|
90 | */↵ | | 90 | */↵
|
91 | public class AntTelnetClient extends TelnetClient {↵ | | 91 | public class AntRExecClient extends RExecClient {↵
|
92 | /**↵ | | 92 | /**↵
|
93 | * Read from the telnet session until the string we are↵ | | 93 | * Read from the rexec session until the string we are↵
|
94 | * waiting for is found↵ | | 94 | * waiting for is found↵
|
95 | * @param s The string to wait on↵ | | 95 | * @param s The string to wait on↵
|
96 | */↵ | | 96 | */↵
|
97 | public void waitForString(String s) {↵ | | 97 | public void waitForString(String s) {↵
|
98 | waitForString(s, null);↵ | | 98 | waitForString(s, null);↵
|
99 | }↵ | | 99 | }↵
|
|
100 | /**↵ | | 100 | /**↵
|
101 | * Read from the telnet session until the string we are↵ | | 101 | * Read from the rexec session until the string we are↵
|
102 | * waiting for is found or the timeout has been reached↵ | | 102 | * waiting for is found or the timeout has been reached↵
|
103 | * @param s The string to wait on↵ | | 103 | * @param s The string to wait on↵
|
104 | * @param timeout The maximum number of seconds to wait↵ | | 104 | * @param timeout The maximum number of seconds to wait↵
|
105 | */↵ | | 105 | */↵
|
106 | public void waitForString(String s, Integer timeout) {↵ | | 106 | public void waitForString(String s, Integer timeout) {↵
|
107 | InputStream is = this.getInputStream();↵ | | 107 | InputStream is = this.getInputStream();↵
|
108 | try {↵ | | 108 | try {↵
|
109 | StringBuffer sb = new StringBuffer();↵ | | 109 | StringBuffer sb = new StringBuffer();↵
|
110 | if (timeout == null || timeout.intValue() == 0) {↵ | | 110 | if (timeout == null || timeout.intValue() == 0) {↵
|
111 | while (sb.toString().indexOf(s) == -1) {↵ | | 111 | while (sb.toString().indexOf(s) == -1) {↵
|
112 | sb.append((char) is.read());↵ | | 112 | sb.append((char) is.read());↵
|
113 | }↵ | | 113 | }↵
|
114 | } els | | 114 | } els
|