peterreilly 2003/11/18 04:08:01
Modified: src/main/org/apache/tools/ant/taskdefs MacroDef.java
MacroInstance.java
src/etc/testcases/taskdefs macrodef.xml
src/testcases/org/apache/tools/ant/taskdefs
MacroDefTest.java
Log:
Do now allow multiple attribute and elements of the same
name for macrodef.
Revision Changes Path
1.13 +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.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- MacroDef.java 11 Nov 2003 12:01:26 -0000 1.12
+++ MacroDef.java 18 Nov 2003 12:08:01 -0000 1.13
@@ -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.11 +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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- MacroInstance.java 18 Nov 2003 10:51:41 -0000 1.10
+++ MacroInstance.java 18 Nov 2003 12:08:01 -0000 1.11
@@ -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();
1.4 +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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- macrodef.xml 23 Sep 2003 13:55:52 -0000 1.3
+++ macrodef.xml 18 Nov 2003 12:08:01 -0000 1.4
@@ -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"/>
1.4 +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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MacroDefTest.java 23 Sep 2003 13:55:52 -0000 1.3
+++ MacroDefTest.java 18 Nov 2003 12:08:01 -0000 1.4
@@ -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]