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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Conditions Task</title>
  5. </head>
  6. <body>
  7. <h2><a name="Conditions">Conditions</a></h2>
  8. <p>Conditions are nested elements of the
  9. <a href="condition.html"><code>&lt;condition&gt;</code></a> and
  10. <a href="waitfor.html"><code>&lt;waitfor&gt;</code></a> tasks.
  11. There are core conditions and custom conditions. Custom
  12. conditions are described in
  13. <a href="../CoreTypes/custom-programming.html#customconditions">
  14. Custom Conditions</a>.
  15. Core Conditions are described below.
  16. </p>
  17. <h3><a name="coreconditions">Core Conditions</a></h3>
  18. <p>These are the nested elements that can be used as conditions in the
  19. <a href="condition.html"><code>&lt;condition&gt;</code></a> and
  20. <a href="waitfor.html"><code>&lt;waitfor&gt;</code></a> tasks.</p>
  21. <h4>not</h4>
  22. <p>The <code>&lt;not&gt;</code> element expects exactly one other
  23. condition to be nested into this element, negating the result of the
  24. condition. It doesn't have any attributes and accepts all nested
  25. elements of the condition task as nested elements as well.</p>
  26. <h4>and</h4> <p>
  27. The <code>&lt;and&gt;</code> element doesn't have any attributes and
  28. accepts an arbitrary number of conditions as nested elements - all
  29. nested elements of the condition task are supported. This condition
  30. is true if all of its contained conditions are, conditions will be
  31. evaluated in the order they have been specified in the build file.</p>
  32. <p>The <code>&lt;and&gt;</code> condition has the same shortcut
  33. semantics as the Java &amp;&amp; operator, as soon as one of the
  34. nested conditions is false, no other condition will be evaluated.</p>
  35. <h4>or</h4> <p>
  36. The <code>&lt;or&gt;</code> element doesn't have any attributes and
  37. accepts an arbitrary number of conditions as nested elements - all
  38. nested elements of the condition task are supported. This condition
  39. is true if at least one of its contained conditions is, conditions
  40. will be evaluated in the order they have been specified in the build
  41. file.</p> <p>The <code>&lt;or&gt;</code> condition has the same
  42. shortcut semantics as the Java || operator, as soon as one of the
  43. nested conditions is true, no other condition will be evaluated.</p>
  44. <h4>available</h4>
  45. <p>This condition is identical to the <a
  46. href="available.html">Available</a> task, all attributes and nested
  47. elements of that task are supported, the property and value attributes
  48. are redundant and will be ignored.</p>
  49. <h4>uptodate</h4>
  50. <p>This condition is identical to the <a
  51. href="uptodate.html">Uptodate</a> task, all attributes and nested
  52. elements of that task are supported, the property and value attributes
  53. are redundant and will be ignored.</p>
  54. <h4>os</h4>
  55. <p>Test whether the current operating system is of a given type. Each
  56. defined attribute is tested and the result is true only if <i>all</i>
  57. the tests succeed.
  58. </p>
  59. <table border="1" cellpadding="2" cellspacing="0">
  60. <tr>
  61. <td valign="top"><b>Attribute</b></td>
  62. <td valign="top"><b>Description</b></td>
  63. <td align="center" valign="top"><b>Required</b></td>
  64. </tr>
  65. <tr>
  66. <td valign="top">family</td>
  67. <td valign="top">The name of the operating system family to expect.</td>
  68. <td valign="top" align="center">No</td>
  69. </tr>
  70. <tr>
  71. <td valign="top">name</td>
  72. <td valign="top">The name of the operating system to expect.</td>
  73. <td valign="top" align="center">No</td>
  74. </tr>
  75. <tr>
  76. <td valign="top">arch</td>
  77. <td valign="top">The architecture of the operating system to expect.</td>
  78. <td valign="top" align="center">No</td>
  79. </tr>
  80. <tr>
  81. <td valign="top">version</td>
  82. <td valign="top">The version of the operating system to expect.</td>
  83. <td valign="top" align="center">No</td>
  84. </tr>
  85. </table>
  86. <p>Supported values for the family attribute are:
  87. <ul>
  88. <li>windows (for all versions of Microsoft Windows)</li>
  89. <li>dos (for all Microsoft DOS based operating systems including
  90. Microsoft Windows and OS/2)</li>
  91. <li>mac (for all Apple Macintosh systems)</li>
  92. <li>unix (for all Unix and Unix-like operating systems)</li>
  93. <li>netware (for Novell NetWare)</li>
  94. <li>os/2 (for OS/2)</li>
  95. <li>tandem (for HP's NonStop Kernel - formerly Tandem)</li>
  96. <li>win9x for Microsoft Windows 95 and 98</li>
  97. <li>z/os for z/OS and OS/390</li>
  98. <li>os/400 for OS/400</li>
  99. <li>openvms for OpenVMS</li>
  100. </ul>
  101. <h4>equals</h4>
  102. <p>Tests whether the two given Strings are identical</p>
  103. <table border="1" cellpadding="2" cellspacing="0">
  104. <tr>
  105. <td valign="top"><b>Attribute</b></td>
  106. <td valign="top"><b>Description</b></td>
  107. <td align="center" valign="top"><b>Required</b></td>
  108. </tr>
  109. <tr>
  110. <td valign="top">arg1</td>
  111. <td valign="top">First string to test.</td>
  112. <td valign="top" align="center">Yes</td>
  113. </tr>
  114. <tr>
  115. <td valign="top">arg2</td>
  116. <td valign="top">Second string to test.</td>
  117. <td valign="top" align="center">Yes</td>
  118. </tr>
  119. <tr>
  120. <td valign="top">casesensitive</td>
  121. <td valign="top">Perform a case sensitive comparision. Default is
  122. true.</td>
  123. <td valign="top" align="center">No</td>
  124. </tr>
  125. <tr>
  126. <td valign="top">trim</td>
  127. <td valign="top">Trim whitespace from arguments before comparing
  128. them. Default is false.</td>
  129. <td valign="top" align="center">No</td>
  130. </tr>
  131. </table>
  132. <h4>isset</h4>
  133. <p>Test whether a given property has been set in this project.</p>
  134. <table border="1" cellpadding="2" cellspacing="0">
  135. <tr>
  136. <td valign="top"><b>Attribute</b></td>
  137. <td valign="top"><b>Description</b></td>
  138. <td align="center" valign="top"><b>Required</b></td>
  139. </tr>
  140. <tr>
  141. <td valign="top">property</td>
  142. <td valign="top">The name of the property to test.</td>
  143. <td valign="top" align="center">Yes</td>
  144. </tr>
  145. </table>
  146. <h4>checksum</h4>
  147. <p>This condition is identical to the <a href="checksum.html">Checksum</a>
  148. task, all attributes and nested elements of that task are supported,
  149. the property and overwrite attributes are redundant and will be
  150. ignored.</p>
  151. <h4>http</h4>
  152. <p>The <code>http</code> condition checks for a valid response from a
  153. web server of the specified url. By default, HTTP responses errors
  154. of 400 or greater are viewed as invalid.</p>
  155. <table border="1" cellpadding="2" cellspacing="0">
  156. <tr>
  157. <td width="12%" valign="top"><b>Attribute</b></td>
  158. <td width="78%" valign="top"><b>Description</b></td>
  159. <td width="10%" valign="top"><b>Required</b></td>
  160. </tr>
  161. <tr>
  162. <td valign="top">url</td>
  163. <td valign="top">The full URL of the page to request. The web server must
  164. return a status code below the value of <tt>errorsBeginAt</tt></td>
  165. <td align="center">Yes.</td>
  166. </tr>
  167. <tr>
  168. <td valign="top">errorsBeginAt</td>
  169. <td valign="top">The lowest HTTP response code that signals an error;
  170. by default '400'; server errors, not-authorized, not-found and the like
  171. are detected</td>
  172. <td align="center">No</td>
  173. </tr>
  174. </table>
  175. <h4>socket</h4>
  176. <p>The <code>socket</code> condition checks for the existence of a
  177. TCP/IP listener at the specified host and port.</p>
  178. <table border="1" cellpadding="2" cellspacing="0">
  179. <tr>
  180. <td width="12%" valign="top"><b>Attribute</b></td>
  181. <td width="78%" valign="top"><b>Description</b></td>
  182. <td width="10%" valign="top"><b>Required</b></td>
  183. </tr>
  184. <tr>
  185. <td valign="top">server</td>
  186. <td valign="top">The DNS name or IP address of the server.</td>
  187. <td align="center">Yes.</td>
  188. </tr>
  189. <tr>
  190. <td valign="top">port</td>
  191. <td valign="top">The port number to connect to.</td>
  192. <td align="center">Yes.</td>
  193. </tr>
  194. </table>
  195. <h4>filesmatch</h4>
  196. <p>Test two files for matching. Nonexistence of either file results in "false".
  197. This test does a byte for byte comparision, so test time scales with
  198. byte size. NB: if the files are different sizes , one of them is missing
  199. or the filenames match the answer is so obvious the detailed test is omitted.
  200. </p>
  201. <table border="1" cellpadding="2" cellspacing="0">
  202. <tr>
  203. <td width="12%" valign="top"><b>Attribute</b></td>
  204. <td width="78%" valign="top"><b>Description</b></td>
  205. <td width="10%" valign="top"><b>Required</b></td>
  206. </tr>
  207. <tr>
  208. <td valign="top">file1</td>
  209. <td valign="top">First file to test</td>
  210. <td align="center">Yes.</td>
  211. </tr>
  212. <tr>
  213. <td valign="top">file2</td>
  214. <td valign="top">Second file to test</td>
  215. <td align="center">Yes.</td>
  216. </tr>
  217. </table>
  218. <h4>contains</h4>
  219. <p>Tests whether a string contains another one.</p>
  220. <table border="1" cellpadding="2" cellspacing="0">
  221. <tr>
  222. <td valign="top"><b>Attribute</b></td>
  223. <td valign="top"><b>Description</b></td>
  224. <td align="center" valign="top"><b>Required</b></td>
  225. </tr>
  226. <tr>
  227. <td valign="top">string</td>
  228. <td valign="top">The string to search in.</td>
  229. <td valign="top" align="center">Yes</td>
  230. </tr>
  231. <tr>
  232. <td valign="top">substring</td>
  233. <td valign="top">The string to search for.</td>
  234. <td valign="top" align="center">Yes</td>
  235. </tr>
  236. <tr>
  237. <td valign="top">casesensitive</td>
  238. <td valign="top">Perform a case sensitive comparision. Default is
  239. true.</td>
  240. <td valign="top" align="center">No</td>
  241. </tr>
  242. </table>
  243. <h4>istrue</h4>
  244. <p>Tests whether a string equals any of the ant definitions of true,
  245. that is "true","yes", or "on"</p>
  246. <table border="1" cellpadding="2" cellspacing="0">
  247. <tr>
  248. <td valign="top"><b>Attribute</b></td>
  249. <td valign="top"><b>Description</b></td>
  250. <td align="center" valign="top"><b>Required</b></td>
  251. </tr>
  252. <tr>
  253. <td valign="top">value</td>
  254. <td valign="top">value to test</td>
  255. <td valign="top" align="center">Yes</td>
  256. </tr>
  257. </table>
  258. <pre>
  259. &lt;istrue value=&quot;${someproperty}&quot;/&gt;
  260. &lt;istrue value=&quot;false&quot;/&gt;
  261. </pre>
  262. <h4>isfalse</h4>
  263. <p>Tests whether a string is not true, the negation of &lt;istrue&gt;
  264. </p>
  265. <table border="1" cellpadding="2" cellspacing="0">
  266. <tr>
  267. <td valign="top"><b>Attribute</b></td>
  268. <td valign="top"><b>Description</b></td>
  269. <td align="center" valign="top"><b>Required</b></td>
  270. </tr>
  271. <tr>
  272. <td valign="top">value</td>
  273. <td valign="top">value to test</td>
  274. <td valign="top" align="center">Yes</td>
  275. </tr>
  276. </table>
  277. <pre>
  278. &lt;isfalse value=&quot;${someproperty}&quot;/&gt;
  279. &lt;isfalse value=&quot;false&quot;/&gt;
  280. </pre>
  281. <h4>isreference</h4>
  282. <p>Test whether a given reference has been defined in this project and
  283. - optionally - is of an expected type.</p>
  284. <p>This condition has been added in Apache Ant 1.6.</p>
  285. <table border="1" cellpadding="2" cellspacing="0">
  286. <tr>
  287. <td valign="top"><b>Attribute</b></td>
  288. <td valign="top"><b>Description</b></td>
  289. <td align="center" valign="top"><b>Required</b></td>
  290. </tr>
  291. <tr>
  292. <td valign="top">refid</td>
  293. <td valign="top">The id of the reference to test.</td>
  294. <td valign="top" align="center">Yes</td>
  295. </tr>
  296. <tr>
  297. <td valign="top">type</td>
  298. <td valign="top">Name of the data type or task this reference is
  299. expected to be.</td>
  300. <td valign="top" align="center">No</td>
  301. </tr>
  302. </table>
  303. <h4>issigned</h4>
  304. <p>
  305. Test whether a jarfile is signed.
  306. If the name of the
  307. signature is passed, the file is checked for presence of that
  308. particular signature; otherwise the file is checked for the
  309. existence of any signature
  310. </p>
  311. <p>
  312. This condition was added in Apache Ant 1.7.
  313. </p>
  314. <table border="1" cellpadding="2" cellspacing="0">
  315. <tr>
  316. <td valign="top"><b>Attribute</b></td>
  317. <td valign="top"><b>Description</b></td>
  318. <td align="center" valign="top"><b>Required</b></td>
  319. </tr>
  320. <tr>
  321. <td valign="top">file</td>
  322. <td valign="top">
  323. The jarfile that is to be tested for the presence
  324. of a signature.
  325. </td>
  326. <td valign="top" align="center">Yes</td>
  327. </tr>
  328. <tr>
  329. <td valign="top">name</td>
  330. <td valign="top"> The signature name to check for.</td>
  331. <td valign="top" align="center">No</td>
  332. </tr>
  333. </table>
  334. <h4>isfileselected</h4>
  335. <p>
  336. Test whether a file passes an embedded selector.
  337. </p>
  338. <p>
  339. This condition was added in Apache Ant 1.7.
  340. </p>
  341. <table border="1" cellpadding="2" cellspacing="0">
  342. <tr>
  343. <td valign="top"><b>Attribute</b></td>
  344. <td valign="top"><b>Description</b></td>
  345. <td align="center" valign="top"><b>Required</b></td>
  346. </tr>
  347. <tr>
  348. <td valign="top">file</td>
  349. <td valign="top">
  350. The file to check if is passes the embedded selector.
  351. </td>
  352. <td valign="top" align="center">Yes</td>
  353. </tr>
  354. <tr>
  355. <td valign="top">basedir</td>
  356. <td valign="top">The base directory to use for name based selectors. It this is not set,
  357. the project's basedirectory will be used.</td>
  358. <td valign="top" align="center">No</td>
  359. </tr>
  360. </table>
  361. <p>
  362. Example usage:
  363. </p>
  364. <blockquote>
  365. <pre>
  366. &lt;isfileselected file="a.xml"&gt;
  367. &lt;date datetime="06/28/2000 2:02 pm" when="equal"/&gt;
  368. &lt;/isfileselected&gt;
  369. </pre></blockquote>
  370. <h4>typefound</h4>
  371. <p>Test whether a given type is defined, and that
  372. its implementation class can be loaded. Types include
  373. tasks, datatypes, scriptdefs, macrodefs and presetdefs.</p>
  374. <p>This condition was added in Apache Ant 1.7.</p>
  375. <table border="1" cellpadding="2" cellspacing="0">
  376. <tr>
  377. <td valign="top"><b>Attribute</b></td>
  378. <td valign="top"><b>Description</b></td>
  379. <td align="center" valign="top"><b>Required</b></td>
  380. </tr>
  381. <tr>
  382. <td valign="top">name</td>
  383. <td valign="top">name of the type</td>
  384. <td valign="top" align="center">Yes</td>
  385. </tr>
  386. </table>
  387. <h4>scriptcondition</h4>
  388. <p>Evaluate a condition based on a script in any
  389. <a href="http://jakarta.apache.org/bsf" target="_top">Apache BSF</a>
  390. supported language.</p>
  391. <p>
  392. See the <a href="../OptionalTasks/script.html">Script</a> task for
  393. an explanation of scripts and dependencies.
  394. </p>
  395. <p>This condition was added in Apache Ant 1.7.</p>
  396. <table border="1" cellpadding="2" cellspacing="0">
  397. <tr>
  398. <td valign="top"><b>Attribute</b></td>
  399. <td valign="top"><b>Description</b></td>
  400. <td align="center" valign="top"><b>Required</b></td>
  401. </tr>
  402. <tr>
  403. <td valign="top">language</td>
  404. <td valign="top">script language</td>
  405. <td valign="top" align="center">Yes</td>
  406. </tr>
  407. <tr>
  408. <td valign="top">value</td>
  409. <td valign="top">default boolean value</td>
  410. <td valign="top" align="center">No -default is "false"</td>
  411. </tr>
  412. <tr>
  413. <td valign="top">src</td>
  414. <td valign="top">filename of script source</td>
  415. <td valign="top" align="center">No</td>
  416. </tr>
  417. </table>
  418. <p>
  419. The script supports script language inline, this script has access to the
  420. same beans as the <code>&lt;script&gt;</code> task, and to the <code>
  421. self</code> bean, which refers back to the condition itself. The
  422. <code>value</code> property of this bean sets the return value:
  423. </p>
  424. <p>
  425. Example:
  426. </p>
  427. <pre>
  428. &lt;scriptcondition language=&quot;javascript&quot;
  429. value=&quot;true&quot;&gt;
  430. self.setValue(false);
  431. &lt;/scriptcondition&gt;
  432. </pre>
  433. Sets the default value of the condition to true, then in the script,
  434. sets the value to false. This condition always evaluates to "false"
  435. <hr>
  436. <p align="center">Copyright &copy; 2001-2005 Apache Software
  437. Foundation. All rights Reserved.</p>
  438. </body>
  439. </html>