peterreilly 2003/11/18 04:09:32 Modified: src/main/org/apache/tools/ant/taskdefs Tag: ANT_16_BRANCH MacroDef.java MacroInstance.java src/etc/testcases/taskdefs Tag: ANT_16_BRANCH macrodef.xml src/testcases/org/apache/tools/ant/taskdefs Tag: ANT_16_BRANCH MacroDefTest.java Log: Sync with HEAD Revision Changes Path No revision No revision 1.7.2.6 +13 -3 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.5 retrieving revision 1.7.2.6 diff -u -r1.7.2.5 -r1.7.2.6 --- MacroDef.java 11 Nov 2003 12:02:09 -0000 1.7.2.5 +++ MacroDef.java 18 Nov 2003 12:09:31 -0000 1.7.2.6 @@ -78,7 +78,7 @@ public class MacroDef extends AntlibDefinition { private NestedSequential nestedSequential; private String name; - private List attributes = new ArrayList(); + private Map attributes = new HashMap(); private Map elements = new HashMap(); /** @@ -170,7 +170,7 @@ /** * @return the nested Attributes */ - public List getAttributes() { + public Map getAttributes() { return attributes; } @@ -221,7 +221,12 @@ throw new BuildException( "the attribute nested element needed a \"name\" attribute"); } - attributes.add(attribute); + if (attributes.get(attribute.getName()) != null) { + throw new BuildException( + "the attribute " + attribute.getName() + + " has already been specified"); + } + attributes.put(attribute.getName(), attribute); } /** @@ -233,6 +238,11 @@ if (element.getName() == null) { throw new BuildException( "the element nested element needed a \"name\" attribute"); + } + if (elements.get(element.getName()) != null) { + throw new BuildException( + "the element " + element.getName() + + " has already been specified"); } elements.put(element.getName(), element); } 1.5.2.6 +3 -3 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.5 retrieving revision 1.5.2.6 diff -u -r1.5.2.5 -r1.5.2.6 --- MacroInstance.java 18 Nov 2003 11:29:07 -0000 1.5.2.5 +++ MacroInstance.java 18 Nov 2003 12:09:31 -0000 1.5.2.6 @@ -294,9 +294,9 @@ public void execute() { localProperties = new Hashtable(); Set copyKeys = new HashSet(map.keySet()); - for (int i = 0; i < macroDef.getAttributes().size(); ++i) { - MacroDef.Attribute attribute = - (MacroDef.Attribute) macroDef.getAttributes().get(i); + for (Iterator i = macroDef.getAttributes().values().iterator(); + i.hasNext();) { + MacroDef.Attribute attribute = (MacroDef.Attribute) i.next(); String value = (String) map.get(attribute.getName()); if (value == null) { value = attribute.getDefault(); No revision No revision 1.2.2.2 +20 -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.1 retrieving revision 1.2.2.2 diff -u -r1.2.2.1 -r1.2.2.2 --- macrodef.xml 23 Sep 2003 13:56:44 -0000 1.2.2.1 +++ macrodef.xml 18 Nov 2003 12:09:31 -0000 1.2.2.2 @@ -20,6 +20,26 @@ <my.echo text="Inner Text"/> </target> + <target name="duplicate.attribute"> + <macrodef name="my.echo"> + <attribute name="text"/> + <attribute name="text"/> + <sequential> + <echo>${text}</echo> + </sequential> + </macrodef> + </target> + + <target name="duplicate.element"> + <macrodef name="my.echo"> + <element name="text"/> + <element name="text"/> + <sequential> + <text/> + </sequential> + </macrodef> + </target> + <target name="uri"> <macrodef name="echo" uri="abc"> <attribute name="text"/> No revision No revision 1.2.2.2 +12 -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.1 retrieving revision 1.2.2.2 diff -u -r1.2.2.1 -r1.2.2.2 --- MacroDefTest.java 23 Sep 2003 13:56:44 -0000 1.2.2.1 +++ MacroDefTest.java 18 Nov 2003 12:09:32 -0000 1.2.2.2 @@ -78,6 +78,18 @@ expectLog("text", "Inner Text"); } + public void testDuplicateAttribute() { + expectBuildException( + "duplicate.attribute", + "the attribute text has already been specified"); + } + + public void testDuplicateElement() { + expectBuildException( + "duplicate.element", + "the element text has already been specified"); + } + public void testUri() { expectLog("uri", "Hello World"); }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]