You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2008/11/11 12:03:45 UTC

svn commit: r713016 - in /ant/core/trunk: ./ docs/manual/ docs/manual/CoreTasks/ src/main/org/apache/tools/ant/ src/main/org/apache/tools/ant/helper/ src/main/org/apache/tools/ant/taskdefs/ src/tests/antunit/taskdefs/ src/tests/antunit/taskdefs/importt...

Author: bodewig
Date: Tue Nov 11 03:03:45 2008
New Revision: 713016

URL: http://svn.apache.org/viewvc?rev=713016&view=rev
Log:
add an <import> variant named <include> that matches EasyAnt's <use>

Added:
    ant/core/trunk/docs/manual/CoreTasks/include.html   (contents, props changed)
      - copied, changed from r713005, ant/core/trunk/docs/manual/CoreTasks/import.html
    ant/core/trunk/src/tests/antunit/taskdefs/importtests/override.xml   (with props)
    ant/core/trunk/src/tests/antunit/taskdefs/include-test.xml   (contents, props changed)
      - copied, changed from r713005, ant/core/trunk/src/tests/antunit/taskdefs/import-test.xml
Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/docs/manual/CoreTasks/import.html
    ant/core/trunk/docs/manual/coretasklist.html
    ant/core/trunk/docs/manual/tasksoverview.html
    ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelper.java
    ant/core/trunk/src/main/org/apache/tools/ant/Target.java
    ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ImportTask.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/defaults.properties
    ant/core/trunk/src/tests/antunit/taskdefs/import-test.xml

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=713016&r1=713015&r2=713016&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Tue Nov 11 03:03:45 2008
@@ -519,6 +519,9 @@
  * <import> has a new attribute "as" that can be used to control the
    prefix prepended to the imported target's names.
 
+ * a new task <include> provides an alternative to <import> that
+   should be preferred when you don't want to override any targets.
+
 Changes from Ant 1.7.0 TO Ant 1.7.1
 =============================================
 

Modified: ant/core/trunk/docs/manual/CoreTasks/import.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/import.html?rev=713016&r1=713015&r2=713016&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/import.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/import.html Tue Nov 11 03:03:45 2008
@@ -27,6 +27,14 @@
   <p>
     Imports another build file into the current project.
   </p>
+
+  <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>
+
   <p>
     On execution it will read another Ant file into
     the same Project. This means that it basically works like the 
@@ -83,7 +91,7 @@
 <p>Note that &quot;builddocs&quot; is not the filename, but the name attribute
 present in the imported project tag.</p>
   <p>
-    If import file does not have a name attribute, the ant.file.projectname
+    If the imported file does not have a name attribute, the ant.file.projectname
     property will not be set.
   </p>
 
@@ -182,6 +190,89 @@
 
 <p>Imports the project defined by the property deploy-platform</p>
 
+<h3>How is &lt;import&gt; different
+  from <a href="include.html">&lt;include&gt;</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>
+&lt;project&gt;
+  &lt;target name="setUp"&gt;
+    &lt;property name="prop" value="in nested"/&gt;
+  &lt;/target&gt;
+
+  &lt;target name="echo" depends="setUp"&gt;
+    &lt;echo&gt;prop has the value ${prop}&lt;/echo&gt;
+  &lt;/target&gt;
+&lt;/project&gt;
+</pre>
+
+<p>When using import like in</p>
+
+<pre>
+&lt;project&gt;
+  &lt;target name="setUp"&gt;
+    &lt;property name="prop" value="in importing"/&gt;
+  &lt;/target&gt;
+
+  &lt;import file="nested.xml" as="nested"/&gt;
+&lt;/project&gt;
+</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>
+&lt;project&gt;
+  &lt;target name="setUp"&gt;
+    &lt;property name="prop" value="in importing"/&gt;
+  &lt;/target&gt;
+
+  &lt;include file="nested.xml" as="nested"/&gt;
+&lt;/project&gt;
+</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>
 
 </body>
 </html>

Copied: ant/core/trunk/docs/manual/CoreTasks/include.html (from r713005, ant/core/trunk/docs/manual/CoreTasks/import.html)
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/include.html?p2=ant/core/trunk/docs/manual/CoreTasks/include.html&p1=ant/core/trunk/docs/manual/CoreTasks/import.html&r1=713005&r2=713016&rev=713016&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/import.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/include.html Tue Nov 11 03:03:45 2008
@@ -19,112 +19,115 @@
 <head>
   <meta http-equiv="Content-Language" content="en-us">
   <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
