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

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