ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peterrei...@apache.org
Subject cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs MacroDefTest.java
Date Fri, 04 Jun 2004 07:39:09 GMT
peterreilly    2004/06/04 00:39:09

  Modified:    docs/manual/CoreTasks Tag: ANT_16_BRANCH macrodef.html
               src/etc/testcases/taskdefs Tag: ANT_16_BRANCH macrodef.xml
               src/main/org/apache/tools/ant Tag: ANT_16_BRANCH
                        DynamicConfigurator.java IntrospectionHelper.java
                        ProjectHelper.java UnknownElement.java
               src/main/org/apache/tools/ant/helper Tag: ANT_16_BRANCH
                        ProjectHelper2.java
               src/main/org/apache/tools/ant/taskdefs Tag: ANT_16_BRANCH
                        MacroDef.java MacroInstance.java
               src/testcases/org/apache/tools/ant/taskdefs Tag:
                        ANT_16_BRANCH MacroDefTest.java
  Added:       src/main/org/apache/tools/ant Tag: ANT_16_BRANCH
                        DynamicAttribute.java DynamicAttributeNS.java
                        DynamicElement.java DynamicElementNS.java
                        DynamicConfiguratorNS.java
  Log:
  sync up changes for DynamicConfiguratorNs and for implicit nested
  elements in macrodef
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.2.2.20  +50 -0     ant/docs/manual/CoreTasks/macrodef.html
  
  Index: macrodef.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/CoreTasks/macrodef.html,v
  retrieving revision 1.2.2.19
  retrieving revision 1.2.2.20
  diff -u -r1.2.2.19 -r1.2.2.20
  --- macrodef.html	26 May 2004 12:25:52 -0000	1.2.2.19
  +++ macrodef.html	4 Jun 2004 07:39:08 -0000	1.2.2.20
  @@ -132,6 +132,17 @@
           <td valign="top" align="center">No</td>
         </tr>
         <tr>
  +        <td valign="top">implicit</td>
  +        <td valign="top">
  +          If true this nested element is implicit. This means that
  +          any nested elements of the macrodef instance will be placed
  +          in the element indicated by the name of this element.
  +          There can only be one element if an element is implicit.
  +          The default value is false. <em>since ant 1.6.2</em>
  +        </td>
  +        <td valign="top" align="center">No</td>
  +      </tr>
  +      <tr>
           <td valign="top">description</td>
           <td valign="top">
             This contains a description
  @@ -253,6 +264,45 @@
         &lt;fileset dir="${gen.dir}" includes = "*.cpp"/&gt;
         &lt;linker refid="linker-libs"/&gt;
      &lt;/cc-elements&gt;
  +&lt;/call-cc&gt;
  +</pre>
  +    </blockquote>
  +    <p>
  +      The following fragment shows &lt;call-cc&gt;, but this time
  +      using an implicit element and with the link and target.dir arguments
  +      having default values.
  +    </p>
  +    <blockquote>
  +<pre class="code">
  +&lt;macrodef name="call-cc"&gt;
  +   &lt;attribute name="target"/&gt;
  +   &lt;attribute name="link" default="executable"/&gt;
  +   &lt;attribute name="target.dir" default="${build.bin.dir}"/&gt;
  +   &lt;element name="cc-elements" implicit="yes"/&gt;
  +   &lt;sequential&gt;
  +      &lt;mkdir dir="${obj.dir}/@{target}"/&gt;
  +      &lt;mkdir dir="@{target.dir}"/&gt;
  +         &lt;cc link="@{link}" objdir="${obj.dir}/@{target}"
  +             outfile="@{target.dir}/@{target}"&gt;
  +            &lt;compiler refid="compiler.options"/&gt;
  +            &lt;cc-elements/&gt;
  +         &lt;/cc&gt;
  +      &lt;/sequential&gt;
  +&lt;/macrodef&gt;
  +</pre>
  +    </blockquote>
  +    <p>
  +      This then can be used as follows, note that &lt;cc-elements&gt;
  +      is not specified.
  +    </p>
  +    <blockquote>
  +<pre class="code">
  +&lt;call-cc target="unittests"/&gt;
  +   &lt;includepath location="${gen.dir}"/&gt;
  +   &lt;includepath location="test"/&gt;
  +   &lt;fileset dir="test/unittest" includes = "**/*.cpp"/&gt;
  +   &lt;fileset dir="${gen.dir}" includes = "*.cpp"/&gt;
  +   &lt;linker refid="linker-libs"/&gt;
   &lt;/call-cc&gt;
   </pre>
       </blockquote>
  
  
  
  No                   revision
  No                   revision
  1.2.2.10  +55 -0     ant/src/etc/testcases/taskdefs/macrodef.xml
  
  Index: macrodef.xml
  ===================================================================
  RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/macrodef.xml,v
  retrieving revision 1.2.2.9
  retrieving revision 1.2.2.10
  diff -u -r1.2.2.9 -r1.2.2.10
  --- macrodef.xml	24 Feb 2004 09:31:48 -0000	1.2.2.9
  +++ macrodef.xml	4 Jun 2004 07:39:08 -0000	1.2.2.10
  @@ -168,4 +168,59 @@
       <d description="hello world"/>
     </target>
   
  +  <target name="implicit">
  +    <macrodef name="implicit">
  +      <element name="implicit" implicit="yes"/>
  +      <sequential>
  +        <echo>Before implicit</echo>
  +        <implicit/>
  +        <echo>After implicit</echo>
  +      </sequential>
  +    </macrodef>
  +
  +    <implicit>
  +      <echo>In implicit</echo>
  +    </implicit>
  +  </target>
  +
  +  <target name="implicit.notoptional">
  +    <macrodef name="implicit">
  +      <element name="implicit" implicit="yes"/>
  +      <sequential>
  +        <echo>Before implicit</echo>
  +        <implicit/>
  +        <echo>After implicit</echo>
  +      </sequential>
  +    </macrodef>
  +
  +    <implicit>
  +    </implicit>
  +  </target>
  +
  +  <target name="implicit.optional">
  +    <macrodef name="implicit">
  +      <element name="implicit" optional="yes" implicit="yes"/>
  +      <sequential>
  +        <echo>Before implicit</echo>
  +        <implicit/>
  +        <echo>After implicit</echo>
  +      </sequential>
  +    </macrodef>
  +
  +    <implicit>
  +    </implicit>
  +  </target>
  +
  +  <target name="implicit.explicit">
  +    <macrodef name="implicit">
  +      <element name="explicit" optional="yes"/>
  +      <element name="implicit" optional="yes" implicit="yes"/>
  +      <sequential>
  +        <implicit/>
  +        <explicit/>
  +      </sequential>
  +    </macrodef>
  +
  +  </target>
  +
   </project>
  
  
  
  No                   revision
  No                   revision
  1.7.2.5   +3 -20     ant/src/main/org/apache/tools/ant/DynamicConfigurator.java
  
  Index: DynamicConfigurator.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/DynamicConfigurator.java,v
  retrieving revision 1.7.2.4
  retrieving revision 1.7.2.5
  diff -u -r1.7.2.4 -r1.7.2.5
  --- DynamicConfigurator.java	9 Mar 2004 17:01:29 -0000	1.7.2.4
  +++ DynamicConfigurator.java	4 Jun 2004 07:39:09 -0000	1.7.2.5
  @@ -22,24 +22,7 @@
    *
    * @since Ant 1.5
    */
  -public interface DynamicConfigurator {
  -
  -    /**
  -     * Set a named attribute to the given value
  -     *
  -     * @param name the name of the attribute
  -     * @param value the new value of the attribute
  -     * @throws BuildException when any error occurs
  -     */
  -    void setDynamicAttribute(String name, String value)
  -            throws BuildException;
  -
  -    /**
  -     * Create an element with the given name
  -     *
  -     * @param name the element nbame
  -     * @throws BuildException when any error occurs
  -     * @return the element created
  -     */
  -    Object createDynamicElement(String name) throws BuildException;
  +public interface DynamicConfigurator
  +    extends DynamicAttribute, DynamicElement {
   }
  +
  
  
  
  1.65.2.15 +64 -15    ant/src/main/org/apache/tools/ant/IntrospectionHelper.java
  
  Index: IntrospectionHelper.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/IntrospectionHelper.java,v
  retrieving revision 1.65.2.14
  retrieving revision 1.65.2.15
  diff -u -r1.65.2.14 -r1.65.2.15
  --- IntrospectionHelper.java	15 Mar 2004 17:33:24 -0000	1.65.2.14
  +++ IntrospectionHelper.java	4 Jun 2004 07:39:09 -0000	1.65.2.15
  @@ -414,7 +414,7 @@
               return true;
           }
   
  -        if  ("setTaskType".equals(name)
  +        if ("setTaskType".equals(name)
                && java.lang.String.class.equals(type)) {
               return true;
           }
  @@ -453,7 +453,8 @@
        *
        * @return a helper for the specified class
        */
  -    public static synchronized IntrospectionHelper getHelper(Project p, Class c) {
  +    public static synchronized IntrospectionHelper getHelper(Project p, 
  +                                                             Class c) {
           IntrospectionHelper ih = (IntrospectionHelper) helpers.get(c);
           if (ih == null) {
               ih = new IntrospectionHelper(c);
  @@ -485,13 +486,30 @@
       public void setAttribute(Project p, Object element, String attributeName,
                                String value) throws BuildException {
           AttributeSetter as
  -            = (AttributeSetter) attributeSetters.get(attributeName);
  +            = (AttributeSetter) attributeSetters.get(
  +                attributeName.toLowerCase(Locale.US));
           if (as == null) {
  -            if (element instanceof DynamicConfigurator) {
  -                DynamicConfigurator dc = (DynamicConfigurator) element;
  -                dc.setDynamicAttribute(attributeName, value);
  +            if (element instanceof DynamicAttributeNS) {
  +                DynamicAttributeNS dc = (DynamicAttributeNS) element;
  +                String uriPlusPrefix =
  +                    ProjectHelper.extractUriFromComponentName(attributeName);
  +                String uri =
  +                    ProjectHelper.extractUriFromComponentName(uriPlusPrefix);
  +                String localName =
  +                    ProjectHelper.extractNameFromComponentName(attributeName);
  +                String qName = ("".equals(uri)
  +                                ? localName : (uri + ":" + localName));
  +
  +                dc.setDynamicAttribute(uri, localName, qName, value);
  +                return;
  +            } else if (element instanceof DynamicAttribute) {
  +                DynamicAttribute dc = (DynamicAttribute) element;
  +                dc.setDynamicAttribute(attributeName.toLowerCase(Locale.US), value);
                   return;
               } else {
  +                if (attributeName.indexOf(':') != -1) {
  +                    return; // Ignore attribute from unknown uri's
  +                }
                   String msg = getElementName(p, element)
                       + " doesn't support the \"" + attributeName
                       + "\" attribute.";
  @@ -511,6 +529,7 @@
               throw new BuildException(t);
           }
       }
  +    
   
       /**
        * Adds PCDATA to an element, using the element's
  @@ -573,7 +592,7 @@
   
       private NestedCreator getNestedCreator(
           Project project, String parentUri, Object parent,
  -        String elementName) throws BuildException {
  +        String elementName, UnknownElement child) throws BuildException {
   
           String uri = ProjectHelper.extractUriFromComponentName(elementName);
           String name = ProjectHelper.extractNameFromComponentName(elementName);
  @@ -592,8 +611,37 @@
           if (nc == null) {
               nc = createAddTypeCreator(project, parent, elementName);
           }
  -        if (nc == null && parent instanceof DynamicConfigurator) {
  -            DynamicConfigurator dc = (DynamicConfigurator) parent;
  +        if (nc == null && parent instanceof DynamicElementNS) {
  +            DynamicElementNS dc = (DynamicElementNS) parent;
  +            String qName = (child == null ? name : child.getQName());
  +            final Object nestedElement =
  +                dc.createDynamicElement(
  +                    (child == null ? "" : child.getNamespace()),
  +                    name, qName);
  +            if (nestedElement != null) {
  +                nc = new NestedCreator() {
  +                    public boolean isPolyMorphic() {
  +                        return false;
  +                    }
  +                    public Class getElementClass() {
  +                        return null;
  +                    }
  +
  +                    public Object getRealObject() {
  +                        return null;
  +                    }
  +
  +                    public Object create(
  +                        Project project, Object parent, Object ignore) {
  +                        return nestedElement;
  +                    }
  +                    public void store(Object parent, Object child) {
  +                    }
  +                };
  +            }
  +        }
  +        if (nc == null && parent instanceof DynamicElement) {
  +            DynamicElement dc = (DynamicElement) parent;
               final Object nestedElement =
                   dc.createDynamicElement(name.toLowerCase(Locale.US));
               if (nestedElement != null) {
  @@ -648,7 +696,7 @@
        */
       public Object createElement(Project project, Object parent,
           String elementName) throws BuildException {
  -        NestedCreator nc = getNestedCreator(project, "", parent, elementName);
  +        NestedCreator nc = getNestedCreator(project, "", parent, elementName, null);
           try {
               Object nestedElement = nc.create(project, parent, null);
               if (project != null) {
  @@ -687,7 +735,7 @@
           Project project, String parentUri, Object parent, String elementName,
           UnknownElement ue) {
           NestedCreator nc = getNestedCreator(
  -            project, parentUri, parent, elementName);
  +            project, parentUri, parent, elementName, ue);
           return new Creator(project, parent, nc);
       }
   
  @@ -701,7 +749,8 @@
        */
       public boolean supportsNestedElement(String elementName) {
           return nestedCreators.containsKey(elementName.toLowerCase(Locale.US))
  -            || DynamicConfigurator.class.isAssignableFrom(bean)
  +            || DynamicElement.class.isAssignableFrom(bean)
  +            || DynamicElementNS.class.isAssignableFrom(bean)
               || addTypeMethods.size() != 0;
       }
   
  @@ -727,7 +776,8 @@
           return (
               nestedCreators.containsKey(name.toLowerCase(Locale.US))
               && (uri.equals(parentUri))) // || uri.equals("")))
  -            || DynamicConfigurator.class.isAssignableFrom(bean)
  +            || DynamicElement.class.isAssignableFrom(bean)
  +            || DynamicElementNS.class.isAssignableFrom(bean)
               || addTypeMethods.size() != 0;
       }
   
  @@ -1113,8 +1163,7 @@
                   Class elementClass = nestedCreator.getElementClass();
                   ComponentHelper helper =
                       ComponentHelper.getComponentHelper(project);
  -                nestedObject = ComponentHelper.getComponentHelper(project)
  -                    .createComponent(polyType);
  +                nestedObject = helper.createComponent(polyType);
                   if (nestedObject == null) {
                       throw new BuildException(
                           "Unable to create object of type " + polyType);
  
  
  
  1.101.2.11 +4 -1      ant/src/main/org/apache/tools/ant/ProjectHelper.java
  
  Index: ProjectHelper.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/ProjectHelper.java,v
  retrieving revision 1.101.2.10
  retrieving revision 1.101.2.11
  diff -u -r1.101.2.10 -r1.101.2.11
  --- ProjectHelper.java	15 Mar 2004 17:33:24 -0000	1.101.2.10
  +++ ProjectHelper.java	4 Jun 2004 07:39:09 -0000	1.101.2.11
  @@ -56,6 +56,9 @@
       /** The URI for defined types/tasks - the format is antlib:<package> */
       public static final String ANTLIB_URI     = "antlib:";
   
  +    /** Polymorphic attribute  */
  +    public static final String ANT_TYPE = "ant-type";
  +
       /**
        * Name of JVM system property which provides the name of the
        * ProjectHelper class to use.
  @@ -309,7 +312,7 @@
           for (int i = 0; i < attrs.getLength(); i++) {
               // reflect these into the target
               String value = replaceProperties(project, attrs.getValue(i),
  -                                           project.getProperties());
  +                                             project.getProperties());
               try {
                   ih.setAttribute(project, target,
                                   attrs.getName(i).toLowerCase(Locale.US), value);
  
  
  
  1.63.2.13 +7 -0      ant/src/main/org/apache/tools/ant/UnknownElement.java
  
  Index: UnknownElement.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/UnknownElement.java,v
  retrieving revision 1.63.2.12
  retrieving revision 1.63.2.13
  diff -u -r1.63.2.12 -r1.63.2.13
  --- UnknownElement.java	7 Apr 2004 12:17:12 -0000	1.63.2.12
  +++ UnknownElement.java	4 Jun 2004 07:39:09 -0000	1.63.2.13
  @@ -72,6 +72,13 @@
       }
   
       /**
  +     * @return the list of nested UnknownElements for this UnknownElement.
  +     */
  +    public List getChildren() {
  +        return children;
  +    }
  +
  +    /**
        * Returns the name of the XML element which generated this unknown
        * element.
        *
  
  
  
  No                   revision
  
  Index: UnknownElement.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/UnknownElement.java,v
  retrieving revision 1.63.2.12
  retrieving revision 1.63.2.13
  diff -u -r1.63.2.12 -r1.63.2.13
  --- UnknownElement.java	7 Apr 2004 12:17:12 -0000	1.63.2.12
  +++ UnknownElement.java	4 Jun 2004 07:39:09 -0000	1.63.2.13
  @@ -72,6 +72,13 @@
       }
   
       /**
  +     * @return the list of nested UnknownElements for this UnknownElement.
  +     */
  +    public List getChildren() {
  +        return children;
  +    }
  +
  +    /**
        * Returns the name of the XML element which generated this unknown
        * element.
        *
  
  
  
  No                   revision
  
  Index: UnknownElement.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/UnknownElement.java,v
  retrieving revision 1.63.2.12
  retrieving revision 1.63.2.13
  diff -u -r1.63.2.12 -r1.63.2.13
  --- UnknownElement.java	7 Apr 2004 12:17:12 -0000	1.63.2.12
  +++ UnknownElement.java	4 Jun 2004 07:39:09 -0000	1.63.2.13
  @@ -72,6 +72,13 @@
       }
   
       /**
  +     * @return the list of nested UnknownElements for this UnknownElement.
  +     */
  +    public List getChildren() {
  +        return children;
  +    }
  +
  +    /**
        * Returns the name of the XML element which generated this unknown
        * element.
        *
  
  
  
  1.1.2.1   +0 -0      ant/src/main/org/apache/tools/ant/DynamicAttribute.java
  
  Index: DynamicAttribute.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/DynamicAttribute.java,v
  retrieving revision 1.1
  retrieving revision 1.1.2.1
  diff -u -r1.1 -r1.1.2.1
  
  
  
  1.1.2.1   +0 -0      ant/src/main/org/apache/tools/ant/DynamicAttributeNS.java
  
  Index: DynamicAttributeNS.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/DynamicAttributeNS.java,v
  retrieving revision 1.1
  retrieving revision 1.1.2.1
  diff -u -r1.1 -r1.1.2.1
  
  
  
  1.1.2.1   +0 -0      ant/src/main/org/apache/tools/ant/DynamicElement.java
  
  Index: DynamicElement.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/DynamicElement.java,v
  retrieving revision 1.1
  retrieving revision 1.1.2.1
  diff -u -r1.1 -r1.1.2.1
  
  
  
  1.1.2.1   +0 -0      ant/src/main/org/apache/tools/ant/DynamicElementNS.java
  
  Index: DynamicElementNS.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/DynamicElementNS.java,v
  retrieving revision 1.1
  retrieving revision 1.1.2.1
  diff -u -r1.1 -r1.1.2.1
  
  
  
  1.2.2.1   +0 -0      ant/src/main/org/apache/tools/ant/DynamicConfiguratorNS.java
  
  Index: DynamicConfiguratorNS.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/DynamicConfiguratorNS.java,v
  retrieving revision 1.2
  retrieving revision 1.2.2.1
  diff -u -r1.2 -r1.2.2.1
  
  
  
  No                   revision
  No                   revision
  1.33.2.13 +6 -3      ant/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
  
  Index: ProjectHelper2.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/helper/ProjectHelper2.java,v
  retrieving revision 1.33.2.12
  retrieving revision 1.33.2.13
  diff -u -r1.33.2.12 -r1.33.2.13
  --- ProjectHelper2.java	14 Apr 2004 15:42:40 -0000	1.33.2.12
  +++ ProjectHelper2.java	4 Jun 2004 07:39:09 -0000	1.33.2.13
  @@ -944,19 +944,22 @@
                   = new RuntimeConfigurable(task, task.getTaskName());
   
               for (int i = 0; i < attrs.getLength(); i++) {
  +                String name = attrs.getLocalName(i);
                   String attrUri = attrs.getURI(i);
                   if (attrUri != null
                       && !attrUri.equals("")
                       && !attrUri.equals(uri)) {
  -                    continue; // Ignore attributes from unknown uris
  +                    name = attrUri + ":" + attrs.getQName(i);
                   }
  -                String name = attrs.getLocalName(i);
                   String value = attrs.getValue(i);
                   // PR: Hack for ant-type value
                   //  an ant-type is a component name which can
                   // be namespaced, need to extract the name
                   // and convert from qualified name to uri/name
  -                if (name.equals("ant-type")) {
  +                if (ANT_TYPE.equals(name)
  +                    || (ANT_CORE_URI.equals(attrUri)
  +                        && ANT_TYPE.equals(attrs.getLocalName(i)))) {
  +                    name = ANT_TYPE;
                       int index = value.indexOf(":");
                       if (index != -1) {
                           String prefix = value.substring(0, index);
  
  
  
  No                   revision
  No                   revision
  1.7.2.19  +28 -2     ant/src/main/org/apache/tools/ant/taskdefs/MacroDef.java
  
  Index: MacroDef.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/MacroDef.java,v
  retrieving revision 1.7.2.18
  retrieving revision 1.7.2.19
  diff -u -r1.7.2.18 -r1.7.2.19
  --- MacroDef.java	17 May 2004 13:30:51 -0000	1.7.2.18
  +++ MacroDef.java	4 Jun 2004 07:39:09 -0000	1.7.2.19
  @@ -46,6 +46,7 @@
       private Map        elements   = new HashMap();
       private String     textName   = null;
       private Text       text       = null;
  +    private boolean    hasImplicitElement = false;
   
       /**
        * Name of the definition
  @@ -254,6 +255,12 @@
                   "the element " + element.getName()
                   + " has already been specified");
           }
  +        if (hasImplicitElement
  +            || (element.isImplicit() && elements.size() != 0)) {
  +            throw new BuildException(
  +                "Only one element allowed when using implicit elements");
  +        }
  +        hasImplicitElement = element.isImplicit();
           elements.put(element.getName(), element);
       }
   
  @@ -507,6 +514,7 @@
       public static class TemplateElement {
           private String name;
           private boolean optional = false;
  +        private boolean implicit = false;
           private String description;
   
           /**
  @@ -547,6 +555,23 @@
           }
   
           /**
  +         * is this element implicit ?
  +         *
  +         * @param implicit if true this element may be left out, default
  +         *                 is false.
  +         */
  +        public void setImplicit(boolean implicit) {
  +            this.implicit = implicit;
  +        }
  +
  +        /**
  +         * @return the implicit attribute
  +         */
  +        public boolean isImplicit() {
  +            return implicit;
  +        }
  +
  +        /**
            * @param desc Description of the element.
            * @since ant 1.6.1
            */
  @@ -584,14 +609,15 @@
               } else if (!name.equals(other.name)) {
                   return false;
               }
  -            return optional == other.optional;
  +            return optional == other.optional && implicit == other.implicit;
           }
   
           /**
            * @return a hash code value for this object.
            */
           public int hashCode() {
  -            return objectHashCode(name) + (optional ? 1 : 0);
  +            return objectHashCode(name)
  +                + (optional ? 1 : 0) + (implicit ? 1 : 0);
           }
       }
   
  
  
  
  1.5.2.21  +59 -19    ant/src/main/org/apache/tools/ant/taskdefs/MacroInstance.java
  
  Index: MacroInstance.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/MacroInstance.java,v
  retrieving revision 1.5.2.20
  retrieving revision 1.5.2.21
  diff -u -r1.5.2.20 -r1.5.2.21
  --- MacroInstance.java	7 Apr 2004 12:39:58 -0000	1.5.2.20
  +++ MacroInstance.java	4 Jun 2004 07:39:09 -0000	1.5.2.21
  @@ -29,7 +29,7 @@
   import java.util.Enumeration;
   
   import org.apache.tools.ant.BuildException;
  -import org.apache.tools.ant.DynamicConfigurator;
  +import org.apache.tools.ant.DynamicAttribute;
   import org.apache.tools.ant.ProjectHelper;
   import org.apache.tools.ant.RuntimeConfigurable;
   import org.apache.tools.ant.Target;
  @@ -44,13 +44,15 @@
    * the parameter values in attributes and text.
    * @since Ant 1.6
    */
  -public class MacroInstance extends Task implements DynamicConfigurator {
  +public class MacroInstance extends Task implements DynamicAttribute, TaskContainer {
       private MacroDef macroDef;
       private Map      map = new HashMap();
       private Map      nsElements = null;
       private Map      presentElements = new HashMap();
       private Hashtable localProperties = new Hashtable();
       private String    text = null;
  +    private String    implicitTag =     null;
  +    private List      unknownElements = new ArrayList();
   
       /**
        * Called from MacroDef.MyAntTypeDefinition#create()
  @@ -79,22 +81,14 @@
       }
   
       /**
  -     * Add an element.
  -     * @param name the name of the element
  -     * @return an inner Element type
  -     * @throws BuildException if the name is not known or if this element
  -     *                        has already been seen
  +     * Method present for BC purposes.
  +     * @param name not used
  +     * @return nothing
  +     * @deprecated
  +     * @throws BuildException always
        */
       public Object createDynamicElement(String name) throws BuildException {
  -        if (getNsElements().get(name) == null) {
  -            throw new BuildException("unsupported element " + name);
  -        }
  -        if (presentElements.get(name) != null) {
  -            throw new BuildException("Element " + name + " already present");
  -        }
  -        Element ret = new Element();
  -        presentElements.put(name, ret);
  -        return ret;
  +        throw new BuildException("Not implemented any more");
       }
   
       private Map getNsElements() {
  @@ -105,12 +99,44 @@
                   Map.Entry entry = (Map.Entry) i.next();
                   nsElements.put((String) entry.getKey(),
                                  entry.getValue());
  +                MacroDef.TemplateElement te = (MacroDef.TemplateElement)
  +                    entry.getValue();
  +                if (te.isImplicit()) {
  +                    implicitTag = te.getName();
  +                }
               }
           }
           return nsElements;
       }
   
       /**
  +     * Add a unknownElement for the macro instances nested elements.
  +     *
  +     * @param nestedTask a nested element.
  +     */
  +    public void addTask(Task nestedTask) {
  +        unknownElements.add(nestedTask);
  +    }
  +
  +    private void processTasks() {
  +        if (implicitTag != null) {
  +            return;
  +        }
  +        for (Iterator i = unknownElements.iterator(); i.hasNext();) {
  +            UnknownElement ue = (UnknownElement) i.next();
  +            String name = ProjectHelper.extractNameFromComponentName(
  +                ue.getTag()).toLowerCase(Locale.US);
  +            if (getNsElements().get(name) == null) {
  +                throw new BuildException("unsupported element " + name);
  +            }
  +            if (presentElements.get(name) != null) {
  +                throw new BuildException("Element " + name + " already present");
  +            }
  +            presentElements.put(name, ue.getChildren());
  +        }
  +    }
  +
  +    /**
        * Embedded element in macro instance
        */
       public static class Element implements TaskContainer {
  @@ -255,9 +281,21 @@
                   UnknownElement child = copy(unknownElement);
                   rc.addChild(child.getWrapper());
                   ret.addChild(child);
  +            } else if (templateElement.isImplicit()) {
  +                if (unknownElements.size() == 0 && !templateElement.isOptional())
{
  +                    throw new BuildException(
  +                        "Missing nested elements for implicit element "
  +                        + templateElement.getName());
  +                }
  +                for (Iterator i = unknownElements.iterator();
  +                     i.hasNext();) {
  +                    UnknownElement child = (UnknownElement) i.next();
  +                    rc.addChild(child.getWrapper());
  +                    ret.addChild(child);
  +                }
               } else {
  -                Element element = (Element) presentElements.get(tag);
  -                if (element == null) {
  +                List list = (List) presentElements.get(tag);
  +                if (list == null) {
                       if (!templateElement.isOptional()) {
                           throw new BuildException(
                               "Required nested element "
  @@ -265,7 +303,7 @@
                       }
                       continue;
                   }
  -                for (Iterator i = element.getUnknownElements().iterator();
  +                for (Iterator i = list.iterator();
                        i.hasNext();) {
                       UnknownElement child = (UnknownElement) i.next();
                       rc.addChild(child.getWrapper());
  @@ -283,6 +321,8 @@
        *
        */
       public void execute() {
  +        getNsElements();
  +        processTasks();
           localProperties = new Hashtable();
           Set copyKeys = new HashSet(map.keySet());
           for (Iterator i = macroDef.getAttributes().iterator(); i.hasNext();) {
  
  
  
  No                   revision
  No                   revision
  1.2.2.14  +20 -0     ant/src/testcases/org/apache/tools/ant/taskdefs/MacroDefTest.java
  
  Index: MacroDefTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/MacroDefTest.java,v
  retrieving revision 1.2.2.13
  retrieving revision 1.2.2.14
  diff -u -r1.2.2.13 -r1.2.2.14
  --- MacroDefTest.java	9 Mar 2004 17:02:01 -0000	1.2.2.13
  +++ MacroDefTest.java	4 Jun 2004 07:39:09 -0000	1.2.2.14
  @@ -108,5 +108,25 @@
               "attribute.description",
               "description is hello world");
       }
  +    public void testImplicit() {
  +        expectLog(
  +            "implicit", "Before implicitIn implicitAfter implicit");
  +    }
  +    public void testImplicitNotOptional() {
  +        expectSpecificBuildException(
  +            "implicit.notoptional",
  +            "Missing nested elements for implicit element implicit",
  +            "Missing nested elements for implicit element implicit");
  +    }
  +    public void testImplicitOptional() {
  +        expectLog(
  +            "implicit.optional", "Before implicitAfter implicit");
  +    }
  +    public void testImplicitExplicit() {
  +        expectSpecificBuildException(
  +            "implicit.explicit",
  +            "Only one element allowed when using implicit elements",
  +            "Only one element allowed when using implicit elements");
  +    }
   }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message