peterreilly 2004/01/22 08:33:16
Modified: src/main/org/apache/tools/ant/taskdefs MacroDef.java
MacroInstance.java
docs/manual/CoreTasks macrodef.html
src/etc/testcases/taskdefs macrodef.xml
src/testcases/org/apache/tools/ant/taskdefs
MacroDefTest.java
Log:
add textname attribute to macrodef
Revision Changes Path
1.19 +41 -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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- MacroDef.java 19 Jan 2004 09:51:01 -0000 1.18
+++ MacroDef.java 22 Jan 2004 16:33:16 -0000 1.19
@@ -81,6 +81,7 @@
private String name;
private List attributes = new ArrayList();
private Map elements = new HashMap();
+ private String textName = null;
/**
* Name of the definition
@@ -91,6 +92,25 @@
}
/**
+ * Name of the text attribute.
+ * @param textName the name of the attribute to use for the
+ * text content of the macro.
+ * @since ant 1.6.1
+ */
+ public void setTextName(String textName) {
+ this.textName = textName;
+ }
+
+ /**
+ * @return the name of the text content attribute
+ * @since ant 1.6.1
+ */
+
+ public String getTextName() {
+ return textName;
+ }
+
+ /**
* This is the sequential nested element of the macrodef.
*
* @return a sequential element to be configured.
@@ -222,6 +242,11 @@
throw new BuildException(
"the attribute nested element needed a \"name\" attribute");
}
+ if (attribute.getName().equals(textName)) {
+ throw new BuildException(
+ "the attribute name \"" + attribute.getName()
+ + "\" has already been used by the textname attribute");
+ }
for (int i = 0; i < attributes.size(); ++i) {
if (((Attribute) attributes.get(i)).getName().equals(
attribute.getName())) {
@@ -324,14 +349,16 @@
/**
* @param desc Description of the element.
+ * @since ant 1.6.1
*/
public void setDescription(String desc) {
description = desc;
}
/**
- * @return the description of the element, or <code>null</code> if
+ * @return the description of the element, or <code>null</code> if
* no description is available.
+ * @since ant 1.6.1
*/
public String getDescription() {
return description;
@@ -383,7 +410,7 @@
public static class TemplateElement {
private String name;
private boolean optional = false;
- private String description;
+ private String description;
/**
* The name of the element.
@@ -424,14 +451,16 @@
/**
* @param desc Description of the element.
+ * @since ant 1.6.1
*/
public void setDescription(String desc) {
description = desc;
}
/**
- * @return the description of the element, or <code>null</code> if
+ * @return the description of the element, or <code>null</code> if
* no description is available.
+ * @since ant 1.6.1
*/
public String getDescription() {
return description;
@@ -489,6 +518,15 @@
}
if (!name.equals(other.name)) {
return false;
+ }
+ if (textName == null) {
+ if (other.textName != null) {
+ return false;
+ }
+ } else {
+ if (!textName.equals(other.textName)) {
+ return false;
+ }
}
if (getURI() == null || getURI().equals("")
|| getURI().equals(ProjectHelper.ANT_CORE_URI)) {
1.17 +13 -0
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.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- MacroInstance.java 19 Jan 2004 09:53:29 -0000 1.16
+++ MacroInstance.java 22 Jan 2004 16:33:16 -0000 1.17
@@ -88,6 +88,7 @@
private Map nsElements = null;
private Map presentElements = new HashMap();
private Hashtable localProperties = new Hashtable();
+ private String text = "";
/**
* Called from MacroDef.MyAntTypeDefinition#create()
@@ -246,6 +247,14 @@
return ret.toString();
}
+ /**
+ * Set the text contents for the macro.
+ * @param text the text to be added to the macro.
+ */
+ public void addText(String text) {
+ this.text = text;
+ }
+
private UnknownElement copy(UnknownElement ue) {
UnknownElement ret = new UnknownElement(ue.getTag());
ret.setNamespace(ue.getNamespace());
@@ -331,6 +340,10 @@
if (copyKeys.contains("id")) {
copyKeys.remove("id");
}
+ if (macroDef.getTextName() != null) {
+ localProperties.put(macroDef.getTextName(), text);
+ }
+
if (copyKeys.size() != 0) {
throw new BuildException(
"Unknown attribute" + (copyKeys.size() > 1 ? "s " : " ")
1.11 +27 -0 ant/docs/manual/CoreTasks/macrodef.html
Index: macrodef.html
===================================================================
RCS file: /home/cvs/ant/docs/manual/CoreTasks/macrodef.html,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- macrodef.html 19 Jan 2004 09:51:01 -0000 1.10
+++ macrodef.html 22 Jan 2004 16:33:16 -0000 1.11
@@ -43,6 +43,16 @@
</td>
<td valign="top" align="center">No</td>
</tr>
+ <tr>
+ <td valign="top">textname</td>
+ <td valign="top">
+ The textname attribute value becomes a macrodef
+ attribute that
+ gets set to the value of the text contents of the macro.
+ <em>since ant 1.6.1</em>
+ </td>
+ <td valign="top" align="center">No</td>
+ </tr>
</table>
<h3>Parameters specified as nested elements</h3>
<h4>attribute</h4>
@@ -88,6 +98,7 @@
<td valign="top">description</td>
<td valign="top">
This contains a description of the attribute.
+ <em>since ant 1.6.1</em>
</td>
<td valign="top" align="center">No</td>
</tr>
@@ -127,6 +138,7 @@
<td valign="top">
This contains a description
informing the user what the contents of the element are expected
to be.
+ <em>since ant 1.6.1</em>
</td>
<td valign="top" align="center">No</td>
</tr>
@@ -196,6 +208,21 @@
<linker refid="linker-libs"/>
</cc-elements>
</call-cc>
+</pre>
+ </blockquote>
+ <p>
+ The following shows the use of the <code>textname</code> attribute.
+ </p>
+ <blockquote>
+<pre class="code">
+<macrodef name="echotest" textname="text">
+ <sequential>
+ <echo>@{text}</echo>
+ </sequential>
+</macrodef>
+<echotest>
+ Hello world
+</echotest>
</pre>
</blockquote>
<hr>
1.8 +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.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- macrodef.xml 19 Jan 2004 09:51:02 -0000 1.7
+++ macrodef.xml 22 Jan 2004 16:33:16 -0000 1.8
@@ -101,4 +101,24 @@
</MYELEMENT>
</ignore>
</target>
+
+ <target name="textname">
+ <macrodef name="echotest" textname="text">
+ <sequential>
+ <echo>@{text}</echo>
+ </sequential>
+ </macrodef>
+ <echotest>
+ Hello world
+ </echotest>
+ </target>
+
+ <target name="duplicatetextname">
+ <macrodef name="echotest" textname="text">
+ <attribute name="text"/>
+ <sequential>
+ <echo>@{text}</echo>
+ </sequential>
+ </macrodef>
+ </target>
</project>
1.9 +11 -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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- MacroDefTest.java 19 Jan 2004 09:53:29 -0000 1.8
+++ MacroDefTest.java 22 Jan 2004 16:33:16 -0000 1.9
@@ -115,5 +115,16 @@
"ignore-element-case",
"nested elementnested element");
}
+
+ public void testTextName() {
+ expectLogContaining(
+ "textname", "Hello world");
+ }
+
+ public void testDuplicateTextName() {
+ expectBuildException(
+ "duplicatetextname",
+ "the attribute text has already been specified");
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]