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

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