ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r938315 - in /ant/core/trunk: CONTRIBUTORS contributors.xml docs/faq.html src/main/org/apache/tools/ant/ProjectHelper.java src/main/org/apache/tools/ant/helper/ProjectHelper2.java src/tests/antunit/core/extension-point-test.xml xdocs/faq.xml
Date Tue, 27 Apr 2010 04:06:38 GMT
Author: bodewig
Date: Tue Apr 27 04:06:37 2010
New Revision: 938315

URL: http://svn.apache.org/viewvc?rev=938315&view=rev
Log:
extension-point doesn't work with import.  PR 48804

Modified:
    ant/core/trunk/CONTRIBUTORS
    ant/core/trunk/contributors.xml
    ant/core/trunk/docs/faq.html
    ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelper.java
    ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
    ant/core/trunk/src/tests/antunit/core/extension-point-test.xml
    ant/core/trunk/xdocs/faq.xml

Modified: ant/core/trunk/CONTRIBUTORS
URL: http://svn.apache.org/viewvc/ant/core/trunk/CONTRIBUTORS?rev=938315&r1=938314&r2=938315&view=diff
==============================================================================
Binary files - no diff available.

Modified: ant/core/trunk/contributors.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/contributors.xml?rev=938315&r1=938314&r2=938315&view=diff
==============================================================================
--- ant/core/trunk/contributors.xml (original)
+++ ant/core/trunk/contributors.xml Tue Apr 27 04:06:37 2010
@@ -178,6 +178,10 @@
     <last>Felder</last>
   </name>
   <name>
+    <first>Brian</first>
+    <last>Repko</last>
+  </name>
+  <name>
     <first>Bruce</first>
     <last>Atherton</last>
   </name>

Modified: ant/core/trunk/docs/faq.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/faq.html?rev=938315&r1=938314&r2=938315&view=diff
==============================================================================
--- ant/core/trunk/docs/faq.html (original)
+++ ant/core/trunk/docs/faq.html Tue Apr 27 04:06:37 2010
@@ -432,6 +432,11 @@
         when I compile my project under Mac OS X.
       
       </a></li>
+                <li><a href="#extension-point-and-import">
+  <code>extension-point</code> doesn't work
+        with <code>import</code> like the documentation
+        states.
+      </a></li>
             </ul>
     
       <h3 class="section">Answers</h3>
@@ -2184,6 +2189,49 @@ mv /tmp/foo $ANT_HOME/bin/antRun
         there is another symlink <code>bundle</code> that points to
         the <code>Home</code> directory and will cause infite
         recursions as well.</p>
+                    <p class="faq">
+      <a name="extension-point-and-import"></a>
+      <code>extension-point</code> doesn't work
+        with <code>import</code> like the documentation
+        states.
+    </p>
+                  <p>Yes, there is
+          a <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=48804">bug
+          in Ant 1.8.0</a>.</p>
+                        <p>When using two build files like</p>
+                        <pre class="code">
+importing.xml:
+&lt;project&gt;
+   ...
+   &lt;import file=&quot;imported.xml&quot;/&gt;
+   &lt;target name=&quot;bar&quot; extensionOf=&quot;foo&quot;/&gt;
+&lt;/project&gt;
+imported.xml:
+&lt;project&gt;
+   &lt;extension-point name=&quot;foo&quot;/&gt;
+&lt;/project&gt;
+</pre>
+                        <p>Ant 1.8.0 will fail, claiming there was no extension point
+          named "foo".</p>
+                        <p>This bug has been fixed for Ant 1.8.1.  For Ant 1.8.0 there
+          is
+          a <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=48804#c9">work-around</a>:
+          add an additional layer of importing like in</p>
+                        <pre class="code">
+importing.xml:
+&lt;project&gt;
+   &lt;target name=&quot;bar&quot; extensionOf=&quot;foo&quot;/&gt;
+&lt;/project&gt;
+imported.xml:
+&lt;project&gt;
+   &lt;extension-point name=&quot;foo&quot;/&gt;
+&lt;/project&gt;
+build.xml:
+&lt;project&gt;
+   &lt;import file=&quot;imported.xml&quot;/&gt;
+   &lt;import file=&quot;importing.xml&quot;/&gt;
+&lt;/project&gt;
+</pre>
                     </div>
   </div>
 

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=938315&r1=938314&r2=938315&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 Apr 27 04:06:37 2010
@@ -19,6 +19,8 @@ package org.apache.tools.ant;
 
 import java.io.File;
 import java.util.Hashtable;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Locale;
 import java.util.Vector;
 
