Debian Codegraph @

manual/Tasks/conditions.html

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