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.

apply.html 16 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Apply Task</title>
  5. <link rel="stylesheet" type="text/css" href="../stylesheets/antmanual.css">
  6. </head>
  7. <body>
  8. <h2><a name="apply">Apply/<i>ExecOn</i></a></h2>
  9. <p><i>The name <code>execon</code> is deprecated and only kept for backwards
  10. compatibility.</i></p>
  11. <h3>Description</h3>
  12. <p>Executes a system command. When the <i>os</i> attribute is specified, then
  13. the command is only executed when Ant is run on one of the specified operating
  14. systems.</p>
  15. <p>The files and/or directories of a number of <a
  16. href="../CoreTypes/fileset.html">FileSet</a>s, <a
  17. href="../CoreTypes/dirset.html">DirSet</a>s (<em>since Ant 1.6</em>)
  18. or <a href="../CoreTypes/filelist.html">FileList</a>s (<em>since Ant
  19. 1.6</em>) are passed as arguments to the system command.</p>
  20. <p>If you specify a nested <a
  21. href="../CoreTypes/mapper.html">mapper</a> and the <i>dest</i> attribute,
  22. the timestamp of each source file is compared to the timestamp of a
  23. target file which is defined by the nested mapper element and searched
  24. for in the given dest.</p>
  25. <p>At least one fileset or filelist is required, and you must not specify more than
  26. one mapper.</p>
  27. <p>Note that you cannot interact with the forked program, the only way
  28. to send input to it is via the input and inputstring attributes.</p>
  29. <h3>Parameters</h3>
  30. <table border="1" cellpadding="2" cellspacing="0">
  31. <tr>
  32. <td valign="top"><b>Attribute</b></td>
  33. <td valign="top"><b>Description</b></td>
  34. <td align="center" valign="top"><b>Required</b></td>
  35. </tr>
  36. <tr>
  37. <td valign="top">executable</td>
  38. <td valign="top">the command to execute without any command line
  39. arguments.</td>
  40. <td align="center" valign="top">Yes</td>
  41. </tr>
  42. <tr>
  43. <td valign="top">dest</td>
  44. <td valign="top">the directory where the <code>&lt;apply&gt;</code> expects the target files will be placed by the
  45. command, when it is executed.
  46. </td>
  47. <td align="center" valign="top">Yes, if you specify a nested mapper</td>
  48. </tr>
  49. <tr>
  50. <td valign="top">spawn</td>
  51. <td valign="top">whether or not you want the commands to be spawned<br/>
  52. Default is false.<br>
  53. If you spawn a command, its output will not be logged by ant.<br/>
  54. The input, output, error, and result property settings are not active when spawning a process.<br>
  55. <em>since Ant 1.6</em>
  56. </td>
  57. <td align="center" valign="top">No</td>
  58. </tr>
  59. <tr>
  60. <td valign="top">dir</td>
  61. <td valign="top">the directory in which the command should be executed.</td>
  62. <td align="center" valign="top">No</td>
  63. </tr>
  64. <tr>
  65. <td valign="top">relative</td>
  66. <td valign="top">whether the filenames should be passed on the
  67. command line as absolute or relative pathnames (relative to the
  68. base directory of the corresponding fileset/list for source files or
  69. the <i>dest</i> attribute for target files).</td>
  70. <td align="center" valign="top">No, default is <i>false</i></td>
  71. </tr>
  72. <tr>
  73. <td valign="top">forwardslash</td>
  74. <td valign="top">whether the file names should be passed
  75. with forward slashes even if the operating system requires other
  76. file separator. The option is ignored if the system file separator
  77. is a forward slash.</td>
  78. <td align="center" valign="top">No, default is <i>false</i></td>
  79. </tr>
  80. <tr>
  81. <td valign="top">os</td>
  82. <td valign="top">list of Operating Systems on which the command may be
  83. executed.</td>
  84. <td align="center" valign="top">No</td>
  85. </tr>
  86. <tr>
  87. <td valign="top">output</td>
  88. <td valign="top">the file to which the output of the command
  89. should be redirected. If the error stream is not also redirected
  90. to a file or property, it will appear in this output.</td>
  91. <td align="center" valign="top">No</td>
  92. </tr>
  93. <tr>
  94. <td valign="top">error</td>
  95. <td valign="top">The file to which the standard error of the
  96. command should be redirected. <em>since Ant 1.6</em></td>
  97. <td align="center" valign="top">No</td>
  98. </tr>
  99. <tr>
  100. <td valign="top">logError</td>
  101. <td valign="top">This attribute is used when you wish to see error
  102. output in Ant's log and you are redirecting output to a
  103. file/property. The error output will not be included in the output
  104. file/property. If you redirect error with the &quot;error&quot; or
  105. &quot;errorProperty&quot; attributes, this will have no effect.
  106. <em>since Ant 1.6</em></td>
  107. <td align="center" valign="top">No</td>
  108. </tr>
  109. <tr>
  110. <td valign="top">append</td>
  111. <td valign="top">whether output should be appended to or overwrite
  112. an existing file. Defaults to false. If you set parallel to
  113. false, you will probably want to set this one to true.</td>
  114. <td align="center" valign="top">No</td>
  115. </tr>
  116. <tr>
  117. <td valign="top">outputproperty</td>
  118. <td valign="top">the name of a property in which the output of the
  119. command should be stored. Unless the error stream is redirected
  120. to a separate file or stream, this property will include the error
  121. output.</td>
  122. <td align="center" valign="top">No</td>
  123. </tr>
  124. <tr>
  125. <td valign="top">errorproperty</td>
  126. <td valign="top">The name of a property in which the standard error of the
  127. command should be stored. <em>since Ant 1.6</em></td>
  128. <td align="center" valign="top">No</td>
  129. </tr>
  130. <tr>
  131. <td valign="top">input</td>
  132. <td valign="top">A file from which the executed command's standard
  133. input is taken. This attribute is mutually exclusive with the
  134. inputstring attribute. <em>since Ant 1.6</em></td>
  135. <td align="center" valign="top">No</td>
  136. </tr>
  137. <tr>
  138. <td valign="top">inputstring</td>
  139. <td valign="top">A string which serves as the input stream for the
  140. executed command. This attribute is mutually exclusive with the
  141. input attribute. <em>since Ant 1.6</em></td>
  142. <td align="center" valign="top">No</td>
  143. </tr>
  144. <tr>
  145. <td valign="top">resultproperty</td>
  146. <td valign="top">the name of a property in which the return code
  147. of the command should be stored. Only of interest if
  148. failonerror=false. If you set parallel to false, only the result
  149. of the first execution will be stored.</td>
  150. <td align="center" valign="top">No</td>
  151. </tr>
  152. <tr>
  153. <td valign="top">timeout</td>
  154. <td valign="top">Stop the command if it doesn't finish within the
  155. specified time (given in milliseconds).</td>
  156. <td align="center" valign="top">No</td>
  157. </tr>
  158. <tr>
  159. <td valign="top">failonerror</td>
  160. <td valign="top">Stop the buildprocess if the command exits with a
  161. returncode other than 0.</td>
  162. <td align="center" valign="top">No</td>
  163. </tr>
  164. <tr>
  165. <td valign="top">failifexecutionfails</td>
  166. <td valign="top">Stop the build if we can't start the program.
  167. Defaults to true. </td>
  168. <td align="center" valign="top">No</td>
  169. </tr>
  170. <tr>
  171. <td valign="top">skipemptyfilesets</td>
  172. <td valign="top">Don't run the command, if no source files have
  173. been found or are newer than their corresponding target
  174. files. Despite its name, this attribute applies to filelists as
  175. well.</td>
  176. <td align="center" valign="top">No, default is <i>false</i></td>
  177. </tr>
  178. <tr>
  179. <td valign="top">parallel</td>
  180. <td valign="top">Run the command only once, appending all files as
  181. arguments. If false, command will be executed once for every file.
  182. Defaults to false. </td>
  183. <td align="center" valign="top">No</td>
  184. </tr>
  185. <tr>
  186. <td valign="top">type</td>
  187. <td valign="top">One of <i>file</i>, <i>dir</i> or
  188. <i>both</i>. If set to <i>file</i>, only the names of plain
  189. files will be sent to the command. If set to <i>dir</i>, only
  190. the names of directories are considered.<br>
  191. <strong>Note:</strong> The type attribute does not apply to
  192. nested <i>dirset</i>s - <i>dirset</i>s always implicitly
  193. assume type to be <i>dir</i>.</td>
  194. <td align="center" valign="top">No, default is <i>file</i></td>
  195. </tr>
  196. <tr>
  197. <td valign="top">newenvironment</td>
  198. <td valign="top">Do not propagate old environment when new environment
  199. variables are specified.</td>
  200. <td align="center" valign="top">No, default is <i>false</i></td>
  201. </tr>
  202. <tr>
  203. <td valign="top">vmlauncher</td>
  204. <td valign="top">Run command using the Java VM's execution facilities
  205. where available. If set to false the underlying OS's shell,
  206. either directly or through the antRun scripts, will be used.
  207. Under some operating systems, this gives access to facilities
  208. not normally available through the VM including, under Windows,
  209. being able to execute scripts, rather than their associated
  210. interpreter. If you want to specify the name of the
  211. executable as a relative path to the directory given by the
  212. dir attribute, it may become necessary to set vmlauncher to
  213. false as well.</td>
  214. <td align="center" valign="top">No, default is <i>true</i></td>
  215. </tr>
  216. <tr>
  217. <td valign="top">resolveExecutable</td>
  218. <td valign="top">When this attribute is true, the name of the
  219. executable if resolved firstly against the project basedir and if
  220. that does not exist, against the execution directory if
  221. specified. On Unix systems, if you only want to allow execution of
  222. commands in the user's path, set this to false. <em>since Ant
  223. 1.6</em></td>
  224. <td align="center" valign="top">No, default is <i>false</i></td>
  225. </tr>
  226. <tr>
  227. <td valign="top">maxparallel</td>
  228. <td valign="top">Limit the amount of parallelism by passing at
  229. most this many sourcefiles at once. Set it to &lt;= 0 for
  230. unlimited. Defaults to unlimited. <em>Since Ant 1.6.</em></td>
  231. <td align="center" valign="top">No</td>
  232. </tr>
  233. <tr>
  234. <td valign="top">addsourcefile</td>
  235. <td valign="top">Whether source file names should be added to the
  236. command automatically. Defaults to <code>true</code>.
  237. <em>Since Ant 1.6.</em></td>
  238. <td align="center" valign="top">No</td>
  239. </tr>
  240. <tr>
  241. <td valign="top">verbose</td>
  242. <td valign="top">Whether to print a summary after execution or not.
  243. Defaults to <code>false</code>. <em>Since Ant 1.6.</em></td>
  244. <td align="center" valign="top">No</td>
  245. </tr>
  246. <tr>
  247. <td valign="top">ignoremissing</td>
  248. <td valign="top">Whether to ignore nonexistent files specified
  249. via filelists. <em>Since Ant 1.6.2.</em></td>
  250. <td align="center" valign="top">No, default is <i>true</i></td>
  251. </tr>
  252. <tr>
  253. <td valign="top">force</td>
  254. <td valign="top">Whether to bypass timestamp comparisons
  255. for target files. <em>Since Ant 1.7.</em></td>
  256. <td align="center" valign="top">No, default is <i>false</i></td>
  257. </tr>
  258. </table>
  259. <h3>Parameters specified as nested elements</h3>
  260. <h4>fileset</h4>
  261. <p>You can use any number of nested <code>&lt;fileset&gt;</code>
  262. elements to define the files for this task and refer to
  263. <code>&lt;fileset&gt;</code>s defined elsewhere.</p>
  264. <h4>filelist</h4>
  265. <p><em>Since Ant 1.6</em></p>
  266. <p>You can use any number of nested <code>&lt;filelist&gt;</code>
  267. elements to define the files for this task and refer to
  268. <code>&lt;filelist&gt;</code>s defined elsewhere.</p>
  269. <h4>dirset</h4>
  270. <p><em>Since Ant 1.6</em></p>
  271. <p>You can use any number of nested <code>&lt;dirset&gt;</code>
  272. elements to define the directories for this task and refer to
  273. <code>&lt;dirset&gt;</code>s defined elsewhere.</p>
  274. <h4>mapper</h4>
  275. <p>A single <code>&lt;mapper&gt;</code> specifies the target files
  276. relative to the <CODE>dest</CODE> attribute for dependency checking.
  277. At least one <code>&lt;fileset&gt;</code> or
  278. <code>&lt;filelist&gt;</code> is required.</p>
  279. <h4>arg</h4>
  280. <p>Command line arguments should be specified as nested
  281. <code>&lt;arg&gt;</code> elements. See <a
  282. href="../using.html#arg">Command line arguments</a>.</p>
  283. <h4>srcfile</h4>
  284. <p>By default the file names of the source files will be added to the
  285. end of the command line (unless you set addsourcefile to
  286. <code>false</code>). If you need to place it somewhere different,
  287. use a nested <code>&lt;srcfile&gt;</code> element between your
  288. <code>&lt;arg&gt;</code> elements to mark the insertion point.</p>
  289. <h4>targetfile</h4>
  290. <p><code>&lt;targetfile&gt;</code> is similar to
  291. <code>&lt;srcfile&gt;</code> and marks the position of the target
  292. filename on the command line. If omitted, the target filenames will
  293. not be added to the command line at all. This element can only be
  294. specified, if you also define a nested mapper and the <i>dest</i>
  295. attribute.</p>
  296. <h4>env</h4>
  297. <p>It is possible to specify environment variables to pass to the
  298. system command via nested <code>&lt;env&gt;</code> elements. See the
  299. description in the section about <a href="exec.html#env">exec</a></p>
  300. <h4>redirector</h4>
  301. <i><b>Since Ant 1.6.2</b></i>
  302. <p>A nested <a href="../CoreTypes/redirector.html">I/O Redirector</a>
  303. can be specified. &lt;apply&gt;'s behavior is like that of
  304. <a href="exec.html#redirector">exec</a> with regard to
  305. redirectors, with the exception that, in non-<i>parallel</i> mode,
  306. file mapping will take place with each iteration. This grants the
  307. user the capacity to receive input from, and send output to, different
  308. files for each sourcefile.
  309. </p>
  310. <h3>Examples</h3>
  311. <blockquote><pre>
  312. &lt;apply executable=&quot;ls&quot;&gt;
  313. &lt;arg value=&quot;-l&quot;/&gt;
  314. &lt;fileset dir=&quot;/tmp&quot;&gt;
  315. &lt;patternset&gt;
  316. &lt;exclude name=&quot;**/*.txt&quot;/&gt;
  317. &lt;/patternset&gt;
  318. &lt;/fileset&gt;
  319. &lt;fileset refid=&quot;other.files&quot;/&gt;
  320. &lt;/apply&gt;
  321. </pre></blockquote>
  322. <p>invokes <code>ls -l</code>, adding the absolute filenames of all
  323. files below <code>/tmp</code> not ending in <code>.txt</code> and all
  324. files of the FileSet with <code>id</code> <code>other.files</code> to
  325. the command line.</p>
  326. <blockquote><pre>
  327. &lt;apply executable=&quot;somecommand&quot; parallel=&quot;false&quot;&gt;
  328. &lt;arg value=&quot;arg1&quot;/&gt;
  329. &lt;srcfile/&gt;
  330. &lt;arg value=&quot;arg2&quot;/&gt;
  331. &lt;fileset dir=&quot;/tmp&quot;/&gt;
  332. &lt;/apply&gt;
  333. </pre></blockquote>
  334. <p>invokes <code>somecommand arg1 SOURCEFILENAME arg2</code> for each
  335. file in <code>/tmp</code> replacing SOURCEFILENAME with the absolute
  336. filename of each file in turn. If <code>parallel</code> had been set
  337. to true, SOURCEFILENAME would be replaced with the absolute filenames
  338. of all files separated by spaces.</p>
  339. <blockquote><pre>
  340. &lt;apply executable=&quot;cc&quot; dest=&quot;src/C&quot; parallel=&quot;false&quot;&gt;
  341. &lt;arg value=&quot;-c&quot;/&gt;
  342. &lt;arg value=&quot;-o&quot;/&gt;
  343. &lt;targetfile/&gt;
  344. &lt;srcfile/&gt;
  345. &lt;fileset dir=&quot;src/C&quot; includes=&quot;*.c&quot;/&gt;
  346. &lt;mapper type=&quot;glob&quot; from=&quot;*.c&quot; to=&quot;*.o&quot;/&gt;
  347. &lt;/apply&gt;
  348. </pre></blockquote>
  349. <p>invokes <code>cc -c -o TARGETFILE SOURCEFILE</code> for each
  350. <code>.c</code> file that is newer than the corresponding
  351. <code>.o</code>, replacing TARGETFILE with the absolute filename of
  352. the <code>.o</code> and SOURCEFILE with the absolute name of the
  353. <code>.c</code> file.</p>
  354. <blockquote><pre>
  355. &lt;mapper id=&quot;out&quot; type=&quot;glob&quot;
  356. from=&quot;src${file.separator}*.file&quot;
  357. to=&quot;dest${file.separator}*.out&quot;/&gt;
  358. &lt;apply executable=&quot;processfile&quot; dest=&quot;dest&quot;&gt;
  359. &lt;fileset dir=&quot;src&quot; includes=&quot;*.file&quot;/&gt;
  360. &lt;mapper refid=&quot;out&quot;/&gt;
  361. &lt;redirector&gt;
  362. &lt;outputmapper refid=&quot;out&quot;/&gt;
  363. &lt;/redirector&gt;
  364. &lt;/apply&gt;
  365. </pre></blockquote>
  366. Applies the fictitious &quot;processfile&quot; executable to all
  367. files matching <code>*.file</code> in the <CODE>src</CODE> directory.
  368. The <CODE>out</CODE> <code>&lt;mapper&gt;</code> has been set up to map
  369. <CODE>*.file</CODE> to <CODE>*.out</CODE>, then this <code>&lt;mapper&gt;</code>
  370. is used to specify <CODE>targetfile</CODE>s for this &lt;apply&gt;
  371. task. A reference to <CODE>out</CODE> is then used as an
  372. <code>&lt;outputmapper&gt;</code> nested in a <code>&lt;redirector&gt;</code>, which in turn is
  373. nested beneath this <code>&lt;apply&gt;</code> instance. This allows us to perform
  374. dependency checking against output files--the target files in this case.
  375. <hr><p align="center">Copyright &copy; 2000-2004 The Apache Software Foundation. All rights
  376. Reserved.</p>
  377. </body>
  378. </html>