-  <title>Import Task</title>
+  <title>Include Task</title>
 </head>
 <body>
-  <h2><a name="import">Import</a></h2>
+  <h2><a name="include">Include</a></h2>
   <h3>Description</h3>
   <p>
-    Imports another build file into the current project.
+    Include another build file into the current project.
   </p>
+
+  <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>
+
   <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>&lt;project&gt;</code>
-    tag.
+    On execution it will read another Ant file into the same Project
+    rewriting the included target names and depends lists.  This is
+    different
+    from <a href="http://ant.apache.org/faq.html#xml-entity-include">Entity
+    Includes as explained in the Ant FAQ</a> in so far as the target
+    names get prefixed by the included project's name or the as
+    attribute and do not appear as if the file was contained in the
+    including file.
   </p>
   <p>
-    The import task may only be used as a top-level task. This means that
+    The include task may only be used as a top-level task. This means that
     it may not be used in a target.
   </p>
   <p>
 There are two further functional aspects that pertain to this task and
 that are not possible with entity includes:
 <ul>
-  <li>target overriding</li>
+  <li>target rewriting</li>
   <li>special properties</li>
 </ul>
   </p>
-<h4>Target overriding</h4>
-
-<p>If a target in the main file is also present in at least one of the
-imported files, the one from the main file takes precedence.</p>
+<h4>Target rewriting</h4>
 
-<p>So if I import for example a <i>docsbuild.xml</i> file named <b>builddocs</b>,
-that contains a &quot;<b>docs</b>&quot; 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
-it is a dependency, with a different implementation. The target from <i>docsbuild.xml</i> is
-made available by the name &quot;<b>builddocs</b><b>.docs</b>&quot;.
-This enables the new implementation to call the old target, thus
-<i>enhancing</i> it with tasks called before or after it.</p>
-
-<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>
+<p>Any target in the included file will be renamed
+  to <i>prefix.name</i> where <i>name</i> is the original target's
+  name and <i>prefix</i> is either the value of the <i>as</i>
+  attribute or the <i>name</i> attribute of the <i>project</i> tag of
+  the included file.</p>
+
+<p>The depends attribute of all included targets is rewritten so that
+  all target names are prefixed as well.  This makes the included file
+  self-contained.</p>
 
 <h4>Special Properties</h4>
 
-<p>Imported files are treated as they are present in the main
+<p>Included files are treated as they are present in the main
 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
+Because of this, for every included file, Ant adds a property that
+contains the path to the included buildfile. With this path, the
+included buildfile can keep resources and be able to reference them
 relative to its position.</p>
 
-<p>So if I import for example a <i>docsbuild.xml</i> file named <b>builddocs</b>,
+<p>So if I include for example a <i>docsbuild.xml</i> file named <b>builddocs</b>,
 I can get its path as <b>ant.file.builddocs</b>, similarly to the <b>ant.file</b>
 property of the main buildfile.</p>
 
 <p>Note that &quot;builddocs&quot; is not the filename, but the name attribute
-present in the imported project tag.</p>
+present in the included project tag.</p>
   <p>
-    If import file does not have a name attribute, the ant.file.projectname
+    If the included file does not have a name attribute, the ant.file.projectname
     property will not be set.
   </p>
 
-<h4>Resolving files against the imported file</h4>
-
-<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>
+<h4>Resolving files against the included file</h4>
 
-<pre>&lt;!-- importing.xml --&gt;
-&lt;project name="importing" basedir="." default="..."&gt;
-&nbsp; &lt;import file="${path_to_imported}/imported.xml"/&gt;
+<p>Suppose your main build file called <code>including.xml</code>
+includes a build file <code>included.xml</code>, located anywhere on
+the file system, and <code>included.xml</code> reads a set of
+properties from <code>included.properties</code>:</p>
+
+<pre>&lt;!-- including.xml --&gt;
+&lt;project name="including" basedir="." default="..."&gt;
+&nbsp; &lt;include file="${path_to_included}/included.xml"/&gt;
 &lt;/project&gt;
 
-&lt;!-- imported.xml --&gt;
-&lt;project name="imported" basedir="." default="..."&gt;
-&nbsp; &lt;property file="imported.properties"/&gt;
+&lt;!-- included.xml --&gt;
+&lt;project name="included" basedir="." default="..."&gt;
+&nbsp; &lt;property file="included.properties"/&gt;
 &lt;/project&gt;
 </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>
