Date: 2004-05-12T13:52:21
Editor: 24.173.157.149 <>
Wiki: Ant Wiki
Page: AntOddities
URL: http://wiki.apache.org/ant/AntOddities
Macrodef needs to use @{} variables instead of ${} for the attribute
references.
Change Log:
------------------------------------------------------------------------------
@@ -78,48 +78,48 @@
== Writing a "Task" for getting the dependency list for a target ==
That was the question I was asked recently on
[http://jguru.com/forums/view.jsp?EID=1122213 jGuru]. That was a nice question
:-) The final result is
-{{{ <macrodef name="dep">
- <attribute name="root"/>
- <attribute name="file" default="${root}.dep"/>
- <sequential>
- <script language="javascript"> <![CDATA[
- // attribute expansion from macrodef (script can�t reach the
values)
- root = "${root}";
- filename = "${file}";
-
- // for collecting the informations
- lineSep = project.getProperty("line.separator");
- list = new java.lang.StringBuffer();
- file = new java.io.File(filename);
-
- // get all targets of the current project
- targets = project.getTargets();
-
- // get the dependencies - including not executing targets
- sorted = project.topoSort(root, targets);
-
- // create the list and break if we have "executed" our root target
- // this code is adapted from Project.executeTarget(String)
- for(it=sorted.iterator(); it.hasNext();) {
- curTarget = it.next();
- list.append(curTarget).append(lineSep);
- if (curTarget.getName().equals(root)) {
- break;
- }
- }
-
- // create the file
- echo = project.createTask("echo");
- echo.setMessage(list.toString());
- echo.setFile(file);
- echo.perform();
- ]]></script>
- </sequential>
- </macrodef>
-
- <target name="dep">
- <dep root="build"/>
- <dep root="dist-lite" file="dist_lite.txt"/>
+{{{ <macrodef name="dep">
+ <attribute name="root"/>
+ <attribute name="file" default="@{root}.dep"/>
+ <sequential>
+ <script language="javascript"> <![CDATA[
+ // attribute expansion from macrodef (script can not reach the
values)
+ root = "@{root}";
+ filename = "@{file}";
+
+ // for collecting the informations
+ lineSep = project.getProperty("line.separator");
+ list = new java.lang.StringBuffer();
+ file = new java.io.File(filename);
+
+ // get all targets of the current project
+ targets = project.getTargets();
+
+ // get the dependencies - including not executing targets
+ sorted = project.topoSort(root, targets);
+
+ // create the list and break if we have "executed" our root target
+ // this code is adapted from Project.executeTarget(String)
+ for(it=sorted.iterator(); it.hasNext();) {
+ curTarget = it.next();
+ list.append(curTarget).append(lineSep);
+ if (curTarget.getName().equals(root)) {
+ break;
+ }
+ }
+
+ // create the file
+ echo = project.createTask("echo");
+ echo.setMessage(list.toString());
+ echo.setFile(file);
+ echo.perform();
+ ]]></script>
+ </sequential>
+ </macrodef>
+
+ <target name="dep">
+ <dep root="build"/>
+ <dep root="dist-lite" file="dist_lite.txt"/>
</target> }}}
''Jan Mat�rne''
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]