source: release-kits/lirk3/resources/gs3-release-maker/ant/docs/manual/CoreTasks/import.html@ 14982

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

initial import of LiRK3

File size: 5.5 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html>
3<head>
4 <meta http-equiv="Content-Language" content="en-us">
5 <title>Import Task</title>
6 <link rel="stylesheet" type="text/css" href="../stylesheets/antmanual.css">
7</head>
8<body>
9 <h2><a name="import">Import</a></h2>
10 <h3>Description</h3>
11 <p>
12 Imports another build file into the current project.
13 </p>
14 <p>
15 On execution it will read another Ant file into
16 the same Project. This means that it basically works like the
17 <a href="http://ant.apache.org/faq.html#xml-entity-include">Entity
18 Includes as explained in the Ant FAQ</a>, as if the imported file was
19 contained in the importing file, minus the top <code>&lt;project&gt;</code>
20 tag.
21 </p>
22 <p>
23 The import task may only be used as a top-level task. This means that
24 it may not be used in a target.
25 </p>
26 <p>
27There are two further functional aspects that pertain to this task and
28that are not possible with entity includes:
29<ul>
30 <li>target overriding</li>
31 <li>special properties</li>
32</ul>
33 </p>
34<h4>Target overriding</h4>
35
36<p>If a target in the main file is also present in at least one of the
37imported files, the one from the main file takes precedence.</p>
38
39<p>So if I import for example a <i>docsbuild.xml</i> file named <b>builddocs</b>,
40that contains a &quot;<b>docs</b>&quot; target, I can redefine it in my main
41buildfile and that is the one that will be called. This makes it easy to
42keep the same target name, so that the overriding target is still called
43by any other targets--in either the main or imported buildfile(s)--for which
44it is a dependency, with a different implementation. The target from <i>docsbuild.xml</i> is
45made available by the name &quot;<b>builddocs</b><b>.docs</b>&quot;.
46This enables the new implementation to call the old target, thus
47<i>enhancing</i> it with tasks called before or after it.</p>
48
49<h4>Special Properties</h4>
50
51<p>Imported files are treated as they are present in the main
52buildfile. This makes it easy to understand, but it makes it impossible
53for them to reference files and resources relative to their path.
54Because of this, for every imported file, Ant adds a property that
55contains the path to the imported buildfile. With this path, the
56imported buildfile can keep resources and be able to reference them
57relative to its position.</p>
58
59<p>So if I import for example a <i>docsbuild.xml</i> file named <b>builddocs</b>,
60I can get its path as <b>ant.file.builddocs</b>, similarly to the <b>ant.file</b>
61property of the main buildfile.</p>
62
63<p>Note that &quot;builddocs&quot; is not the filename, but the name attribute
64present in the imported project tag.</p>
65
66<h4>Resolving files against the imported file</h4>
67
68<p>Suppose your main build file called <code>importing.xml</code>
69imports a build file <code>imported.xml</code>, located anywhere on
70the file system, and <code>imported.xml</code> reads a set of
71properties from <code>imported.properties</code>:</p>
72
73<pre>&lt;!-- importing.xml --&gt;
74&lt;project name="importing" basedir="." default="..."&gt;
75&nbsp; &lt;import file="${path_to_imported}/imported.xml"/&gt;
76&lt;/project&gt;
77
78&lt;!-- imported.xml --&gt;
79&lt;project name="imported" basedir="." default="..."&gt;
80&nbsp; &lt;property file="imported.properties"/&gt;
81&lt;/project&gt;
82</pre>
83
84<p>This snippet however will resolve <code>imported.properties</code>
85against the basedir of <code>importing.xml</code>, because the basedir
86of <code>imported.xml</code> is ignored by Ant. The right way to use
87<code>imported.properties</code> is:</p>
88
89<pre>
90&lt;!-- imported.xml --&gt;
91&lt;project name="imported" basedir="." default="..."&gt;
92&nbsp; &lt;dirname property="imported.basedir" file="${ant.file.imported}"/&gt;
93&nbsp; &lt;property file="${imported.basedir}/imported.properties"/&gt;
94&lt;/project&gt;
95</pre>
96
97<p>As explained above <code>${ant.file.imported}</code> stores the
98path of the build script, that defines the project called
99<code>imported</code>, (in short it stores the path to
100<code>imported.xml</code>) and <a
101href="dirname.html"><code>&lt;dirname&gt;</code></a> takes its
102directory. This technique also allows <code>imported.xml</code> to be
103used as a standalone file (without being imported in other
104project).</p>
105
106<h3>Parameters</h3>
107<table border="1" cellpadding="2" cellspacing="0">
108 <tbody>
109 <tr>
110 <td valign="top"><b>Attribute</b></td>
111 <td valign="top"><b>Description</b></td>
112 <td align="center" valign="top"><b>Required</b></td>
113 </tr>
114 <tr>
115 <td valign="top">
116 file
117 </td>
118 <td valign="top">
119 The file to import. If this is a relative file name, the file name will be resolved
120 relative to the <i>importing</i> file. <b>Note</b>, this is unlike most other
121 ant file attributes, where relative files are resolved relative to ${basedir}.
122 </td>
123 <td valign="top" align="center">Yes</td>
124 </tr>
125 <tr>
126 <td valign="top">
127 optional
128 </td>
129 <td valign="top">
130 If true, do not stop the build if the file does not exist,
131 default is false.
132 </td>
133 <td valign="top" align="center">No</td>
134 </tr>
135 </tbody>
136</table>
137
138<h3>Examples</h3>
139<pre>&nbsp; &lt;import file=&quot;../common-targets.xml&quot;/&gt;
140</pre>
141
142<p>Imports targets from the common-targets.xml file that is in a parent
143directory.</p>
144
145<pre>&nbsp; &lt;import file=&quot;${deploy-platform}.xml&quot;/&gt;
146</pre>
147
148<p>Imports the project defined by the property deploy-platform</p>
149
150<hr>
151<p align="center">Copyright &copy; 2003-2005 The Apache Software
152Foundation. All rights
153Reserved.</p>
154</body>
155</html>
Note: See TracBrowser for help on using the repository browser.