git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275948 13f79535-47bb-0310-9956-ffa450edef68master
@@ -43,6 +43,16 @@ | |||||
</td> | </td> | ||||
<td valign="top" align="center">No</td> | <td valign="top" align="center">No</td> | ||||
</tr> | </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> | </table> | ||||
<h3>Parameters specified as nested elements</h3> | <h3>Parameters specified as nested elements</h3> | ||||
<h4>attribute</h4> | <h4>attribute</h4> | ||||
@@ -88,6 +98,7 @@ | |||||
<td valign="top">description</td> | <td valign="top">description</td> | ||||
<td valign="top"> | <td valign="top"> | ||||
This contains a description of the attribute. | This contains a description of the attribute. | ||||
<em>since ant 1.6.1</em> | |||||
</td> | </td> | ||||
<td valign="top" align="center">No</td> | <td valign="top" align="center">No</td> | ||||
</tr> | </tr> | ||||
@@ -127,6 +138,7 @@ | |||||
<td valign="top"> | <td valign="top"> | ||||
This contains a description | This contains a description | ||||
informing the user what the contents of the element are expected to be. | informing the user what the contents of the element are expected to be. | ||||
<em>since ant 1.6.1</em> | |||||
</td> | </td> | ||||
<td valign="top" align="center">No</td> | <td valign="top" align="center">No</td> | ||||
</tr> | </tr> | ||||
@@ -196,6 +208,21 @@ | |||||
<linker refid="linker-libs"/> | <linker refid="linker-libs"/> | ||||
</cc-elements> | </cc-elements> | ||||
</call-cc> | </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> | </pre> | ||||
</blockquote> | </blockquote> | ||||
<hr> | <hr> | ||||
@@ -101,4 +101,24 @@ | |||||
</MYELEMENT> | </MYELEMENT> | ||||
</ignore> | </ignore> | ||||
</target> | </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> | </project> |
@@ -81,6 +81,7 @@ public class MacroDef extends AntlibDefinition { | |||||
private String name; | private String name; | ||||
private List attributes = new ArrayList(); | private List attributes = new ArrayList(); | ||||
private Map elements = new HashMap(); | private Map elements = new HashMap(); | ||||
private String textName = null; | |||||
/** | /** | ||||
* Name of the definition | * Name of the definition | ||||
@@ -90,6 +91,25 @@ public class MacroDef extends AntlibDefinition { | |||||
this.name = name; | this.name = name; | ||||
} | } | ||||
/** | |||||
* 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. | * This is the sequential nested element of the macrodef. | ||||
* | * | ||||
@@ -222,6 +242,11 @@ public class MacroDef extends AntlibDefinition { | |||||
throw new BuildException( | throw new BuildException( | ||||
"the attribute nested element needed a \"name\" attribute"); | "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) { | for (int i = 0; i < attributes.size(); ++i) { | ||||
if (((Attribute) attributes.get(i)).getName().equals( | if (((Attribute) attributes.get(i)).getName().equals( | ||||
attribute.getName())) { | attribute.getName())) { | ||||
@@ -324,14 +349,16 @@ public class MacroDef extends AntlibDefinition { | |||||
/** | /** | ||||
* @param desc Description of the element. | * @param desc Description of the element. | ||||
* @since ant 1.6.1 | |||||
*/ | */ | ||||
public void setDescription(String desc) { | public void setDescription(String desc) { | ||||
description = 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. | * no description is available. | ||||
* @since ant 1.6.1 | |||||
*/ | */ | ||||
public String getDescription() { | public String getDescription() { | ||||
return description; | return description; | ||||
@@ -383,7 +410,7 @@ public class MacroDef extends AntlibDefinition { | |||||
public static class TemplateElement { | public static class TemplateElement { | ||||
private String name; | private String name; | ||||
private boolean optional = false; | private boolean optional = false; | ||||
private String description; | |||||
private String description; | |||||
/** | /** | ||||
* The name of the element. | * The name of the element. | ||||
@@ -424,14 +451,16 @@ public class MacroDef extends AntlibDefinition { | |||||
/** | /** | ||||
* @param desc Description of the element. | * @param desc Description of the element. | ||||
* @since ant 1.6.1 | |||||
*/ | */ | ||||
public void setDescription(String desc) { | public void setDescription(String desc) { | ||||
description = 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. | * no description is available. | ||||
* @since ant 1.6.1 | |||||
*/ | */ | ||||
public String getDescription() { | public String getDescription() { | ||||
return description; | return description; | ||||
@@ -490,6 +519,15 @@ public class MacroDef extends AntlibDefinition { | |||||
if (!name.equals(other.name)) { | if (!name.equals(other.name)) { | ||||
return false; | return false; | ||||
} | } | ||||
if (textName == null) { | |||||
if (other.textName != null) { | |||||
return false; | |||||
} | |||||
} else { | |||||
if (!textName.equals(other.textName)) { | |||||
return false; | |||||
} | |||||
} | |||||
if (getURI() == null || getURI().equals("") | if (getURI() == null || getURI().equals("") | ||||
|| getURI().equals(ProjectHelper.ANT_CORE_URI)) { | || getURI().equals(ProjectHelper.ANT_CORE_URI)) { | ||||
if (!(other.getURI() == null || other.getURI().equals("") | if (!(other.getURI() == null || other.getURI().equals("") | ||||
@@ -88,6 +88,7 @@ public class MacroInstance extends Task implements DynamicConfigurator { | |||||
private Map nsElements = null; | private Map nsElements = null; | ||||
private Map presentElements = new HashMap(); | private Map presentElements = new HashMap(); | ||||
private Hashtable localProperties = new Hashtable(); | private Hashtable localProperties = new Hashtable(); | ||||
private String text = ""; | |||||
/** | /** | ||||
* Called from MacroDef.MyAntTypeDefinition#create() | * Called from MacroDef.MyAntTypeDefinition#create() | ||||
@@ -246,6 +247,14 @@ public class MacroInstance extends Task implements DynamicConfigurator { | |||||
return ret.toString(); | 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) { | private UnknownElement copy(UnknownElement ue) { | ||||
UnknownElement ret = new UnknownElement(ue.getTag()); | UnknownElement ret = new UnknownElement(ue.getTag()); | ||||
ret.setNamespace(ue.getNamespace()); | ret.setNamespace(ue.getNamespace()); | ||||
@@ -331,6 +340,10 @@ public class MacroInstance extends Task implements DynamicConfigurator { | |||||
if (copyKeys.contains("id")) { | if (copyKeys.contains("id")) { | ||||
copyKeys.remove("id"); | copyKeys.remove("id"); | ||||
} | } | ||||
if (macroDef.getTextName() != null) { | |||||
localProperties.put(macroDef.getTextName(), text); | |||||
} | |||||
if (copyKeys.size() != 0) { | if (copyKeys.size() != 0) { | ||||
throw new BuildException( | throw new BuildException( | ||||
"Unknown attribute" + (copyKeys.size() > 1 ? "s " : " ") | "Unknown attribute" + (copyKeys.size() > 1 ? "s " : " ") | ||||
@@ -115,5 +115,16 @@ public class MacroDefTest extends BuildFileTest { | |||||
"ignore-element-case", | "ignore-element-case", | ||||
"nested elementnested element"); | "nested elementnested element"); | ||||
} | } | ||||
public void testTextName() { | |||||
expectLogContaining( | |||||
"textname", "Hello world"); | |||||
} | |||||
public void testDuplicateTextName() { | |||||
expectBuildException( | |||||
"duplicatetextname", | |||||
"the attribute text has already been specified"); | |||||
} | |||||
} | } | ||||