ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r708204 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/IntrospectionHelper.java src/main/org/apache/tools/ant/UnknownElement.java src/tests/antunit/core/nested-elements-test.xml
Date Mon, 27 Oct 2008 14:49:01 GMT
Author: bodewig
Date: Mon Oct 27 07:49:00 2008
New Revision: 708204

URL: http://svn.apache.org/viewvc?rev=708204&view=rev
Log:
allow TaskContainer and DynamicElement(NS) to coexist.  Hijacked PR 41647 for this.

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java
    ant/core/trunk/src/main/org/apache/tools/ant/UnknownElement.java
    ant/core/trunk/src/tests/antunit/core/nested-elements-test.xml

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=708204&r1=708203&r2=708204&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Mon Oct 27 07:49:00 2008
@@ -270,6 +270,10 @@
    TaskContainers at the same time.
    Bugzilla Report 41647.
 
+ * Tasks that implementes DynamicElemen or DynamicElementNS failed to
+   work as TaskContainers at the same time.
+   Bugzilla Report 41647.
+
 Other changes:
 --------------
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java?rev=708204&r1=708203&r2=708204&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java Mon Oct 27 07:49:00
2008
@@ -475,6 +475,21 @@
     }
 
     /**
+     * part of the error message created by {@link #throwNotSupported
+     * throwNotSupported}.
+     * @since Ant 1.8.0
+     */
+    protected static final String NOT_SUPPORTED_CHILD_PREFIX =
+        " doesn't support the nested \"";
+
+    /**
+     * part of the error message created by {@link #throwNotSupported
+     * throwNotSupported}.
+     * @since Ant 1.8.0
+     */
+    protected static final String NOT_SUPPORTED_CHILD_POSTFIX = "\" element.";
+
+    /**
      * Utility method to throw a NotSupported exception
      *
      * @param project the Project instance.
@@ -483,7 +498,8 @@
      */
     public void throwNotSupported(Project project, Object parent, String elementName) {
         String msg = project.getElementName(parent)
-                + " doesn't support the nested \"" + elementName + "\" element.";
+            + NOT_SUPPORTED_CHILD_PREFIX + elementName
+            + NOT_SUPPORTED_CHILD_POSTFIX;
         throw new UnsupportedElementException(msg, elementName);
     }
 
@@ -690,42 +706,26 @@
      * Indicate if this element supports a nested element of the
      * given name.
      *
