From a70b2bcac49f3c36b89ae6fd7e2e9b4dd052326f Mon Sep 17 00:00:00 2001
From: Gaetan Boismal <gaetan.boismal@forgerock.com>
Date: Wed, 17 Dec 2014 11:32:30 +0000
Subject: [PATCH] OPENDJ-1656 (CR-5711) start-ds -V displays no information

---
 opendj-cli/src/main/java/com/forgerock/opendj/cli/VersionHandler.java |   37 +++++++++++++++++++++++++++++++++++++
 opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java |   19 +++++++++++++++++--
 2 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java b/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java
index 43a7ca7..2f33aaf 100644
--- a/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java
+++ b/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java
@@ -130,6 +130,9 @@
     /** Indicates whether the version argument was provided. */
     private boolean versionPresent;
 
+    /** The handler to call to print the product version. */
+    private VersionHandler versionHandler;
+
     /**
      * The set of arguments defined for this parser, referenced by short ID.
      */
@@ -958,11 +961,12 @@
                         // usage information.
                         writeUsageToOutputStream();
                         return;
-                    } else if (OPTION_LONG_PRODUCT_VERSION.equals(argName)) {
+                    } else if (versionHandler != null && OPTION_LONG_PRODUCT_VERSION.equals(argName)) {
                         // "--version" will always be interpreted as requesting
                         // version information.
                         usageOrVersionDisplayed = true;
                         versionPresent = true;
+                        versionHandler.printVersion();
                         return;
                     } else {
                         // There is no such argument registered.
@@ -1035,13 +1039,14 @@
                     if (argCharacter == '?') {
                         writeUsageToOutputStream();
                         return;
-                    } else if (argCharacter == OPTION_SHORT_PRODUCT_VERSION
+                    } else if (versionHandler != null && argCharacter == OPTION_SHORT_PRODUCT_VERSION
                             && !shortIDMap.containsKey(OPTION_SHORT_PRODUCT_VERSION)) {
                         // "-V" will always be interpreted as requesting
                         // version information except if it's already defined
                         // (e.g in ldap tools).
                         usageOrVersionDisplayed = true;
                         versionPresent = true;
+                        versionHandler.printVersion();
                         return;
                     } else {
                         // There is no such argument registered.
@@ -1313,6 +1318,16 @@
     }
 
     /**
+     * Sets the version handler which will be used to display the product version.
+     *
+     * @param handler
+     *            The version handler.
+     */
+    public void setVersionHandler(final VersionHandler handler) {
+        versionHandler = handler;
+    }
+
+    /**
      * Indicates whether the version or the usage information has been displayed
      * to the end user either by an explicit argument like "-H" or "--help", or
      * by a built-in argument like "-?".
diff --git a/opendj-cli/src/main/java/com/forgerock/opendj/cli/VersionHandler.java b/opendj-cli/src/main/java/com/forgerock/opendj/cli/VersionHandler.java
new file mode 100644
index 0000000..e31166c
--- /dev/null
+++ b/opendj-cli/src/main/java/com/forgerock/opendj/cli/VersionHandler.java
@@ -0,0 +1,37 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
+ * or http://forgerock.org/license/CDDLv1.0.html.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at legal-notices/CDDLv1_0.txt.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information:
+ *      Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ *      Copyright 2014 ForgeRock AS
+ */
+package com.forgerock.opendj.cli;
+
+/**
+ * A handler for printing product version.
+ */
+//@FunctionalInterface
+public interface VersionHandler {
+
+    /** Invoked when the version of the product should be printed. */
+    void printVersion();
+
+}

--
Gitblit v1.10.0