Reposted with my suggestion in a diff file. Also, see comments below.

> -----Original Message-----
> From: Christopher Elkins [mailto:[EMAIL PROTECTED]
> Sent: zondag 13 augustus 2000 22:59
> To: [EMAIL PROTECTED]
> Subject: Re: Suggestion for new commandline switch -targets
>
>
> > Hi,
> >
> > In the attached version of Main.java there are some simple modifications
> > which make ant recognize a -targets option.
> >
> > This will print out a list of all the targets available in the selected
> > build-file. It is meant as some sort of documentation on what
> the build-file
> > can do. Execution is suppressed.
> >
> > Do you guys like this suggestion, and if so, how do I go about
> incorporating
> > it in ant?
> >
> First, you should submit your patch in diff form
> <http://jakarta.apache.org/guidelines/source.html>. It makes it
> much easier to
> evaluate.
>
> Second, I think this would be a useful addition. Many ant-using
> projects create
> their own targets (e.g., "usage") to provide similar functionality as your
> patch. Standardizing such behavior would be a very good thing.
>
> However, not all targets in a build file are suitable and/or relevant for
> calling from the command-line. For example, calling the "prepare"
> target in
> jakarta-ant/build.xml from the command-line would have limited utility.
> Therefore, it might be useful to add an attribute to the <target> tag that
> allowed one to specify whether that target should be output in
> Main.printTargets().

Or perhaps a 'private' attribute, which can make a target invisible from the
outside and only visible to 'depends' clauses.
Another optional attribute could be 'description', to be printed as part of
the target list.
Let me know what you think of this,

>
> > Regards,
> > Marcel Schutte
> >
>
> --
> Christopher Elkins
>
>
Regards,
Marcel Schutte
--- R:\jakarta-ant\jakarta-ant\src\main\org\apache\tools\ant\Main.java  Sun Jul 
16 01:39:58 2000
+++ R:\jakarta-ant\src\main\org\apache\tools\ant\Main.java      Sun Aug 13 
19:16:16 2000
@@ -95,6 +95,13 @@
      */
     private boolean readyToRun = false;
 
+//MS:begin
+    /**
+     * Indicates we should only parse and display the current buildfile's 
targets
+     */
+    private boolean parseNdisplayTargets = false;
+//MS:end
+
     /**
      * Command line entry point. This method kicks off the building
      * of a project object and executes a build using either a given
@@ -190,6 +197,11 @@
                     value = args[++i];
 
                 definedProps.put(name, value);
+//MS:begin
+            } else if (arg.equals("-targets")) {
+                // set the flag to display the targets and quit
+                parseNdisplayTargets = true;
+//MS:end
             } else if (arg.startsWith("-")) {
                 // we don't have any more args to recognize!
                 String msg = "Unknown arg: " + arg;
@@ -244,7 +256,6 @@
         try {
             addBuildListeners(project);
             project.fireBuildStarted();
-            
             project.init();
 
             // set user-define properties
@@ -274,9 +285,14 @@
             if (targets.size() == 0) {
                 targets.addElement(project.getDefaultTarget());
             }
-
-            // actually do some work
-            project.executeTargets(targets);
+//MS:begin
+            if (parseNdisplayTargets) {
+                printTargets(project);
+            } else {
+                // actually do some work
+                project.executeTargets(targets);
+            }
+//MS:end
         }
         catch(RuntimeException exc) {
             error = exc;
@@ -332,6 +348,9 @@
         msg.append("  -listener <classname>  add an instance of class as a 
project listener" + lSep);
         msg.append("  -buildfile <file>      use given buildfile" + lSep);
         msg.append("  -D<property>=<value>   use value for given property" + 
lSep);
+//MS:begin
+        msg.append("  -targets               list the available targets" + 
lSep);
+//MS:end
         System.out.println(msg.toString());
     }
 
@@ -358,4 +377,20 @@
             System.err.println("Could not load the version information.");
         }
     }
+
+//MS:begin
+    /**
+     * Print out a list of all targest in the current buildfile
+     */
+    private static void printTargets(Project project) {
+        String lSep = System.getProperty("line.separator");
+        StringBuffer msg = new StringBuffer();
+        Enumeration ptargets = project.getTargets().keys();
+        msg.append("Targets: " + lSep);
+        while (ptargets.hasMoreElements()) {
+          msg.append(" -"+ptargets.nextElement()+lSep);
+        }
+        System.out.println(msg.toString());
+    }
+//MS:end
 }

Reply via email to