source: release-kits/lirk3/bin/ant-installer/web/manual/manual/CoreTasks/conditions.html@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 30.4 KB
Line 
1<!--
2 Licensed to the Apache Software Foundation (ASF) under one or more
3 contributor license agreements. See the NOTICE file distributed with
4 this work for additional information regarding copyright ownership.
5 The ASF licenses this file to You under the Apache License, Version 2.0
6 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16-->
17<html>
18
19<head>
20<meta http-equiv="Content-Language" content="en-us">
21<link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
22<title>Conditions Task</title>
23</head>
24
25<body>
26
27<h2><a name="Conditions">Conditions</a></h2>
28 <p>Conditions are nested elements of the
29<a href="condition.html"><code>&lt;condition&gt;</code></a> and
30<a href="waitfor.html"><code>&lt;waitfor&gt;</code></a> tasks.
31 There are core conditions and custom conditions. Custom
32 conditions are described in
33 <a href="../CoreTypes/custom-programming.html#customconditions">
34 Custom Conditions</a>.
35 Core Conditions are described below.
36 </p>
37 <h3><a name="coreconditions">Core Conditions</a></h3>
38
39<p>These are the nested elements that can be used as conditions in the
40<a href="condition.html"><code>&lt;condition&gt;</code></a> and
41<a href="waitfor.html"><code>&lt;waitfor&gt;</code></a> tasks.</p>
42
43<h4>not</h4>
44<p>The <code>&lt;not&gt;</code> element expects exactly one other
45condition to be nested into this element, negating the result of the
46condition. It doesn't have any attributes and accepts all nested
47elements of the condition task as nested elements as well.</p>
48
49<h4>and</h4> <p>
50The <code>&lt;and&gt;</code> element doesn't have any attributes and
51accepts an arbitrary number of conditions as nested elements - all
52nested elements of the condition task are supported. This condition
53is true if all of its contained conditions are, conditions will be
54evaluated in the order they have been specified in the build file.</p>
55<p>The <code>&lt;and&gt;</code> condition has the same shortcut
56semantics as the Java &amp;&amp; operator, as soon as one of the
57nested conditions is false, no other condition will be evaluated.</p>
58
59<h4>or</h4> <p>
60The <code>&lt;or&gt;</code> element doesn't have any attributes and
61accepts an arbitrary number of conditions as nested elements - all
62nested elements of the condition task are supported. This condition
63is true if at least one of its contained conditions is, conditions
64will be evaluated in the order they have been specified in the build
65file.</p> <p>The <code>&lt;or&gt;</code> condition has the same
66shortcut semantics as the Java || operator, as soon as one of the
67nested conditions is true, no other condition will be evaluated.</p>
68
69<h4>xor</h4>
70<p>The <code>&lt;xor&gt;</code> element performs an exclusive
71or on all nested elements, similar to the <code>^</code> operator
72in Java. It only evaluates to true if an odd number of nested conditions
73are true. There is no shortcutting of evaluation, unlike the <code>&lt;and&gt;</code>
74and <code>&lt;or&gt;</code> tests.
75It doesn't have any attributes and accepts all nested
76elements of the condition task as nested elements as well.</p>
77
78<h4>available</h4>
79<p>This condition is identical to the <a
80href="available.html">Available</a> task, all attributes and nested
81elements of that task are supported, the property and value attributes
82are redundant and will be ignored.</p>
83
84<h4>uptodate</h4>
85<p>This condition is identical to the <a
86href="uptodate.html">Uptodate</a> task, all attributes and nested
87elements of that task are supported, the property and value attributes
88are redundant and will be ignored.</p>
89
90<h4>os</h4>
91<p>Test whether the current operating system is of a given type. Each
92defined attribute is tested and the result is true only if <i>all</i>
93the tests succeed.
94</p>
95<table border="1" cellpadding="2" cellspacing="0">
96 <tr>
97 <td valign="top"><b>Attribute</b></td>
98 <td valign="top"><b>Description</b></td>
99 <td align="center" valign="top"><b>Required</b></td>
100 </tr>
101 <tr>
102 <td valign="top">family</td>
103 <td valign="top">The name of the operating system family to expect.</td>
104 <td valign="top" align="center">No</td>
105 </tr>
106 <tr>
107 <td valign="top">name</td>
108 <td valign="top">The name of the operating system to expect.</td>
109 <td valign="top" align="center">No</td>
110 </tr>
111 <tr>
112 <td valign="top">arch</td>
113 <td valign="top">The architecture of the operating system to expect.</td>
114 <td valign="top" align="center">No</td>
115 </tr>
116 <tr>
117 <td valign="top">version</td>
118 <td valign="top">The version of the operating system to expect.</td>
119 <td valign="top" align="center">No</td>
120 </tr>
121</table>
122<p>Supported values for the family attribute are:
123<ul>
124 <li>windows (for all versions of Microsoft Windows)</li>
125 <li>dos (for all Microsoft DOS based operating systems including
126 Microsoft Windows and OS/2)</li>
127 <li>mac (for all Apple Macintosh systems)</li>
128 <li>unix (for all Unix and Unix-like operating systems)</li>
129 <li>netware (for Novell NetWare)</li>
130 <li>os/2 (for OS/2)</li>
131 <li>tandem (for HP's NonStop Kernel - formerly Tandem)</li>
132 <li>win9x for Microsoft Windows 95 and 98, ME and CE</li>
133 <li>winnt for Microsoft Windows NT-based systems, including Windows 2000, XP and
134 successors</li>
135 <li>z/os for z/OS and OS/390</li>
136 <li>os/400 for OS/400</li>
137 <li>openvms for OpenVMS</li>
138</ul>
139
140<h4>equals</h4>
141<p>Tests whether the two given Strings are identical</p>
142<table border="1" cellpadding="2" cellspacing="0">
143 <tr>
144 <td valign="top"><b>Attribute</b></td>
145 <td valign="top"><b>Description</b></td>
146 <td align="center" valign="top"><b>Required</b></td>
147 </tr>
148 <tr>
149 <td valign="top">arg1</td>
150 <td valign="top">First string to test.</td>
151 <td valign="top" align="center">Yes</td>
152 </tr>
153 <tr>
154 <td valign="top">arg2</td>
155 <td valign="top">Second string to test.</td>
156 <td valign="top" align="center">Yes</td>
157 </tr>
158 <tr>
159 <td valign="top">casesensitive</td>
160 <td valign="top">Perform a case sensitive comparision. Default is
161 true.</td>
162 <td valign="top" align="center">No</td>
163 </tr>
164 <tr>
165 <td valign="top">trim</td>
166 <td valign="top">Trim whitespace from arguments before comparing
167 them. Default is false.</td>
168 <td valign="top" align="center">No</td>
169 </tr>
170</table>
171
172<h4>isset</h4>
173<p>Test whether a given property has been set in this project.</p>
174<table border="1" cellpadding="2" cellspacing="0">
175 <tr>
176 <td valign="top"><b>Attribute</b></td>
177 <td valign="top"><b>Description</b></td>
178 <td align="center" valign="top"><b>Required</b></td>
179 </tr>
180 <tr>
181 <td valign="top">property</td>
182 <td valign="top">The name of the property to test.</td>
183 <td valign="top" align="center">Yes</td>
184 </tr>
185</table>
186
187<h4>checksum</h4>
188<p>This condition is identical to the <a href="checksum.html">Checksum</a>
189task, all attributes and nested elements of that task are supported,
190the property and overwrite attributes are redundant and will be
191ignored.</p>
192
193<h4>http</h4>
194<p>The <code>http</code> condition checks for a valid response from a
195web server of the specified url. By default, HTTP responses errors
196of 400 or greater are viewed as invalid.</p>
197<table border="1" cellpadding="2" cellspacing="0">
198 <tr>
199 <td width="12%" valign="top"><b>Attribute</b></td>
200 <td width="78%" valign="top"><b>Description</b></td>
201 <td width="10%" valign="top"><b>Required</b></td>
202 </tr>
203 <tr>
204 <td valign="top">url</td>
205 <td valign="top">The full URL of the page to request. The web server must
206 return a status code below the value of <tt>errorsBeginAt</tt></td>
207 <td align="center">Yes.</td>
208 </tr>
209 <tr>
210 <td valign="top">errorsBeginAt</td>
211 <td valign="top">The lowest HTTP response code that signals an error;
212 by default '400'; server errors, not-authorized, not-found and the like
213 are detected</td>
214 <td align="center">No</td>
215 </tr>
216</table>
217
218<h4>socket</h4>
219<p>The <code>socket</code> condition checks for the existence of a
220TCP/IP listener at the specified host and port.</p>
221<table border="1" cellpadding="2" cellspacing="0">
222 <tr>
223 <td width="12%" valign="top"><b>Attribute</b></td>
224 <td width="78%" valign="top"><b>Description</b></td>
225 <td width="10%" valign="top"><b>Required</b></td>
226 </tr>
227 <tr>
228 <td valign="top">server</td>
229 <td valign="top">The DNS name or IP address of the server.</td>
230 <td align="center">Yes.</td>
231 </tr>
232 <tr>
233 <td valign="top">port</td>
234 <td valign="top">The port number to connect to.</td>
235 <td align="center">Yes.</td>
236 </tr>
237</table>
238
239<h4>filesmatch</h4>
240<p>Test two files for matching. Nonexistence of one file results in "false",
241although if neither exists they are considered equal in terms of content.
242This test does a byte for byte comparision, so test time scales with
243byte size. NB: if the files are different sizes, one of them is missing
244or the filenames match the answer is so obvious the detailed test is omitted.
245
246</p>
247<table border="1" cellpadding="2" cellspacing="0">
248 <tr>
249 <td width="12%" valign="top"><b>Attribute</b></td>
250 <td width="78%" valign="top"><b>Description</b></td>
251 <td width="10%" valign="top"><b>Required</b></td>
252 </tr>
253 <tr>
254 <td valign="top">file1</td>
255 <td valign="top">First file to test</td>
256 <td align="center">Yes</td>
257 </tr>
258 <tr>
259 <td valign="top">file2</td>
260 <td valign="top">Second file to test</td>
261 <td align="center">Yes</td>
262 </tr>
263 <tr>
264 <td valign="top">textfile</td>
265 <td valign="top">Whether to ignore line endings
266 when comparing files; defaults to <i>false</i>, while
267 <i>true</i> bypasses the size comparison. <b>Since Ant 1.7</b>
268 </td>
269 <td align="center">No</td>
270 </tr>
271</table>
272
273<h4>contains</h4>
274<p>Tests whether a string contains another one.</p>
275<table border="1" cellpadding="2" cellspacing="0">
276 <tr>
277 <td valign="top"><b>Attribute</b></td>
278 <td valign="top"><b>Description</b></td>
279 <td align="center" valign="top"><b>Required</b></td>
280 </tr>
281 <tr>
282 <td valign="top">string</td>
283 <td valign="top">The string to search in.</td>
284 <td valign="top" align="center">Yes</td>
285 </tr>
286 <tr>
287 <td valign="top">substring</td>
288 <td valign="top">The string to search for.</td>
289 <td valign="top" align="center">Yes</td>
290 </tr>
291 <tr>
292 <td valign="top">casesensitive</td>
293 <td valign="top">Perform a case sensitive comparision. Default is
294 true.</td>
295 <td valign="top" align="center">No</td>
296 </tr>
297</table>
298
299<h4>istrue</h4>
300<p>Tests whether a string equals any of the ant definitions of true,
301that is "true","yes", or "on"</p>
302<table border="1" cellpadding="2" cellspacing="0">
303 <tr>
304 <td valign="top"><b>Attribute</b></td>
305 <td valign="top"><b>Description</b></td>
306 <td align="center" valign="top"><b>Required</b></td>
307 </tr>
308 <tr>
309 <td valign="top">value</td>
310 <td valign="top">value to test</td>
311 <td valign="top" align="center">Yes</td>
312 </tr>
313</table>
314<blockquote><pre>
315&lt;istrue value=&quot;${someproperty}&quot;/&gt;
316&lt;istrue value=&quot;false&quot;/&gt;
317</pre></blockquote>
318
319<h4>isfalse</h4>
320<p>Tests whether a string is not true, the negation of &lt;istrue&gt;
321</p>
322<table border="1" cellpadding="2" cellspacing="0">
323 <tr>
324 <td valign="top"><b>Attribute</b></td>
325 <td valign="top"><b>Description</b></td>
326 <td align="center" valign="top"><b>Required</b></td>
327 </tr>
328 <tr>
329 <td valign="top">value</td>
330 <td valign="top">value to test</td>
331 <td valign="top" align="center">Yes</td>
332 </tr>
333</table>
334<blockquote><pre>
335&lt;isfalse value=&quot;${someproperty}&quot;/&gt;
336&lt;isfalse value=&quot;false&quot;/&gt;
337</pre></blockquote>
338
339<h4>isreference</h4>
340
341<p>Test whether a given reference has been defined in this project and
342- optionally - is of an expected type.</p>
343
344<p>This condition has been added in Apache Ant 1.6.</p>
345
346<table border="1" cellpadding="2" cellspacing="0">
347 <tr>
348 <td valign="top"><b>Attribute</b></td>
349 <td valign="top"><b>Description</b></td>
350 <td align="center" valign="top"><b>Required</b></td>
351 </tr>
352 <tr>
353 <td valign="top">refid</td>
354 <td valign="top">The id of the reference to test.</td>
355 <td valign="top" align="center">Yes</td>
356 </tr>
357 <tr>
358 <td valign="top">type</td>
359 <td valign="top">Name of the data type or task this reference is
360 expected to be.</td>
361 <td valign="top" align="center">No</td>
362 </tr>
363</table>
364 <h4>issigned</h4>
365 <p>
366 Test whether a jarfile is signed.
367 If the name of the
368 signature is passed, the file is checked for presence of that
369 particular signature; otherwise the file is checked for the
370 existence of any signature. It does not perform rigorous
371 signature validation; it only looks for the presence of a signature.
372 </p>
373 <p>
374 This condition was added in Apache Ant 1.7.
375 </p>
376 <table border="1" cellpadding="2" cellspacing="0">
377 <tr>
378 <td valign="top"><b>Attribute</b></td>
379 <td valign="top"><b>Description</b></td>
380 <td align="center" valign="top"><b>Required</b></td>
381 </tr>
382 <tr>
383 <td valign="top">file</td>
384 <td valign="top">
385 The jarfile that is to be tested for the presence
386 of a signature.
387 </td>
388 <td valign="top" align="center">Yes</td>
389 </tr>
390 <tr>
391 <td valign="top">name</td>
392 <td valign="top"> The signature name to check for.</td>
393 <td valign="top" align="center">No</td>
394 </tr>
395 </table>
396 <h4>isfileselected</h4>
397 <p>
398 Test whether a file passes an embedded
399 <a href="../CoreTypes/selectors.html">selector</a>.
400 </p>
401 <p>
402 This condition was added in Apache Ant 1.6.3.
403 </p>
404 <table border="1" cellpadding="2" cellspacing="0">
405 <tr>
406 <td valign="top"><b>Attribute</b></td>
407 <td valign="top"><b>Description</b></td>
408 <td align="center" valign="top"><b>Required</b></td>
409 </tr>
410 <tr>
411 <td valign="top">file</td>
412 <td valign="top">
413 The file to check if is passes the embedded selector.
414 </td>
415 <td valign="top" align="center">Yes</td>
416 </tr>
417 <tr>
418 <td valign="top">basedir</td>
419 <td valign="top">The base directory to use for name based selectors. It this is not set,
420 the project's basedirectory will be used.</td>
421 <td valign="top" align="center">No</td>
422 </tr>
423 </table>
424 <p>
425 Example usage:
426 </p>
427<blockquote><pre>
428&lt;isfileselected file="a.xml"&gt;
429 &lt;date datetime="06/28/2000 2:02 pm" when="equal"/&gt;
430&lt;/isfileselected&gt;
431</pre></blockquote>
432<h4>typefound</h4>
433
434<p>Test whether a given type is defined, and that
435its implementation class can be loaded. Types include
436tasks, datatypes, scriptdefs, macrodefs and presetdefs.</p>
437
438<p>This condition was added in Apache Ant 1.7.</p>
439
440<table border="1" cellpadding="2" cellspacing="0">
441 <tr>
442 <td valign="top"><b>Attribute</b></td>
443 <td valign="top"><b>Description</b></td>
444 <td align="center" valign="top"><b>Required</b></td>
445 </tr>
446 <tr>
447 <td valign="top">name</td>
448 <td valign="top">name of the type</td>
449 <td valign="top" align="center">Yes</td>
450 </tr>
451 <tr>
452 <td valign="top">uri</td>
453 <td valign="top">
454 The uri that this type lives in.
455 </td>
456 <td valign="top" align="center">No</td>
457 </tr>
458</table>
459
460 <p>
461 Example usages:
462 </p>
463<blockquote><pre>
464&lt;typefound name="junit"/&gt;
465&lt;typefound uri="antlib:org.apache.maven.artifact.ant" name="artifact"/&gt;
466</pre></blockquote>
467
468<h4>scriptcondition</h4>
469
470<p>Evaluate a condition based on a script in any
471<a href="http://jakarta.apache.org/bsf" target="_top">Apache BSF</a>
472 or
473 <a href="https://scripting.dev.java.net">JSR 223</a>
474supported language.
475</p>
476<p>
477See the <a href="../OptionalTasks/script.html">Script</a> task for
478an explanation of scripts and dependencies.
479</p>
480
481<p>This condition was added in Apache Ant 1.7.</p>
482
483<table border="1" cellpadding="2" cellspacing="0">
484 <tr>
485 <td valign="top"><b>Attribute</b></td>
486 <td valign="top"><b>Description</b></td>
487 <td align="center" valign="top"><b>Required</b></td>
488 </tr>
489 <tr>
490 <td valign="top">language</td>
491 <td valign="top">script language</td>
492 <td valign="top" align="center">Yes</td>
493 </tr>
494 <tr>
495 <td valign="top">manager</td>
496 <td valign="top">
497 The script engine manager to use.
498 See the <a href="../OptionalTasks/script.html">script</a> task
499 for using this attribute.
500 </td>
501 <td valign="top" align="center">No - default is "auto"</td>
502 </tr>
503 <tr>
504 <td valign="top">value</td>
505 <td valign="top">default boolean value</td>
506 <td valign="top" align="center">No -default is "false"</td>
507 </tr>
508 <tr>
509 <td valign="top">src</td>
510 <td valign="top">filename of script source</td>
511 <td valign="top" align="center">No</td>
512 </tr>
513 <tr>
514 <td valign="top">setbeans</td>
515 <td valign="top">whether to have all properties, references and targets as
516 global variables in the script.</td>
517 <td valign="top" align="center">No, default is "true".</td>
518 </tr>
519 <tr>
520 <td valign="top">classpath</td>
521 <td valign="top">
522 The classpath to pass into the script.
523 </td>
524 <td align="center" valign="top">No</td>
525 </tr>
526 <tr>
527 <td valign="top">classpathref</td>
528 <td valign="top">The classpath to use, given as a
529 <a href="../using.html#references">reference</a> to a path defined elsewhere.
530 <td align="center" valign="top">No</td>
531 </tr>
532</table>
533<h5>Parameters specified as nested elements</h5>
534<h6>classpath</h6>
535 <p>
536 See the <a href="../OptionalTasks/script.html">script</a> task
537 for using this nested element.
538 </p>
539<h5>Description</h5>
540<p>
541The script supports script language inline, this script has access to the
542same beans as the <code>&lt;script&gt;</code> task, and to the <code>
543self</code> bean, which refers back to the condition itself. The
544<code>value</code> property of this bean sets the return value:
545</p>
546<p>
547Example:
548</p>
549<blockquote><pre>
550&lt;scriptcondition language=&quot;javascript&quot;
551 value=&quot;true&quot;&gt;
552 self.setValue(false);
553&lt;/scriptcondition&gt;
554</pre></blockquote>
555
556Sets the default value of the condition to true, then in the script,
557sets the value to false. This condition always evaluates to "false"
558
559<h4>parsersupports</h4>
560
561<p>Tests whether Ant's XML parser supports a given
562feature or property, as per the SAX/JAXP specifications, by
563attempting to set the appropriate property/feature/</p>
564
565<p>This condition was added in Apache Ant 1.7.</p>
566
567<table border="1" cellpadding="2" cellspacing="0">
568 <tr>
569 <td valign="top"><b>Attribute</b></td>
570 <td valign="top"><b>Description</b></td>
571 <td align="center" valign="top"><b>Required</b></td>
572 </tr>
573 <tr>
574 <td valign="top">property</td>
575 <td valign="top">property to set</td>
576 <td valign="top" align="center">one of property or feature</td>
577 </tr>
578 <tr>
579 <td valign="top">feature</td>
580 <td valign="top">feature to set</td>
581 <td valign="top" align="center">one of property or feature</td>
582 </tr>
583 <tr>
584 <td valign="top">value</td>
585 <td valign="top">string (property) or boolean (feature)</td>
586 <td valign="top" align="center">For property tests, but not for feature tests</td>
587 </tr>
588</table>
589
590<blockquote><pre>
591&lt;parsersupports feature="http://xml.org/sax/features/namespaces"/&gt;
592</pre></blockquote>
593Check for namespace support. All SAX2 parsers should have this.
594<blockquote><pre>
595&lt;or&gt;
596 &lt;parsersupports
597 feature="http://apache.org/xml/features/validation/schema"/&gt;
598 &lt;parsersupports
599 feature="http://java.sun.com/xml/jaxp/properties/schemaSource"/&gt;
600&lt;/or&gt;
601</pre></blockquote>
602
603Check for XML Schema support.
604
605<pre>
606&lt;parsersupports
607 property="http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation"
608 value="document.xsd"/&gt;
609</pre>
610
611Check for Xerces-specific definition of the location of the no namespace schema.
612
613<h4>isreachable</h4>
614
615<p>Uses Java1.5+ networking APIs to probe for a (remote) system being
616reachable. Exactly what probe mechanisms are used is an implementation
617feature of the JVM. They may include ICMP "ping" packets, UDP or TCP connections
618to port 7 "echo service" or other means. On Java1.4 and earlier, being able
619to resolve the hostname is considered success. This means that if DNS is not
620working or a URL/hostname is bad, the test will fail, but otherwise succeed
621even if the remote host is actually absent.
622
623</p>
624<p>
625This condition turns unknown host exceptions into false conditions. This is
626because on a laptop, DNS is one of the first services when the network goes; you
627are implicitly offline.
628</p>
629<p>
630 If a URL is supplied instead of a host, the hostname is extracted
631 and used in the test - all other parts of the URL are discarded.
632</p>
633<p>
634The test may not work through firewalls, that is, something may be reachable
635using a protocol such as HTTP, while the lower level ICMP packets get dropped
636on the floor. Similarly, a host may detected as reachable with ICMP, but
637not reachable on other ports (i.e. port 80), because of firewalls.
638</p>
639<p>
640
641This condition was added in Apache Ant 1.7.</p>
642
643<table border="1" cellpadding="2" cellspacing="0">
644 <tr>
645 <td valign="top"><b>Attribute</b></td>
646 <td valign="top"><b>Description</b></td>
647 <td align="center" valign="top"><b>Required</b></td>
648 </tr>
649 <tr>
650 <td valign="top">host</td>
651 <td valign="top">host to check for</td>
652 <td valign="top" align="center">one of url or host</td>
653 </tr>
654 <tr>
655 <td valign="top">url</td>
656 <td valign="top">URL containing hostname</td>
657 <td valign="top" align="center">one of url or host</td>
658 </tr>
659 <tr>
660 <td valign="top">timeout</td>
661 <td valign="top">timeout in seconds</td>
662 <td valign="top" align="center">no, default is 30s</td>
663 </tr>
664</table>
665
666<blockquote><pre>
667&lt;condition property="offline"&gt;
668 &lt;isreachable url="http://ibiblio.org/maven/" /&gt;
669&lt;/condition&gt;
670</pre></blockquote>
671
672<p>
673Probe for the maven repository being reachable.
674</p>
675
676<blockquote><pre>
677&lt;condition property="offline"&gt;
678 &lt;isreachable host="ibiblio.org" timeout="10" /&gt;
679&lt;/condition&gt;
680</pre></blockquote>
681
682<p>
683Probe for the maven repository being reachable using the hostname, ten second timeout..
684</p>
685
686<h4>length</h4>
687<p>This condition is a facet of the <a href="length.html">Length</a> task.
688 It is used to test the length of a string or one or more files.
689 <b>Since Ant 1.6.3</b>
690</p>
691
692<blockquote><pre>
693&lt;length string=" foo " trim="true" length="3" /&gt;
694</pre></blockquote>
695<p>Verify a string is of a certain length.</p>
696
697<blockquote><pre>
698&lt;length file=&quot;foo&quot; when=&quot;greater&quot; length=&quot;0&quot; /&gt;
699</pre></blockquote>
700<p>Verify that file <i>foo</i> is not empty.</p>
701
702<h4>isfailure</h4>
703
704<p>Test the return code of an executable (see the
705<a href="exec.html">Exec</a> task) for failure. <b>Since Ant 1.7</b></p>
706
707<table border="1" cellpadding="2" cellspacing="0">
708 <tr>
709 <td valign="top"><b>Attribute</b></td>
710 <td valign="top"><b>Description</b></td>
711 <td align="center" valign="top"><b>Required</b></td>
712 </tr>
713 <tr>
714 <td valign="top">code</td>
715 <td valign="top">The return code to test.</td>
716 <td valign="top" align="center">Yes</td>
717 </tr>
718</table>
719
720<h4>resourcecount</h4>
721<p>This condition is a facet of the
722 <a href="resourcecount.html">ResourceCount</a> task.
723 It is used to test the size of a
724 <a href="../CoreTypes/resources.html#collection">resource collection</a>.
725 <b>Since Ant 1.7</b>
726</p>
727
728<blockquote><pre>
729&lt;resourcecount refid=&quot;myresourcecollection&quot; when=&quot;greater&quot; length=&quot;0&quot; /&gt;
730</pre></blockquote>
731<p>Verify that a resource collection is not empty.</p>
732
733<h4>resourcesmatch</h4>
734<p>Test resources for matching. Nonexistence of one or more resources results in
735"false", although if none exists they are considered equal in terms of content.
736By default this test does a byte for byte comparision, so test time scales with
737byte size. NB: if the files are different sizes, one of them is missing
738or the filenames match the answer is so obvious the detailed test is omitted.
739The resources to check are specified as nested
740<a href="../CoreTypes/resources.html#collection">resource collections</a>,
741meaning that more than two resources can be checked; in this case all resources
742must match. <b>Since Ant 1.7</b>
743</p>
744<table border="1" cellpadding="2" cellspacing="0">
745 <tr>
746 <td width="12%" valign="top"><b>Attribute</b></td>
747 <td width="78%" valign="top"><b>Description</b></td>
748 <td width="10%" valign="top"><b>Required</b></td>
749 </tr>
750 <tr>
751 <td valign="top">astext</td>
752 <td valign="top">Whether to ignore line endings
753 when comparing resource content; defaults to <i>false</i>,
754 while <i>true</i> bypasses the size comparison.
755 </td>
756 <td align="center">No</td>
757 </tr>
758</table>
759
760<h4>hasmethod</h4>
761
762<p> Tests for a class having a method or field. If the class is not found
763 or fails to load, the build fails.
764
765 <b>Since Ant 1.7</b>
766</p>
767
768<table border="1" cellpadding="2" cellspacing="0">
769 <tr>
770 <td width="12%" valign="top"><b>Attribute</b></td>
771 <td width="78%" valign="top"><b>Description</b></td>
772 <td width="10%" valign="top"><b>Required</b></td>
773 </tr>
774 <tr>
775 <td valign="top">classname</td>
776 <td valign="top">name of the class to load</td>
777 <td align="center">yes</td>
778 </tr>
779 <tr>
780 <td valign="top">field</td>
781 <td valign="top">name of a field to look for</td>
782 <td align="center">one of field or method</td>
783 </tr>
784 <tr>
785 <td valign="top">method</td>
786 <td valign="top">name of a method to look for</td>
787 <td align="center">one of field or method</td>
788 </tr>
789
790 <tr>
791 <td valign="top">ignoreSystemClasses</td>
792 <td valign="top">should system classes be ignored?</td>
793 <td align="center">No -default is false</td>
794 </tr>
795 <tr>
796 <td valign="top">classpath</td>
797 <td valign="top">a class path</td>
798 <td align="center">No</td>
799 </tr>
800 <tr>
801 <td valign="top">classpathref</td>
802 <td valign="top">reference to a class path</td>
803 <td align="center">No</td>
804 </tr>
805</table>
806
807<p>
808 There is also a nested &lt;classpath&gt; element, which can be used to specify
809 a classpath.
810</p>
811<blockquote><pre>
812&lt;hasmethod classname="java.util.ArrayList" method="trimToSize" /&gt;
813</pre></blockquote>
814
815<p>Looks for the method trimToSize in the ArrayList class.</p>
816
817<h4>matches</h4>
818
819<p>
820 Test if the specified string matches the specified regular
821 expression pattern.
822 <b>Since Ant 1.7</b></p>
823
824<table border="1" cellpadding="2" cellspacing="0">
825 <tr>
826 <td valign="top"><b>Attribute</b></td>
827 <td valign="top"><b>Description</b></td>
828 <td align="center" valign="top"><b>Required</b></td>
829 </tr>
830 <tr>
831 <td valign="top">string</td>
832 <td valign="top">The string to test.</td>
833 <td valign="top" align="center">Yes</td>
834 </tr>
835 <tr>
836 <td valign="top">pattern</td>
837 <td valign="top">The regular expression pattern used to test.</td>
838 <td valign="top" align="center">Yes, unless there is a nested
839 <code>&lt;regexp&gt;</code> element.</td>
840 </tr>
841 <tr>
842 <td valign="top">casesensitive</td>
843 <td valign="top">Perform a case sensitive match. Default is
844 true.</td>
845 <td valign="top" align="center">No</td>
846 </tr>
847 <tr>
848 <td valign="top">multiline</td>
849 <td valign="top">
850 Perform a multi line match.
851 Default is false.</td>
852 <td valign="top" align="center">No</td>
853 </tr>
854 <tr>
855 <td valign="top">singleline</td>
856 <td valign="top">
857 This allows '.' to match new lines.
858 SingleLine is not to be confused with multiline, SingleLine is a perl
859 regex term, it corresponds to dotall in java regex.
860 Default is false.</td>
861 <td valign="top" align="center">No</td>
862 </tr>
863</table>
864
865 <p>
866 There is also an optional &lt;regexp&gt; element, which can be used to specify
867 a regular expression instead of the "pattern" attribute.
868 See <a href="../CoreTypes/regexp.html">Regexp Type</a> for the description
869 of the nested element regexp and of
870 the choice of regular expression implementation.
871 </p>
872 <p>
873 An example:
874 </p>
875<blockquote><pre>
876&lt;condition property="legal-password"&gt;
877 &lt;matches pattern="[1-9]" string="${user-input}"/&gt;
878&lt;/condition&gt;
879&lt;fail message="Your password should at least contain one number"
880 unless="legal-password"/&gt;
881</pre></blockquote>
882 <p>
883 The following example sets the property "ok" if
884 the property "input" is three characters long, starting
885 with 'a' and ending with 'b'.
886 </p>
887<blockquote><pre>
888&lt;condition property="ok"&gt;
889 &lt;matches string="${input}" pattern="^a.b$"/&gt;
890&lt;/condition&gt;
891</pre></blockquote>
892 <p>
893 The following defines a reference regular expression for
894 matching dates and then uses antunit to check if the
895 property "today" is in the correct format:
896 </p>
897<blockquote><pre>
898&lt;regexp id="date.pattern" pattern="^[0123]\d-[01]\d-[12]\d\d\d$"/&gt;
899
900&lt;au:assertTrue xmlns:au="antlib:org.apache.ant.antunit"&gt;
901 &lt;matches string="${today}"&gt;
902 &lt;regexp refid="date.pattern"/&gt;
903 &lt;/matches&gt;
904&lt;/au:assertTrue&gt;
905</pre></blockquote>
906 <p>
907 The following example shows the use of the singleline and the casesensitive
908 flags.
909 </p>
910<blockquote><pre>
911&lt;au:assertTrue&gt;
912 &lt;matches string="AB${line.separator}C" pattern="^ab.*C$"
913 casesensitive="false"
914 singleline="true"/&gt;
915&lt;/au:assertTrue&gt;
916&lt;au:assertFalse&gt;
917 &lt;matches string="AB${line.separator}C" pattern="^ab.*C$"
918 casesensitive="false"
919 singleline="false"/&gt;
920&lt;/au:assertFalse&gt;
921</pre></blockquote>
922<h4>antversion</h4>
923
924<p>
925 Test the ant version.
926 <b>Since Ant 1.7.0</b></p>
927
928<table border="1" cellpadding="2" cellspacing="0">
929 <tr>
930 <td valign="top"><b>Attribute</b></td>
931 <td valign="top"><b>Description</b></td>
932 <td align="center" valign="top"><b>Required</b></td>
933 </tr>
934 <tr>
935 <td valign="top">atleast</td>
936 <td valign="top">The version that this at least.
937 The format is major.minor.point.</td>
938 <td valign="top" rowspan="2" align="center">One of these.</td>
939 </tr>
940 <tr>
941 <td valign="top">exactly</td>
942 <td valign="top">The version that this ant is exactly.
943 The format is major.minor.point.</td>
944 </tr>
945</table>
946 <p>
947 An example:
948 </p>
949<blockquote><pre>
950&lt;condition property="ant-is-exact-7"&gt;
951 &lt;antversion exactly="1.7.0"/&gt;
952&lt;/condition&gt;
953</pre></blockquote>
954</body>
955</html>
Note: See TracBrowser for help on using the repository browser.