From 94da71c7641a9cdccc8e4b5f0bd814fb75a70b7c Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 27 Aug 2008 13:24:42 +0000 Subject: [PATCH] change command line parser so that version is only printed once - and version as well as diagnostics methods know the current loglevel. The former is PR 45695, the later useful for 45692. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@689477 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 3 ++ .../org/apache/tools/ant/Diagnostics.java | 10 ++++++ src/main/org/apache/tools/ant/Main.java | 31 +++++++++++++------ 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index faeff3b50..51440bda7 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -180,6 +180,9 @@ Fixed bugs: crashed or a timeout occured in . Bugzilla Report 37312. + * ant -v -version would print the version information twice. + Bugzilla Report 45695. + Other changes: -------------- diff --git a/src/main/org/apache/tools/ant/Diagnostics.java b/src/main/org/apache/tools/ant/Diagnostics.java index 4309731e6..aa7ff3931 100644 --- a/src/main/org/apache/tools/ant/Diagnostics.java +++ b/src/main/org/apache/tools/ant/Diagnostics.java @@ -261,6 +261,16 @@ public final class Diagnostics { * @param out the stream to print the report to. */ public static void doReport(PrintStream out) { + doReport(out, Project.MSG_INFO); + } + + /** + * Print a report to the given stream. + * @param out the stream to print the report to. + * @param logLevel denotes the level of detail requested as one of + * Project's MSG_* constants. + */ + public static void doReport(PrintStream out, int logLevel) { out.println("------- Ant diagnostics report -------"); out.println(Main.getAntVersion()); header(out, "Implementation Version"); diff --git a/src/main/org/apache/tools/ant/Main.java b/src/main/org/apache/tools/ant/Main.java index 00fb063b3..5a53f4052 100644 --- a/src/main/org/apache/tools/ant/Main.java +++ b/src/main/org/apache/tools/ant/Main.java @@ -305,25 +305,24 @@ public class Main implements AntMain { // cycle through given args + boolean justPrintUsage = false; + boolean justPrintVersion = false; + boolean justPrintDiagnostics = false; + for (int i = 0; i < args.length; i++) { String arg = args[i]; if (arg.equals("-help") || arg.equals("-h")) { - printUsage(); - return; + justPrintUsage = true; } else if (arg.equals("-version")) { - printVersion(); - return; + justPrintVersion = true; } else if (arg.equals("-diagnostics")) { - Diagnostics.doReport(System.out); - return; + justPrintDiagnostics = true; } else if (arg.equals("-quiet") || arg.equals("-q")) { msgOutputLevel = Project.MSG_WARN; } else if (arg.equals("-verbose") || arg.equals("-v")) { - printVersion(); msgOutputLevel = Project.MSG_VERBOSE; } else if (arg.equals("-debug") || arg.equals("-d")) { - printVersion(); msgOutputLevel = Project.MSG_DEBUG; } else if (arg.equals("-noinput")) { allowInput = false; @@ -395,6 +394,20 @@ public class Main implements AntMain { } } + if (msgOutputLevel >= Project.MSG_VERBOSE || justPrintVersion) { + printVersion(msgOutputLevel); + } + + if (justPrintUsage || justPrintVersion || justPrintDiagnostics) { + if (justPrintUsage) { + printUsage(); + } + if (justPrintDiagnostics) { + Diagnostics.doReport(System.out, msgOutputLevel); + } + return; + } + // if buildFile was not specified on the command line, if (buildFile == null) { // but -find then search for it @@ -919,7 +932,7 @@ public class Main implements AntMain { * * @exception BuildException if the version information is unavailable */ - private static void printVersion() throws BuildException { + private static void printVersion(int logLevel) throws BuildException { System.out.println(getAntVersion()); }