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

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