conor 00/08/22 08:38:33
Modified: src/main/org/apache/tools/ant Main.java ProjectHelper.java
Target.java
Log:
Print Projet help information
Submitted by: Marcel Schutte <[EMAIL PROTECTED]>
Revision Changes Path
1.16 +62 -3 jakarta-ant/src/main/org/apache/tools/ant/Main.java
Index: Main.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Main.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- Main.java 2000/08/14 12:30:32 1.15
+++ Main.java 2000/08/22 15:38:32 1.16
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999, 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -108,6 +108,11 @@
private boolean readyToRun = false;
/**
+ * Indicates we should only parse and display the project help
information
+ */
+ private boolean projectHelp = false;
+
+ /**
* Command line entry point. This method kicks off the building
* of a project object and executes a build using either a given
* target or the default target.
@@ -211,6 +216,9 @@
loggerClassname = args[++i];
} else if (arg.equals("-emacs")) {
emacsMode = true;
+ } else if (arg.equals("-projecthelp")) {
+ // set the flag to display the targets and quit
+ projectHelp = true;
} else if (arg.startsWith("-")) {
// we don't have any more args to recognize!
String msg = "Unknown arg: " + arg;
@@ -295,8 +303,12 @@
targets.addElement(project.getDefaultTarget());
}
- // actually do some work
- project.executeTargets(targets);
+ if (projectHelp) {
+ printTargets(project);
+ } else {
+ // actually do some work
+ project.executeTargets(targets);
+ }
}
catch(RuntimeException exc) {
error = exc;
@@ -369,6 +381,7 @@
msg.append("ant [options] [target]" + lSep);
msg.append("Options: " + lSep);
msg.append(" -help print this message" + lSep);
+ msg.append(" -projecthelp print project help information"
+ lSep);
msg.append(" -version print the version information
and exit" + lSep);
msg.append(" -quiet be extra quiet" + lSep);
msg.append(" -verbose be extra verbose" + lSep);
@@ -403,5 +416,51 @@
} catch (NullPointerException npe) {
System.err.println("Could not load the version information.");
}
+ }
+
+ /**
+ * Print out a list of all targets in the current buildfile
+ */
+ private static void printTargets(Project project) {
+ // find the target with the longest name and
+ // filter out the targets with no description
+ int maxLength = 0;
+ Enumeration ptargets = project.getTargets().elements();
+ String targetName;
+ String targetDescription;
+ Target currentTarget;
+ Vector names = new Vector();
+ Vector descriptions = new Vector();
+
+ while (ptargets.hasMoreElements()) {
+ currentTarget = (Target)ptargets.nextElement();
+ targetName = currentTarget.getName();
+ targetDescription = currentTarget.getDescription();
+ if (targetDescription == null) {
+ targetDescription = "";
+ }
+
+ names.addElement(targetName);
+ descriptions.addElement(targetDescription);
+ if (targetName.length() > maxLength) {
+ maxLength = targetName.length();
+ }
+ }
+
+ // now, start printing the targets and their descriptions
+ String lSep = System.getProperty("line.separator");
+ // got a bit annoyed that I couldn't find a pad function
+ String spaces = " ";
+ while (spaces.length()<maxLength) {
+ spaces += spaces;
+ }
+ StringBuffer msg = new StringBuffer();
+ msg.append("Targets: " + lSep);
+ for (int i=0; i<names.size(); i++) {
+ msg.append(" -"+names.elementAt(i));
+ msg.append(spaces.substring(0, maxLength -
((String)names.elementAt(i)).length() + 2));
+ msg.append(descriptions.elementAt(i)+lSep);
+ }
+ System.out.println(msg.toString());
}
}
1.24 +5 -1
jakarta-ant/src/main/org/apache/tools/ant/ProjectHelper.java
Index: ProjectHelper.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/ProjectHelper.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- ProjectHelper.java 2000/08/11 12:29:34 1.23
+++ ProjectHelper.java 2000/08/22 15:38:32 1.24
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999, 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -284,6 +284,7 @@
String ifCond = null;
String unlessCond = null;
String id = null;
+ String description = null;
for (int i = 0; i < attrs.getLength(); i++) {
String key = attrs.getName(i);
@@ -299,6 +300,8 @@
unlessCond = value;
} else if (key.equals("id")) {
id = value;
+ } else if (key.equals("description")) {
+ description = value;
} else {
throw new SAXParseException("Unexpected attribute \"" +
key + "\"", locator);
}
@@ -312,6 +315,7 @@
target.setName(name);
target.setIf(ifCond);
target.setUnless(unlessCond);
+ target.setDescription(description);
project.addTarget(name, target);
if (id != null && !id.equals(""))
1.9 +10 -1 jakarta-ant/src/main/org/apache/tools/ant/Target.java
Index: Target.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Target.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Target.java 2000/07/12 12:40:28 1.8
+++ Target.java 2000/08/22 15:38:33 1.9
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999, 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -70,6 +70,7 @@
private Vector dependencies = new Vector(2);
private Vector tasks = new Vector(5);
private Project project;
+ private String description = null;
public void setProject(Project project) {
this.project = project;
@@ -115,6 +116,14 @@
public void setUnless(String property) {
this.unlessCondition = (property == null) ? "" : property;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getDescription() {
+ return description;
}
public String toString() {