+<p>This snippet however will resolve <code>included.properties</code>
+against the basedir of <code>including.xml</code>, because the basedir
+of <code>included.xml</code> is ignored by Ant. The right way to use
+<code>included.properties</code> is:</p>
 
 <pre>
-&lt;!-- imported.xml --&gt;
-&lt;project name="imported" basedir="." default="..."&gt;
-&nbsp; &lt;dirname property="imported.basedir" file="${ant.file.imported}"/&gt;
-&nbsp; &lt;property file="${imported.basedir}/imported.properties"/&gt;
+&lt;!-- included.xml --&gt;
+&lt;project name="included" basedir="." default="..."&gt;
+&nbsp; &lt;dirname property="included.basedir" file="${ant.file.included}"/&gt;
+&nbsp; &lt;property file="${included.basedir}/included.properties"/&gt;
 &lt;/project&gt;
 </pre>
 
-<p>As explained above <code>${ant.file.imported}</code> stores the
+<p>As explained above <code>${ant.file.included}</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
+<code>included</code>, (in short it stores the path to
+<code>included.xml</code>) and <a
 href="dirname.html"><code>&lt;dirname&gt;</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
+directory. This technique also allows <code>included.xml</code> to be
+used as a standalone file (without being included in other
 project).</p>
 
 <h3>Parameters</h3>
@@ -140,8 +143,8 @@
         file
       </td>
       <td valign="top">
-        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
+        The file to include. If this is a relative file name, the file name will be resolved
+        relative to the <i>including</i> file. <b>Note</b>, this is unlike most other
         ant file attributes, where relative files are resolved relative to ${basedir}.
       </td>
       <td valign="top" align="center">Yes</td>
@@ -165,23 +168,107 @@
         ommitted, the name attribute of the project tag of the
         imported file will be used.
       </td>
-      <td valign="top" align="center">No</td>
+      <td valign="top" align="center">Yes, if the included file's
+        project tag doesn't specify a name attribute.</td>
     </tr>
   </tbody>
 </table>
 
 <h3>Examples</h3>
-<pre>&nbsp; &lt;import file=&quot;../common-targets.xml&quot;/&gt;
+<pre>&nbsp; &lt;include file=&quot;../common-targets.xml&quot;/&gt;
 </pre>
 
-<p>Imports targets from the common-targets.xml file that is in a parent
+<p>Includes targets from the common-targets.xml file that is in a parent
 directory.</p>
 
-<pre>&nbsp; &lt;import file=&quot;${deploy-platform}.xml&quot;/&gt;
+<pre>&nbsp; &lt;include file=&quot;${deploy-platform}.xml&quot;/&gt;
 </pre>
 
-<p>Imports the project defined by the property deploy-platform</p>
+<p>Includes the project defined by the property deploy-platform</p>
+
+<h3>How is <a href="import.html">&lt;import&gt;</a> different
+  from &lt;include&gt;?</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>
+&lt;project&gt;
+  &lt;target name="setUp"&gt;
+    &lt;property name="prop" value="in nested"/&gt;
+  &lt;/target&gt;
+
+  &lt;target name="echo" depends="setUp"&gt;
+    &lt;echo&gt;prop has the value ${prop}&lt;/echo&gt;
+  &lt;/target&gt;
+&lt;/project&gt;
+</pre>
+
+<p>When using import like in</p>
+
+<pre>
+&lt;project&gt;
+  &lt;target name="setUp"&gt;
+    &lt;property name="prop" value="in importing"/&gt;
+  &lt;/target&gt;
+
+  &lt;import file="nested.xml" as="nested"/&gt;
+&lt;/project&gt;
+</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>
+&lt;project&gt;
+  &lt;target name="setUp"&gt;
+    &lt;property name="prop" value="in importing"/&gt;
+  &lt;/target&gt;
+
+  &lt;include file="nested.xml" as="nested"/&gt;
+&lt;/project&gt;
+</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>
 
 </body>
 </html>

Propchange: ant/core/trunk/docs/manual/CoreTasks/include.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/core/trunk/docs/manual/CoreTasks/include.html
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: ant/core/trunk/docs/manual/CoreTasks/include.html
------------------------------------------------------------------------------
    svn:mergeinfo = 

