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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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
  16. <a href="../CoreTypes/fileset.html">FileSet</a>s,
  17. <a href="../CoreTypes/dirset.html">DirSet</a>s
  18. (<em>since&nbsp;Ant&nbsp;1.6</em>) or
  19. <a href="../CoreTypes/filelist.html">FileList</a>s
  20. (<em>since&nbsp;Ant&nbsp;1.6</em>)
  21. are passed as arguments to the system command.</p>
  22. <p>If you specify a nested <a href="../CoreTypes/mapper.html">mapper</a>,
  23. the timestamp of each source file is compared to the timestamp of a
  24. target file which is defined by the nested mapper element and searched
  25. for in the given <i>dest</i>, if specified.</p>
  26. <p>At least one fileset or filelist is required,
  27. and you must not specify more than one mapper.</p>
  28. <p>Note that you cannot interact with the forked program, the only way
  29. to send input to it is via the input and inputstring attributes.</p>
  30. <h3>Parameters</h3>
  31. <table border="1" cellpadding="2" cellspacing="0">
  32. <tr>
  33. <td valign="top"><b>Attribute</b></td>
  34. <td valign="top"><b>Description</b></td>
  35. <td align="center" valign="top"><b>Required</b></td>
  36. </tr>
  37. <tr>
  38. <td valign="top">executable</td>
  39. <td valign="top">the command to execute without any command line
  40. arguments.</td>
  41. <td align="center" valign="top">Yes</td>
  42. </tr>
  43. <tr>
  44. <td valign="top">dest</td>
  45. <td valign="top">the directory where the command is expected to place
  46. target files when it is executed. This attribute is valid only when used
  47. in conjunction with a nested mapper; if omitted, the target filenames
  48. returned by the mapper will be interpreted as absolute paths.</td>
  49. <td align="center" valign="top">No</td>
  50. </tr>
  51. <tr>
  52. <td valign="top">spawn</td>
  53. <td valign="top">whether or not you want the commands to be spawned.<br />
  54. If you spawn a command, its output will not be logged by ant.<br />
  55. The input, output, error, and result property settings are not active when spawning a process.<br />
  56. <em>since&nbsp;Ant&nbsp;1.6</em>
  57. </td>
  58. <td align="center" valign="top">No, default is <i>false</i></td>
  59. </tr>
  60. <tr>
  61. <td valign="top">dir</td>
  62. <td valign="top">the directory in which the command should be executed.</td>
  63. <td align="center" valign="top">No</td>
  64. </tr>
  65. <tr>
  66. <td valign="top">relative</td>
  67. <td valign="top">whether the filenames should be passed on the
  68. command line as relative pathnames (relative to the base directory
  69. of the corresponding fileset/list for source files or the
  70. <i>dest</i> attribute for target files).</td>
  71. <td align="center" valign="top">No, default is <i>false</i></td>
  72. </tr>
  73. <tr>
  74. <td valign="top">forwardslash</td>
  75. <td valign="top">whether the file names should be passed
  76. with forward slashes even if the operating system requires other
  77. file separator. The option is ignored if the system file separator
  78. is a forward slash.</td>
  79. <td align="center" valign="top">No, default is <i>false</i></td>
  80. </tr>
  81. <tr>
  82. <td valign="top">os</td>
  83. <td valign="top">list of Operating Systems on which the command may be
  84. executed.</td>
  85. <td align="center" valign="top">No</td>
  86. </tr>
  87. <tr>
  88. <td valign="top">output</td>
  89. <td valign="top">the file to which the output of the command
  90. should be redirected. If the error stream is not also redirected
  91. to a file or property, it will appear in this output.</td>
  92. <td align="center" valign="top">No</td>
  93. </tr>
  94. <tr>
  95. <td valign="top">error</td>
  96. <td valign="top">The file to which the standard error of the
  97. command should be redirected. <em>since&nbsp;Ant&nbsp;1.6</em></td>
  98. <td align="center" valign="top">No</td>
  99. </tr>
  100. <tr>
  101. <td valign="top">logError</td>
  102. <td valign="top">This attribute is used when you wish to see error
  103. output in Ant's log and you are redirecting output to a
  104. file/property. The error output will not be included in the output
  105. file/property. If you redirect error with the &quot;error&quot; or
  106. &quot;errorProperty&quot; attributes, this will have no effect.
  107. <em>since&nbsp;Ant&nbsp;1.6</em></td>
  108. <td align="center" valign="top">No</td>
  109. </tr>
  110. <tr>
  111. <td valign="top">append</td>
  112. <td valign="top">whether output should be appended to or overwrite
  113. an existing file. If you set parallel to false, you will probably
  114. want to set this one to true.</td>
  115. <td align="center" valign="top">No, default is <i>false</i></td>
  116. </tr>
  117. <tr>
  118. <td valign="top">outputproperty</td>
  119. <td valign="top">the name of a property in which the output of the
  120. command should be stored. Unless the error stream is redirected
  121. to a separate file or stream, this property will include the error
  122. output.</td>
  123. <td align="center" valign="top">No</td>
  124. </tr>
  125. <tr>
  126. <td valign="top">errorproperty</td>
  127. <td valign="top">The name of a property in which the standard error of the
  128. command should be stored. <em>since&nbsp;Ant&nbsp;1.6</em></td>
  129. <td align="center" valign="top">No</td>
  130. </tr>
  131. <tr>
  132. <td valign="top">input</td>
  133. <td valign="top">A file from which the executed command's standard
  134. input is taken. This attribute is mutually exclusive with the
  135. inputstring attribute. <em>since&nbsp;Ant&nbsp;1.6</em></td>
  136. <td align="center" valign="top">No</td>
  137. </tr>
  138. <tr>
  139. <td valign="top">inputstring</td>
  140. <td valign="top">A string which serves as the input stream for the
  141. executed command. This attribute is mutually exclusive with the
  142. input attribute. <em>since&nbsp;Ant&nbsp;1.6</em></td>
  143. <td align="center" valign="top">No</td>
  144. </tr>
  145. <tr>
  146. <td valign="top">resultproperty</td>
  147. <td valign="top">the name of a property in which the return code
  148. of the command should be stored. Only of interest if
  149. failonerror=false. If you set parallel to false, only the result
  150. of the first execution will be stored.</td>
  151. <td align="center" valign="top">No</td>
  152. </tr>
  153. <tr>
  154. <td valign="top">timeout</td>
  155. <td valign="top">Stop the command if it doesn't finish within the
  156. specified time (given in milliseconds).</td>
  157. <td align="center" valign="top">No</td>
  158. </tr>
  159. <tr>
  160. <td valign="top">failonerror</td>
  161. <td valign="top">Stop the buildprocess if the command exits with a
  162. returncode other than 0.</td>
  163. <td align="center" valign="top">No</td>
  164. </tr>
  165. <tr>
  166. <td valign="top">failifexecutionfails</td>
  167. <td valign="top">Stop the build if we can't start the program.
  168. Defaults to true. </td>
  169. <td align="center" valign="top">No</td>
  170. </tr>
  171. <tr>
  172. <td valign="top">skipemptyfilesets</td>
  173. <td valign="top">Don't run the command, if no source files have
  174. been found or are newer than their corresponding target
  175. files. Despite its name, this attribute applies to filelists as
  176. well.</td>
  177. <td align="center" valign="top">No, default is <i>false</i></td>
  178. </tr>
  179. <tr>
  180. <td valign="top">parallel</td>
  181. <td valign="top">Run the command only once, appending all files as
  182. arguments. If false, command will be executed once for every file.</td>
  183. <td align="center" valign="top">No, default is <i>false</i></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.
  223. <em>since&nbsp;Ant&nbsp;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. <em>Since&nbsp;Ant&nbsp;1.6.</em></td>
  231. <td align="center" valign="top">No, unlimited by default</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. <em>Since&nbsp;Ant&nbsp;1.6.</em></td>
  237. <td align="center" valign="top">No, default is <i>true</i></td>
  238. </tr>
  239. <tr>
  240. <td valign="top">verbose</td>
  241. <td valign="top">Whether to print a summary after execution or not.
  242. <em>Since&nbsp;Ant&nbsp;1.6.</em></td>
  243. <td align="center" valign="top">No, default <i>false</i></td>
  244. </tr>
  245. <tr>
  246. <td valign="top">ignoremissing</td>
  247. <td valign="top">Whether to ignore nonexistent files specified
  248. via filelists. <em>Since&nbsp;Ant&nbsp;1.6.2.</em></td>
  249. <td align="center" valign="top">No, default is <i>true</i></td>
  250. </tr>
  251. <tr>
  252. <td valign="top">force</td>
  253. <td valign="top">Whether to bypass timestamp comparisons
  254. for target files. <em>Since&nbsp;Ant&nbsp;1.6.3.</em></td>
  255. <td align="center" valign="top">No, default is <i>false</i></td>
  256. </tr>
  257. </table>
  258. <h3>Parameters specified as nested elements</h3>
  259. <h4>fileset</h4>
  260. <p>You can use any number of nested <code>&lt;fileset&gt;</code>
  261. elements to define the files for this task and refer to
  262. <code>&lt;fileset&gt;</code>s defined elsewhere.</p>
  263. <h4>filelist</h4>
  264. <p><em>Since&nbsp;Ant&nbsp;1.6</em></p>
  265. <p>You can use any number of nested <code>&lt;filelist&gt;</code>
  266. elements to define the files for this task and refer to
  267. <code>&lt;filelist&gt;</code>s defined elsewhere.</p>
  268. <h4>dirset</h4>
  269. <p><em>Since&nbsp;Ant&nbsp;1.6</em></p>
  270. <p>You can use any number of nested <code>&lt;dirset&gt;</code>
  271. elements to define the directories for this task and refer to
  272. <code>&lt;dirset&gt;</code>s defined elsewhere.</p>
  273. <h4>mapper</h4>
  274. <p>A single <code>&lt;mapper&gt;</code> specifies the target files relative
  275. to the <code>dest</code> attribute for dependency checking. If the
  276. <code>dest</code> attribute is specified it will be used as a base directory
  277. for resolving relative pathnames returned by the mapper. At least one
  278. <code>&lt;fileset&gt;</code> or <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.</p>
  295. <h4>env</h4>
  296. <p>It is possible to specify environment variables to pass to the
  297. system command via nested <code>&lt;env&gt;</code> elements. See the
  298. description in the section about <a href="exec.html#env">exec</a></p>
  299. <h4>redirector</h4>
  300. <i><b>Since&nbsp;Ant&nbsp;1.6.2</b></i>
  301. <p>A nested <a href="../CoreTypes/redirector.html">I/O Redirector</a>
  302. can be specified. &lt;apply&gt;'s behavior is like that of
  303. <a href="exec.html#redirector">exec</a> with regard to
  304. redirectors, with the exception that, in non-<i>parallel</i> mode,
  305. file mapping will take place with each iteration. This grants the
  306. user the capacity to receive input from, and send output to, different
  307. files for each sourcefile.
  308. </p>
  309. <h3>Examples</h3>
  310. <blockquote><pre>
  311. &lt;apply executable=&quot;ls&quot;&gt;
  312. &lt;arg value=&quot;-l&quot;/&gt;
  313. &lt;fileset dir=&quot;/tmp&quot;&gt;
  314. &lt;patternset&gt;
  315. &lt;exclude name=&quot;**/*.txt&quot;/&gt;
  316. &lt;/patternset&gt;
  317. &lt;/fileset&gt;
  318. &lt;fileset refid=&quot;other.files&quot;/&gt;
  319. &lt;/apply&gt;
  320. </pre></blockquote>
  321. <p>invokes <code>ls -l</code>, adding the absolute filenames of all
  322. files below <code>/tmp</code> not ending in <code>.txt</code> and all
  323. files of the FileSet with <code>id</code> <code>other.files</code> to
  324. the command line.</p>
  325. <blockquote><pre>
  326. &lt;apply executable=&quot;somecommand&quot; parallel=&quot;false&quot;&gt;
  327. &lt;arg value=&quot;arg1&quot;/&gt;
  328. &lt;srcfile/&gt;
  329. &lt;arg value=&quot;arg2&quot;/&gt;
  330. &lt;fileset dir=&quot;/tmp&quot;/&gt;
  331. &lt;/apply&gt;
  332. </pre></blockquote>
  333. <p>invokes <code>somecommand arg1 SOURCEFILENAME arg2</code> for each
  334. file in <code>/tmp</code> replacing SOURCEFILENAME with the absolute
  335. filename of each file in turn. If <code>parallel</code> had been set
  336. to true, SOURCEFILENAME would be replaced with the absolute filenames
  337. of all files separated by spaces.</p>
  338. <blockquote><pre>
  339. &lt;apply executable=&quot;cc&quot; dest=&quot;src/C&quot; parallel=&quot;false&quot;&gt;
  340. &lt;arg value=&quot;-c&quot;/&gt;
  341. &lt;arg value=&quot;-o&quot;/&gt;
  342. &lt;targetfile/&gt;
  343. &lt;srcfile/&gt;
  344. &lt;fileset dir=&quot;src/C&quot; includes=&quot;*.c&quot;/&gt;
  345. &lt;mapper type=&quot;glob&quot; from=&quot;*.c&quot; to=&quot;*.o&quot;/&gt;
  346. &lt;/apply&gt;
  347. </pre></blockquote>
  348. <p>invokes <code>cc -c -o TARGETFILE SOURCEFILE</code> for each
  349. <code>.c</code> file that is newer than the corresponding
  350. <code>.o</code>, replacing TARGETFILE with the absolute filename of
  351. the <code>.o</code> and SOURCEFILE with the absolute name of the
  352. <code>.c</code> file.</p>
  353. <blockquote><pre>
  354. &lt;mapper id=&quot;out&quot; type=&quot;glob&quot;
  355. from=&quot;src${file.separator}*.file&quot;
  356. to=&quot;dest${file.separator}*.out&quot;/&gt;
  357. &lt;apply executable=&quot;processfile&quot; dest=&quot;dest&quot;&gt;
  358. &lt;fileset dir=&quot;src&quot; includes=&quot;*.file&quot;/&gt;
  359. &lt;mapper refid=&quot;out&quot;/&gt;
  360. &lt;redirector&gt;
  361. &lt;outputmapper refid=&quot;out&quot;/&gt;
  362. &lt;/redirector&gt;
  363. &lt;/apply&gt;
  364. </pre></blockquote>
  365. Applies the fictitious &quot;processfile&quot; executable to all
  366. files matching <code>*.file</code> in the <code>src</code> directory.
  367. The <code>out</code> <code>&lt;mapper&gt;</code> has been set up to map
  368. <code>*.file</code> to <code>*.out</code>, then this <code>&lt;mapper&gt;</code>
  369. is used to specify <code>targetfile</code>s for this &lt;apply&gt;
  370. task. A reference to <code>out</code> is then used as an
  371. <code>&lt;outputmapper&gt;</code> nested in a <code>&lt;redirector&gt;</code>, which in turn is
  372. nested beneath this <code>&lt;apply&gt;</code> instance. This allows us to perform
  373. dependency checking against output files--the target files in this case.
  374. <hr><p align="center">Copyright &copy; 2000-2005 The Apache Software Foundation. All rights
  375. Reserved.</p>
  376. </body>
  377. </html>