From a39783c0d0b94e6eef5e7836168d919442c77f56 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 03 Feb 2015 13:55:55 +0000
Subject: [PATCH] OPENDJ-1778 Tools --help display the java class name instead of the command name

---
 opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java |   54 +++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 47 insertions(+), 7 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 4133815..c75d28d 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
@@ -74,6 +74,8 @@
     public static final String DEFAULT_OPENDJ_PROPERTIES_FILE_EXTENSION = ".properties";
     /** The name of a command-line script used to launch a tool. */
     public static final String PROPERTY_SCRIPT_NAME = "com.forgerock.opendj.ldap.tools.scriptName";
+    /** The legacy name of a command-line script used to launch a tool. */
+    public static final String PROPERTY_SCRIPT_NAME_LEGACY = "org.opends.server.scriptName";
 
     /** The argument that will be used to indicate the file properties. */
     private StringArgument filePropertiesPathArgument;
@@ -425,7 +427,7 @@
 
         // We have a location for the properties file.
         final Properties argumentProperties = new Properties();
-        final String scriptName = System.getProperty(PROPERTY_SCRIPT_NAME);
+        final String scriptName = getScriptName();
         try {
             final Properties p = new Properties();
             final FileInputStream fis = new FileInputStream(propertiesFilePath);
@@ -651,13 +653,8 @@
      */
     private void getUsage(final StringBuilder buffer) {
         usageOrVersionDisplayed = true;
-        final String scriptName = System.getProperty(PROPERTY_SCRIPT_NAME);
-        if (scriptName == null || scriptName.length() == 0) {
-            buffer.append(INFO_ARGPARSER_USAGE_JAVA_CLASSNAME.get(mainClassName));
-        } else {
-            buffer.append(INFO_ARGPARSER_USAGE_JAVA_SCRIPTNAME.get(scriptName));
-        }
 
+        buffer.append(getLocalizableScriptName());
         if (allowsTrailingArguments) {
             buffer.append(" ");
             if (trailingArgsDisplayName != null) {
@@ -741,6 +738,49 @@
     }
 
     /**
+     * Returns the script name or a Java equivalent command-line string.
+     *
+     * @return the script name or a Java equivalent command-line string
+     */
+    String getScriptNameOrJava() {
+        final String scriptName = getScriptName();
+        if (scriptName != null && scriptName.length() != 0) {
+            return scriptName;
+        }
+        return "java " + getMainClassName();
+    }
+
+    /**
+     * Returns the script name as a {@link LocalizableMessage}.
+     *
+     * @return the script name as a {@link LocalizableMessage}
+     */
+    LocalizableMessage getLocalizableScriptName() {
+        final String scriptName = getScriptName();
+        if (scriptName == null || scriptName.length() == 0) {
+            return INFO_ARGPARSER_USAGE_JAVA_CLASSNAME.get(mainClassName);
+        }
+        return INFO_ARGPARSER_USAGE_JAVA_SCRIPTNAME.get(scriptName);
+    }
+
+    /**
+     * Returns the script name if set.
+     *
+     * @return the script name, or {@code null} if not set
+     */
+    String getScriptName() {
+        final String scriptName = System.getProperty(PROPERTY_SCRIPT_NAME);
+        if (scriptName != null && scriptName.length() != 0) {
+            return scriptName;
+        }
+        final String legacyScriptName = System.getProperty(PROPERTY_SCRIPT_NAME_LEGACY);
+        if (legacyScriptName != null && legacyScriptName.length() != 0) {
+            return legacyScriptName;
+        }
+        return null;
+    }
+
+    /**
      * Returns the usage argument.
      *
      * @return the usageArgument

--
Gitblit v1.10.0