KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > antmod > tasks > Targets


1 package org.antmod.tasks;
2
3 import java.text.Collator JavaDoc;
4 import java.util.ArrayList JavaDoc;
5 import java.util.Collections JavaDoc;
6 import java.util.Iterator JavaDoc;
7 import java.util.List JavaDoc;
8 import java.util.Map JavaDoc;
9
10 import org.apache.tools.ant.BuildException;
11 import org.apache.tools.ant.Target;
12 import org.apache.tools.ant.taskdefs.Echo;
13
14 /**
15  * Targets extends the Echo task by printing information about the
16  * available targets (names and descriptions, if available) in the
17  * current project.
18  *
19  * @author Herko ter Horst
20  */

21 public class Targets extends Echo {
22     
23     public void execute()throws BuildException {
24         // messageBuf will contain the full message we want to display
25
StringBuffer JavaDoc messageBuf = new StringBuffer JavaDoc("\n");
26
27         // retrieve all targets from the project
28
Map JavaDoc targets = getProject().getTargets();
29         List JavaDoc targetNames = new ArrayList JavaDoc(targets.keySet());
30         Collections.sort(targetNames, Collator.getInstance());
31         
32         // append all targets and their descriptions to the message
33
Iterator JavaDoc it = targetNames.iterator();
34         while(it.hasNext()) {
35             String JavaDoc targetName = (String JavaDoc)it.next();
36             Target target = (Target)targets.get(targetName);
37             
38             messageBuf.append("\t");
39             messageBuf.append(targetName);
40             String JavaDoc description = target.getDescription();
41             if(description != null && description.length() > 0) {
42                 messageBuf.append(" - ");
43                 messageBuf.append(description);
44             }
45             messageBuf.append("\n");
46         }
47         
48         // add the prepared message to the text
49
addText(messageBuf.toString());
50         
51         // leave it up to the Echo task to display the text
52
super.execute();
53     }
54 }
55
Popular Tags