From ff3b4829ffd6f5705d3782449535bc2c2cc86eaa Mon Sep 17 00:00:00 2001
From: lutoff <lutoff@localhost>
Date: Tue, 15 May 2007 14:17:08 +0000
Subject: [PATCH] Fix for [Issue 1608]  setup and uninstall don't have -V/--version argument

---
 opends/src/quicksetup/org/opends/quicksetup/Launcher.java |   77 ++++++++++++++++++++++++++++++++++++--
 1 files changed, 73 insertions(+), 4 deletions(-)

diff --git a/opends/src/quicksetup/org/opends/quicksetup/Launcher.java b/opends/src/quicksetup/org/opends/quicksetup/Launcher.java
index 785847d..ca453f6 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/Launcher.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/Launcher.java
@@ -27,6 +27,14 @@
 
 package org.opends.quicksetup;
 
+import static org.opends.server.util.DynamicConstants.BUILD_ID;
+import static org.opends.server.util.DynamicConstants.FIX_IDS;
+import static org.opends.server.util.DynamicConstants.MAJOR_VERSION;
+import static org.opends.server.util.DynamicConstants.MINOR_VERSION;
+import static org.opends.server.util.DynamicConstants.POINT_VERSION;
+import static org.opends.server.util.DynamicConstants.PRODUCT_NAME;
+import static org.opends.server.util.DynamicConstants.VERSION_QUALIFIER;
+
 import org.opends.quicksetup.util.Utils;
 import org.opends.quicksetup.i18n.ResourceProvider;
 
@@ -82,11 +90,33 @@
   }
 
   /**
+   * Indicates whether or not the launcher should print a version
+   * statement based on the content of the arguments passed into
+   * the constructor.
+   * @return boolean where true indicates version should be printed
+   */
+  protected boolean shouldPrintVersion() {
+    boolean printVersion = false;
+    if ((args != null) && (args.length > 0))
+    {
+      for (String arg : args)
+      {
+        if (arg.equalsIgnoreCase("-V") || arg.equalsIgnoreCase("--version"))
+        {
+          printVersion = true;
+        }
+      }
+    }
+    return printVersion;
+  }
+  
+  /**
    * Indicates whether the launcher will launch a command line versus
    * a graphical application based on the contents of the arguments
    * passed into the constructor.
-   * @return boolean where true indicates that a CLI application should
-   * be launched
+   * 
+   * @return boolean where true indicates that a CLI application
+   *         should be launched
    */
   protected boolean isCli() {
     boolean isCli = false;
@@ -243,9 +273,44 @@
   }
 
   /**
-   * Prints a usage statement to terminal and exits
+   * Prints the version statement to terminal and exits
    * with an error code.
    */
+  private void printVersion()
+  {
+    String EOL = System.getProperty("line.separator");
+    StringBuilder buffer = new StringBuilder();
+    buffer.append(PRODUCT_NAME);
+    buffer.append(" ");
+    buffer.append(MAJOR_VERSION);
+    buffer.append(".");
+    buffer.append(MINOR_VERSION);
+    if ((VERSION_QUALIFIER == null) || (VERSION_QUALIFIER.length() == 0))
+    {
+      buffer.append(".");
+      buffer.append(POINT_VERSION);
+    }
+    else
+    {
+      buffer.append(VERSION_QUALIFIER);
+    }
+    buffer.append(EOL);
+    buffer.append("Build " + BUILD_ID);
+    buffer.append(EOL);
+
+    if ((FIX_IDS != null) && (FIX_IDS.length() > 0))
+    {
+      buffer.append("Fix IDs:  " + FIX_IDS);
+      buffer.append(EOL);
+    }
+    System.out.print(buffer);
+    return;
+  }
+
+  /**
+   * Prints a usage statement to terminal and exits with an error
+   * code.
+   */
   protected abstract void printUsage();
 
   /**
@@ -276,7 +341,11 @@
    * The main method which is called by the uninstall command lines.
    */
   public void launch() {
-    if (shouldPrintUsage()) {
+    if (shouldPrintVersion())
+    {
+      printVersion();
+    }
+    else if (shouldPrintUsage()) {
       printUsage();
     } else if (isCli()) {
       int exitCode = launchCli(args, createCliApplication());

--
Gitblit v1.10.0