source: release-kits/lirk3/bin/ant-installer/web/manual1.6.2/manual/CoreTasks/apply.html@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 15.8 KB
Line 
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
13compatibility.</i></p>
14<h3>Description</h3>
15<p>Executes a system command. When the <i>os</i> attribute is specified, then
16the command is only executed when Ant is run on one of the specified operating
17systems.</p>
18<p>The files and/or directories of a number of <a
19href="../CoreTypes/fileset.html">FileSet</a>s, <a
20href="../CoreTypes/dirset.html">DirSet</a>s (<em>since Ant 1.6</em>)
21or <a href="../CoreTypes/filelist.html">FileList</a>s (<em>since Ant
221.6</em>) are passed as arguments to the system command.</p>
23<p>If you specify a nested <a
24href="../CoreTypes/mapper.html">mapper</a> and the <i>dest</i> attribute,
25the timestamp of each source file is compared to the timestamp of a
26target file which is defined by the nested mapper element and searched
27for in the given dest.</p>
28<p>At least one fileset or filelist is required, and you must not specify more than
29one mapper.</p>
30
31<p>Note that you cannot interact with the forked program, the only way
32to send input to it is via the input and inputstring attributes.</p>
33
34<h3>Parameters</h3>
35<table border="1" cellpadding="2" cellspacing="0">
36 <tr>
37 <td valign="top"><b>Attribute</b></td>
38 <td valign="top"><b>Description</b></td>
39 <td align="center" valign="top"><b>Required</b></td>
40 </tr>
41 <tr>
42 <td valign="top">executable</td>
43 <td valign="top">the command to execute without any command line
44 arguments.</td>
45 <td align="center" valign="top">Yes</td>
46 </tr>
47 <tr>
48 <td valign="top">dest</td>
49 <td valign="top">the directory where the &lt;apply&gt; expects the target files will be placed by the
50 command, when it is executed.
51 </td>
52 <td align="center" valign="top">Yes, if you specify a nested mapper</td>
53 </tr>
54 <tr>
55 <td valign="top">spawn</td>
56 <td valign="top">whether or not you want the commands to be spawned<br/>
57 Default is false.<br>
58 If you spawn a command, its output will not be logged by ant.<br/>
59 The input, output, error, and result property settings are not active when spawning a process.<br>
60 <em>since Ant 1.6</em>
61 </td>
62 <td align="center" valign="top">No</td>
63 </tr>
64
65 <tr>
66 <td valign="top">dir</td>
67 <td valign="top">the directory in which the command should be executed.</td>
68 <td align="center" valign="top">No</td>
69 </tr>
70 <tr>
71 <td valign="top">relative</td>
72 <td valign="top">whether the filenames should be passed on the
73 command line as absolute or relative pathnames (relative to the
74 base directory of the corresponding fileset/list for source files or
75 the <i>dest</i> attribute for target files).</td>
76 <td align="center" valign="top">No, default is <i>false</i></td>
77 </tr>
78 <tr>
79 <td valign="top">forwardslash</td>
80 <td valign="top">whether the file names should be passed
81 with forward slashes even if the operating system requires other
82 file separator. The option is ignored if the system file separator
83 is a forward slash.</td>
84 <td align="center" valign="top">No, default is <i>false</i></td>
85 </tr>
86 <tr>
87 <td valign="top">os</td>
88 <td valign="top">list of Operating Systems on which the command may be
89 executed.</td>
90 <td align="center" valign="top">No</td>
91 </tr>
92 <tr>
93 <td valign="top">output</td>
94 <td valign="top">the file to which the output of the command
95 should be redirected. If the error stream is not also redirected
96 to a file or property, it will appear in this output.</td>
97 <td align="center" valign="top">No</td>
98 </tr>
99 <tr>
100 <td valign="top">error</td>
101 <td valign="top">The file to which the standard error of the
102 command should be redirected. <em>since Ant 1.6</em></td>
103 <td align="center" valign="top">No</td>
104 </tr>
105 <tr>
106 <td valign="top">logError</td>
107 <td valign="top">This attribute is used when you wish to see error
108 output in Ant's log and you are redirecting output to a
109 file/property. The error output will not be included in the output
110 file/property. If you redirect error with the &quot;error&quot; or
111 &quot;errorProperty&quot; attributes, this will have no effect.
112 <em>since Ant 1.6</em></td>
113 <td align="center" valign="top">No</td>
114 </tr>
115 <tr>
116 <td valign="top">append</td>
117 <td valign="top">whether output should be appended to or overwrite
118 an existing file. Defaults to false. If you set parallel to
119 false, you will probably want to set this one to true.</td>
120 <td align="center" valign="top">No</td>
121 </tr>
122 <tr>
123 <td valign="top">outputproperty</td>
124 <td valign="top">the name of a property in which the output of the
125 command should be stored. Unless the error stream is redirected
126 to a separate file or stream, this property will include the error
127 output.</td>
128 <td align="center" valign="top">No</td>
129 </tr>
130 <tr>
131 <td valign="top">errorproperty</td>
132 <td valign="top">The name of a property in which the standard error of the
133 command should be stored. <em>since Ant 1.6</em></td>
134 <td align="center" valign="top">No</td>
135 </tr>
136 <tr>
137 <td valign="top">input</td>
138 <td valign="top">A file from which the executed command's standard
139 input is taken. This attribute is mutually exclusive with the
140 inputstring attribute. <em>since Ant 1.6</em></td>
141 <td align="center" valign="top">No</td>
142 </tr>
143 <tr>
144 <td valign="top">inputstring</td>
145 <td valign="top">A string which serves as the input stream for the
146 executed command. This attribute is mutually exclusive with the
147 input attribute. <em>since Ant 1.6</em></td>
148 <td align="center" valign="top">No</td>
149 </tr>
150 <tr>
151 <td valign="top">resultproperty</td>
152 <td valign="top">the name of a property in which the return code
153 of the command should be stored. Only of interest if
154 failonerror=false. If you set parallel to false, only the result
155 of the first execution will be stored.</td>
156 <td align="center" valign="top">No</td>
157 </tr>
158 <tr>
159 <td valign="top">timeout</td>
160 <td valign="top">Stop the command if it doesn't finish within the
161 specified time (given in milliseconds).</td>
162 <td align="center" valign="top">No</td>
163 </tr>
164 <tr>
165 <td valign="top">failonerror</td>
166 <td valign="top">Stop the buildprocess if the command exits with a
167 returncode other than 0.</td>
168 <td align="center" valign="top">No</td>
169 </tr>
170 <tr>
171 <td valign="top">failifexecutionfails</td>
172 <td valign="top">Stop the build if we can't start the program.
173 Defaults to true. </td>
174 <td align="center" valign="top">No</td>
175 </tr>
176 <tr>
177 <td valign="top">skipemptyfilesets</td>
178 <td valign="top">Don't run the command, if no source files have
179 been found or are newer than their corresponding target
180 files. Despite its name, this attribute applies to filelists as
181 well.</td>
182 <td align="center" valign="top">No, default is <i>false</i></td>
183 </tr>
184 <tr>
185 <td valign="top">parallel</td>
186 <td valign="top">Run the command only once, appending all files as
187 arguments. If false, command will be executed once for every file.
188 Defaults to false. </td>
189 <td align="center" valign="top">No</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. <em>since Ant
229 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 &lt;= 0 for
236 unlimited. Defaults to unlimited. <em>Since Ant 1.6.</em></td>
237 <td align="center" valign="top">No</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. Defaults to <code>true</code>.
243 <em>Since Ant 1.6.</em></td>
244 <td align="center" valign="top">No</td>
245 </tr>
246 <tr>
247 <td valign="top">verbose</td>
248 <td valign="top">Whether to print a summary after execution or not.
249 Defaults to <code>false</code>. <em>Since Ant 1.6.</em></td>
250 <td align="center" valign="top">No</td>
251 </tr>
252 <tr>
253 <td valign="top">ignoremissing</td>
254 <td valign="top">Whether to ignore nonexistent files specified
255 via filelists. <em>Since Ant 1.6.2.</em></td>
256 <td align="center" valign="top">No, default is <i>true</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>
262elements 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>
267elements 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>
272elements 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
276relative to the <CODE>dest</CODE> attribute for dependency checking.
277At 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
282href="../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
285end of the command line (unless you set addsourcefile to
286<code>false</code>). If you need to place it somewhere different,
287use 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
292filename on the command line. If omitted, the target filenames will
293not be added to the command line at all. This element can only be
294specified, if you also define a nested mapper and the <i>dest</i>
295attribute.</p>
296<h4>env</h4>
297<p>It is possible to specify environment variables to pass to the
298system command via nested <code>&lt;env&gt;</code> elements. See the
299description 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>
303can be specified. &lt;apply&gt;'s behavior is like that of
304<a href="exec.html#redirector">exec</a> with regard to
305redirectors, with the exception that, in non-<i>parallel</i> mode,
306file mapping will take place with each iteration. This grants the
307user the capacity to receive input from, and send output to, different
308files 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
323files below <code>/tmp</code> not ending in <code>.txt</code> and all
324files of the FileSet with <code>id</code> <code>other.files</code> to
325the 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
335file in <code>/tmp</code> replacing SOURCEFILENAME with the absolute
336filename of each file in turn. If <code>parallel</code> had been set
337to true, SOURCEFILENAME would be replaced with the absolute filenames
338of 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
352the <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
359&lt;apply executable=&quot;processfile&quot; dest=&quot;dest&quot;&gt;
360 &lt;fileset dir=&quot;src&quot; includes=&quot;*.file&quot;/&gt;
361 &lt;mapper refid=&quot;out&quot; /&gt;
362 &lt;redirector&gt;
363 &lt;outputmapper refid=&quot;out&quot; /&gt;
364 &lt;/redirector&gt;
365&lt;/apply&gt;
366</pre></blockquote>
367Applies the fictitious &quot;processfile&quot; executable to all
368files matching <code>*.file</code> in the <CODE>src</CODE> directory.
369The <CODE>out</CODE> &lt;mapper&gt; has been set up to map
370<CODE>*.file</CODE> to <CODE>*.out</CODE>, then this &lt;mapper&gt;
371is used to specify <CODE>targetfile</CODE>s for this &lt;apply&gt;
372task. A reference to <CODE>out</CODE> is then used as an
373&lt;outputmapper&gt; nested in a &lt;redirector&gt;, which in turn is
374nested beneath this &lt;apply&gt; instance. This allows us to perform
375dependency checking against output files--the target files in this case.
376
377<hr><p align="center">Copyright &copy; 2000-2004 The Apache Software Foundation. All rights
378Reserved.</p>
379
380</body>
381</html>
Note: See TracBrowser for help on using the repository browser.