2006-09-11 04:19:00 +00:00
|
|
|
<!--
|
|
|
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
contributor license agreements. See the NOTICE file distributed with
|
|
|
|
this work for additional information regarding copyright ownership.
|
|
|
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
(the "License"); you may not use this file except in compliance with
|
|
|
|
the License. You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
-->
|
2003-07-09 16:24:38 +00:00
|
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-Language" content="en-us">
|
2005-04-29 18:58:16 +00:00
|
|
|
<link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
|
2007-05-02 06:15:35 +00:00
|
|
|
<title>Import Task</title>
|
2003-07-09 16:24:38 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
2003-09-19 09:43:43 +00:00
|
|
|
<h2><a name="import">Import</a></h2>
|
|
|
|
<h3>Description</h3>
|
|
|
|
<p>
|
|
|
|
Imports another build file into the current project.
|
|
|
|
</p>
|
2008-11-11 11:03:45 +00:00
|
|
|
|
|
|
|
<p>
|
|
|
|
<b>Note</b> this task heavily relies on the ProjectHelper
|
|
|
|
implementation and doesn't really perform any work of its own. If
|
|
|
|
you have configured Ant to use a ProjectHelper other than Ant's
|
|
|
|
default, this task may or may not work.
|
|
|
|
</p>
|
|
|
|
|
2003-09-19 09:43:43 +00:00
|
|
|
<p>
|
|
|
|
On execution it will read another Ant file into
|
|
|
|
the same Project. This means that it basically works like the
|
|
|
|
<a href="http://ant.apache.org/faq.html#xml-entity-include">Entity
|
|
|
|
Includes as explained in the Ant FAQ</a>, as if the imported file was
|
|
|
|
contained in the importing file, minus the top <code><project></code>
|
|
|
|
tag.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
The import task may only be used as a top-level task. This means that
|
|
|
|
it may not be used in a target.
|
|
|
|
</p>
|
|
|
|
<p>
|
2003-07-09 16:24:38 +00:00
|
|
|
There are two further functional aspects that pertain to this task and
|
2003-09-19 09:43:43 +00:00
|
|
|
that are not possible with entity includes:
|
2003-07-09 16:24:38 +00:00
|
|
|
<ul>
|
|
|
|
<li>target overriding</li>
|
2003-09-19 09:43:43 +00:00
|
|
|
<li>special properties</li>
|
2003-07-09 16:24:38 +00:00
|
|
|
</ul>
|
2003-09-19 09:43:43 +00:00
|
|
|
</p>
|
2004-06-29 09:04:59 +00:00
|
|
|
<h4>Target overriding</h4>
|
|
|
|
|
|
|
|
<p>If a target in the main file is also present in at least one of the
|
2005-02-18 13:32:19 +00:00
|
|
|
imported files, the one from the main file takes precedence.</p>
|
2004-06-29 09:04:59 +00:00
|
|
|
|
|
|
|
<p>So if I import for example a <i>docsbuild.xml</i> file named <b>builddocs</b>,
|
2004-04-16 21:21:50 +00:00
|
|
|
that contains a "<b>docs</b>" target, I can redefine it in my main
|
|
|
|
buildfile and that is the one that will be called. This makes it easy to
|
|
|
|
keep the same target name, so that the overriding target is still called
|
|
|
|
by any other targets--in either the main or imported buildfile(s)--for which
|
2005-02-18 13:32:19 +00:00
|
|
|
it is a dependency, with a different implementation. The target from <i>docsbuild.xml</i> is
|
2004-04-16 21:21:50 +00:00
|
|
|
made available by the name "<b>builddocs</b><b>.docs</b>".
|
|
|
|
This enables the new implementation to call the old target, thus
|
2004-06-29 09:04:59 +00:00
|
|
|
<i>enhancing</i> it with tasks called before or after it.</p>
|
|
|
|
|
2008-11-11 09:36:51 +00:00
|
|
|
<p>If you use the <i>as</i> attribute of the task, its value will be
|
|
|
|
used to prefix the overriden target's name instead of the name
|
|
|
|
attribute of the project tag.</p>
|
|
|
|
|
2004-06-29 09:04:59 +00:00
|
|
|
<h4>Special Properties</h4>
|
|
|
|
|
|
|
|
<p>Imported files are treated as they are present in the main
|
2003-07-09 16:24:38 +00:00
|
|
|
buildfile. This makes it easy to understand, but it makes it impossible
|
|
|
|
for them to reference files and resources relative to their path.
|
|
|
|
Because of this, for every imported file, Ant adds a property that
|
|
|
|
contains the path to the imported buildfile. With this path, the
|
|
|
|
imported buildfile can keep resources and be able to reference them
|
2004-06-29 09:04:59 +00:00
|
|
|
relative to its position.</p>
|
|
|
|
|
|
|
|
<p>So if I import for example a <i>docsbuild.xml</i> file named <b>builddocs</b>,
|
2003-07-09 16:24:38 +00:00
|
|
|
I can get its path as <b>ant.file.builddocs</b>, similarly to the <b>ant.file</b>
|
2004-06-29 09:04:59 +00:00
|
|
|
property of the main buildfile.</p>
|
|
|
|
|
|
|
|
<p>Note that "builddocs" is not the filename, but the name attribute
|
|
|
|
present in the imported project tag.</p>
|
2006-10-05 21:48:49 +00:00
|
|
|
<p>
|
2008-11-11 11:03:45 +00:00
|
|
|
If the imported file does not have a name attribute, the ant.file.projectname
|
2006-10-05 21:48:49 +00:00
|
|
|
property will not be set.
|
|
|
|
</p>
|
2004-06-29 09:01:53 +00:00
|
|
|
|
2004-06-29 09:04:59 +00:00
|
|
|
<h4>Resolving files against the imported file</h4>
|
2004-06-29 09:01:53 +00:00
|
|
|
|
|
|
|
<p>Suppose your main build file called <code>importing.xml</code>
|
|
|
|
imports a build file <code>imported.xml</code>, located anywhere on
|
|
|
|
the file system, and <code>imported.xml</code> reads a set of
|
|
|
|
properties from <code>imported.properties</code>:</p>
|
|
|
|
|
2004-06-29 14:53:27 +00:00
|
|
|
<pre><!-- importing.xml -->
|
2004-06-29 09:01:53 +00:00
|
|
|
<project name="importing" basedir="." default="...">
|
|
|
|
<import file="${path_to_imported}/imported.xml"/>
|
|
|
|
</project>
|
|
|
|
|
2004-06-29 14:53:27 +00:00
|
|
|
<!-- imported.xml -->
|
2004-06-29 09:01:53 +00:00
|
|
|
<project name="imported" basedir="." default="...">
|
|
|
|
<property file="imported.properties"/>
|
|
|
|
</project>
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p>This snippet however will resolve <code>imported.properties</code>
|
|
|
|
against the basedir of <code>importing.xml</code>, because the basedir
|
|
|
|
of <code>imported.xml</code> is ignored by Ant. The right way to use
|
|
|
|
<code>imported.properties</code> is:</p>
|
|
|
|
|
|
|
|
<pre>
|
2004-06-29 14:53:27 +00:00
|
|
|
<!-- imported.xml -->
|
2004-06-29 09:01:53 +00:00
|
|
|
<project name="imported" basedir="." default="...">
|
|
|
|
<dirname property="imported.basedir" file="${ant.file.imported}"/>
|
|
|
|
<property file="${imported.basedir}/imported.properties"/>
|
|
|
|
</project>
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p>As explained above <code>${ant.file.imported}</code> stores the
|
|
|
|
path of the build script, that defines the project called
|
|
|
|
<code>imported</code>, (in short it stores the path to
|
|
|
|
<code>imported.xml</code>) and <a
|
|
|
|
href="dirname.html"><code><dirname></code></a> takes its
|
|
|
|
directory. This technique also allows <code>imported.xml</code> to be
|
|
|
|
used as a standalone file (without being imported in other
|
|
|
|
project).</p>
|
|
|
|
|
2003-07-09 16:24:38 +00:00
|
|
|
<h3>Parameters</h3>
|
|
|
|
<table border="1" cellpadding="2" cellspacing="0">
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td valign="top"><b>Attribute</b></td>
|
|
|
|
<td valign="top"><b>Description</b></td>
|
|
|
|
<td align="center" valign="top"><b>Required</b></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
2004-04-16 22:43:27 +00:00
|
|
|
<td valign="top">
|
|
|
|
file
|
2003-07-09 16:24:38 +00:00
|
|
|
</td>
|
2004-04-16 22:43:27 +00:00
|
|
|
<td valign="top">
|
2004-04-29 10:13:17 +00:00
|
|
|
The file to import. If this is a relative file name, the file name will be resolved
|
|
|
|
relative to the <i>importing</i> file. <b>Note</b>, this is unlike most other
|
|
|
|
ant file attributes, where relative files are resolved relative to ${basedir}.
|
2003-07-09 16:24:38 +00:00
|
|
|
</td>
|
|
|
|
<td valign="top" align="center">Yes</td>
|
|
|
|
</tr>
|
2003-10-16 17:04:01 +00:00
|
|
|
<tr>
|
2004-04-16 22:43:27 +00:00
|
|
|
<td valign="top">
|
|
|
|
optional
|
2003-10-16 17:04:01 +00:00
|
|
|
</td>
|
|
|
|
<td valign="top">
|
2004-04-29 10:13:17 +00:00
|
|
|
If true, do not stop the build if the file does not exist,
|
2004-04-16 22:43:27 +00:00
|
|
|
default is false.
|
2003-10-16 17:04:01 +00:00
|
|
|
</td>
|
|
|
|
<td valign="top" align="center">No</td>
|
|
|
|
</tr>
|
2008-11-11 09:36:51 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">
|
|
|
|
as
|
|
|
|
</td>
|
|
|
|
<td valign="top">
|
|
|
|
Specifies the prefix prepended to the target names. If
|
|
|
|
ommitted, the name attribute of the project tag of the
|
|
|
|
imported file will be used.
|
|
|
|
</td>
|
|
|
|
<td valign="top" align="center">No</td>
|
|
|
|
</tr>
|
2003-07-09 16:24:38 +00:00
|
|
|
</tbody>
|
|
|
|
</table>
|
2004-06-29 09:04:59 +00:00
|
|
|
|
2003-07-09 16:24:38 +00:00
|
|
|
<h3>Examples</h3>
|
2004-11-19 09:07:12 +00:00
|
|
|
<pre> <import file="../common-targets.xml"/>
|
2004-06-29 09:04:59 +00:00
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p>Imports targets from the common-targets.xml file that is in a parent
|
|
|
|
directory.</p>
|
|
|
|
|
2004-11-19 09:07:12 +00:00
|
|
|
<pre> <import file="${deploy-platform}.xml"/>
|
2004-06-29 09:04:59 +00:00
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p>Imports the project defined by the property deploy-platform</p>
|
|
|
|
|
2008-11-11 11:03:45 +00:00
|
|
|
<h3>How is <import> different
|
|
|
|
from <a href="include.html"><include></a>?</h3>
|
|
|
|
|
|
|
|
<p>When using import the imported targets are available by up to two
|
|
|
|
names. Their "normal" name without any prefix and potentially with
|
|
|
|
a prefixed name (the value of the as attribute or the imported
|
|
|
|
project's name attribute, if any).</p>
|
|
|
|
|
|
|
|
<p>When using include the included targets are only available in the
|
|
|
|
prefixed form.</p>
|
|
|
|
|
|
|
|
<p>When using import, the imported target's depends attribute
|
|
|
|
remains unchanged, i.e. it uses "normal" names and allows you to
|
|
|
|
override targets in the dependency list.</p>
|
|
|
|
|
|
|
|
<p>When using include, the included target's depends attribute is
|
|
|
|
rewritten so that prefixed names are used. This allows writers of
|
|
|
|
the included file to control which target is invoked as part of the
|
|
|
|
dependencies.</p>
|
|
|
|
|
|
|
|
<p>It is possible to include the same file more than once by using
|
|
|
|
different prefixes, it is not possible to import the same file more
|
|
|
|
than once.</p>
|
|
|
|
|
|
|
|
<p>Use import if you intend to override a target, otherwise use include.</p>
|
|
|
|
|
|
|
|
<p><i>nested.xml</i> shall be:</p>
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
<project>
|
|
|
|
<target name="setUp">
|
|
|
|
<property name="prop" value="in nested"/>
|
|
|
|
</target>
|
|
|
|
|
|
|
|
<target name="echo" depends="setUp">
|
|
|
|
<echo>prop has the value ${prop}</echo>
|
|
|
|
</target>
|
|
|
|
</project>
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p>When using import like in</p>
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
<project>
|
|
|
|
<target name="setUp">
|
|
|
|
<property name="prop" value="in importing"/>
|
|
|
|
</target>
|
|
|
|
|
|
|
|
<import file="nested.xml" as="nested"/>
|
|
|
|
</project>
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p>Running the target <i>nested.echo</i> will emit:
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
setUp:
|
|
|
|
|
|
|
|
nested.echo:
|
|
|
|
[echo] prop has the value in importing
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p>When using include like in</p>
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
<project>
|
|
|
|
<target name="setUp">
|
|
|
|
<property name="prop" value="in importing"/>
|
|
|
|
</target>
|
|
|
|
|
|
|
|
<include file="nested.xml" as="nested"/>
|
|
|
|
</project>
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p>Running the target <i>nested.echo</i> will emit:
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
nested.setUp:
|
|
|
|
|
|
|
|
nested.echo:
|
|
|
|
[echo] prop has the value in nested
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p>and there won't be any target named "echo" on the including build file.</p>
|
2006-09-11 20:22:51 +00:00
|
|
|
|
2003-07-09 16:24:38 +00:00
|
|
|
</body>
|
|
|
|
</html>
|