Browse Source

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
master
Stefan Bodewig 17 years ago
parent
commit
94da71c764
3 changed files with 35 additions and 9 deletions
  1. +3
    -0
      WHATSNEW
  2. +10
    -0
      src/main/org/apache/tools/ant/Diagnostics.java
  3. +22
    -9
      src/main/org/apache/tools/ant/Main.java

+ 3
- 0
WHATSNEW View File

@@ -180,6 +180,9 @@ Fixed bugs:
crashed or a timeout occured in <junit>.
Bugzilla Report 37312.

* ant -v -version would print the version information twice.
Bugzilla Report 45695.

Other changes:
--------------



+ 10
- 0
src/main/org/apache/tools/ant/Diagnostics.java View File

@@ -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");


+ 22
- 9
src/main/org/apache/tools/ant/Main.java View File

@@ -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());
}



Loading…
Cancel
Save