peterreilly 2003/12/03 05:22:30
Modified: . Tag: ANT_16_BRANCH build.xml
docs/manual/CoreTasks Tag: ANT_16_BRANCH macrodef.html
docs/manual/CoreTypes Tag: ANT_16_BRANCH antlib.html
src/etc/testcases/taskdefs Tag: ANT_16_BRANCH macrodef.xml
src/main/org/apache/tools/ant/taskdefs Tag: ANT_16_BRANCH
MacroDef.java MacroInstance.java
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.392.2.11 +2 -2 ant/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/ant/build.xml,v
retrieving revision 1.392.2.10
retrieving revision 1.392.2.11
diff -u -r1.392.2.10 -r1.392.2.11
--- build.xml 3 Dec 2003 10:37:36 -0000 1.392.2.10
+++ build.xml 3 Dec 2003 13:22:29 -0000 1.392.2.11
@@ -816,10 +816,10 @@
<macrodef name="optional-jar">
<attribute name="dep"/>
<sequential>
- <jar destfile="${build.lib}/${optional.jars.prefix}-${dep}.jar"
+ <jar destfile="${build.lib}/[EMAIL PROTECTED]"
basedir="${build.classes}"
manifest="${manifest.tmp}">
- <selector refid="needs.${dep}"/>
+ <selector refid="[EMAIL PROTECTED]"/>
</jar>
</sequential>
</macrodef>
No revision
No revision
1.2.2.5 +22 -13 ant/docs/manual/CoreTasks/macrodef.html
Index: macrodef.html
===================================================================
RCS file: /home/cvs/ant/docs/manual/CoreTasks/macrodef.html,v
retrieving revision 1.2.2.4
retrieving revision 1.2.2.5
diff -u -r1.2.2.4 -r1.2.2.5
--- macrodef.html 31 Oct 2003 09:56:42 -0000 1.2.2.4
+++ macrodef.html 3 Dec 2003 13:22:30 -0000 1.2.2.5
@@ -4,6 +4,11 @@
<meta http-equiv="Content-Language" content="en-us"></meta>
<title>MacroDef Task</title>
<link rel="stylesheet" type="text/css" href="../stylesheets/antmanual.css">
+ <style type="text/css">
+ <!--
+ .code { background: #EFEFEF; margin-top: }
+ -->
+ </style>
</head>
<body>
@@ -50,8 +55,12 @@
</p>
<p>
This attribute is placed in the body of the templated
- task using the ant property notation - ${attribute name}.
- Note that is not an actual ant property.
+ task using a notation similar to the ant property notation
+ - @{attribute name}. (May be remembered as "put the substitution
+ AT this location").
+ The escape sequence @@{x} is used to allow @{x} to be
+ placed in the text without substitution of x.
+ This corresponds to the $${x} escape sequence for properties
</p>
<h3>Parameters</h3>
<table border="1" cellpadding="2" cellspacing="0">
@@ -108,12 +117,12 @@
runs it.
</p>
<blockquote>
- <pre>
+<pre class=code>
<macrodef name="testing">
<attribute name="v" default="NOT SET"/>
<element name="some-tasks" optional="yes"/>
<sequential>
- <echo>v is ${v}</echo>
+ <echo>v is @{v}</echo>
<some-tasks/>
</sequential>
</macrodef>
@@ -123,7 +132,7 @@
<echo>this is a test</echo>
</some-tasks>
</testing>
- </pre>
+</pre>
</blockquote>
<p>
The following fragment defines a task called <call-cc> which
@@ -133,29 +142,29 @@
<a href="http://ant-contrib.sourceforge.net/">ant-contrib</a> project.
</p>
<blockquote>
- <pre>
+<pre class="code">
<macrodef name="call-cc">
<attribute name="target"/>
<attribute name="link"/>
<attribute name="target.dir"/>
<element name="cc-elements"/>
<sequential>
- <mkdir dir="${obj.dir}/${target}"/>
- <mkdir dir="${target.dir}"/>
- <cc link="${link}" objdir="${obj.dir}/${target}"
- outfile="${target.dir}/${target}">
+ <mkdir dir="${obj.dir}/@{target}"/>
+ <mkdir dir="@{target.dir}"/>
+ <cc link="@{link}" objdir="${obj.dir}/@{target}"
+ outfile="@{target.dir}/@{target}">
<compiler refid="compiler.options"/>
<cc-elements/>
</cc>
</sequential>
</macrodef>
- </pre>
+</pre>
</blockquote>
<p>
This then can be used as follows:
</p>
<blockquote>
- <pre>
+<pre class="code">
<call-cc target="unittests" link="executable"
target.dir="${build.bin.dir}">
<cc-elements>
@@ -166,7 +175,7 @@
<linker refid="linker-libs"/>
</cc-elements>
</call-cc>
- </pre>
+</pre>
</blockquote>
<hr>
<p align="center">Copyright © 2003 Apache Software
No revision
No revision
1.3.2.5 +2 -2 ant/docs/manual/CoreTypes/antlib.html
Index: antlib.html
===================================================================
RCS file: /home/cvs/ant/docs/manual/CoreTypes/antlib.html,v
retrieving revision 1.3.2.4
retrieving revision 1.3.2.5
diff -u -r1.3.2.4 -r1.3.2.5
--- antlib.html 18 Nov 2003 11:29:06 -0000 1.3.2.4
+++ antlib.html 3 Dec 2003 13:22:30 -0000 1.3.2.5
@@ -90,7 +90,7 @@
<attribute name="dir"/>
<sequential>
<antcontrib:shellscript shell="bash"> <!-- HERE -->
- ls -Rl ${dir}
+ ls -Rl @{dir}
</antcontrib:shellscript>
</sequential>
</macrodef>
@@ -133,7 +133,7 @@
<element name="do"/>
<sequential>
<current:if>
- <current:isallowed test="${action}"/>
+ <current:isallowed test="@{action}"/>
<current:then>
<current:do/>
</current:then>
No revision
No revision
1.2.2.3 +14 -4 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.2
retrieving revision 1.2.2.3
diff -u -r1.2.2.2 -r1.2.2.3
--- macrodef.xml 18 Nov 2003 12:09:31 -0000 1.2.2.2
+++ macrodef.xml 3 Dec 2003 13:22:30 -0000 1.2.2.3
@@ -4,7 +4,7 @@
<macrodef name="my.echo">
<attribute name="text"/>
<sequential>
- <echo message="${text}"/>
+ <echo message="@{text}"/>
</sequential>
</macrodef>
<my.echo text="Hello World"/>
@@ -14,7 +14,7 @@
<macrodef name="my.echo">
<attribute name="text"/>
<sequential>
- <echo>${text}</echo>
+ <echo>@{text}</echo>
</sequential>
</macrodef>
<my.echo text="Inner Text"/>
@@ -25,7 +25,7 @@
<attribute name="text"/>
<attribute name="text"/>
<sequential>
- <echo>${text}</echo>
+ <echo>@{text}</echo>
</sequential>
</macrodef>
</target>
@@ -44,7 +44,7 @@
<macrodef name="echo" uri="abc">
<attribute name="text"/>
<sequential>
- <echo message="${text}"/>
+ <echo message="@{text}"/>
</sequential>
</macrodef>
<x:echo xmlns:x="abc" text="Hello World"/>
@@ -65,4 +65,14 @@
</nested>
</target>
+ <target name="double">
+ <macrodef name="double">
+ <attribute name="prop"/>
+ <sequential>
+ <echo>@@{prop} is '@{prop}', value of [EMAIL PROTECTED] is '[EMAIL
PROTECTED]'</echo>
+ </sequential>
+ </macrodef>
+ <property name="property" value="A property value"/>
+ <double prop="property"/>
+ </target>
</project>
No revision
No revision
1.7.2.7 +44 -8 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.6
retrieving revision 1.7.2.7
diff -u -r1.7.2.6 -r1.7.2.7
--- MacroDef.java 18 Nov 2003 12:09:31 -0000 1.7.2.6
+++ MacroDef.java 3 Dec 2003 13:22:30 -0000 1.7.2.7
@@ -78,8 +78,8 @@
public class MacroDef extends AntlibDefinition {
private NestedSequential nestedSequential;
private String name;
- private Map attributes = new HashMap();
- private Map elements = new HashMap();
+ private List attributes = new ArrayList();
+ private Map elements = new HashMap();
/**
* Name of the definition
@@ -170,7 +170,7 @@
/**
* @return the nested Attributes
*/
- public Map getAttributes() {
+ public List getAttributes() {
return attributes;
}
@@ -221,12 +221,15 @@
throw new BuildException(
"the attribute nested element needed a \"name\" attribute");
}
- if (attributes.get(attribute.getName()) != null) {
- throw new BuildException(
- "the attribute " + attribute.getName()
- + " has already been specified");
+ for (int i = 0; i < attributes.size(); ++i) {
+ if (((Attribute) attributes.get(i)).getName().equals(
+ attribute.getName())) {
+ throw new BuildException(
+ "the attribute " + attribute.getName()
+ + " has already been specified");
+ }
}
- attributes.put(attribute.getName(), attribute);
+ attributes.add(attribute);
}
/**
@@ -347,6 +350,13 @@
}
return true;
}
+
+ /**
+ * @return a hash code value for this object.
+ */
+ public int hashCode() {
+ return objectHashCode(defaultValue) + objectHashCode(name);
+ }
}
/**
@@ -416,6 +426,13 @@
}
return optional == other.optional;
}
+
+ /**
+ * @return a hash code value for this object.
+ */
+ public int hashCode() {
+ return objectHashCode(name) + (optional ? 1 : 0);
+ }
}
/**
@@ -464,6 +481,17 @@
}
/**
+ * @return a hash code value for this object.
+ */
+ public int hashCode() {
+ return objectHashCode(name)
+ + objectHashCode(getURI())
+ + objectHashCode(nestedSequential)
+ + objectHashCode(attributes)
+ + objectHashCode(elements);
+ }
+
+ /**
* extends AntTypeDefinition, on create
* of the object, the template macro definition
* is given.
@@ -524,6 +552,14 @@
}
MyAntTypeDefinition otherDef = (MyAntTypeDefinition) other;
return macroDef.equals(otherDef.macroDef);
+ }
+ }
+
+ private static int objectHashCode(Object o) {
+ if (o == null) {
+ return 0;
+ } else {
+ return o.hashCode();
}
}
}
1.5.2.7 +40 -18
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.6
retrieving revision 1.5.2.7
diff -u -r1.5.2.6 -r1.5.2.7
--- MacroInstance.java 18 Nov 2003 12:09:31 -0000 1.5.2.6
+++ MacroInstance.java 3 Dec 2003 13:22:30 -0000 1.5.2.7
@@ -87,7 +87,6 @@
private Map nsElements = null;
private Map presentElements = new HashMap();
private Hashtable localProperties = new Hashtable();
-
/**
* Called from MacroDef.MyAntTypeDefinition#create()
@@ -142,7 +141,7 @@
}
return nsElements;
}
-
+
/**
* Embedded element in macro instance
*/
@@ -166,11 +165,15 @@
}
}
- private static final int STATE_NORMAL = 0;
+ private static final int STATE_NORMAL = 0;
private static final int STATE_EXPECT_BRACKET = 1;
- private static final int STATE_EXPECT_NAME = 2;
-
+ private static final int STATE_EXPECT_NAME = 2;
+ private static final int STATE_EXPECT_EXCAPE = 3;
+
private String macroSubs(String s, Map macroMapping) {
+ if (s == null) {
+ return null;
+ }
StringBuffer ret = new StringBuffer();
StringBuffer macroName = null;
boolean inMacro = false;
@@ -179,48 +182,67 @@
char ch = s.charAt(i);
switch (state) {
case STATE_NORMAL:
- if (ch == '$') {
- state = 1;
+ if (ch == '@') {
+ state = STATE_EXPECT_BRACKET;
} else {
ret.append(ch);
- }
+ }
break;
case STATE_EXPECT_BRACKET:
if (ch == '{') {
- state = 2;
+ state = STATE_EXPECT_NAME;
macroName = new StringBuffer();
+ } else if (ch == '@') {
+ state = STATE_EXPECT_EXCAPE;
} else {
- state = 0;
- ret.append('$');
+ state = STATE_NORMAL;
+ ret.append('@');
ret.append(ch);
}
break;
case STATE_EXPECT_NAME:
if (ch == '}') {
- state = 0;
+ state = STATE_NORMAL;
String name = macroName.toString();
String value = (String) macroMapping.get(name);
if (value == null) {
- ret.append("${" + name + "}");
+ ret.append("@{" + name + "}");
} else {
ret.append(value);
}
macroName = null;
} else {
- macroName.append(s.charAt(i));
+ macroName.append(ch);
+ }
+ break;
+ case STATE_EXPECT_EXCAPE:
+ state = STATE_NORMAL;
+ if (ch == '{') {
+ ret.append("@");
+ } else {
+ ret.append("@@");
}
+ ret.append(ch);
+ break;
+ default:
+ break;
}
}
switch (state) {
case STATE_NORMAL:
break;
case STATE_EXPECT_BRACKET:
- ret.append('$');
+ ret.append('@');
break;
case STATE_EXPECT_NAME:
- ret.append("${");
+ ret.append("@{");
ret.append(macroName.toString());
break;
+ case STATE_EXPECT_EXCAPE:
+ ret.append("@@");
+ break;
+ default:
+ break;
}
return ret.toString();
@@ -294,12 +316,12 @@
public void execute() {
localProperties = new Hashtable();
Set copyKeys = new HashSet(map.keySet());
- for (Iterator i = macroDef.getAttributes().values().iterator();
- i.hasNext();) {
+ for (Iterator i = macroDef.getAttributes().iterator(); i.hasNext();)
{
MacroDef.Attribute attribute = (MacroDef.Attribute) i.next();
String value = (String) map.get(attribute.getName());
if (value == null) {
value = attribute.getDefault();
+ value = macroSubs(value, localProperties);
}
if (value == null) {
throw new BuildException(
No revision
No revision
1.2.2.3 +5 -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.2
retrieving revision 1.2.2.3
diff -u -r1.2.2.2 -r1.2.2.3
--- MacroDefTest.java 18 Nov 2003 12:09:32 -0000 1.2.2.2
+++ MacroDefTest.java 3 Dec 2003 13:22:30 -0000 1.2.2.3
@@ -98,5 +98,10 @@
expectLog("nested", "A nested element");
}
+ public void testDouble() {
+ expectLog(
+ "double",
+ "@{prop} is 'property', value of ${property} is 'A property
value'");
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]