diff --git a/docs/manual/CoreTasks/macrodef.html b/docs/manual/CoreTasks/macrodef.html index 0fb7e384b..38820023e 100644 --- a/docs/manual/CoreTasks/macrodef.html +++ b/docs/manual/CoreTasks/macrodef.html @@ -43,6 +43,16 @@
+ The following shows the use of the textname
attribute.
+
++<macrodef name="echotest" textname="text"> + <sequential> + <echo>@{text}</echo> + </sequential> +</macrodef> +<echotest> + Hello world +</echotest>
null
if
+ * @return the description of the element, or null
if
* no description is available.
+ * @since ant 1.6.1
*/
public String getDescription() {
return description;
@@ -383,7 +410,7 @@ public class MacroDef extends AntlibDefinition {
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 @@ public class MacroDef extends AntlibDefinition {
/**
* @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 null
if
+ * @return the description of the element, or null
if
* no description is available.
+ * @since ant 1.6.1
*/
public String getDescription() {
return description;
@@ -490,6 +519,15 @@ public class MacroDef extends AntlibDefinition {
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)) {
if (!(other.getURI() == null || other.getURI().equals("")
diff --git a/src/main/org/apache/tools/ant/taskdefs/MacroInstance.java b/src/main/org/apache/tools/ant/taskdefs/MacroInstance.java
index b37762380..d02dcff02 100644
--- a/src/main/org/apache/tools/ant/taskdefs/MacroInstance.java
+++ b/src/main/org/apache/tools/ant/taskdefs/MacroInstance.java
@@ -88,6 +88,7 @@ public class MacroInstance extends Task implements DynamicConfigurator {
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 @@ public class MacroInstance extends Task implements DynamicConfigurator {
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 @@ public class MacroInstance extends Task implements DynamicConfigurator {
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 " : " ")
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/MacroDefTest.java b/src/testcases/org/apache/tools/ant/taskdefs/MacroDefTest.java
index edebf6c9e..a7290704e 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/MacroDefTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/MacroDefTest.java
@@ -115,5 +115,16 @@ public class MacroDefTest extends BuildFileTest {
"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");
+ }
}