+     * <p>Note that this method will always return true if the
+     * introspected class is {@link #isDynamic dynamic}, so be
+     * prepared to catch an exception about unsupported children when
+     * calling {@link #getElementCreator getElementCreator}.</p>
+     *
      * @param parentUri   the uri of the parent
      * @param elementName the name of the nested element being checked
      * @param project currently executing project instance
-     * @param parent  the parent element (an instance of the introspected class)
-     * @param childQName QName of the child element, may be null
+     * @param parent the parent element
      *
      * @return true if the given nested element is supported
      * @since Ant 1.8.0.
      */
     public boolean supportsNestedElement(String parentUri, String elementName,
-                                         Project project, Object parent,
-                                         String childQName) {
+                                         Project project, Object parent) {
         if (addTypeMethods.size() > 0
             && createAddTypeCreator(project, parent, elementName) != null) {
             return true;
         }
-        if (isDynamic()) {
-            /*
-              breaks several tests, in particular EchoXML because it
-              creates additional empty child elements in XMLFragment
-
-            String localName =
-                ProjectHelper.extractNameFromComponentName(elementName);
-            String uri = ProjectHelper.extractUriFromComponentName(elementName);
-            if (uri.equals(ProjectHelper.ANT_CORE_URI)) {
-                uri = "";
-            }
-            if (createDynamicElement(parent, uri, localName,
-                                     childQName == null ? localName : childQName)
-                != null) {
-                return true;
-            }
-            */
-            return true;
-        }
-        return supportsReflectElement(parentUri, elementName);
+        return isDynamic() || supportsReflectElement(parentUri, elementName);
     }
 
     /**

Modified: ant/core/trunk/src/main/org/apache/tools/ant/UnknownElement.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/UnknownElement.java?rev=708204&r1=708203&r2=708204&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/UnknownElement.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/UnknownElement.java Mon Oct 27 07:49:00 2008
@@ -542,11 +542,19 @@
         RuntimeConfigurable childWrapper) {
         String childName = ProjectHelper.genComponentName(
             child.getNamespace(), child.getTag());
-        if (ih.supportsNestedElement(parentUri, childName,
-                                     getProject(), parent, child.getQName())) {
-            IntrospectionHelper.Creator creator =
-                ih.getElementCreator(
-                    getProject(), parentUri, parent, childName, child);
+        if (ih.supportsNestedElement(parentUri, childName, getProject(),
+                                     parent)) {
+            IntrospectionHelper.Creator creator = null;
+            try {
+                creator = ih.getElementCreator(getProject(), parentUri,
+                                               parent, childName, child);
+            } catch (UnsupportedElementException use) {
+                if (!ih.isDynamic()) {
+                    throw use;
+                }
+                // can't trust supportsNestedElement for dynamic elements
+                return false;
+            }
             creator.setPolyType(childWrapper.getPolyType());
             Object realChild = creator.create();
             if (realChild instanceof PreSetDef.PreSetDefinition) {

Modified: ant/core/trunk/src/tests/antunit/core/nested-elements-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/core/nested-elements-test.xml?rev=708204&r1=708203&r2=708204&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/core/nested-elements-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/core/nested-elements-test.xml Mon Oct 27 07:49:00 2008
@@ -19,7 +19,7 @@
 
   <import file="../antunit-base.xml"/>
 
-  <target name="testConditionBaseAndTasContainer">
+  <target name="testConditionBaseAndTaskContainer">
     <mkdir dir="${input}"/>
     <mkdir dir="${output}"/>
     <echo file="${input}/ConditionRun.java">
@@ -51,4 +51,75 @@
     </conditionrun>
     <au:assertLogContains text="Hello"/>
   </target>
+
+  <target name="testDynamicElementAndTaskContainer">
+    <mkdir dir="${input}"/>
+    <mkdir dir="${output}"/>
+    <echo file="${input}/Dynamic.java">
+import org.apache.tools.ant.*;
+import java.util.*;
+
+public class Dynamic implements TaskContainer, DynamicElement {
+    private List tasks = new ArrayList();
+
+    public void addTask(Task task) {
+        tasks.add(task);
+    }
+
+    public void execute() {
+        for (Iterator iter = tasks.iterator(); iter.hasNext(); ) {
+            Task t = (Task) iter.next();
+            t.perform();
+        }
+    }
+    public Object createDynamicElement(String name) {
+        return null;
+    }
+}
+    </echo>
+    <javac destdir="${output}"
+           srcdir="${input}"/>
+    <taskdef name="dyn" classpath="${output}"
+             classname="Dynamic"/>
+    <dyn>
+      <echo>Hello</echo>
+    </dyn>
+    <au:assertLogContains text="Hello"/>
+  </target>
+
+  <target name="testDynamicElementNSAndTaskContainer">
+    <mkdir dir="${input}"/>
+    <mkdir dir="${output}"/>
+    <echo file="${input}/Dynamic.java">
+import org.apache.tools.ant.*;
+import java.util.*;
+
+public class Dynamic implements TaskContainer, DynamicElementNS {
+    private List tasks = new ArrayList();
+
+    public void addTask(Task task) {
+        tasks.add(task);
+    }
+
+    public void execute() {
+        for (Iterator iter = tasks.iterator(); iter.hasNext(); ) {
+            Task t = (Task) iter.next();
+            t.perform();
+        }
+    }
+    public Object createDynamicElement(String uri, String localName,
+                                       String qName) {
+        return null;
+    }
+}
+    </echo>
+    <javac destdir="${output}"
+           srcdir="${input}"/>
+    <taskdef name="dyn" classpath="${output}"
+             classname="Dynamic"/>
+    <dyn>
+      <echo>Hello</echo>
+    </dyn>
+    <au:assertLogContains text="Hello"/>
+  </target>
 </project>



Mime
View raw message