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