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 31 KiB

7 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  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. https://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <html lang="en">
  17. <head>
  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 scope="col">Attribute</th>
  72. <th scope="col">Description</th>
  73. <th scope="col">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 scope="col">Attribute</th>
  119. <th scope="col">Description</th>
  120. <th scope="col">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 scope="col">Attribute</th>
  154. <th scope="col">Description</th>
  155. <th scope="col">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 scope="col">Attribute</th>
  173. <th scope="col">Description</th>
  174. <th scope="col">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. <tr>
  202. <td>readTimeout</td>
  203. <td>Read timeout, in milliseconds, that will be used while reading from the target URL.
  204. Accepts any value &ge; 0. Value of 0 implies wait indefinitely. Value &lt; 0 will be silently
  205. ignored.<br/>
  206. <em>since Ant 1.10.6</em></td>
  207. <td>No; defaults to <q>0</q></td>
  208. </tr>
  209. </table>
  210. <h4 id="socket">socket</h4>
  211. <p>The <code>socket</code> condition checks for the existence of a TCP/IP listener at the specified
  212. host and port.</p>
  213. <table class="attr">
  214. <tr>
  215. <th scope="col">Attribute</th>
  216. <th scope="col">Description</th>
  217. <th scope="col">Required</th>
  218. </tr>
  219. <tr>
  220. <td>server</td>
  221. <td>The DNS name or IP address of the server.</td>
  222. <td>Yes</td>
  223. </tr>
  224. <tr>
  225. <td>port</td>
  226. <td>The port number to connect to.</td>
  227. <td>Yes</td>
  228. </tr>
  229. </table>
  230. <h4 id="filesmatch">filesmatch</h4>
  231. <p>Test two files for matching. Nonexistence of one file results in <q>false</q>, although if
  232. neither exists they are considered equal in terms of content. This test does a byte for byte
  233. comparison, so test time scales with byte size. <strong>Note</strong>: if the files are different
  234. sizes, one of them is missing or the filenames match the answer is so obvious the detailed test is
  235. omitted.
  236. </p>
  237. <table class="attr">
  238. <tr>
  239. <th scope="col">Attribute</th>
  240. <th scope="col">Description</th>
  241. <th scope="col">Required</th>
  242. </tr>
  243. <tr>
  244. <td>file1</td>
  245. <td>First file to test</td>
  246. <td>Yes</td>
  247. </tr>
  248. <tr>
  249. <td>file2</td>
  250. <td>Second file to test</td>
  251. <td>Yes</td>
  252. </tr>
  253. <tr>
  254. <td>textfile</td>
  255. <td>Whether to ignore line endings when comparing files. <em>Since Ant 1.7</em>
  256. </td>
  257. <td>No; defaults to <q>false</q> which triggers a binary comparison</td>
  258. </tr>
  259. </table>
  260. <h4 id="contains">contains</h4>
  261. <p>Tests whether a string contains another one.</p>
  262. <table class="attr">
  263. <tr>
  264. <th scope="col">Attribute</th>
  265. <th scope="col">Description</th>
  266. <th scope="col">Required</th>
  267. </tr>
  268. <tr>
  269. <td>string</td>
  270. <td>The string to search in.</td>
  271. <td>Yes</td>
  272. </tr>
  273. <tr>
  274. <td>substring</td>
  275. <td>The string to search for.</td>
  276. <td>Yes</td>
  277. </tr>
  278. <tr>
  279. <td>casesensitive</td>
  280. <td>Perform a case sensitive comparison.</td>
  281. <td>No; default is <q>true</q></td>
  282. </tr>
  283. </table>
  284. <h4 id="istrue">istrue</h4>
  285. <p>Tests whether a string equals any of the Ant definitions of true, that
  286. is <q>true</q>, <q>yes</q>, or <q>on</q></p>
  287. <table class="attr">
  288. <tr>
  289. <th scope="col">Attribute</th>
  290. <th scope="col">Description</th>
  291. <th scope="col">Required</th>
  292. </tr>
  293. <tr>
  294. <td>value</td>
  295. <td>value to test</td>
  296. <td>Yes</td>
  297. </tr>
  298. </table>
  299. <pre>
  300. &lt;istrue value=&quot;${someproperty}&quot;/&gt;
  301. &lt;istrue value=&quot;false&quot;/&gt;</pre>
  302. <h4 id="isfalse">isfalse</h4>
  303. <p>Tests whether a string is not true, the negation of <code>&lt;istrue&gt;</code></p>
  304. <table class="attr">
  305. <tr>
  306. <th scope="col">Attribute</th>
  307. <th scope="col">Description</th>
  308. <th scope="col">Required</th>
  309. </tr>
  310. <tr>
  311. <td>value</td>
  312. <td>value to test</td>
  313. <td>Yes</td>
  314. </tr>
  315. </table>
  316. <pre>
  317. &lt;isfalse value=&quot;${someproperty}&quot;/&gt;
  318. &lt;isfalse value=&quot;false&quot;/&gt;</pre>
  319. <h4 id="isreference">isreference</h4>
  320. <p>Test whether a given reference has been defined in this project and&mdash;optionally&mdash;is of
  321. an expected type.</p>
  322. <p><em>Since Apache Ant 1.6</em>.</p>
  323. <table class="attr">
  324. <tr>
  325. <th scope="col">Attribute</th>
  326. <th scope="col">Description</th>
  327. <th scope="col">Required</th>
  328. </tr>
  329. <tr>
  330. <td>refid</td>
  331. <td>The <var>id</var> of the reference to test.</td>
  332. <td>Yes</td>
  333. </tr>
  334. <tr>
  335. <td>type</td>
  336. <td>Name of the data type or task this reference is expected to be.</td>
  337. <td>No</td>
  338. </tr>
  339. </table>
  340. <h4 id="issigned">issigned</h4>
  341. <p>Test whether a jarfile is signed. If the name of the signature is passed, the file is checked
  342. for presence of that particular signature; otherwise the file is checked for the existence of any
  343. signature. It does not perform rigorous signature validation; it only looks for the presence of a
  344. signature.</p>
  345. <p><em>Since Apache Ant 1.7</em>.</p>
  346. <table class="attr">
  347. <tr>
  348. <th scope="col">Attribute</th>
  349. <th scope="col">Description</th>
  350. <th scope="col">Required</th>
  351. </tr>
  352. <tr>
  353. <td>file</td>
  354. <td>The jarfile that is to be tested for the presence of a signature.</td>
  355. <td>Yes</td>
  356. </tr>
  357. <tr>
  358. <td>name</td>
  359. <td>The signature name to check for.</td>
  360. <td>No</td>
  361. </tr>
  362. </table>
  363. <h4 id="isfileselected">isfileselected</h4>
  364. <p>Test whether a file passes an embedded <a href="../Types/selectors.html">selector</a>.</p>
  365. <p><em>Since Apache Ant 1.6.3</em>.</p>
  366. <table class="attr">
  367. <tr>
  368. <th scope="col">Attribute</th>
  369. <th scope="col">Description</th>
  370. <th scope="col">Required</th>
  371. </tr>
  372. <tr>
  373. <td>file</td>
  374. <td>The file to check if is passes the embedded selector.</td>
  375. <td>Yes</td>
  376. </tr>
  377. <tr>
  378. <td>basedir</td>
  379. <td>The base directory to use for name based selectors. It this is not set, the
  380. project's <var>basedir</var> will be used.</td>
  381. <td>No</td>
  382. </tr>
  383. </table>
  384. <p>Example usage:</p>
  385. <pre>
  386. &lt;isfileselected file="a.xml"&gt;
  387. &lt;date datetime="06/28/2000 2:02 pm" when="equal"/&gt;
  388. &lt;/isfileselected&gt;</pre>
  389. <h4 id="typefound">typefound</h4>
  390. <p>Test whether a given type is defined, and that its implementation class can be loaded. Types
  391. include tasks, datatypes, scriptdefs, macrodefs and presetdefs.</p>
  392. <p><em>Since Apache Ant 1.7</em>.</p>
  393. <table class="attr">
  394. <tr>
  395. <th scope="col">Attribute</th>
  396. <th scope="col">Description</th>
  397. <th scope="col">Required</th>
  398. </tr>
  399. <tr>
  400. <td>name</td>
  401. <td>Name of the type</td>
  402. <td>Yes</td>
  403. </tr>
  404. <tr>
  405. <td>uri</td>
  406. <td>The URI that this type lives in.</td>
  407. <td>No</td>
  408. </tr>
  409. </table>
  410. <p>Example usages:</p>
  411. <pre>
  412. &lt;typefound name="junit"/&gt;
  413. &lt;typefound uri="antlib:org.apache.maven.artifact.ant" name="artifact"/&gt;</pre>
  414. <h4 id="scriptcondition">scriptcondition</h4>
  415. <p>Evaluate a condition based on a script in any <a href="https://jakarta.apache.org/bsf"
  416. target="_top">Apache BSF</a>
  417. or <a href="https://jcp.org/aboutJava/communityprocess/maintenance/jsr223/223ChangeLog.html"
  418. target="_top">JSR 223</a> supported language.</p>
  419. <p>See the <a href="../Tasks/script.html">Script</a> task for an explanation of scripts and
  420. dependencies.</p>
  421. <p><em>Since Apache Ant 1.7</em>.</p>
  422. <table class="attr">
  423. <tr>
  424. <th scope="col">Attribute</th>
  425. <th scope="col">Description</th>
  426. <th scope="col">Required</th>
  427. </tr>
  428. <tr>
  429. <td>language</td>
  430. <td>script language</td>
  431. <td>Yes</td>
  432. </tr>
  433. <tr>
  434. <td>manager</td>
  435. <td>The script engine manager to use. See the <a href="../Tasks/script.html">script</a> task
  436. for using this attribute.</td>
  437. <td>No; default is <q>auto</q></td>
  438. </tr>
  439. <tr>
  440. <td>value</td>
  441. <td>default boolean value</td>
  442. <td>No; default is <q>false</q></td>
  443. </tr>
  444. <tr>
  445. <td>src</td>
  446. <td>filename of script source</td>
  447. <td>No</td>
  448. </tr>
  449. <tr>
  450. <td>encoding</td>
  451. <td>The encoding of the script source. <em>Since Ant 1.10.2</em>.</td>
  452. <td>No; defaults to default JVM character encoding</td>
  453. </tr>
  454. <tr>
  455. <td>setbeans</td>
  456. <td>whether to have all properties, references and targets as global variables in the
  457. script. <em>since Ant 1.8.0</em></td>
  458. <td>No; default is <q>true</q></td>
  459. </tr>
  460. <tr>
  461. <td>classpath</td>
  462. <td>The classpath to pass into the script.</td>
  463. <td>No</td>
  464. </tr>
  465. <tr>
  466. <td>classpathref</td>
  467. <td>The classpath to use, given as a <a href="../using.html#references">reference</a> to a path
  468. defined elsewhere.</td>
  469. <td>No</td>
  470. </tr>
  471. </table>
  472. <h5>Parameters specified as nested elements</h5>
  473. <h6>classpath</h6>
  474. <p>See the <a href="../Tasks/script.html">script</a> task for using this nested element.</p>
  475. <h5>Description</h5>
  476. <p>The script supports script language inline, this script has access to the same beans as
  477. the <code>&lt;script&gt;</code> task, and to the <code>self</code> bean, which refers back to the
  478. condition itself. If the script evaluates to a boolean result, this is the result of the condition's
  479. evaluation (<em>since Ant 1.7.1</em>). Alternatively, <code>self.value</code> can be used to set
  480. the evaluation result.</p>
  481. <p>Example:</p>
  482. <pre>
  483. &lt;scriptcondition language=&quot;javascript&quot;
  484. value=&quot;true&quot;&gt;
  485. self.setValue(false);
  486. &lt;/scriptcondition&gt;</pre>
  487. <p>Sets the default value of the condition to <q>true</q>, then in the script, sets the value
  488. to <q>false</q>. This condition always evaluates to <q>false</q>.</p>
  489. <h4 id="parsersupports">parsersupports</h4>
  490. <p>Tests whether Ant's XML parser supports a given feature or property, as per the SAX/JAXP
  491. specifications, by attempting to set the appropriate property/feature</p>
  492. <p><em>Since Apache Ant 1.7</em>.</p>
  493. <table class="attr">
  494. <tr>
  495. <th scope="col">Attribute</th>
  496. <th scope="col">Description</th>
  497. <th scope="col">Required</th>
  498. </tr>
  499. <tr>
  500. <td>property</td>
  501. <td>property to set</td>
  502. <td rowspan="2">Exactly one of the two</td>
  503. </tr>
  504. <tr>
  505. <td>feature</td>
  506. <td class="left">feature to set</td>
  507. </tr>
  508. <tr>
  509. <td>value</td>
  510. <td>string (property) or boolean (feature)</td>
  511. <td>For property tests, but not for feature tests</td>
  512. </tr>
  513. </table>
  514. <pre>&lt;parsersupports feature="http://xml.org/sax/features/namespaces"/&gt;</pre>
  515. <p>Check for namespace support. All SAX2 parsers should have this.</p>
  516. <pre>
  517. &lt;or&gt;
  518. &lt;parsersupports
  519. feature="http://apache.org/xml/features/validation/schema"/&gt;
  520. &lt;parsersupports
  521. feature="http://java.sun.com/xml/jaxp/properties/schemaSource"/&gt;
  522. &lt;/or&gt;</pre>
  523. <p>Check for XML Schema support.</p>
  524. <pre>
  525. &lt;parsersupports
  526. property="http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation"
  527. value="document.xsd"/&gt;</pre>
  528. <p>Check for Xerces-specific definition of the location of the no namespace schema.</p>
  529. <h4 id="isreachable">isreachable</h4>
  530. <p>Uses Java 5+ networking APIs to probe for a (remote) system being reachable. Exactly what probe
  531. mechanisms are used is an implementation feature of the JVM. They may include ICMP "ping" packets,
  532. UDP or TCP connections to port 7 "echo service" or other means.</p>
  533. <p>This condition turns unknown host exceptions into false conditions. This is because on a laptop,
  534. DNS is one of the first services when the network goes; you are implicitly offline.</p>
  535. <p>If a URL is supplied instead of a <var>host</var>, the hostname is extracted and used in the
  536. test&mdash;all other parts of the URL are discarded.</p>
  537. <p>The test may not work through firewalls, that is, something may be reachable using a protocol
  538. such as HTTP, while the lower level ICMP packets get dropped on the floor. Similarly, a host may
  539. detected as reachable with ICMP, but not reachable on other ports (i.e. port 80), because of
  540. firewalls.</p>
  541. <p><em>Since Apache Ant 1.7</em>.</p>
  542. <table class="attr">
  543. <tr>
  544. <th scope="col">Attribute</th>
  545. <th scope="col">Description</th>
  546. <th scope="col">Required</th>
  547. </tr>
  548. <tr>
  549. <td>host</td>
  550. <td>host to check for</td>
  551. <td rowspan="2">Exactly one of the two</td>
  552. </tr>
  553. <tr>
  554. <td>url</td>
  555. <td class="left">URL containing hostname</td>
  556. </tr>
  557. <tr>
  558. <td>timeout</td>
  559. <td>timeout in seconds</td>
  560. <td>No; default is <q>30</q></td>
  561. </tr>
  562. </table>
  563. <pre>
  564. &lt;condition property="offline"&gt;
  565. &lt;isreachable url="https://ibiblio.org/maven/"/&gt;
  566. &lt;/condition&gt;</pre>
  567. <p>Probe for the Maven repository being reachable.</p>
  568. <pre>
  569. &lt;condition property="offline"&gt;
  570. &lt;isreachable host="ibiblio.org" timeout="10"/&gt;
  571. &lt;/condition&gt;</pre>
  572. <p>Probe for the Maven repository being reachable using the hostname, ten second timeout.</p>
  573. <h4 id="length">length</h4>
  574. <p><em>Since Ant 1.6.3</em></p>
  575. <p>This condition is a facet of the <a href="length.html">Length</a> task. It is used to test the
  576. length of a string or one or more files.</p>
  577. <pre>&lt;length string=" foo " trim="true" length="3"/&gt;</pre>
  578. <p>Verify a string is of a certain length.</p>
  579. <pre>&lt;length file=&quot;foo&quot; when=&quot;greater&quot; length=&quot;0&quot;/&gt;</pre>
  580. <p>Verify that file <samp>foo</samp> is not empty.</p>
  581. <h4 id="isfailure">isfailure</h4>
  582. <p><em>Since Ant 1.7</em></p>
  583. <p>Test the return code of an executable (see the <a href="exec.html">Exec</a> task) for
  584. failure.</p>
  585. <table class="attr">
  586. <tr>
  587. <th scope="col">Attribute</th>
  588. <th scope="col">Description</th>
  589. <th scope="col">Required</th>
  590. </tr>
  591. <tr>
  592. <td>code</td>
  593. <td>The return code to test.</td>
  594. <td>Yes</td>
  595. </tr>
  596. </table>
  597. <h4 id="resourcecount">resourcecount</h4>
  598. <p><em>Since Ant 1.7</em></p>
  599. <p>This condition is a facet of the <a href="resourcecount.html">ResourceCount</a> task. It is used
  600. to test the size of a <a href="../Types/resources.html#collection">resource
  601. collection</a>.</p>
  602. <pre>&lt;resourcecount refid=&quot;myresourcecollection&quot; when=&quot;greater&quot; count=&quot;0&quot;/&gt;</pre>
  603. <p>Verify that a resource collection is not empty.</p>
  604. <h4 id="resourcesmatch">resourcesmatch</h4>
  605. <p><em>Since Ant 1.7</em></p>
  606. <p>Test resources for matching. Nonexistence of one or more resources results in <q>false</q>,
  607. although if none exists they are considered equal in terms of content. By default, this test does a
  608. byte for byte comparison, so test time scales with byte size. <strong>Note</strong>: if the files
  609. are different sizes, one of them is missing or the filenames match the answer is so obvious the
  610. detailed test is omitted. The resources to check are specified as
  611. nested <a href="../Types/resources.html#collection">resource collections</a>, meaning that more than
  612. two resources can be checked; in this case all resources must match.</p>
  613. <table class="attr">
  614. <tr>
  615. <th scope="col">Attribute</th>
  616. <th scope="col">Description</th>
  617. <th scope="col">Required</th>
  618. </tr>
  619. <tr>
  620. <td>astext</td>
  621. <td>Whether to ignore line endings when comparing resource content; <q>true</q> triggers a
  622. binary comparison.</td>
  623. <td>No; defaults to <q>false</q></td>
  624. </tr>
  625. </table>
  626. <h4 id="resourcecontains">resourcecontains</h4>
  627. <p><em>Since Ant 1.7.1</em></p>
  628. <p>Tests whether a resource contains a given (sub)string.</p>
  629. <p>The resources to check are specified via references or&mdash;in the case of file
  630. resources&mdash;via the <var>resource</var> attribute.</p>
  631. <table class="attr">
  632. <tr>
  633. <th scope="col">Attribute</th>
  634. <th scope="col">Description</th>
  635. <th scope="col">Required</th>
  636. </tr>
  637. <tr>
  638. <td>resource</td>
  639. <td>Name of a file that is the resource to test.</td>
  640. <td rowspan="2">Exactly one of the two</td>
  641. </tr>
  642. <tr>
  643. <td>refid</td>
  644. <td class="left">Reference to a resource defined inside the project.</td>
  645. </tr>
  646. <tr>
  647. <td>substring</td>
  648. <td>The string to search for.</td>
  649. <td>Yes</td>
  650. </tr>
  651. <tr>
  652. <td>casesensitive</td>
  653. <td>Perform a case sensitive comparison.</td>
  654. <td>No; default is <q>true</q></td>
  655. </tr>
  656. </table>
  657. <h4 id="hasmethod">hasmethod</h4>
  658. <p><em>Since Ant 1.7</em></p>
  659. <p>Tests for a class having a method or field. If the class is not found or fails to load, the build
  660. fails.</p>
  661. <table class="attr">
  662. <tr>
  663. <th scope="col">Attribute</th>
  664. <th scope="col">Description</th>
  665. <th scope="col">Required</th>
  666. </tr>
  667. <tr>
  668. <td>classname</td>
  669. <td>name of the class to load</td>
  670. <td>yes</td>
  671. </tr>
  672. <tr>
  673. <td>field</td>
  674. <td>name of a field to look for</td>
  675. <td rowspan="2">Exactly one of the two</td>
  676. </tr>
  677. <tr>
  678. <td>method</td>
  679. <td class="left">name of a method to look for</td>
  680. </tr>
  681. <tr>
  682. <td>ignoreSystemClasses</td>
  683. <td>should system classes be ignored?</td>
  684. <td>No; default is <q>false</q></td>
  685. </tr>
  686. <tr>
  687. <td>classpath</td>
  688. <td>a class path</td>
  689. <td>No</td>
  690. </tr>
  691. <tr>
  692. <td>classpathref</td>
  693. <td>reference to a class path</td>
  694. <td>No</td>
  695. </tr>
  696. </table>
  697. <p>There is also a nested <code>&lt;classpath&gt;</code> element, which can be used to specify a
  698. classpath.</p>
  699. <pre>&lt;hasmethod classname="java.util.ArrayList" method="trimToSize"/&gt;</pre>
  700. <p>Looks for the method <code class="code">trimToSize()</code> in
  701. the <code class="code">java.util.ArrayList</code> class.</p>
  702. <h4 id="matches">matches</h4>
  703. <p><em>Since Ant 1.7</em></p>
  704. <p>Test if the specified string matches the specified regular expression pattern</p>
  705. <table class="attr">
  706. <tr>
  707. <th scope="col">Attribute</th>
  708. <th scope="col">Description</th>
  709. <th scope="col">Required</th>
  710. </tr>
  711. <tr>
  712. <td>string</td>
  713. <td>The string to test.</td>
  714. <td>Yes</td>
  715. </tr>
  716. <tr>
  717. <td>pattern</td>
  718. <td>The regular expression pattern used to test.</td>
  719. <td>Yes, unless there is a nested <code>&lt;regexp&gt;</code> element</td>
  720. </tr>
  721. <tr>
  722. <td>casesensitive</td>
  723. <td>Perform a case sensitive match.</td>
  724. <td>No; default is <q>true</q></td>
  725. </tr>
  726. <tr>
  727. <td>multiline</td>
  728. <td>Perform a multi line match.</td>
  729. <td>No; default is <q>false</q></td>
  730. </tr>
  731. <tr>
  732. <td>singleline</td>
  733. <td>This allows <q>.</q> to match new lines. <var>SingleLine</var> is not to be confused with
  734. multiline, <var>SingleLine</var> is a perl regex term, it corresponds to <var>dotall</var> in
  735. Java regex.</td>
  736. <td>No; default is <q>false</q></td>
  737. </tr>
  738. </table>
  739. <p>There is also an optional <code>&lt;regexp&gt;</code> element, which can be used to specify a
  740. regular expression instead of the <var>pattern</var> attribute.
  741. See <a href="../Types/regexp.html">Regexp Type</a> for the description of the nested element regexp
  742. and of the choice of regular expression implementation.</p>
  743. <p>An example:</p>
  744. <pre>
  745. &lt;condition property="legal-password"&gt;
  746. &lt;matches pattern="[1-9]" string="${user-input}"/&gt;
  747. &lt;/condition&gt;
  748. &lt;fail message="Your password should at least contain one number"
  749. unless="legal-password"/&gt;</pre>
  750. <p>The following example sets the property <code>ok</code> if the property <code>input</code> is
  751. three characters long, starting with <q>a</q> and ending with <q>b</q>.</p>
  752. <pre>
  753. &lt;condition property="ok"&gt;
  754. &lt;matches string="${input}" pattern="^a.b$"/&gt;
  755. &lt;/condition&gt;</pre>
  756. <p>The following defines a reference regular expression for matching dates and then uses antunit to
  757. check if the property <code>today</code> is in the correct format:</p>
  758. <pre>
  759. &lt;regexp id="date.pattern" pattern="^[0123]\d-[01]\d-[12]\d\d\d$"/&gt;
  760. &lt;au:assertTrue xmlns:au="antlib:org.apache.ant.antunit"&gt;
  761. &lt;matches string="${today}"&gt;
  762. &lt;regexp refid="date.pattern"/&gt;
  763. &lt;/matches&gt;
  764. &lt;/au:assertTrue&gt;</pre>
  765. <p>The following example shows the use of the <var>singleline</var> and the <var>casesensitive</var>
  766. flags.</p>
  767. <pre>
  768. &lt;au:assertTrue&gt;
  769. &lt;matches string="AB${line.separator}C" pattern="^ab.*C$"
  770. casesensitive="false"
  771. singleline="true"/&gt;
  772. &lt;/au:assertTrue&gt;
  773. &lt;au:assertFalse&gt;
  774. &lt;matches string="AB${line.separator}C" pattern="^ab.*C$"
  775. casesensitive="false"
  776. singleline="false"/&gt;
  777. &lt;/au:assertFalse&gt;</pre>
  778. <h4 id="antversion">antversion</h4>
  779. <p>This condition is identical to the <a href="antversion.html">Antversion</a> task, all attributes
  780. are supported, the <var>property</var> attribute is redundant and will be ignored.</p>
  781. <h4 id="hasfreespace">hasfreespace</h4>
  782. <p><em>Since Ant 1.7.0</em></p>
  783. <p>Tests a partition to see if there is enough space.</p>
  784. <p>Needed attribute can be specified using standard computing terms:</p>
  785. <ul>
  786. <li>K : Kilobytes (1024 bytes)</li>
  787. <li>M : Megabytes (1024 K)</li>
  788. <li>G : Gigabytes (1024 M)</li>
  789. <li>T : Terabytes (1024 G)</li>
  790. <li>P : Petabytes (1024 T)</li>
  791. </ul>
  792. <table class="attr">
  793. <tr>
  794. <th scope="col">Attribute</th>
  795. <th scope="col">Description</th>
  796. <th scope="col">Required</th>
  797. </tr>
  798. <tr>
  799. <td>partition</td>
  800. <td>The partition or filesystem to check for free space</td>
  801. <td>Yes</td>
  802. </tr>
  803. <tr>
  804. <td>needed</td>
  805. <td>The amount of free space needed.</td>
  806. <td>Yes</td>
  807. </tr>
  808. </table>
  809. <p>An example:</p>
  810. <pre>&lt;hasfreespace partition="c:" needed="100M"/&gt;</pre>
  811. <h4 id="islastmodified">islastmodified</h4>
  812. <p><em>Since Ant 1.8.0</em></p>
  813. <p>Tests the last modified date of a resource.</p>
  814. <table class="attr">
  815. <tr>
  816. <th scope="col">Attribute</th>
  817. <th scope="col">Description</th>
  818. <th scope="col">Required</th>
  819. </tr>
  820. <tr>
  821. <td>millis</td>
  822. <td>Specifies the expected modification time of the resource in milliseconds since midnight Jan
  823. 1 1970.</td>
  824. <td rowspan="2">Exactly one of the two</td>
  825. </tr>
  826. <tr>
  827. <td>datetime</td>
  828. <td class="left">Specifies the expected modification time of the resource. The special
  829. value <q>now</q> indicates the current time.</td>
  830. </tr>
  831. <tr>
  832. <td>pattern</td>
  833. <td>SimpleDateFormat-compatible pattern string.</td>
  834. <td>No; defaults to <q>MM/dd/YYYY hh:mm a</q> or <q>MM/dd/YYYY hh:mm:ss a</q></td>
  835. </tr>
  836. <tr>
  837. <td>mode</td>
  838. <td>How to compare the timestamp. Accepted values
  839. are <q>equals</q>, <q>before</q>, <q>not-before</q>, <q>after</q> and <q>not-after</q>.
  840. <td>No; defaults to <q>equals</q></td>
  841. </tr>
  842. </table>
  843. <p>The actual resource to test is specified as a nested element.</p>
  844. <p>An example:</p>
  845. <pre>
  846. &lt;islastmodified dateTime="08/18/2009 04:41:19 AM" mode="not-before"&gt;
  847. &lt;file file="${file}"/&gt;
  848. &lt;/islastmodified&gt;</pre>
  849. <h4 id="resourceexists">resourceexists</h4>
  850. <p><em>Since Ant 1.8.0</em></p>
  851. <p>Tests a resource for existence.</p>
  852. <p>The actual resource to test is specified as a nested element.</p>
  853. <p>An example:</p>
  854. <pre>
  855. &lt;resourceexists&gt;
  856. &lt;file file="${file}"/&gt;
  857. &lt;/resourceexists&gt;</pre>
  858. <h4 id="javaversion">javaversion</h4>
  859. <p><em>Since Ant 1.10.2</em></p>
  860. <p>Tests the version of the JVM executing Ant.</p>
  861. <table class="attr">
  862. <tr>
  863. <th scope="col">Attribute</th>
  864. <th scope="col">Description</th>
  865. <th scope="col">Required</th>
  866. </tr>
  867. <tr>
  868. <td class="left">atleast</td>
  869. <td>The version that this JVM is of at least. The format
  870. is <code>major.minor.point</code>. Starting with Java 9 really only the major number is
  871. determined.</td>
  872. <td rowspan="3">Exactly one of the three</td>
  873. </tr>
  874. <tr>
  875. <td>atmost</td>
  876. <td class="left">The version that this JVM is of at most. The format
  877. is <code>major.minor.point</code>. Starting with Java 9 really only the major number is
  878. determined.<br/>
  879. <em>Since Ant 1.10.10</em>
  880. </td>
  881. </tr>
  882. <tr>
  883. <td>exactly</td>
  884. <td class="left">The version that this JVM is of exactly. The format
  885. is <code>major.minor.point</code>. Starting with Java 9 really only the major number is
  886. determined.</td>
  887. </tr>
  888. </table>
  889. <p>An example:</p>
  890. <pre>&lt;javaversion atleast=&quot;9&quot;/&gt;</pre>
  891. <p>will evaluate to true if the current JVM is Java 9 or above.</p>
  892. </body>
  893. </html>