timeout occurs. Submitted by: Denis Hennessy <denis@network365.com> As a side effect, <condition> gains two new conditions. This also means we now have a way to check whether we are on a networked system and run/omit testcases that require network to be established based on such a condition. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270050 13f79535-47bb-0310-9956-ffa450edef68master
@@ -63,7 +63,7 @@ Other changes: | |||||
* Added support for specifying CVS_RSH in the <cvs/> task | * Added support for specifying CVS_RSH in the <cvs/> task | ||||
* New tasks bzip2 and bunzip2 to pack and unpack files using the | * New tasks bzip2 and bunzip2 to pack and unpack files using the | ||||
BZip2 alogrithm, replaceregexp, checksum, translate | |||||
BZip2 alogrithm, replaceregexp, checksum, translate, waitfor | |||||
* The attributes zipfile, jarfile, warfile and earfile (from the Zip, | * The attributes zipfile, jarfile, warfile and earfile (from the Zip, | ||||
Jar, War and Ear tasks) have been deprecated and superseded by a | Jar, War and Ear tasks) have been deprecated and superseded by a | ||||
@@ -72,7 +72,7 @@ Other changes: | |||||
* Added a new condition <isset> that test for the existence of a | * Added a new condition <isset> that test for the existence of a | ||||
property to the condition task. | property to the condition task. | ||||
* Added a new condition <checksum>. | |||||
* Added a new conditions <checksum>, <http>, <socket>. | |||||
* Ant's testcases require JUnit 3.7 or above as they now use the new | * Ant's testcases require JUnit 3.7 or above as they now use the new | ||||
assertTrue method instead of assert. | assertTrue method instead of assert. | ||||
@@ -38,130 +38,8 @@ you must specify exactly one condition.</p> | |||||
</tr> | </tr> | ||||
</table> | </table> | ||||
<h3><a name="nested">Parameters specified as nested elements</a></h3> | <h3><a name="nested">Parameters specified as nested elements</a></h3> | ||||
<p>All conditions to test are specified as nested elements.</p> | |||||
<h4>not</h4> | |||||
<p>The <code><not></code> element expects exactly one other | |||||
condition to be nested into this element, negating the result of the | |||||
condition. It doesn't have any attributes and accepts all nested | |||||
elements of the condition task as nested elements as well.</p> | |||||
<h4>and</h4> <p> | |||||
The <code><and></code> element doesn't have any attributes and | |||||
accepts an arbitrary number of conditions as nested elements - all | |||||
nested elements of the condition task are supported. This condition | |||||
is true if all of its contained conditions are, conditions will be | |||||
evaluated in the order they have been specified in the build file.</p> | |||||
<p>The <code><and></code> condition has the same shortcut | |||||
semantics as the Java && operator, as soon as one of the | |||||
nested conditions is false, no other condition will be evaluated.</p> | |||||
<h4>or</h4> <p> | |||||
The <code><or></code> element doesn't have any attributes and | |||||
accepts an arbitrary number of conditions as nested elements - all | |||||
nested elements of the condition task are supported. This condition | |||||
is true if at least one of its contained conditions is, conditions | |||||
will be evaluated in the order they have been specified in the build | |||||
file.</p> <p>The <code><or></code> condition has the same | |||||
shortcut semantics as the Java || operator, as soon as one of the | |||||
nested conditions is true, no other condition will be evaluated.</p> | |||||
<h4>available</h4> | |||||
<p>This condition is identical to the <a | |||||
href="available.html">Available</a> task, all attributes and nested | |||||
elements of that task are supported, the property and value attributes | |||||
are redundant and will be ignored.</p> | |||||
<h4>uptodate</h4> | |||||
<p>This condition is identical to the <a | |||||
href="uptodate.html">Uptodate</a> task, all attributes and nested | |||||
elements of that task are supported, the property and value attributes | |||||
are redundant and will be ignored.</p> | |||||
<h4>os</h4> | |||||
<p>Test whether the current operating system is of a given type. Each | |||||
defined attribute is tested and the result is true only if <i>all</i> | |||||
the tests succeed. | |||||
</p> | |||||
<table border="1" cellpadding="2" cellspacing="0"> | |||||
<tr> | |||||
<td valign="top"><b>Attribute</b></td> | |||||
<td valign="top"><b>Description</b></td> | |||||
<td align="center" valign="top"><b>Required</b></td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">family</td> | |||||
<td valign="top">The name of the operating system family to expect.</td> | |||||
<td valign="top" align="center">No</td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">name</td> | |||||
<td valign="top">The name of the operating system to expect.</td> | |||||
<td valign="top" align="center">No</td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">arch</td> | |||||
<td valign="top">The architecture of the operating system to expect.</td> | |||||
<td valign="top" align="center">No</td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">version</td> | |||||
<td valign="top">The version of the operating system to expect.</td> | |||||
<td valign="top" align="center">No</td> | |||||
</tr> | |||||
</table> | |||||
<p>Supported values for the family attribute are: | |||||
<ul> | |||||
<li>windows (for all versions of Microsoft Windows)</li> | |||||
<li>dos (for all Microsoft DOS based operating systems including | |||||
Microsoft Windows and OS/2)</li> | |||||
<li>mac (for all Apple Macintosh systems)</li> | |||||
<li>unix (for all Unix and Unix-like operating systems)</li> | |||||
<li>netware (for Novell NetWare)</li> | |||||
<li>os/2 (for OS/2)</li> | |||||
</ul> | |||||
<h4>equals</h4> | |||||
<p>Tests whether the two given Strings are identical</p> | |||||
<table border="1" cellpadding="2" cellspacing="0"> | |||||
<tr> | |||||
<td valign="top"><b>Attribute</b></td> | |||||
<td valign="top"><b>Description</b></td> | |||||
<td align="center" valign="top"><b>Required</b></td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">arg1</td> | |||||
<td valign="top">First string to test.</td> | |||||
<td valign="top" align="center">Yes</td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">arg2</td> | |||||
<td valign="top">Second string to test.</td> | |||||
<td valign="top" align="center">Yes</td> | |||||
</tr> | |||||
</table> | |||||
<h4>isset</h4> | |||||
<p>Test whether a given property has been set in this project.</p> | |||||
<table border="1" cellpadding="2" cellspacing="0"> | |||||
<tr> | |||||
<td valign="top"><b>Attribute</b></td> | |||||
<td valign="top"><b>Description</b></td> | |||||
<td align="center" valign="top"><b>Required</b></td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">property</td> | |||||
<td valign="top">The name of the property to test.</td> | |||||
<td valign="top" align="center">Yes</td> | |||||
</tr> | |||||
</table> | |||||
<h4>checksum</h4> | |||||
<p>This condition is identical to the <a | |||||
href="checksum.html">Checksum</a> task, all attributes and nested | |||||
elements of that task are supported, the property and overwrite | |||||
attributes are redundant and will be ignored.</p> | |||||
<p>All conditions to test are specified as nested elements, for a | |||||
complete list see <a href="conditions.html">here</a>.</p> | |||||
<h3>Examples</h3> | <h3>Examples</h3> | ||||
<pre> | <pre> | ||||
@@ -0,0 +1,181 @@ | |||||
<html> | |||||
<head> | |||||
<meta http-equiv="Content-Language" content="en-us"> | |||||
<title>Apache Ant User Manual</title> | |||||
</head> | |||||
<body> | |||||
<h2><a name="Conditions">Conditions</a></h2> | |||||
<p>These are the nested elements that can be used as conditions in the | |||||
<a href="condition.html"><code><condition></code></a> and | |||||
<a href="waitfor.html"><code><waitfor></code></a> tasks.</p> | |||||
<h4>not</h4> | |||||
<p>The <code><not></code> element expects exactly one other | |||||
condition to be nested into this element, negating the result of the | |||||
condition. It doesn't have any attributes and accepts all nested | |||||
elements of the condition task as nested elements as well.</p> | |||||
<h4>and</h4> <p> | |||||
The <code><and></code> element doesn't have any attributes and | |||||
accepts an arbitrary number of conditions as nested elements - all | |||||
nested elements of the condition task are supported. This condition | |||||
is true if all of its contained conditions are, conditions will be | |||||
evaluated in the order they have been specified in the build file.</p> | |||||
<p>The <code><and></code> condition has the same shortcut | |||||
semantics as the Java && operator, as soon as one of the | |||||
nested conditions is false, no other condition will be evaluated.</p> | |||||
<h4>or</h4> <p> | |||||
The <code><or></code> element doesn't have any attributes and | |||||
accepts an arbitrary number of conditions as nested elements - all | |||||
nested elements of the condition task are supported. This condition | |||||
is true if at least one of its contained conditions is, conditions | |||||
will be evaluated in the order they have been specified in the build | |||||
file.</p> <p>The <code><or></code> condition has the same | |||||
shortcut semantics as the Java || operator, as soon as one of the | |||||
nested conditions is true, no other condition will be evaluated.</p> | |||||
<h4>available</h4> | |||||
<p>This condition is identical to the <a | |||||
href="available.html">Available</a> task, all attributes and nested | |||||
elements of that task are supported, the property and value attributes | |||||
are redundant and will be ignored.</p> | |||||
<h4>uptodate</h4> | |||||
<p>This condition is identical to the <a | |||||
href="uptodate.html">Uptodate</a> task, all attributes and nested | |||||
elements of that task are supported, the property and value attributes | |||||
are redundant and will be ignored.</p> | |||||
<h4>os</h4> | |||||
<p>Test whether the current operating system is of a given type. Each | |||||
defined attribute is tested and the result is true only if <i>all</i> | |||||
the tests succeed. | |||||
</p> | |||||
<table border="1" cellpadding="2" cellspacing="0"> | |||||
<tr> | |||||
<td valign="top"><b>Attribute</b></td> | |||||
<td valign="top"><b>Description</b></td> | |||||
<td align="center" valign="top"><b>Required</b></td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">family</td> | |||||
<td valign="top">The name of the operating system family to expect.</td> | |||||
<td valign="top" align="center">No</td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">name</td> | |||||
<td valign="top">The name of the operating system to expect.</td> | |||||
<td valign="top" align="center">No</td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">arch</td> | |||||
<td valign="top">The architecture of the operating system to expect.</td> | |||||
<td valign="top" align="center">No</td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">version</td> | |||||
<td valign="top">The version of the operating system to expect.</td> | |||||
<td valign="top" align="center">No</td> | |||||
</tr> | |||||
</table> | |||||
<p>Supported values for the family attribute are: | |||||
<ul> | |||||
<li>windows (for all versions of Microsoft Windows)</li> | |||||
<li>dos (for all Microsoft DOS based operating systems including | |||||
Microsoft Windows and OS/2)</li> | |||||
<li>mac (for all Apple Macintosh systems)</li> | |||||
<li>unix (for all Unix and Unix-like operating systems)</li> | |||||
<li>netware (for Novell NetWare)</li> | |||||
<li>os/2 (for OS/2)</li> | |||||
</ul> | |||||
<h4>equals</h4> | |||||
<p>Tests whether the two given Strings are identical</p> | |||||
<table border="1" cellpadding="2" cellspacing="0"> | |||||
<tr> | |||||
<td valign="top"><b>Attribute</b></td> | |||||
<td valign="top"><b>Description</b></td> | |||||
<td align="center" valign="top"><b>Required</b></td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">arg1</td> | |||||
<td valign="top">First string to test.</td> | |||||
<td valign="top" align="center">Yes</td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">arg2</td> | |||||
<td valign="top">Second string to test.</td> | |||||
<td valign="top" align="center">Yes</td> | |||||
</tr> | |||||
</table> | |||||
<h4>isset</h4> | |||||
<p>Test whether a given property has been set in this project.</p> | |||||
<table border="1" cellpadding="2" cellspacing="0"> | |||||
<tr> | |||||
<td valign="top"><b>Attribute</b></td> | |||||
<td valign="top"><b>Description</b></td> | |||||
<td align="center" valign="top"><b>Required</b></td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">property</td> | |||||
<td valign="top">The name of the property to test.</td> | |||||
<td valign="top" align="center">Yes</td> | |||||
</tr> | |||||
</table> | |||||
<h4>checksum</h4> | |||||
<p>This condition is identical to the <a href="checksum.html">Checksum</a> | |||||
task, all attributes and nested elements of that task are supported, | |||||
the property and overwrite attributes are redundant and will be | |||||
ignored.</p> | |||||
<h4>http</h4> | |||||
<p>The <code>http</code> condition checks for a valid response from a | |||||
web server of the specified url.</p> | |||||
<table border="1" cellpadding="2" cellspacing="0"> | |||||
<tr> | |||||
<td width="12%" valign="top"><b>Attribute</b></td> | |||||
<td width="78%" valign="top"><b>Description</b></td> | |||||
<td width="10%" valign="top"><b>Required</b></td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">url</td> | |||||
<td valign="top">The full URL of the page to request. The web server must | |||||
return a status code of <500..</td> | |||||
<td align="center">Yes.</td> | |||||
</tr> | |||||
</table> | |||||
<h4>socket</h4> | |||||
<p>The <code>socket</code> condition checks for the existence of a | |||||
TCP/IP listener at the specified host and port.</p> | |||||
<table border="1" cellpadding="2" cellspacing="0"> | |||||
<tr> | |||||
<td width="12%" valign="top"><b>Attribute</b></td> | |||||
<td width="78%" valign="top"><b>Description</b></td> | |||||
<td width="10%" valign="top"><b>Required</b></td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">server</td> | |||||
<td valign="top">The DNS name or IP address of the server.</td> | |||||
<td align="center">Yes.</td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">port</td> | |||||
<td valign="top">The port number to connect to.</td> | |||||
<td align="center">Yes.</td> | |||||
</tr> | |||||
</table> | |||||
<hr> | |||||
<p align="center">Copyright © 2001 Apache Software | |||||
Foundation. All rights Reserved.</p> | |||||
</body> | |||||
</html> |
@@ -0,0 +1,79 @@ | |||||
<html> | |||||
<head> | |||||
<meta http-equiv="Content-Language" content="en-us"> | |||||
<title>Apache Ant User Manual</title> | |||||
</head> | |||||
<body> | |||||
<h2>Waitfor</h2> | |||||
<h3>Description</h3> | |||||
<p>Blocks execution until a set of specified conditions become true. This is intended | |||||
to be used with the <a href="parallel.html">parallel</a> task to | |||||
synchronize a set of processes.</p> | |||||
<p>The conditions to wait for are defined in <a href="waitfor.html#nested">nested elements</a>, if multiple conditions | |||||
are specified, then the task will wait until all conditions are true..</p> | |||||
<p></p> | |||||
<p>The time attributes (maxwait and checkevery) are specified in milliseconds | |||||
unless the values are followed by one of the following suffixes: "ms", | |||||
"s", "m", "h" which cause the value to be interpreted | |||||
as milliseconds, seconds, minutes or hours.</p> | |||||
<h3>Parameters</h3> | |||||
<table border="1" cellpadding="2" cellspacing="0"> | |||||
<tr> | |||||
<td valign="top"><b>Attribute</b></td> | |||||
<td valign="top"><b>Description</b></td> | |||||
<td align="center" valign="top"><b>Required</b></td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">maxwait</td> | |||||
<td valign="top">The maximum amount of time to wait for all the required conditions | |||||
to become true before failing the task. Defaults to 5 minutes.</td> | |||||
<td valign="top" align="center">No</td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">checkevery</td> | |||||
<td valign="top">The amount of time to wait between each test of the conditions. | |||||
Defaults to 200mS.</td> | |||||
<td valign="top" align="center">No</td> | |||||
</tr> | |||||
</table> | |||||
<h3><a name="nested">Nested Elements</a></h3> | |||||
<p>The available conditions that satisfy the | |||||
<code><waitfor></code> task are the same as those for the | |||||
<a href="condition.html"><code><condition></code></a> task. See | |||||
<a href="conditions.html">here</a> for the full list.</p> | |||||
<h3>Examples</h3> | |||||
<blockquote> | |||||
<p><code><waitfor maxwait="30s"><br> | |||||
<available file="errors.log"/><br> | |||||
</waitfor></code></p> | |||||
</blockquote> | |||||
<p>waits up to 30 seconds for a file called errors.log to appear.</p> | |||||
<blockquote> | |||||
<p><code><waitfor maxwait="3m" checkevery="500ms"><br> | |||||
<http url="http://localhost/myapp/index.html"/><br> | |||||
</waitfor></code></p> | |||||
</blockquote> | |||||
<p>waits up to 3 minutes (and checks every 500mS) for a web server on localhost | |||||
to serve up the specified URL.</p> | |||||
<blockquote> | |||||
<p><code><waitfor maxwait="10s"><br> | |||||
<and><br> | |||||
<socket server="dbserver" port="1521"/><br> | |||||
<http url="http://webserver/mypage.html"/><br> | |||||
</and><br> | |||||
</waitfor></code></p> | |||||
</blockquote> | |||||
<p>waits up to 10 seconds for a server on the dbserver machine to begin listening | |||||
on port 1521 and for the http://webserver/mypage.html web page | |||||
to become available.</p> | |||||
<hr><p align="center">Copyright © 2000,2001 Apache Software Foundation. All rights | |||||
Reserved.</p> | |||||
</body> | |||||
</html> | |||||
@@ -81,6 +81,8 @@ | |||||
<a href="CoreTasks/unzip.html">Unwar</a><br> | <a href="CoreTasks/unzip.html">Unwar</a><br> | ||||
<a href="CoreTasks/unzip.html">Unzip</a><br> | <a href="CoreTasks/unzip.html">Unzip</a><br> | ||||
<a href="CoreTasks/uptodate.html">Uptodate</a><br> | <a href="CoreTasks/uptodate.html">Uptodate</a><br> | ||||
<a href="CoreTasks/waitfor.html">Waitfor</a><br> | |||||
<a href="CoreTasks/waitfor.html">Waitfor</a><br> | |||||
<a href="CoreTasks/war.html">War</a><br> | <a href="CoreTasks/war.html">War</a><br> | ||||
<a href="CoreTasks/zip.html">Zip</a><br> | <a href="CoreTasks/zip.html">Zip</a><br> | ||||
</body> | </body> | ||||
@@ -0,0 +1,174 @@ | |||||
/* | |||||
* The Apache Software License, Version 1.1 | |||||
* | |||||
* Copyright (c) 1999 The Apache Software Foundation. All rights | |||||
* reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in | |||||
* the documentation and/or other materials provided with the | |||||
* distribution. | |||||
* | |||||
* 3. The end-user documentation included with the redistribution, if | |||||
* any, must include the following acknowlegement: | |||||
* "This product includes software developed by the | |||||
* Apache Software Foundation (http://www.apache.org/)." | |||||
* Alternately, this acknowlegement may appear in the software itself, | |||||
* if and wherever such third-party acknowlegements normally appear. | |||||
* | |||||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||||
* Foundation" must not be used to endorse or promote products derived | |||||
* from this software without prior written permission. For written | |||||
* permission, please contact apache@apache.org. | |||||
* | |||||
* 5. Products derived from this software may not be called "Apache" | |||||
* nor may "Apache" appear in their names without prior written | |||||
* permission of the Apache Group. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
* ==================================================================== | |||||
* | |||||
* This software consists of voluntary contributions made by many | |||||
* individuals on behalf of the Apache Software Foundation. For more | |||||
* information on the Apache Software Foundation, please see | |||||
* <http://www.apache.org/>. | |||||
*/ | |||||
package org.apache.tools.ant.taskdefs; | |||||
import org.apache.tools.ant.BuildException; | |||||
import org.apache.tools.ant.Project; | |||||
import org.apache.tools.ant.taskdefs.condition.ConditionBase; | |||||
import org.apache.tools.ant.taskdefs.condition.Condition; | |||||
import java.io.File; | |||||
import java.io.IOException; | |||||
import java.net.*; | |||||
import java.util.Vector; | |||||
/** | |||||
* Wait for an external event to occur. | |||||
* | |||||
* Wait for an external process to start or to complete some | |||||
* task. This is useful with the <code>parallel</code> task to | |||||
* syncronize the execution of tests with server startup. | |||||
* | |||||
* The following attributes can be specified on a waitfor task: | |||||
* <ul> | |||||
* <li>maxwait - maximum length of time to wait before giving up</li> | |||||
* <li>checkevery - amount of time to sleep between each check</li> | |||||
* </ul> | |||||
* | |||||
* The time value can include a suffix of "ms", "s", "m", "h" to | |||||
* indicate that the value is in milliseconds, seconds, minutes or | |||||
* hours. The default is milliseconds. | |||||
* | |||||
* @author <a href="mailto:denis@network365.com">Denis Hennessy</a> | |||||
*/ | |||||
public class WaitFor extends ConditionBase { | |||||
private long maxWaitMillis = 1000 * 60 * 3; // default max wait time | |||||
private long checkEveryMillis = 500; | |||||
/** | |||||
* Set the maximum length of time to wait | |||||
*/ | |||||
public void setMaxWait(String time) { | |||||
maxWaitMillis = parseTime(time); | |||||
} | |||||
/** | |||||
* Set the time between each check | |||||
*/ | |||||
public void setCheckEvery(String time) { | |||||
checkEveryMillis = parseTime(time); | |||||
} | |||||
/** | |||||
* Check repeatedly for the specified conditions until they become | |||||
* true or the timeout expires. | |||||
*/ | |||||
public void execute() throws BuildException { | |||||
if (countConditions() > 1) { | |||||
throw new BuildException("You must not nest more than one condition into <waitfor>"); | |||||
} | |||||
if (countConditions() < 1) { | |||||
throw new BuildException("You must nest a condition into <waitfor>"); | |||||
} | |||||
Condition c = (Condition) getConditions().nextElement(); | |||||
long start = System.currentTimeMillis(); | |||||
long end = start + maxWaitMillis; | |||||
while (System.currentTimeMillis() < end) { | |||||
if (c.eval()) { | |||||
return; | |||||
} | |||||
try { | |||||
Thread.sleep(checkEveryMillis); | |||||
} catch (InterruptedException e) { | |||||
} | |||||
} | |||||
throw new BuildException("Task did not complete in time"); | |||||
} | |||||
/** | |||||
* Parse a time in the format nnnnnxx where xx is a common time | |||||
* multiplier suffix. | |||||
*/ | |||||
protected long parseTime(String value) { | |||||
int i = 0; | |||||
for (i = 0; i < value.length(); i++) { | |||||
char ch = value.charAt(i); | |||||
if (ch < '0' || ch > '9') { | |||||
break; | |||||
} | |||||
} | |||||
if (i == 0) { | |||||
throw new NumberFormatException(); | |||||
} | |||||
String digits = value.substring(0, i); | |||||
return Long.parseLong(digits) * getMultiplier(value.substring(i)); | |||||
} | |||||
/** | |||||
* Look for and decipher a multiplier suffix in the string. | |||||
* @param value - a string with a series of digits followed by the | |||||
* scale suffix. | |||||
*/ | |||||
protected long getMultiplier(String value) { | |||||
String lowercaseValue = value.toLowerCase(); | |||||
if (lowercaseValue.startsWith("ms")) { | |||||
return 1; | |||||
} | |||||
if (lowercaseValue.startsWith("s")) { | |||||
return 1000; | |||||
} | |||||
if (lowercaseValue.startsWith("m")) { | |||||
return 1000 * 60; | |||||
} | |||||
if (lowercaseValue.startsWith("h")) { | |||||
return 1000 * 60 * 60; | |||||
} | |||||
return 1; | |||||
} | |||||
} |
@@ -154,6 +154,20 @@ public abstract class ConditionBase extends ProjectComponent { | |||||
*/ | */ | ||||
public void addIsSet(IsSet i) {conditions.addElement(i);} | public void addIsSet(IsSet i) {conditions.addElement(i);} | ||||
/** | |||||
* Add an <http> condition. | |||||
* | |||||
* @since 1.7 | |||||
*/ | |||||
public void addHttp(Http h) {conditions.addElement(h);} | |||||
/** | |||||
* Add a <socket> condition. | |||||
* | |||||
* @since 1.7 | |||||
*/ | |||||
public void addSocket(Socket s) {conditions.addElement(s);} | |||||
/** | /** | ||||
* Inner class that configures those conditions with a project | * Inner class that configures those conditions with a project | ||||
* instance that need it. | * instance that need it. | ||||
@@ -0,0 +1,107 @@ | |||||
/* | |||||
* The Apache Software License, Version 1.1 | |||||
* | |||||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||||
* reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in | |||||
* the documentation and/or other materials provided with the | |||||
* distribution. | |||||
* | |||||
* 3. The end-user documentation included with the redistribution, if | |||||
* any, must include the following acknowlegement: | |||||
* "This product includes software developed by the | |||||
* Apache Software Foundation (http://www.apache.org/)." | |||||
* Alternately, this acknowlegement may appear in the software itself, | |||||
* if and wherever such third-party acknowlegements normally appear. | |||||
* | |||||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||||
* Foundation" must not be used to endorse or promote products derived | |||||
* from this software without prior written permission. For written | |||||
* permission, please contact apache@apache.org. | |||||
* | |||||
* 5. Products derived from this software may not be called "Apache" | |||||
* nor may "Apache" appear in their names without prior written | |||||
* permission of the Apache Group. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
* ==================================================================== | |||||
* | |||||
* This software consists of voluntary contributions made by many | |||||
* individuals on behalf of the Apache Software Foundation. For more | |||||
* information on the Apache Software Foundation, please see | |||||
* <http://www.apache.org/>. | |||||
*/ | |||||
package org.apache.tools.ant.taskdefs.condition; | |||||
import org.apache.tools.ant.BuildException; | |||||
import org.apache.tools.ant.Project; | |||||
import org.apache.tools.ant.ProjectComponent; | |||||
import java.io.IOException; | |||||
import java.net.MalformedURLException; | |||||
import java.net.HttpURLConnection; | |||||
import java.net.URLConnection; | |||||
import java.net.URL; | |||||
/** | |||||
* Condition to wait for a HTTP request to succeed. Its attribute(s) are: | |||||
* url - the URL of the request. | |||||
* | |||||
* @author <a href="mailto:denis@network365.com">Denis Hennessy</a> | |||||
*/ | |||||
public class Http extends ProjectComponent implements Condition { | |||||
String spec = null; | |||||
public void setUrl(String url) { | |||||
spec = url; | |||||
} | |||||
public boolean eval() throws BuildException { | |||||
if (spec == null) { | |||||
throw new BuildException("No url specified in HTTP task"); | |||||
} | |||||
log("Checking for " + spec, Project.MSG_VERBOSE); | |||||
try { | |||||
URL url = new URL(spec); | |||||
try { | |||||
URLConnection conn = url.openConnection(); | |||||
if (conn instanceof HttpURLConnection) { | |||||
HttpURLConnection http = (HttpURLConnection) conn; | |||||
int code = http.getResponseCode(); | |||||
log("Result code for " + spec + " was " + code, Project.MSG_VERBOSE); | |||||
if (code > 0 && code < 500) { | |||||
return true; | |||||
} else { | |||||
return false; | |||||
} | |||||
} | |||||
} catch (java.io.IOException e) { | |||||
return false; | |||||
} | |||||
} catch (MalformedURLException e) { | |||||
throw new BuildException("Badly formed URL: " + spec, e); | |||||
} | |||||
return true; | |||||
} | |||||
} |
@@ -0,0 +1,98 @@ | |||||
/* | |||||
* The Apache Software License, Version 1.1 | |||||
* | |||||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||||
* reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in | |||||
* the documentation and/or other materials provided with the | |||||
* distribution. | |||||
* | |||||
* 3. The end-user documentation included with the redistribution, if | |||||
* any, must include the following acknowlegement: | |||||
* "This product includes software developed by the | |||||
* Apache Software Foundation (http://www.apache.org/)." | |||||
* Alternately, this acknowlegement may appear in the software itself, | |||||
* if and wherever such third-party acknowlegements normally appear. | |||||
* | |||||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||||
* Foundation" must not be used to endorse or promote products derived | |||||
* from this software without prior written permission. For written | |||||
* permission, please contact apache@apache.org. | |||||
* | |||||
* 5. Products derived from this software may not be called "Apache" | |||||
* nor may "Apache" appear in their names without prior written | |||||
* permission of the Apache Group. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
* ==================================================================== | |||||
* | |||||
* This software consists of voluntary contributions made by many | |||||
* individuals on behalf of the Apache Software Foundation. For more | |||||
* information on the Apache Software Foundation, please see | |||||
* <http://www.apache.org/>. | |||||
*/ | |||||
package org.apache.tools.ant.taskdefs.condition; | |||||
import org.apache.tools.ant.BuildException; | |||||
import org.apache.tools.ant.Project; | |||||
import org.apache.tools.ant.ProjectComponent; | |||||
import java.io.IOException; | |||||
/** | |||||
* Condition to wait for a TCP/IP socket to have a listener. Its attribute(s) are: | |||||
* server - the name of the server. | |||||
* port - the port number of the socket. | |||||
* | |||||
* @author <a href="mailto:denis@network365.com">Denis Hennessy</a> | |||||
*/ | |||||
public class Socket extends ProjectComponent implements Condition { | |||||
String server = null; | |||||
int port = 0; | |||||
public void setServer(String server) { | |||||
this.server = server; | |||||
} | |||||
public void setPort(int port) { | |||||
this.port = port; | |||||
} | |||||
public boolean eval() throws BuildException { | |||||
if (server == null) { | |||||
throw new BuildException("No server specified in Socket task"); | |||||
} | |||||
if (port == 0) { | |||||
throw new BuildException("No port specified in Socket task"); | |||||
} | |||||
log("Checking for listener at " + server + ":" + port, Project.MSG_VERBOSE); | |||||
try { | |||||
java.net.Socket socket = new java.net.Socket(server, port); | |||||
} catch (IOException e) { | |||||
return false; | |||||
} | |||||
return true; | |||||
} | |||||
} |
@@ -56,6 +56,7 @@ dependset=org.apache.tools.ant.taskdefs.DependSet | |||||
bzip2=org.apache.tools.ant.taskdefs.BZip2 | bzip2=org.apache.tools.ant.taskdefs.BZip2 | ||||
bunzip2=org.apache.tools.ant.taskdefs.BUnzip2 | bunzip2=org.apache.tools.ant.taskdefs.BUnzip2 | ||||
checksum=org.apache.tools.ant.taskdefs.Checksum | checksum=org.apache.tools.ant.taskdefs.Checksum | ||||
waitfor=org.apache.tools.ant.taskdefs.WaitFor | |||||
# optional tasks | # optional tasks | ||||
script=org.apache.tools.ant.taskdefs.optional.Script | script=org.apache.tools.ant.taskdefs.optional.Script | ||||