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

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