You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

conditions.html 30 KiB

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