01: package org.antmod.tasks;
02:
03: import java.text.Collator;
04: import java.util.ArrayList;
05: import java.util.Collections;
06: import java.util.Iterator;
07: import java.util.List;
08: import java.util.Map;
09:
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 messageBuf = new StringBuffer("\n");
26:
27: // retrieve all targets from the project
28: Map targets = getProject().getTargets();
29: List targetNames = new ArrayList(targets.keySet());
30: Collections.sort(targetNames, Collator.getInstance());
31:
32: // append all targets and their descriptions to the message
33: Iterator it = targetNames.iterator();
34: while (it.hasNext()) {
35: String targetName = (String) it.next();
36: Target target = (Target) targets.get(targetName);
37:
38: messageBuf.append("\t");
39: messageBuf.append(targetName);
40: String 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: }
|