Lines 66-71
Link Here
|
66 |
import java.io.BufferedOutputStream; |
66 |
import java.io.BufferedOutputStream; |
67 |
import java.io.InputStream; |
67 |
import java.io.InputStream; |
68 |
import java.io.InputStreamReader; |
68 |
import java.io.InputStreamReader; |
|
|
69 |
import java.io.BufferedReader; |
69 |
import java.net.HttpURLConnection; |
70 |
import java.net.HttpURLConnection; |
70 |
import java.net.URL; |
71 |
import java.net.URL; |
71 |
import java.net.URLConnection; |
72 |
import java.net.URLConnection; |
Lines 135-144
Link Here
|
135 |
this.username = username; |
136 |
this.username = username; |
136 |
} |
137 |
} |
137 |
|
138 |
|
|
|
139 |
protected boolean failonerror = true; |
140 |
|
141 |
public boolean getFailOnError(){ |
142 |
return this.failonerror; |
143 |
} |
144 |
|
145 |
public void setFailOnError(boolean failonerror){ |
146 |
this.failonerror = failonerror; |
147 |
} |
148 |
|
149 |
|
138 |
|
150 |
|
139 |
// --------------------------------------------------------- Public Methods |
151 |
// --------------------------------------------------------- Public Methods |
140 |
|
152 |
|
141 |
|
153 |
|
|
|
154 |
protected void validate() throws BuildException { |
155 |
if ((username == null) || (password == null) || (url == null)) { |
156 |
throw new BuildException |
157 |
("Must specify all of 'username', 'password', and 'url'"); |
158 |
} |
159 |
} |
160 |
|
142 |
/** |
161 |
/** |
143 |
* Execute the specified command. This logic only performs the common |
162 |
* Execute the specified command. This logic only performs the common |
144 |
* attribute validation required by all subclasses; it does not perform |
163 |
* attribute validation required by all subclasses; it does not perform |
Lines 147-164
Link Here
|
147 |
* @exception BuildException if a validation error occurs |
166 |
* @exception BuildException if a validation error occurs |
148 |
*/ |
167 |
*/ |
149 |
public void execute() throws BuildException { |
168 |
public void execute() throws BuildException { |
150 |
|
169 |
validate(); |
151 |
if ((username == null) || (password == null) || (url == null)) { |
170 |
try { |
152 |
throw new BuildException |
171 |
executeProtected(); |
153 |
("Must specify all of 'username', 'password', and 'url'"); |
172 |
} catch (BuildException e){ |
|
|
173 |
if (failonerror){ |
174 |
throw e; |
175 |
} |
176 |
log(e.getMessage(), Project.MSG_WARN); |
154 |
} |
177 |
} |
155 |
|
|
|
156 |
} |
178 |
} |
157 |
|
179 |
|
158 |
|
|
|
159 |
// ------------------------------------------------------ Protected Methods |
180 |
// ------------------------------------------------------ Protected Methods |
160 |
|
181 |
|
161 |
|
182 |
|
|
|
183 |
protected abstract void executeProtected() throws BuildException; |
184 |
|
162 |
/** |
185 |
/** |
163 |
* Execute the specified command, based on the configured properties. |
186 |
* Execute the specified command, based on the configured properties. |
164 |
* |
187 |
* |
Lines 190-196
Link Here
|
190 |
throws BuildException { |
213 |
throws BuildException { |
191 |
|
214 |
|
192 |
URLConnection conn = null; |
215 |
URLConnection conn = null; |
193 |
InputStreamReader reader = null; |
216 |
BufferedReader reader = null; |
194 |
try { |
217 |
try { |
195 |
|
218 |
|
196 |
// Create a connection for this command |
219 |
// Create a connection for this command |
Lines 245-279
Link Here
|
245 |
} |
268 |
} |
246 |
|
269 |
|
247 |
// Process the response message |
270 |
// Process the response message |
248 |
reader = new InputStreamReader(hconn.getInputStream()); |
271 |
reader = new BufferedReader(new InputStreamReader(hconn.getInputStream())); |
249 |
StringBuffer buff = new StringBuffer(); |
272 |
String line = reader.readLine(); |
250 |
String error = null; |
273 |
if (!line.startsWith("OK -")) { |
251 |
boolean first = true; |
274 |
throw new BuildException(line); |
252 |
while (true) { |
|
|
253 |
int ch = reader.read(); |
254 |
if (ch < 0) { |
255 |
break; |
256 |
} else if ((ch == '\r') || (ch == '\n')) { |
257 |
String line = buff.toString(); |
258 |
buff.setLength(0); |
259 |
log(line, Project.MSG_INFO); |
260 |
if (first) { |
261 |
if (!line.startsWith("OK -")) { |
262 |
error = line; |
263 |
} |
264 |
first = false; |
265 |
} |
266 |
} else { |
267 |
buff.append((char) ch); |
268 |
} |
269 |
} |
270 |
if (buff.length() > 0) { |
271 |
log(buff.toString(), Project.MSG_INFO); |
272 |
} |
275 |
} |
273 |
if (error != null) { |
276 |
log(line, Project.MSG_INFO); |
274 |
throw new BuildException(error); |
277 |
while ( (line = reader.readLine()) != null) { |
|
|
278 |
log(line, Project.MSG_INFO); |
275 |
} |
279 |
} |
276 |
|
280 |
} catch (BuildException e){ |
|
|
281 |
throw e; |
277 |
} catch (Throwable t) { |
282 |
} catch (Throwable t) { |
278 |
throw new BuildException(t); |
283 |
throw new BuildException(t); |
279 |
} finally { |
284 |
} finally { |