Modified: ant/core/trunk/docs/manual/coretasklist.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/coretasklist.html?rev=713016&r1=713015&r2=713016&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/coretasklist.html (original)
+++ ant/core/trunk/docs/manual/coretasklist.html Tue Nov 11 03:03:45 2008
@@ -77,6 +77,7 @@
 <a href="CoreTasks/unpack.html">GUnzip</a><br/>
 <a href="CoreTasks/pack.html">GZip</a><br/>
 <a href="CoreTasks/import.html">Import</a><br/>
+<a href="CoreTasks/include.html">Include</a><br/>
 <a href="CoreTasks/input.html">Input</a><br/>
 <a href="CoreTasks/jar.html">Jar</a><br/>
 <a href="CoreTasks/java.html">Java</a><br/>

Modified: ant/core/trunk/docs/manual/tasksoverview.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/tasksoverview.html?rev=713016&r1=713015&r2=713016&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/tasksoverview.html (original)
+++ ant/core/trunk/docs/manual/tasksoverview.html Tue Nov 11 03:03:45 2008
@@ -844,6 +844,11 @@
   </tr>
 
   <tr valign="top">
+    <td nowrap><a href="CoreTasks/include.html">Include</a></td>
+    <td><p>Include another build file.</p></td>
+  </tr>
+
+  <tr valign="top">
     <td nowrap><a href="OptionalTasks/javacc.html">JavaCC</a></td>
     <td><p>Invokes the
      <a HREF="http://javacc.dev.java.net/" target="_top">

Modified: ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelper.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelper.java?rev=713016&r1=713015&r2=713016&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelper.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelper.java Tue Nov 11 03:03:45 2008
@@ -128,7 +128,7 @@
      *
      * @return the configured prefix or null
      *
