ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/condition Http.java Socket.java ConditionBase.java
Date Fri, 30 Nov 2001 12:05:28 GMT
bodewig     01/11/30 04:05:27

  Modified:    .        WHATSNEW
               docs/manual coretasklist.html
               docs/manual/CoreTasks condition.html
               src/main/org/apache/tools/ant/taskdefs defaults.properties
               src/main/org/apache/tools/ant/taskdefs/condition
                        ConditionBase.java
  Added:       docs/manual/CoreTasks conditions.html waitfor.html
               src/main/org/apache/tools/ant/taskdefs WaitFor.java
               src/main/org/apache/tools/ant/taskdefs/condition Http.java
                        Socket.java
  Log:
  New task <waitfor> that waits until a given condition gets true or a
  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.
  
  Revision  Changes    Path
  1.181     +2 -2      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.180
  retrieving revision 1.181
  diff -u -r1.180 -r1.181
  --- WHATSNEW	2001/11/25 08:08:03	1.180
  +++ WHATSNEW	2001/11/30 12:05:27	1.181
  @@ -63,7 +63,7 @@
   * Added support for specifying CVS_RSH in the <cvs/> task
   
   * 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, 
     Jar, War and Ear tasks) have been deprecated and superseded by a 
  @@ -72,7 +72,7 @@
   * Added a new condition <isset> that test for the existence of a
     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
     assertTrue method instead of assert.
  
  
  
  1.27      +2 -0      jakarta-ant/docs/manual/coretasklist.html
  
  Index: coretasklist.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/manual/coretasklist.html,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- coretasklist.html	2001/11/21 07:31:01	1.26
  +++ coretasklist.html	2001/11/30 12:05:27	1.27
  @@ -81,6 +81,8 @@
   <a href="CoreTasks/unzip.html">Unwar</a><br>
   <a href="CoreTasks/unzip.html">Unzip</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/zip.html">Zip</a><br>
   </body>
  
  
  
  1.10      +2 -124    jakarta-ant/docs/manual/CoreTasks/condition.html
  
  Index: condition.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTasks/condition.html,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- condition.html	2001/11/26 14:22:19	1.9
  +++ condition.html	2001/11/30 12:05:27	1.10
  @@ -38,130 +38,8 @@
     </tr>
   </table>
   <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>&lt;not&gt;</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>&lt;and&gt;</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>&lt;and&gt;</code> condition has the same shortcut
  -semantics as the Java &amp;&amp; operator, as soon as one of the
  -nested conditions is false, no other condition will be evaluated.</p>
  -
  -<h4>or</h4> <p>
  -The <code>&lt;or&gt;</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>&lt;or&gt;</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>
   <pre>
  
  
  
  1.1                  jakarta-ant/docs/manual/CoreTasks/conditions.html
  
  Index: conditions.html
  ===================================================================
  <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>&lt;condition&gt;</code></a>
and 
  <a href="waitfor.html"><code>&lt;waitfor&gt;</code></a>
tasks.</p>
  
  <h4>not</h4>
  <p>The <code>&lt;not&gt;</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>&lt;and&gt;</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>&lt;and&gt;</code> condition has the same shortcut
  semantics as the Java &amp;&amp; operator, as soon as one of the
  nested conditions is false, no other condition will be evaluated.</p>
  
  <h4>or</h4> <p>
  The <code>&lt;or&gt;</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>&lt;or&gt;</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 &lt;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 &copy; 2001 Apache Software
  Foundation. All rights Reserved.</p>
  
  </body>
  </html>
  
  
  1.1                  jakarta-ant/docs/manual/CoreTasks/waitfor.html
  
  Index: waitfor.html
  ===================================================================
  <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: &quot;ms&quot;,

    &quot;s&quot;, &quot;m&quot;, &quot;h&quot; 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>&lt;waitfor&gt;</code> task are the same as those for the 
  <a href="condition.html"><code>&lt;condition&gt;</code></a>
task. See
  <a href="conditions.html">here</a> for the full list.</p>
  
  <h3>Examples</h3>
  <blockquote> 
    <p><code>&lt;waitfor maxwait=&quot;30s&quot;&gt;<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&lt;available file="errors.log"/&gt;<br>
      &lt;/waitfor&gt;</code></p>
  </blockquote>
  <p>waits up to 30 seconds for a file called errors.log to appear.</p>
  <blockquote>
    <p><code>&lt;waitfor maxwait=&quot;3m&quot; checkevery=&quot;500ms&quot;&gt;<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&lt;http url=&quot;http://localhost/myapp/index.html&quot;/&gt;<br>
      &lt;/waitfor&gt;</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>&lt;waitfor maxwait=&quot;10s&quot;&gt;<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&lt;and&gt;<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;socket
server=&quot;dbserver&quot; port=&quot;1521&quot;/&gt;<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;http
url=&quot;http://webserver/mypage.html&quot;/&gt;<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&lt;/and&gt;<br>
      &lt;/waitfor&gt;</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 &copy; 2000,2001 Apache Software Foundation.
All rights
  Reserved.</p>
  
  </body>
  </html>
  
  
  
  
  1.98      +1 -0      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties
  
  Index: defaults.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties,v
  retrieving revision 1.97
  retrieving revision 1.98
  diff -u -r1.97 -r1.98
  --- defaults.properties	2001/11/16 12:30:58	1.97
  +++ defaults.properties	2001/11/30 12:05:27	1.98
  @@ -56,6 +56,7 @@
   bzip2=org.apache.tools.ant.taskdefs.BZip2
   bunzip2=org.apache.tools.ant.taskdefs.BUnzip2
   checksum=org.apache.tools.ant.taskdefs.Checksum
  +waitfor=org.apache.tools.ant.taskdefs.WaitFor
   
   # optional tasks
   script=org.apache.tools.ant.taskdefs.optional.Script
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/taskdefs/WaitFor.java
  
  Index: WaitFor.java
  ===================================================================
  /*
   * 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;
      }
  }
  
  
  
  1.7       +15 -1     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java
  
  Index: ConditionBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ConditionBase.java	2001/11/22 08:45:03	1.6
  +++ ConditionBase.java	2001/11/30 12:05:27	1.7
  @@ -70,7 +70,7 @@
    * and the "container" conditions are in sync.
    *
    * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
  - * @version $Revision: 1.6 $
  + * @version $Revision: 1.7 $
    */
   public abstract class ConditionBase extends ProjectComponent {
       private Vector conditions = new Vector();
  @@ -153,6 +153,20 @@
        * @since 1.1
        */
       public void addIsSet(IsSet i) {conditions.addElement(i);}
  +
  +    /**
  +     * Add an &lt;http&gt; condition.
  +     *
  +     * @since 1.7
  +     */
  +    public void addHttp(Http h) {conditions.addElement(h);}
  +
  +    /**
  +     * Add a &lt;socket&gt; condition.
  +     *
  +     * @since 1.7
  +     */
  +    public void addSocket(Socket s) {conditions.addElement(s);}
   
       /**
        * Inner class that configures those conditions with a project
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/taskdefs/condition/Http.java
  
  Index: Http.java
  ===================================================================
  /*
   * 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;
      }
  }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/taskdefs/condition/Socket.java
  
  Index: Socket.java
  ===================================================================
  /*
   * 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;
      }
  
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message