@@ -89,6 +91,7 @@ public class ProjectHelper {
     // that read build files using ProjectHelper ).
 
     private Vector importStack = new Vector();
+    private List extensionStack = new LinkedList();
 
     /**
      *  Import stack.
@@ -101,6 +104,18 @@ public class ProjectHelper {
         return importStack;
     }
 
+    /**
+     * Extension stack.
+     * Used to keep track of targets that extend extension points.
+     *
+     * @return a list of two element string arrays where the first
+     * element is the name of the extensionpoint and the second the
+     * name of the target
+     */
+    public List getExtensionStack() {
+        return extensionStack;
+    }
+
     private final static ThreadLocal targetPrefix = new ThreadLocal() {
             protected Object initialValue() {
                 return (String) null;

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=938315&r1=938314&r2=938315&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 Apr 27 04:06:37
2010
@@ -177,6 +177,28 @@ public class ProjectHelper2 extends Proj
             parse(project, source, new RootHandler(context, mainHandler));
             // Execute the top-level target
             context.getImplicitTarget().execute();
+
+            // resolve extensionOf attributes
+            for (Iterator i = getExtensionStack().iterator(); i.hasNext(); ) {
+                String[] extensionInfo = (String[]) i.next();
+                String tgName = extensionInfo[0];
+                String name = extensionInfo[1];
+                Hashtable projectTargets = project.getTargets();
+                if (!projectTargets.containsKey(tgName)) {
+                    throw new BuildException("can't add target "
+                                             + name + " to extension-point "
+                                             + tgName
+                                             + " because the extension-point"
+                                             + " is unknown.");
+                }
+                Target t = (Target) projectTargets.get(tgName);
+                if (!(t instanceof ExtensionPoint)) {
+                    throw new BuildException("referenced target "
+                                             + tgName
+                                             + " is not an extension-point");
+                }
+                t.addDependency(name);
+            }
         }
     }
 
@@ -987,6 +1009,9 @@ public class ProjectHelper2 extends Proj
                 project.addOrReplaceTarget(newName, newTarget);
             }
             if (extensionPoint != null) {
+                ProjectHelper helper =
+                    (ProjectHelper) context.getProject().
+                        getReference(ProjectHelper.PROJECTHELPER_REFERENCE);
                 for (Iterator iter =
                          Target.parseDepends(extensionPoint, name, "extensionOf")
                          .iterator();
@@ -995,20 +1020,12 @@ public class ProjectHelper2 extends Proj
                     if (isInIncludeMode()) {
                         tgName = prefix + sep + tgName;
                     }
-                    if (!projectTargets.containsKey(tgName)) {
-                        throw new BuildException("can't add target "
-                                                 + name + " to extension-point "
-                                                 + tgName
-                                                 + " because the extension-point"
-                                                 + " is unknown.");
-                    }
-                    Target t = (Target) projectTargets.get(tgName);
-                    if (!(t instanceof ExtensionPoint)) {
-                        throw new BuildException("referenced target "
-                                                 + tgName
-                                                 + " is not an extension-point");
-                    }
-                    t.addDependency(name);
+
+                    // defer extensionpoint resolution until the full
+                    // import stack has been processed
+                    helper.getExtensionStack().add(new String[] {
+                            tgName, name
+                        });
                 }
             }
         }