-     * @since ant 1.8.0
+     * @since Ant 1.8.0
      */
     public static String getCurrentTargetPrefix() {
         return (String) targetPrefix.get();
@@ -137,12 +137,47 @@
     /**
      * Sets the prefix to prepend to imported target names.
      *
-     * @since ant 1.8.0
+     * @since Ant 1.8.0
      */
     public static void setCurrentTargetPrefix(String prefix) {
         targetPrefix.set(prefix);
     }
 
+    private final static ThreadLocal inIncludeMode = new ThreadLocal() {
+            protected Object initialValue() {
+                return Boolean.FALSE;
+            }
+        };
+
+    /**
+     * Whether the current file should be read in include as opposed
+     * to import mode.
+     *
+     * <p>In include mode included targets are only known by their
+     * prefixed names and their depends lists get rewritten so that
+     * all dependencies get the prefix as well.</p>
+     *
+     * <p>In import mode imported targets are known by an adorned as
+     * well as a prefixed name and the unadorned target may be
+     * overwritten in the importing build file.  The depends list of
+     * the imported targets is not modified at all.</p>
+     *
+     * @since Ant 1.8.0
+     */
+    public static boolean isInIncludeMode() {
+        return inIncludeMode.get() == Boolean.TRUE;
+    }
+
+    /**
+     * Sets whether the current file should be read in include as
+     * opposed to import mode.
+     *
+     * @since Ant 1.8.0
+     */
+    public static void setInIncludeMode(boolean includeMode) {
+        inIncludeMode.set(includeMode ? Boolean.TRUE : Boolean.FALSE);
+    }
+
     // --------------------  Parse method  --------------------
     /**
      * Parses the project file, configuring the project as it goes.

Modified: ant/core/trunk/src/main/org/apache/tools/ant/Target.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/Target.java?rev=713016&r1=713015&r2=713016&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/Target.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/Target.java Tue Nov 11 03:03:45 2008
@@ -125,19 +125,31 @@
      *             depends on. Must not be <code>null</code>.
      */
     public void setDepends(String depS) {
-        if (depS.length() > 0) {
+        for (Iterator iter = parseDepends(depS, getName()).iterator();
+             iter.hasNext(); ) {
+            addDependency((String) iter.next());
+        }
+    }
+
+    public static List/*<String>*/ parseDepends(String depends,
+                                                String targetName) {
+        ArrayList list = new ArrayList();
+        if (depends.length() > 0) {
             StringTokenizer tok =
-                new StringTokenizer(depS, ",", true);
+                new StringTokenizer(depends, ",", true);
             while (tok.hasMoreTokens()) {
                 String token = tok.nextToken().trim();
 
                 // Make sure the dependency is not empty string
                 if ("".equals(token) || ",".equals(token)) {
-                    throw new BuildException("Syntax Error: depends " + "attribute of target \""
-                            + getName() + "\" has an empty string as dependency.");
+                    throw new BuildException("Syntax Error: depends "
+                                             + "attribute of target \""
+                                             + targetName
+                                             + "\" has an empty string as "
+                                             + "dependency.");
                 }
 
-                addDependency(token);
+                list.add(token);
 
                 // Make sure that depends attribute does not
                 // end in a ,
@@ -145,12 +157,15 @@
                     token = tok.nextToken();
                     if (!tok.hasMoreTokens() || !",".equals(token)) {
                         throw new BuildException("Syntax Error: Depend "
-                                + "attribute for target \"" + getName()
-                                + "\" ends with a , character");
+                                                 + "attribute for target \""
+                                                 + targetName
+                                                 + "\" ends with a \",\" "
+                                                 + "character");
                     }
                 }
             }
         }
+        return list;
     }
 
     /**

Modified: ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java?rev=713016&r1=713015&r2=713016&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java Tue Nov 11 03:03:45 2008
@@ -45,6 +45,7 @@
 import java.net.URL;
 import java.util.HashMap;
 import java.util.Hashtable;
+import java.util.Iterator;
 import java.util.Map;
 import java.util.Stack;
 
@@ -845,9 +846,25 @@
                         context.getLocator());
             }
 
+            String prefix = null;
+            boolean isInIncludeMode =
+                context.isIgnoringProjectTag() && isInIncludeMode();
+            if (isInIncludeMode) {
+                prefix = getTargetPrefix(context);
+                if (prefix == null) {
+                    throw new BuildException("can't include build file "
+                                             + context.getBuildFile()
+                                             + ", no as attribute has been given"
+                                             + " and the project tag doesn't"
+                                             + " specify a name attribute");
+                }
+                name = prefix + "." + name;
+            }
+
             // Check if this target is in the current build file
             if (context.getCurrentTargets().get(name) != null) {
-                throw new BuildException("Duplicate target '" + name + "'", target.getLocation());
+                throw new BuildException("Duplicate target '" + name + "'",
+                                         target.getLocation());
             }
             Hashtable projectTargets = project.getTargets();
             boolean   usedTarget = false;
@@ -862,12 +879,19 @@
                 usedTarget = true;
             }
             if (depends.length() > 0) {
-                target.setDepends(depends);
+                if (!isInIncludeMode) {
+                    target.setDepends(depends);
+                } else {
+                    for (Iterator iter =
+                             Target.parseDepends(depends, name).iterator();
+                         iter.hasNext(); ) {
+                        target.addDependency(prefix + "." + iter.next());
+                    }
+                }
             }
-            String prefix = null;
-            if (context.isIgnoringProjectTag()
+            if (!isInIncludeMode && context.isIgnoringProjectTag()
                 && (prefix = getTargetPrefix(context)) != null) {
-                // In an impored file (and not completely
+                // In an imported file (and not completely
                 // ignoring the project tag or having a preconfigured prefix)
                 String newName = prefix + "." + name;
                 Target newTarget = usedTarget ? new Target(target) : target;

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ImportTask.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ImportTask.java?rev=713016&r1=713015&r2=713016&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ImportTask.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ImportTask.java Tue Nov 11 03:03:45 2008
@@ -145,7 +145,7 @@
             }
         }
 
-        if (importStack.contains(importedFile)) {
+        if (!isInIncludeMode() && importStack.contains(importedFile)) {
             getProject().log(
                 "Skipped already imported file:\n   "
                 + importedFile + "\n", Project.MSG_VERBOSE);
@@ -155,14 +155,36 @@
         // nested invokations are possible like an imported file
         // importing another one
         String oldPrefix = ProjectHelper.getCurrentTargetPrefix();
+        boolean oldIncludeMode = ProjectHelper.isInIncludeMode();
         try {
             ProjectHelper.setCurrentTargetPrefix(targetPrefix);
+            ProjectHelper.setInIncludeMode(isInIncludeMode());
             helper.parse(getProject(), importedFile);
         } catch (BuildException ex) {
             throw ProjectHelper.addLocationToBuildException(
                 ex, getLocation());
         } finally {
             ProjectHelper.setCurrentTargetPrefix(oldPrefix);
+            ProjectHelper.setInIncludeMode(oldIncludeMode);
         }
     }
+
+    /**
+     * Whether the task is in include (as opposed to import) mode.
+     *
+     * <p>In include mode included targets are only known by their
+     * prefixed names and their depends lists get rewritten so that
+     * all dependencies get the prefix as well.</p>
+     *
+     * <p>In import mode imported targets are known by an adorned as
+     * well as a prefixed name and the unadorned target may be
+     * overwritten in the importing build file.  The depends list of
+     * the imported targets is not modified at all.</p>
+     *
+     * @since Ant 1.8.0
+     */
+    protected final boolean isInIncludeMode() {
+        return "include".equals(getTaskType());
+    }
+
 }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/defaults.properties
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/defaults.properties?rev=713016&r1=713015&r2=713016&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/defaults.properties (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/defaults.properties Tue Nov 11 03:03:45 2008
@@ -56,6 +56,7 @@
 gunzip=org.apache.tools.ant.taskdefs.GUnzip
 gzip=org.apache.tools.ant.taskdefs.GZip
 import=org.apache.tools.ant.taskdefs.ImportTask
+include=org.apache.tools.ant.taskdefs.ImportTask
 input=org.apache.tools.ant.taskdefs.Input
 jar=org.apache.tools.ant.taskdefs.Jar
 java=org.apache.tools.ant.taskdefs.Java

Modified: ant/core/trunk/src/tests/antunit/taskdefs/import-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/import-test.xml?rev=713016&r1=713015&r2=713016&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/import-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/import-test.xml Tue Nov 11 03:03:45 2008
@@ -28,4 +28,22 @@
   <target name="testExplicitPrefix" depends="c.b">
     <au:assertEquals expected="baz" actual="${foo}"/>
   </target>
+
+  <target name="testNoExplicitPrefixUsedWithoutPrefix" depends="a">
+    <au:assertEquals expected="bar" actual="${foo}"/>
+  </target>
+
+  <target name="testExplicitPrefixUsedWithoutPrefix" depends="b">
+    <au:assertEquals expected="baz" actual="${foo}"/>
+  </target>
+
+  <import file="importtests/override.xml"/>
+
+  <target name="setProperty">
+    <property name="prop" value="in including/importing"/>
+  </target>
+
+  <target name="testOverride" depends="override.dummy">
+    <au:assertEquals expected="in including/importing" actual="${prop}"/>
+  </target>
 </project>

Added: ant/core/trunk/src/tests/antunit/taskdefs/importtests/override.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/importtests/override.xml?rev=713016&view=auto
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/importtests/override.xml (added)
+++ ant/core/trunk/src/tests/antunit/taskdefs/importtests/override.xml Tue Nov 11 03:03:45 2008
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<!--
+  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.
+-->
+<project name="override">
+  <target name="setProperty">
+    <property name="prop" value="in included/imported"/>
+  </target>
+
+  <target name="dummy" depends="setProperty"/>
+</project>
+

Propchange: ant/core/trunk/src/tests/antunit/taskdefs/importtests/override.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: ant/core/trunk/src/tests/antunit/taskdefs/include-test.xml (from r713005, ant/core/trunk/src/tests/antunit/taskdefs/import-test.xml)
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/include-test.xml?p2=ant/core/trunk/src/tests/antunit/taskdefs/include-test.xml&p1=ant/core/trunk/src/tests/antunit/taskdefs/import-test.xml&r1=713005&r2=713016&rev=713016&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/import-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/include-test.xml Tue Nov 11 03:03:45 2008
@@ -18,8 +18,8 @@
 <project default="antunit" xmlns:au="antlib:org.apache.ant.antunit">
   <import file="../antunit-base.xml" />
 
-  <import file="importtests/a.xml"/>
-  <import file="importtests/b.xml" as="c"/>
+  <include file="importtests/a.xml"/>
+  <include file="importtests/b.xml" as="c"/>
 
   <target name="testNoExplicitPrefix" depends="a.a">
     <au:assertEquals expected="bar" actual="${foo}"/>
@@ -28,4 +28,14 @@
   <target name="testExplicitPrefix" depends="c.b">
     <au:assertEquals expected="baz" actual="${foo}"/>
   </target>
+
+  <include file="importtests/override.xml"/>
+
+  <target name="setProperty">
+    <property name="prop" value="in including/importing"/>
+  </target>
+
+  <target name="testNoOverride" depends="override.dummy">
+    <au:assertEquals expected="in included/imported" actual="${prop}"/>
+  </target>
 </project>

Propchange: ant/core/trunk/src/tests/antunit/taskdefs/include-test.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/core/trunk/src/tests/antunit/taskdefs/include-test.xml
------------------------------------------------------------------------------
    svn:mergeinfo =