Modified: ant/core/trunk/src/tests/antunit/core/extension-point-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/core/extension-point-test.xml?rev=938315&r1=938314&r2=938315&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/core/extension-point-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/core/extension-point-test.xml Tue Apr 27 04:06:37 2010
@@ -57,30 +57,35 @@
     <au:assertLogContains text="In target bar"/>
   </target>
 
-  <target name="testExtensionPointMustBeKnown">
+  <target name="testCantAddToPlainTarget">
     <mkdir dir="${output}"/>
     <echo file="${output}/build.xml"><![CDATA[
 <project default="foo">
-  <extension-point name="bar" extensionOf="foo"/>
-  <extension-point name="foo"/>
+  <target name="foo"/>
+  <target name="bar" extensionOf="foo"/>
 </project>]]></echo>
     <au:expectfailure
-       expectedMessage="can't add target bar to extension-point foo because the extension-point
is unknown">
+       expectedMessage="referenced target foo is not an extension-point">
       <ant dir="${output}"/>
     </au:expectfailure>
   </target>
 
-  <target name="testCantAddToPlainTarget">
+  <target name="testExtensionPointInImportedBuildfile" description="Bug 48804">
     <mkdir dir="${output}"/>
+    <echo file="${output}/master.xml"><![CDATA[
+<project default="bar">
+  <extension-point name="foo"/>
+  <target name="bar" depends="foo"/>
+</project>]]></echo>
     <echo file="${output}/build.xml"><![CDATA[
-<project default="foo">
-  <target name="foo"/>
-  <target name="bar" extensionOf="foo"/>
+<project>
+  <import file="master.xml"/>
+  <target name="prepare" extensionOf="foo">
+    <echo>in target prepare</echo>
+  </target>
 </project>]]></echo>
-    <au:expectfailure
-       expectedMessage="referenced target foo is not an extension-point">
-      <ant dir="${output}"/>
-    </au:expectfailure>
+    <ant dir="${output}" target="bar"/>
+    <au:assertLogContains text="in target prepare"/>
   </target>
 
 </project>

Modified: ant/core/trunk/xdocs/faq.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/xdocs/faq.xml?rev=938315&r1=938314&r2=938315&view=diff
==============================================================================
--- ant/core/trunk/xdocs/faq.xml (original)
+++ ant/core/trunk/xdocs/faq.xml Tue Apr 27 04:06:37 2010
@@ -1912,6 +1912,54 @@ mv /tmp/foo $ANT_HOME/bin/antRun
         recursions as well.</p>
       </answer>
     </faq>
+
+    <faq id="extension-point-and-import">
+      <question><code>extension-point</code> doesn't work
+        with <code>import</code> like the documentation
+        states.</question>
+
+      <answer>
+        <p>Yes, there is
+          a <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=48804">bug
+          in Ant 1.8.0</a>.</p>
+
+        <p>When using two build files like</p>
+        <source><![CDATA[
+importing.xml:
+<project>
+   ...
+   <import file="imported.xml"/>
+   <target name="bar" extensionOf="foo"/>
+</project>
+imported.xml:
+<project>
+   <extension-point name="foo"/>
+</project>
+]]></source>
+        <p>Ant 1.8.0 will fail, claiming there was no extension point
+          named "foo".</p>
+
+        <p>This bug has been fixed for Ant 1.8.1.  For Ant 1.8.0 there
+          is
+          a <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=48804#c9">work-around</a>:
+          add an additional layer of importing like in</p>
+        <source><![CDATA[
+importing.xml:
+<project>
+   <target name="bar" extensionOf="foo"/>
+</project>
+imported.xml:
+<project>
+   <extension-point name="foo"/>
+</project>
+build.xml:
+<project>
+   <import file="imported.xml"/>
+   <import file="importing.xml"/>
+</project>
+]]></source>
+      </answer>
+    </faq>
   </faqsection>
 
 </document>



Mime
View raw message