From 4ad7941050e0fe5d5ba4b7801e10c33c897f91b0 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 20 Jan 2015 09:26:46 +0000
Subject: [PATCH] OPENDJ-1734 (CR-5811) V/-version option does not work for some tools

---
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/DBTest.java                                     |   14 
 opendj-sdk/opendj-config/src/main/java/org/forgerock/opendj/config/dsconfig/DSConfig.java                        |   49 +
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPPasswordModify.java                         |    4 
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDIFModify.java                                 |    4 
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPSearch.java                                 |    4 
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPDelete.java                                 |    4 
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/CreateRCScript.java                             |   20 
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/VerifyIndex.java                                |    3 
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/upgrade/UpgradeCli.java                         |   73 +-
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/ManageAccount.java                              |   45 -
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsreplication/ReplicationCliArgumentParser.java |  494 +++++--------------
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/EncodePassword.java                             |    5 
 opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/SubCommandArgumentParser.java                       |  178 +------
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/makeldif/MakeLDIF.java                          |    5 
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/status/StatusCliArgumentParser.java             |   29 
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDIFSearch.java                                 |   37 -
 opendj-sdk/opendj3-server-dev/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java        |   20 
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/JavaPropertiesToolArgumentParser.java           |   63 +-
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/util/Base64.java                                      |   46 -
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/DirectoryServer.java                             |   52 +-
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/StopDS.java                                     |   45 -
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/util/args/LDAPConnectionArgumentParser.java           |   22 
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDIFDiff.java                                   |    4 
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/ListBackends.java                               |   14 
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPModify.java                                 |    4 
 opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java                                 |   95 ++-
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPCompare.java                                |    4 
 opendj-sdk/opendj3-server-dev/src/guitools/org/opends/guitools/controlpanel/ControlPanelArgumentParser.java      |   66 -
 28 files changed, 510 insertions(+), 893 deletions(-)

diff --git a/opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java b/opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java
index 30759fb..a569cd9 100644
--- a/opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java
+++ b/opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java
@@ -33,7 +33,6 @@
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.IOException;
 import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Comparator;
@@ -48,6 +47,7 @@
 
 import org.forgerock.i18n.LocalizableMessage;
 import org.forgerock.i18n.LocalizableMessageBuilder;
+import org.forgerock.i18n.slf4j.LocalizedLogger;
 import org.forgerock.util.Utils;
 
 /**
@@ -61,6 +61,8 @@
  * on the command-line.
  */
 public class ArgumentParser {
+
+    private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
     /**
      * The name of the OpenDJ configuration direction in the user home
      * directory.
@@ -655,27 +657,17 @@
         return buffer.toString();
     }
 
-    private void writeUsageToOutputStream() {
-        try {
-            getUsage(usageOutputStream);
-        } catch (final Exception e) {
-            // Ignored.
-        }
-    }
-
     /**
-     * Writes usage information based on the defined arguments to the provided
-     * output stream.
+     * Writes message to the usage output stream.
      *
-     * @param outputStream
-     *            The output stream to which the usage information should be
-     *            written.
-     * @throws IOException
-     *             If a problem occurs while attempting to write the usage
-     *             information to the provided output stream.
+     * @param message the message to write
      */
-    void getUsage(final OutputStream outputStream) throws IOException {
-        outputStream.write(getBytes(getUsage()));
+    void writeToUsageOutputStream(CharSequence message) {
+        try {
+            usageOutputStream.write(getBytes(message.toString()));
+        } catch (final Exception e) {
+            logger.traceException(e);
+        }
     }
 
     /**
@@ -777,6 +769,15 @@
     }
 
     /**
+     * Returns the usage argument.
+     *
+     * @return the usageArgument
+     */
+    Argument getUsageArgument() {
+        return usageArgument;
+    }
+
+    /**
      * Retrieves a message containing usage information based on the defined
      * arguments.
      *
@@ -789,6 +790,22 @@
     }
 
     /**
+     * Returns the version handler.
+     *
+     * @return the version handler
+     */
+    VersionHandler getVersionHandler() {
+        return versionHandler;
+    }
+
+    /** Prints the version. */
+    void printVersion() {
+        versionPresent = true;
+        usageOrVersionDisplayed = true;
+        versionHandler.printVersion();
+    }
+
+    /**
      * Returns whether the usage argument was provided or not. This method
      * should be called after a call to parseArguments.
      *
@@ -811,6 +828,16 @@
     }
 
     /**
+     * Indicates whether subcommand names and long argument strings should be treated in a case-sensitive manner.
+     *
+     * @return <CODE>true</CODE> if subcommand names and long argument strings should be treated in a case-sensitive
+     *         manner, or <CODE>false</CODE> if they should not.
+     */
+    boolean longArgumentsCaseSensitive() {
+        return longArgumentsCaseSensitive;
+    }
+
+    /**
      * Parses the provided set of arguments and updates the information
      * associated with this parser accordingly.
      *
@@ -901,14 +928,12 @@
                     if (OPTION_LONG_HELP.equals(argName)) {
                         // "--help" will always be interpreted as requesting
                         // usage information.
-                        writeUsageToOutputStream();
+                        writeToUsageOutputStream(getUsage());
                         return;
                     } 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();
+                        printVersion();
                         return;
                     } else {
                         // There is no such argument registered.
@@ -921,7 +946,7 @@
                     // If this is the usage argument, then immediately stop and
                     // print usage information.
                     if (usageArgument != null && usageArgument.getName().equals(a.getName())) {
-                        writeUsageToOutputStream();
+                        writeToUsageOutputStream(getUsage());
                         return;
                     }
                 }
@@ -979,16 +1004,11 @@
                 final Argument a = shortIDMap.get(argCharacter);
                 if (a == null) {
                     if (argCharacter == '?') {
-                        writeUsageToOutputStream();
+                        writeToUsageOutputStream(getUsage());
                         return;
                     } 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();
+                        printVersion();
                         return;
                     } else {
                         // There is no such argument registered.
@@ -1000,7 +1020,7 @@
                     // If this is the usage argument, then immediately stop and
                     // print usage information.
                     if (usageArgument != null && usageArgument.getName().equals(a.getName())) {
-                        writeUsageToOutputStream();
+                        writeToUsageOutputStream(getUsage());
                         return;
                     }
                 }
@@ -1055,7 +1075,7 @@
                             // If this is the usage argument,
                             // then immediately stop and print usage information.
                             if (usageArgument != null && usageArgument.getName().equals(b.getName())) {
-                                writeUsageToOutputStream();
+                                writeToUsageOutputStream(getUsage());
                                 return;
                             }
                         }
@@ -1260,6 +1280,15 @@
     }
 
     /**
+     * Sets whether the usage or version displayed.
+     *
+     * @param usageOrVersionDisplayed the usageOrVersionDisplayed to set
+     */
+    public void setUsageOrVersionDisplayed(boolean usageOrVersionDisplayed) {
+        this.usageOrVersionDisplayed = usageOrVersionDisplayed;
+    }
+
+    /**
      * Sets the version handler which will be used to display the product version.
      *
      * @param handler
diff --git a/opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/SubCommandArgumentParser.java b/opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/SubCommandArgumentParser.java
index a09b968..3d3e9bd 100644
--- a/opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/SubCommandArgumentParser.java
+++ b/opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/SubCommandArgumentParser.java
@@ -31,7 +31,6 @@
 import static com.forgerock.opendj.cli.Utils.*;
 import static com.forgerock.opendj.util.StaticUtils.*;
 
-import java.io.IOException;
 import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -61,17 +60,11 @@
     private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
     private static final String INDENT = "    ";
 
-    /** The argument that will be used to trigger the display of usage information. */
-    private Argument usageArgument;
     /** The arguments that will be used to trigger the display of usage information for groups of sub-commands. */
     private final Map<Argument, Collection<SubCommand>> usageGroupArguments =
         new HashMap<Argument, Collection<SubCommand>>();
     /** The set of unnamed trailing arguments that were provided for this parser. */
     private final ArrayList<String> trailingArguments = new ArrayList<String>();
-    /** Indicates whether subcommand and long argument names should be treated in a case-sensitive manner. */
-    private final boolean longArgumentsCaseSensitive;
-    /** Indicates whether the usage information has been displayed. */
-    private boolean usageOrVersionDisplayed;
 
     /** The set of global arguments defined for this parser, referenced by short ID. */
     private final Map<Character, Argument> globalShortIDMap = new HashMap<Character, Argument>();
@@ -84,26 +77,11 @@
     /** The set of subcommands defined for this parser, referenced by subcommand name. */
     private final SortedMap<String, SubCommand> subCommands = new TreeMap<String, SubCommand>();
 
-    /** The output stream to which usage information should be printed. */
-    private OutputStream usageOutputStream;
-
-    /**
-     * The fully-qualified name of the Java class that should be invoked to launch the program with which this argument
-     * parser is associated.
-     */
-    private final String mainClassName;
-
-    /**A human-readable description for the tool, which will be included when displaying usage information.     */
-    private final LocalizableMessage toolDescription;
-
     /** The raw set of command-line arguments that were provided. */
     private String[] rawArguments;
     /**The subcommand requested by the user as part of the command-line arguments.     */
     private SubCommand subCommand;
 
-    /** Indicates whether the version argument was provided. */
-    private boolean versionPresent;
-
     /**
      * Creates a new instance of this subcommand argument parser with no arguments.
      *
@@ -118,42 +96,6 @@
     public SubCommandArgumentParser(String mainClassName, LocalizableMessage toolDescription,
             boolean longArgumentsCaseSensitive) {
         super(mainClassName, toolDescription, longArgumentsCaseSensitive);
-        this.mainClassName = mainClassName;
-        this.toolDescription = toolDescription;
-        this.longArgumentsCaseSensitive = longArgumentsCaseSensitive;
-    }
-
-    /**
-     * Retrieves the fully-qualified name of the Java class that should be invoked to launch the program with which this
-     * argument parser is associated.
-     *
-     * @return The fully-qualified name of the Java class that should be invoked to launch the program with which this
-     *         argument parser is associated.
-     */
-    @Override
-    public String getMainClassName() {
-        return mainClassName;
-    }
-
-    /**
-     * Retrieves a human-readable description for this tool, which should be included at the top of the command-line
-     * usage information.
-     *
-     * @return A human-readable description for this tool, or {@code null} if none is available.
-     */
-    @Override
-    public LocalizableMessage getToolDescription() {
-        return toolDescription;
-    }
-
-    /**
-     * Indicates whether subcommand names and long argument strings should be treated in a case-sensitive manner.
-     *
-     * @return <CODE>true</CODE> if subcommand names and long argument strings should be treated in a case-sensitive
-     *         manner, or <CODE>false</CODE> if they should not.
-     */
-    public boolean longArgumentsCaseSensitive() {
-        return longArgumentsCaseSensitive;
     }
 
     /**
@@ -380,7 +322,7 @@
 
         String longID = argument.getLongIdentifier();
         if (longID != null) {
-            if (!longArgumentsCaseSensitive) {
+            if (!longArgumentsCaseSensitive()) {
                 longID = toLowerCase(longID);
             }
 
@@ -436,7 +378,7 @@
 
         String longID = argument.getLongIdentifier();
         if (longID != null) {
-            if (!longArgumentsCaseSensitive) {
+            if (!longArgumentsCaseSensitive()) {
                 longID = toLowerCase(longID);
             }
 
@@ -466,9 +408,7 @@
      */
     @Override
     public void setUsageArgument(Argument argument, OutputStream outputStream) {
-        usageArgument = argument;
-        usageOutputStream = outputStream;
-
+        super.setUsageArgument(argument, outputStream);
         usageGroupArguments.put(argument, Collections.<SubCommand> emptySet());
     }
 
@@ -523,7 +463,7 @@
         this.rawArguments = rawArguments;
         this.subCommand = null;
         this.trailingArguments.clear();
-        this.usageOrVersionDisplayed = false;
+        setUsageOrVersionDisplayed(false);
 
         boolean inTrailingArgs = false;
 
@@ -572,7 +512,7 @@
 
                 // If we're not case-sensitive, then convert the name to lowercase.
                 String origArgName = argName;
-                if (!longArgumentsCaseSensitive) {
+                if (!longArgumentsCaseSensitive()) {
                     argName = toLowerCase(argName);
                 }
 
@@ -587,13 +527,11 @@
                         if (OPTION_LONG_HELP.equals(argName)) {
                             // "--help" will always be interpreted as requesting usage
                             // information.
-                            getUsage(usageOutputStream);
+                            writeToUsageOutputStream(getUsage());
                             return;
-                        } else if (OPTION_LONG_PRODUCT_VERSION.equals(argName)) {
+                        } else if (OPTION_LONG_PRODUCT_VERSION.equals(argName) && getVersionHandler() != null) {
                             // "--version" will always be interpreted as requesting usage
                             // information.
-                            versionPresent = true;
-                            usageOrVersionDisplayed = true;
                             printVersion();
                             return;
                         } else if (subCommand != null) {
@@ -612,7 +550,7 @@
                 // If this is a usage argument, then immediately stop and print
                 // usage information.
                 if (usageGroupArguments.containsKey(a)) {
-                    getUsage(a, usageOutputStream);
+                    getUsage(a);
                     return;
                 }
 
@@ -670,17 +608,15 @@
                     if (subCommand == null) {
                         if (argCharacter == '?') {
                             // "-?" will always be interpreted as requesting usage.
-                            getUsage(usageOutputStream);
-                            if (usageArgument != null) {
-                                usageArgument.setPresent(true);
+                            writeToUsageOutputStream(getUsage());
+                            if (getUsageArgument() != null) {
+                                getUsageArgument().setPresent(true);
                             }
                             return;
-                        } else if (argCharacter == OPTION_SHORT_PRODUCT_VERSION) {
+                        } else if (argCharacter == OPTION_SHORT_PRODUCT_VERSION && getVersionHandler() != null) {
                             // "-V" will always be interpreted as requesting
                             // version information except if it's already defined.
                             if (dashVAccepted()) {
-                                usageOrVersionDisplayed = true;
-                                versionPresent = true;
                                 printVersion();
                                 return;
                             } else {
@@ -699,12 +635,10 @@
                         if (a == null) {
                             if (argCharacter == '?') {
                                 // "-?" will always be interpreted as requesting usage.
-                                getUsage(usageOutputStream);
+                                writeToUsageOutputStream(getUsage());
                                 return;
-                            } else if (argCharacter == OPTION_SHORT_PRODUCT_VERSION) {
+                            } else if (argCharacter == OPTION_SHORT_PRODUCT_VERSION && getVersionHandler() != null) {
                                 if (dashVAccepted()) {
-                                    usageOrVersionDisplayed = true;
-                                    versionPresent = true;
                                     printVersion();
                                     return;
                                 }
@@ -722,7 +656,7 @@
                 // If this is the usage argument, then immediately stop and print
                 // usage information.
                 if (usageGroupArguments.containsKey(a)) {
-                    getUsage(a, usageOutputStream);
+                    getUsage(a);
                     return;
                 }
 
@@ -784,7 +718,7 @@
                         // If this is the usage argument, then immediately stop and
                         // print usage information.
                         if (usageGroupArguments.containsKey(b)) {
-                            getUsage(b, usageOutputStream);
+                            getUsage(b);
                             return;
                         }
                     }
@@ -802,7 +736,7 @@
             } else {
                 // It must be the sub-command.
                 String nameToCheck = arg;
-                if (!longArgumentsCaseSensitive) {
+                if (!longArgumentsCaseSensitive()) {
                     nameToCheck = toLowerCase(arg);
                 }
 
@@ -861,10 +795,10 @@
      *            The subcommand for which to display the usage information.
      */
     public void getSubCommandUsage(LocalizableMessageBuilder buffer, SubCommand subCommand) {
-        usageOrVersionDisplayed = true;
+        setUsageOrVersionDisplayed(true);
         String scriptName = System.getProperty(PROPERTY_SCRIPT_NAME);
         if (scriptName == null || scriptName.length() == 0) {
-            scriptName = "java " + mainClassName;
+            scriptName = "java " + getMainClassName();
         }
         buffer.append(INFO_ARGPARSER_USAGE_JAVA_SCRIPTNAME.get(scriptName));
         buffer.append("  ");
@@ -895,6 +829,8 @@
             buffer.append(INFO_SUBCMD_OPTIONS.get());
             buffer.append(EOL);
         }
+
+        final Argument usageArgument = getUsageArgument();
         for (Argument a : subCommand.getArguments()) {
             // If this argument is hidden, then skip it.
             if (a.isHidden()) {
@@ -1007,10 +943,10 @@
      * @return A string describing how the user can get more help.
      */
     public LocalizableMessage getHelpUsageReference() {
-        usageOrVersionDisplayed = true;
+        setUsageOrVersionDisplayed(true);
         String scriptName = System.getProperty(PROPERTY_SCRIPT_NAME);
         if (scriptName == null || scriptName.length() == 0) {
-            scriptName = "java " + mainClassName;
+            scriptName = "java " + getMainClassName();
         }
 
         LocalizableMessageBuilder buffer = new LocalizableMessageBuilder();
@@ -1030,17 +966,6 @@
     }
 
     /**
-     * Indicates whether 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 "-?".
-     *
-     * @return {@code true} if the usage information has been displayed, or {@code false} if not.
-     */
-    @Override
-    public boolean usageOrVersionDisplayed() {
-        return usageOrVersionDisplayed;
-    }
-
-    /**
      * Adds the provided subcommand to this argument parser. This is only intended for use by the
      * <CODE>SubCommand</CODE> constructor and does not do any validation of its own to ensure that there are no
      * conflicts with the subcommand or any of its arguments.
@@ -1053,9 +978,10 @@
     }
 
     /** Get usage for a specific usage argument. */
-    private void getUsage(Argument a, OutputStream outputStream) {
+    private void getUsage(Argument a) {
         LocalizableMessageBuilder buffer = new LocalizableMessageBuilder();
 
+        final Argument usageArgument = getUsageArgument();
         if (a.equals(usageArgument) && subCommand != null) {
             getSubCommandUsage(buffer, subCommand);
         } else if (a.equals(usageArgument) && usageGroupArguments.size() <= 1) {
@@ -1065,33 +991,20 @@
             // Using groups - so display all sub-commands group help.
             getFullUsage(Collections.<SubCommand> emptySet(), true, buffer);
         } else {
-            // Requested help on specific group - don't display global
-            // options.
+            // Requested help on specific group - don't display global options.
             getFullUsage(usageGroupArguments.get(a), false, buffer);
         }
 
-        try {
-            outputStream.write(buffer.toString().getBytes());
-        } catch (Exception e) {
-            logger.traceException(e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    public void getUsage(OutputStream outputStream) {
-        try {
-            outputStream.write(getUsage().getBytes());
-        } catch (IOException e) {
-            logger.traceException(e);
-        }
+        writeToUsageOutputStream(buffer);
     }
 
     /**
      * Appends complete usage information for the specified set of sub-commands.
      */
     private void getFullUsage(Collection<SubCommand> c, boolean showGlobalOptions, LocalizableMessageBuilder buffer) {
-        usageOrVersionDisplayed = true;
+        setUsageOrVersionDisplayed(true);
+
+        final LocalizableMessage toolDescription = getToolDescription();
         if (toolDescription != null && toolDescription.length() > 0) {
             buffer.append(wrapText(toolDescription, MAX_LINE_WIDTH - 1));
             buffer.append(EOL).append(EOL);
@@ -1099,7 +1012,7 @@
 
         String scriptName = System.getProperty(PROPERTY_SCRIPT_NAME);
         if (scriptName == null || scriptName.length() == 0) {
-            scriptName = "java " + mainClassName;
+            scriptName = "java " + getMainClassName();
         }
         buffer.append(INFO_ARGPARSER_USAGE.get());
         buffer.append("  ");
@@ -1122,6 +1035,7 @@
             buffer.append(EOL);
         }
 
+        final Argument usageArgument = getUsageArgument();
         if (c.isEmpty()) {
             // Display usage arguments (except the default one).
             for (Argument a : globalArgumentList) {
@@ -1216,6 +1130,7 @@
             value = "";
         }
 
+        final Argument usageArgument = getUsageArgument();
         Character shortIDChar = a.getShortIdentifier();
         if (shortIDChar != null) {
             if (a.equals(usageArgument)) {
@@ -1292,28 +1207,6 @@
     }
 
     /**
-     * Returns whether the usage argument was provided or not. This method should be called after a call to
-     * parseArguments.
-     *
-     * @return <CODE>true</CODE> if the usage argument was provided and <CODE>false</CODE> otherwise.
-     */
-    @Override
-    public boolean isUsageArgumentPresent() {
-        return usageArgument != null && usageArgument.isPresent();
-    }
-
-    /**
-     * Returns whether the version argument was provided or not. This method should be called after a call to
-     * parseArguments.
-     *
-     * @return <CODE>true</CODE> if the version argument was provided and <CODE>false</CODE> otherwise.
-     */
-    @Override
-    public boolean isVersionArgumentPresent() {
-        return super.isVersionArgumentPresent() && !versionPresent;
-    }
-
-    /**
      * Generate reference documentation for dsconfig subcommands in DocBook 5 XML format. As the number of categories is
      * large, the subcommand entries are sorted here by name for inclusion in a &lt;refsect1&gt; covering all dsconfig
      * Subcommands as part of the &lt;refentry&gt; for dsconfig (in man-dsconfig.xml).
@@ -1401,9 +1294,4 @@
         return "<refsect2 xml:id=\"dsconfig-" + sc.getName() + "\">" + EOL + " <title>dsconfig " + sc.getName()
                 + "</title>" + EOL + " <para>" + sc.getDescription() + "</para>" + EOL + options + "</refsect2>" + EOL;
     }
-
-    void printVersion() {
-        // TODO
-        // DirectoryServer.printVersion(usageOutputStream);
-    }
 }
diff --git a/opendj-sdk/opendj-config/src/main/java/org/forgerock/opendj/config/dsconfig/DSConfig.java b/opendj-sdk/opendj-config/src/main/java/org/forgerock/opendj/config/dsconfig/DSConfig.java
index 16d6a54..e8fcc50 100644
--- a/opendj-sdk/opendj-config/src/main/java/org/forgerock/opendj/config/dsconfig/DSConfig.java
+++ b/opendj-sdk/opendj-config/src/main/java/org/forgerock/opendj/config/dsconfig/DSConfig.java
@@ -28,17 +28,12 @@
 
 import static com.forgerock.opendj.cli.ArgumentConstants.*;
 import static com.forgerock.opendj.cli.CliMessages.*;
+import static com.forgerock.opendj.cli.Utils.*;
 import static com.forgerock.opendj.dsconfig.DsconfigMessages.*;
-import static com.forgerock.opendj.cli.Utils.SHELL_COMMENT_SEPARATOR;
-import static com.forgerock.opendj.cli.Utils.canWrite;
-import static com.forgerock.opendj.cli.Utils.filterExitCode;
-import static com.forgerock.opendj.cli.Utils.formatDateTimeStringForEquivalentCommand;
-import static com.forgerock.opendj.cli.Utils.getCurrentOperationDateMessage;
-import static com.forgerock.opendj.util.StaticUtils.stackTraceToSingleLineString;
-import static org.forgerock.opendj.config.dsconfig.ArgumentExceptionFactory.displayManagedObjectDecodingException;
-import static org.forgerock.opendj.config.dsconfig.ArgumentExceptionFactory.displayMissingMandatoryPropertyException;
-import static org.forgerock.opendj.config.dsconfig.ArgumentExceptionFactory.displayOperationRejectedException;
-import static org.forgerock.util.Utils.closeSilently;
+import static com.forgerock.opendj.util.StaticUtils.*;
+
+import static org.forgerock.opendj.config.dsconfig.ArgumentExceptionFactory.*;
+import static org.forgerock.util.Utils.*;
 
 import java.io.BufferedReader;
 import java.io.BufferedWriter;
@@ -49,13 +44,16 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PrintStream;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Date;
+import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeMap;
@@ -71,6 +69,7 @@
 import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
 import org.forgerock.opendj.config.client.OperationRejectedException;
 import org.forgerock.opendj.config.server.ConfigException;
+
 import com.forgerock.opendj.cli.ArgumentException;
 import com.forgerock.opendj.cli.ArgumentGroup;
 import com.forgerock.opendj.cli.BooleanArgument;
@@ -88,6 +87,7 @@
 import com.forgerock.opendj.cli.StringArgument;
 import com.forgerock.opendj.cli.SubCommand;
 import com.forgerock.opendj.cli.SubCommandArgumentParser;
+import com.forgerock.opendj.cli.VersionHandler;
 
 /**
  * This class provides a command-line tool which enables administrators to configure the Directory Server.
@@ -97,14 +97,10 @@
     /** The name of this tool. */
     static final String DSCONFIGTOOLNAME = "dsconfig";
 
-    /**
-     * The name of a command-line script used to launch an administrative tool.
-     */
+    /** The name of a command-line script used to launch an administrative tool. */
     static final String PROPERTY_SCRIPT_NAME = "org.opends.server.scriptName";
 
-    /**
-     * A menu call-back which runs a sub-command interactively.
-     */
+    /** A menu call-back which runs a sub-command interactively. */
     private class SubCommandHandlerMenuCallback implements MenuCallback<Integer> {
 
         /** The sub-command handler. */
@@ -406,6 +402,27 @@
         super(new PrintStream(out), new PrintStream(err));
 
         this.parser = new SubCommandArgumentParser(getClass().getName(), INFO_DSCFG_TOOL_DESCRIPTION.get(), false);
+        this.parser.setVersionHandler(new VersionHandler() {
+            @Override
+            public void printVersion() {
+                System.out.println(getVersionString());
+            }
+
+            private String getVersionString() {
+                try {
+                    final Enumeration<URL> resources = getClass().getClassLoader().getResources(
+                            "META-INF/maven/org.forgerock.opendj/opendj-config/pom.properties");
+                    while (resources.hasMoreElements()) {
+                        final Properties props = new Properties();
+                        props.load(resources.nextElement().openStream());
+                        return (String) props.get("version");
+                    }
+                } catch (IOException e) {
+                    errPrintln(LocalizableMessage.raw(e.getMessage()));
+                }
+                return "";
+            }
+        });
     }
 
     /** {@inheritDoc} */
diff --git a/opendj-sdk/opendj3-server-dev/src/guitools/org/opends/guitools/controlpanel/ControlPanelArgumentParser.java b/opendj-sdk/opendj3-server-dev/src/guitools/org/opends/guitools/controlpanel/ControlPanelArgumentParser.java
index 960dde6..139f221 100644
--- a/opendj-sdk/opendj3-server-dev/src/guitools/org/opends/guitools/controlpanel/ControlPanelArgumentParser.java
+++ b/opendj-sdk/opendj3-server-dev/src/guitools/org/opends/guitools/controlpanel/ControlPanelArgumentParser.java
@@ -22,9 +22,8 @@
  *
  *
  *      Copyright 2009-2010 Sun Microsystems, Inc.
- *      Portions Copyright 2011-2014 ForgeRock AS
+ *      Portions Copyright 2011-2015 ForgeRock AS
  */
-
 package org.opends.guitools.controlpanel;
 
 import static org.opends.messages.ToolMessages.*;
@@ -36,6 +35,7 @@
 import org.opends.quicksetup.UserData;
 import org.opends.quicksetup.util.Utils;
 import org.opends.server.admin.AdministrationConnector;
+import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 
 import com.forgerock.opendj.cli.ArgumentException;
 import com.forgerock.opendj.cli.ArgumentParser;
@@ -50,46 +50,24 @@
  */
 public class ControlPanelArgumentParser extends ArgumentParser
 {
-  /**
-   * The 'hostName' global argument.
-   */
-  private StringArgument hostNameArg = null;
+  /** The 'hostName' global argument. */
+  private StringArgument hostNameArg;
+  /** The 'port' global argument. */
+  private IntegerArgument portArg;
 
-  /**
-   * The 'port' global argument.
-   */
-  private IntegerArgument portArg = null;
+  /** The 'bindDN' global argument. */
+  private StringArgument bindDnArg;
+  /** The 'bindPasswordFile' global argument. */
+  private FileBasedArgument bindPasswordFileArg;
+  /** The 'bindPassword' global argument. */
+  private StringArgument bindPasswordArg;
 
-  /**
-   * The 'bindDN' global argument.
-   */
-  private StringArgument bindDnArg = null;
-
-  /**
-   * The 'bindPasswordFile' global argument.
-   */
-  private FileBasedArgument bindPasswordFileArg = null;
-
-  /**
-   * The 'bindPassword' global argument.
-   */
-  private StringArgument bindPasswordArg = null;
-
-  /**
-   * The 'trustAllArg' global argument.
-   */
-  private BooleanArgument trustAllArg = null;
-
-  /**
-   * The 'remoteArg' global argument.
-   */
-  private BooleanArgument remoteArg = null;
-
-  /**
-   * Argument to specify the connect timeout.
-   */
-  private IntegerArgument connectTimeoutArg = null;
-
+  /** The 'trustAllArg' global argument. */
+  private BooleanArgument trustAllArg;
+  /** The 'remoteArg' global argument. */
+  private BooleanArgument remoteArg;
+  /** Argument to specify the connect timeout. */
+  private IntegerArgument connectTimeoutArg;
   private BooleanArgument showUsageArg;
 
   /**
@@ -102,6 +80,7 @@
       LocalizableMessage msg)
   {
     super(mainClassName, msg, false);
+    setVersionHandler(new DirectoryServerVersionHandler());
   }
 
   /**
@@ -161,10 +140,8 @@
     setUsageArgument(showUsageArg);
   }
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public void parseArguments(String[] args) throws ArgumentException
   {
     LinkedHashSet<LocalizableMessage> errorMessages = new LinkedHashSet<LocalizableMessage>();
@@ -295,5 +272,4 @@
   {
     return remoteArg.isPresent();
   }
-
 }
diff --git a/opendj-sdk/opendj3-server-dev/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java b/opendj-sdk/opendj3-server-dev/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java
index 42c0ae8..daa94a9 100644
--- a/opendj-sdk/opendj3-server-dev/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java
+++ b/opendj-sdk/opendj3-server-dev/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java
@@ -22,15 +22,13 @@
  *
  *
  *      Copyright 2008-2010 Sun Microsystems, Inc.
- *      Portions Copyright 2014 ForgeRock AS
+ *      Portions Copyright 2014-2015 ForgeRock AS
  */
-
 package org.opends.guitools.uninstaller;
 
-import static com.forgerock.opendj.cli.ArgumentConstants.OPTION_LONG_REFERENCED_HOST_NAME;
-import static com.forgerock.opendj.cli.ArgumentConstants.OPTION_SHORT_HOST;
-import static com.forgerock.opendj.cli.Utils.LINE_SEPARATOR;
+import static com.forgerock.opendj.cli.ArgumentConstants.*;
 import static com.forgerock.opendj.cli.CliMessages.*;
+import static com.forgerock.opendj.cli.Utils.*;
 
 import java.io.OutputStream;
 import java.util.ArrayList;
@@ -41,6 +39,7 @@
 import org.opends.quicksetup.UserData;
 import org.opends.server.admin.client.cli.SecureConnectionCliArgs;
 import org.opends.server.admin.client.cli.SecureConnectionCliParser;
+import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 
 import com.forgerock.opendj.cli.Argument;
 import com.forgerock.opendj.cli.ArgumentException;
@@ -49,10 +48,7 @@
 import com.forgerock.opendj.cli.ReturnCode;
 import com.forgerock.opendj.cli.StringArgument;
 
-/**
- * Class used to parse and populate the arguments of the Uninstaller.
- *
- */
+/** Class used to parse and populate the arguments of the Uninstaller. */
 public class UninstallerArgumentParser extends SecureConnectionCliParser
 {
   private BooleanArgument cliArg;
@@ -90,6 +86,7 @@
       LocalizableMessage toolDescription, boolean longArgumentsCaseSensitive)
   {
     super(mainClassName, toolDescription, longArgumentsCaseSensitive);
+    setVersionHandler(new DirectoryServerVersionHandler());
   }
 
   /**
@@ -343,12 +340,11 @@
    */
   public String getReferencedHostName()
   {
-    String hostName = null;
     if (referencedHostNameArg.isPresent())
     {
-      hostName = referencedHostNameArg.getValue();
+      return referencedHostNameArg.getValue();
     }
-    return hostName;
+    return null;
   }
 
   /**
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/DirectoryServer.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/DirectoryServer.java
index 5ee245c..f8b0bcf 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/DirectoryServer.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/DirectoryServer.java
@@ -22,10 +22,19 @@
  *
  *
  *      Copyright 2006-2010 Sun Microsystems, Inc.
- *      Portions Copyright 2010-2014 ForgeRock AS.
+ *      Portions Copyright 2010-2015 ForgeRock AS.
  */
 package org.opends.server.core;
 
+import static org.forgerock.util.Reject.*;
+import static org.opends.messages.CoreMessages.*;
+import static org.opends.messages.ToolMessages.*;
+import static org.opends.server.config.ConfigConstants.*;
+import static org.opends.server.schema.SchemaConstants.*;
+import static org.opends.server.util.DynamicConstants.*;
+import static org.opends.server.util.ServerConstants.*;
+import static org.opends.server.util.StaticUtils.*;
+
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -220,15 +229,6 @@
 import com.forgerock.opendj.cli.VersionHandler;
 import com.forgerock.opendj.util.OperatingSystem;
 
-import static org.forgerock.util.Reject.*;
-import static org.opends.messages.CoreMessages.*;
-import static org.opends.messages.ToolMessages.*;
-import static org.opends.server.config.ConfigConstants.*;
-import static org.opends.server.schema.SchemaConstants.*;
-import static org.opends.server.util.DynamicConstants.*;
-import static org.opends.server.util.ServerConstants.*;
-import static org.opends.server.util.StaticUtils.*;
-
 /**
  * This class defines the core of the Directory Server.  It manages the startup
  * and shutdown processes and coordinates activities between all other
@@ -809,6 +809,23 @@
   private org.forgerock.opendj.config.server.ServerManagementContext serverManagementContext;
 
   /**
+   * Class that prints the version of OpenDJ server to System.out.
+   */
+  public static final class DirectoryServerVersionHandler implements VersionHandler
+  {
+    /** {@inheritDoc} */
+    @Override
+    public void printVersion()
+    {
+      try
+      {
+        DirectoryServer.printVersion(System.out);
+      }
+      catch (Exception e){}
+    }
+  }
+
+  /**
    * Temporary class to provide instance methods instead of static methods for
    * server. Once all static methods related to context are removed from the
    * server then DirectoryServer class can be used directly as implementation of
@@ -7781,19 +7798,6 @@
          new ArgumentParser("org.opends.server.core.DirectoryServer",
                             theToolDescription, false);
 
-    final VersionHandler versionHandler = new VersionHandler()
-    {
-      @Override
-      public void printVersion()
-      {
-        try
-        {
-          DirectoryServer.printVersion(System.out);
-        }
-        catch (Exception e){}
-      }
-    };
-
     // Initialize all the command-line argument types and register them with the
     // parser.
     try
@@ -7871,7 +7875,7 @@
       displayUsage = CommonArguments.getShowUsage();
       argParser.addArgument(displayUsage);
       argParser.setUsageArgument(displayUsage);
-      argParser.setVersionHandler(versionHandler);
+      argParser.setVersionHandler(new DirectoryServerVersionHandler());
     }
     catch (ArgumentException ae)
     {
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/CreateRCScript.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/CreateRCScript.java
index af30aae..c6bee3c 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/CreateRCScript.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/CreateRCScript.java
@@ -22,11 +22,15 @@
  *
  *
  *      Copyright 2008 Sun Microsystems, Inc.
- *      Portions Copyright 2010-2014 ForgeRock AS
+ *      Portions Copyright 2010-2015 ForgeRock AS
  */
 package org.opends.server.tools;
 
-
+import static org.opends.messages.ToolMessages.*;
+import static org.opends.server.config.ConfigConstants.*;
+import static org.opends.server.util.DynamicConstants.*;
+import static org.opends.server.util.ServerConstants.*;
+import static org.opends.server.util.StaticUtils.*;
 
 import java.io.File;
 import java.io.OutputStream;
@@ -35,27 +39,20 @@
 
 import org.forgerock.i18n.LocalizableMessage;
 import org.opends.server.core.DirectoryServer;
+import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.opends.server.loggers.JDKLogging;
 import org.opends.server.types.FilePermission;
 import org.opends.server.types.NullOutputStream;
 import org.opends.server.util.EmbeddedUtils;
 import org.opends.server.util.SetupUtils;
 
-import com.forgerock.opendj.cli.ArgumentParser;
 import com.forgerock.opendj.cli.ArgumentException;
+import com.forgerock.opendj.cli.ArgumentParser;
 import com.forgerock.opendj.cli.BooleanArgument;
 import com.forgerock.opendj.cli.CommonArguments;
 import com.forgerock.opendj.cli.StringArgument;
 import com.forgerock.opendj.util.OperatingSystem;
 
-import static org.opends.messages.ToolMessages.*;
-import static org.opends.server.config.ConfigConstants.*;
-import static org.opends.server.util.ServerConstants.*;
-import static org.opends.server.util.DynamicConstants.*;
-import static org.opends.server.util.StaticUtils.*;
-
-
-
 /**
  * This program provides a tool that may be used to generate an RC script that
  * can be used to start, stop, and restart the Directory Server, as well as to
@@ -122,6 +119,7 @@
     LocalizableMessage description = INFO_CREATERC_TOOL_DESCRIPTION.get();
     ArgumentParser argParser =
          new ArgumentParser(CreateRCScript.class.getName(), description, false);
+    argParser.setVersionHandler(new DirectoryServerVersionHandler());
 
     BooleanArgument showUsage;
     StringArgument  javaArgs;
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/DBTest.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/DBTest.java
index a2cd58c..c88356f 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/DBTest.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/DBTest.java
@@ -26,6 +26,12 @@
  */
 package org.opends.server.tools;
 
+import static com.forgerock.opendj.cli.ArgumentConstants.*;
+import static com.forgerock.opendj.cli.Utils.*;
+
+import static org.opends.messages.ToolMessages.*;
+import static org.opends.server.util.StaticUtils.*;
+
 import java.io.OutputStream;
 import java.io.PrintStream;
 import java.text.ParseException;
@@ -42,6 +48,7 @@
 import org.opends.server.backends.jeb.*;
 import org.opends.server.core.CoreConfigManager;
 import org.opends.server.core.DirectoryServer;
+import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.opends.server.core.LockFileManager;
 import org.opends.server.extensions.ConfigFileHandler;
 import org.opends.server.loggers.JDKLogging;
@@ -70,12 +77,6 @@
 import com.sleepycat.je.LockMode;
 import com.sleepycat.je.OperationStatus;
 
-import static com.forgerock.opendj.cli.ArgumentConstants.*;
-import static com.forgerock.opendj.cli.Utils.*;
-
-import static org.opends.messages.ToolMessages.*;
-import static org.opends.server.util.StaticUtils.*;
-
 /**
  * This program provides a utility that may be used to debug a JE backend. This
  * tool provides the ability list various containers in the backend as well as
@@ -175,6 +176,7 @@
 
     LocalizableMessage toolDescription = INFO_DESCRIPTION_DBTEST_TOOL.get();
     this.parser = new SubCommandArgumentParser(getClass().getName(), toolDescription, false);
+    this.parser.setVersionHandler(new DirectoryServerVersionHandler());
   }
 
   /** Displays the provided message followed by a help usage reference. */
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/EncodePassword.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/EncodePassword.java
index 7cfe209..0f80960 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/EncodePassword.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/EncodePassword.java
@@ -22,7 +22,7 @@
  *
  *
  *      Copyright 2006-2010 Sun Microsystems, Inc.
- *      Portions Copyright 2011-2014 ForgeRock AS.
+ *      Portions Copyright 2011-2015 ForgeRock AS.
  */
 package org.opends.server.tools;
 
@@ -48,6 +48,7 @@
 import org.opends.server.core.CoreConfigManager;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.core.PasswordStorageSchemeConfigManager;
+import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.opends.server.crypto.CryptoManagerSync;
 import org.opends.server.extensions.ConfigFileHandler;
 import org.opends.server.loggers.JDKLogging;
@@ -156,7 +157,7 @@
     ArgumentParser argParser =
          new ArgumentParser("org.opends.server.tools.EncodePassword",
                             toolDescription, false);
-
+    argParser.setVersionHandler(new DirectoryServerVersionHandler());
 
     // Initialize all the command-line argument types and register them with the
     // parser.
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/JavaPropertiesToolArgumentParser.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/JavaPropertiesToolArgumentParser.java
index eab5546..1db8849 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/JavaPropertiesToolArgumentParser.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/JavaPropertiesToolArgumentParser.java
@@ -22,13 +22,14 @@
  *
  *
  *      Copyright 2007-2010 Sun Microsystems, Inc.
- *      Portions Copyright 2014 ForgeRock AS
+ *      Portions Copyright 2014-2015 ForgeRock AS
  */
 package org.opends.server.tools;
 
+import static com.forgerock.opendj.cli.Utils.*;
+import static com.forgerock.opendj.util.OperatingSystem.*;
+
 import static org.opends.messages.ToolMessages.*;
-import static com.forgerock.opendj.cli.Utils.canWrite;
-import static com.forgerock.opendj.util.OperatingSystem.isWindows;
 
 import java.io.File;
 import java.util.LinkedHashSet;
@@ -37,6 +38,7 @@
 import org.opends.quicksetup.Constants;
 import org.opends.quicksetup.Installation;
 import org.opends.quicksetup.util.Utils;
+import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 
 import com.forgerock.opendj.cli.ArgumentException;
 import com.forgerock.opendj.cli.ArgumentParser;
@@ -49,13 +51,13 @@
  */
 public class JavaPropertiesToolArgumentParser extends ArgumentParser
 {
-  // Usage argument
+  /** Usage argument. */
   BooleanArgument   showUsageArg;
-  // Quiet argument
+  /** Quiet argument. */
   BooleanArgument   quietArg;
-  // The file containing the properties
+  /** The file containing the properties. */
   StringArgument propertiesFileArg;
-  // The file that is generated
+  /** The file that is generated. */
   StringArgument destinationFileArg;
 
   /**
@@ -68,6 +70,7 @@
     super(mainClassName,
         INFO_JAVAPROPERTIES_TOOL_DESCRIPTION.get(getDefaultPropertiesValue()),
         false);
+    setVersionHandler(new DirectoryServerVersionHandler());
   }
 
   /**
@@ -103,10 +106,8 @@
     setUsageArgument(showUsageArg);
   }
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public void parseArguments(String[] args) throws ArgumentException
   {
     LinkedHashSet<LocalizableMessage> errorMessages = new LinkedHashSet<LocalizableMessage>();
@@ -157,41 +158,28 @@
    */
   private String getDefaultDestinationValue()
   {
-    String value;
     // Use this instead of Installation.getLocal() because making that call
     // starts a new JVM and the command-line becomes less responsive.
     String installPath = Utils.getInstallPathFromClasspath();
     String root = Utils.getInstancePathFromInstallPath(installPath);
     if (root != null)
     {
-      String libDir = Utils.getPath(root, Installation.LIBRARIES_PATH_RELATIVE);
-      if (isWindows())
-      {
-        value = Utils.getPath(libDir,
-            Installation.SET_JAVA_PROPERTIES_FILE_WINDOWS);
-      }
-      else
-      {
-        value = Utils.getPath(libDir,
-            Installation.SET_JAVA_PROPERTIES_FILE_UNIX);
-      }
+      return getPath(Utils.getPath(root, Installation.LIBRARIES_PATH_RELATIVE));
     }
     else
     {
       // This can happen when we are not launched using the command-line (for
       // instance from the WebInstaller).
-      if (isWindows())
-      {
-        value = Utils.getPath(Installation.LIBRARIES_PATH_RELATIVE,
-            Installation.SET_JAVA_PROPERTIES_FILE_WINDOWS);
-      }
-      else
-      {
-        value = Utils.getPath(Installation.LIBRARIES_PATH_RELATIVE,
-            Installation.SET_JAVA_PROPERTIES_FILE_UNIX);
-      }
+      return getPath(Installation.LIBRARIES_PATH_RELATIVE);
     }
-    return value;
+  }
+
+  private String getPath(String libDir)
+  {
+    final String relativePath = isWindows()
+        ? Installation.SET_JAVA_PROPERTIES_FILE_WINDOWS
+        : Installation.SET_JAVA_PROPERTIES_FILE_UNIX;
+    return Utils.getPath(libDir, relativePath);
   }
 
   /**
@@ -201,7 +189,6 @@
    */
   private static String getDefaultPropertiesValue()
   {
-    String defaultPropertiesValue;
     // Use this instead of Installation.getLocal() because making that call
     // starts a new JVM and the command-line becomes less responsive.
     String installPath = Utils.getInstallPathFromClasspath();
@@ -209,15 +196,13 @@
     if (root != null)
     {
       String configDir = Utils.getPath(root, Installation.CONFIG_PATH_RELATIVE);
-      defaultPropertiesValue = Utils.getPath(configDir,
-          Installation.DEFAULT_JAVA_PROPERTIES_FILE);
+      return Utils.getPath(configDir, Installation.DEFAULT_JAVA_PROPERTIES_FILE);
     }
     else
     {
       // This can happen when we are not launched using the command-line (for
       // instance from the WebInstaller).
-      defaultPropertiesValue = Installation.DEFAULT_JAVA_PROPERTIES_FILE;
+      return Installation.DEFAULT_JAVA_PROPERTIES_FILE;
     }
-    return defaultPropertiesValue;
   }
 }
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPCompare.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPCompare.java
index f6f58be..7543a0c 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPCompare.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPCompare.java
@@ -22,7 +22,7 @@
  *
  *
  *      Copyright 2006-2010 Sun Microsystems, Inc.
- *      Portions Copyright 2012-2014 ForgeRock AS
+ *      Portions Copyright 2012-2015 ForgeRock AS
  */
 package org.opends.server.tools;
 
@@ -42,6 +42,7 @@
 import org.forgerock.opendj.ldap.ByteString;
 import org.forgerock.opendj.ldap.DecodeException;
 import org.opends.server.controls.LDAPAssertionRequestControl;
+import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.opends.server.protocols.ldap.CompareRequestProtocolOp;
 import org.opends.server.protocols.ldap.CompareResponseProtocolOp;
 import org.opends.server.protocols.ldap.LDAPFilter;
@@ -411,6 +412,7 @@
     ArgumentParser argParser = new ArgumentParser(CLASS_NAME, toolDescription,
                                         false, true, 1, 0,
                                         " \'attribute:value\' \"DN\" ...");
+    argParser.setVersionHandler(new DirectoryServerVersionHandler());
 
     try
     {
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPDelete.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPDelete.java
index 2d002b2..003eacc 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPDelete.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPDelete.java
@@ -22,7 +22,7 @@
  *
  *
  *      Copyright 2006-2010 Sun Microsystems, Inc.
- *      Portions Copyright 2012-2014 ForgeRock AS.
+ *      Portions Copyright 2012-2015 ForgeRock AS.
  */
 package org.opends.server.tools;
 
@@ -42,6 +42,7 @@
 import org.forgerock.opendj.ldap.ByteString;
 import org.forgerock.opendj.ldap.DecodeException;
 import org.opends.server.controls.SubtreeDeleteControl;
+import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.opends.server.protocols.ldap.DeleteRequestProtocolOp;
 import org.opends.server.protocols.ldap.DeleteResponseProtocolOp;
 import org.opends.server.protocols.ldap.LDAPMessage;
@@ -329,6 +330,7 @@
     LocalizableMessage toolDescription = INFO_LDAPDELETE_TOOL_DESCRIPTION.get();
     ArgumentParser argParser = new ArgumentParser(CLASS_NAME, toolDescription,
                                                   false, true, 0, 1, "\"DN\"");
+    argParser.setVersionHandler(new DirectoryServerVersionHandler());
     try
     {
       propertiesFileArgument = new StringArgument("propertiesFilePath",
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPModify.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPModify.java
index 45c5ab4..614921c 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPModify.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPModify.java
@@ -23,7 +23,7 @@
  *
  *      Copyright 2006-2010 Sun Microsystems, Inc.
  *      Portions Copyright 2012 profiq, s.r.o.
- *      Portions Copyright 2012-2014 ForgeRock AS.
+ *      Portions Copyright 2012-2015 ForgeRock AS.
  */
 package org.opends.server.tools;
 
@@ -42,6 +42,7 @@
 import org.forgerock.opendj.ldap.DecodeException;
 import org.forgerock.opendj.ldap.ResultCode;
 import org.opends.server.controls.*;
+import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.opends.server.plugins.ChangeNumberControlPlugin;
 import org.opends.server.protocols.ldap.AddRequestProtocolOp;
 import org.opends.server.protocols.ldap.AddResponseProtocolOp;
@@ -608,6 +609,7 @@
     LocalizableMessage toolDescription = INFO_LDAPMODIFY_TOOL_DESCRIPTION.get();
     ArgumentParser argParser = new ArgumentParser(CLASS_NAME, toolDescription,
                                                   false);
+    argParser.setVersionHandler(new DirectoryServerVersionHandler());
     try
     {
       propertiesFileArgument = new StringArgument("propertiesFilePath",
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPPasswordModify.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPPasswordModify.java
index d72d87c..3ce398e 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPPasswordModify.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPPasswordModify.java
@@ -22,7 +22,7 @@
  *
  *
  *      Copyright 2006-2010 Sun Microsystems, Inc.
- *      Portions Copyright 2013-2014 ForgeRock AS
+ *      Portions Copyright 2013-2015 ForgeRock AS
  */
 package org.opends.server.tools;
 
@@ -36,6 +36,7 @@
 import org.opends.server.controls.PasswordPolicyErrorType;
 import org.opends.server.controls.PasswordPolicyResponseControl;
 import org.opends.server.controls.PasswordPolicyWarningType;
+import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.forgerock.opendj.io.*;
 import org.opends.server.protocols.ldap.ExtendedRequestProtocolOp;
 import org.opends.server.protocols.ldap.ExtendedResponseProtocolOp;
@@ -182,6 +183,7 @@
     LocalizableMessage toolDescription = INFO_LDAPPWMOD_TOOL_DESCRIPTION.get();
     ArgumentParser argParser = new ArgumentParser(CLASS_NAME, toolDescription,
                                                   false);
+    argParser.setVersionHandler(new DirectoryServerVersionHandler());
 
     try
     {
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPSearch.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPSearch.java
index 4e3971d..be577e8 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPSearch.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPSearch.java
@@ -22,7 +22,7 @@
  *
  *
  *      Copyright 2006-2010 Sun Microsystems, Inc.
- *      Portions Copyright 2012-2014 ForgeRock AS
+ *      Portions Copyright 2012-2015 ForgeRock AS
  */
 package org.opends.server.tools;
 
@@ -39,6 +39,7 @@
 import org.forgerock.opendj.ldap.ByteString;
 import org.forgerock.opendj.ldap.DecodeException;
 import org.opends.server.controls.*;
+import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.opends.server.protocols.ldap.*;
 import org.opends.server.types.*;
 import org.opends.server.util.Base64;
@@ -692,6 +693,7 @@
     ArgumentParser argParser = new ArgumentParser(CLASS_NAME, toolDescription,
                                                   false, true, 0, 0,
                                                   "[filter] [attributes ...]");
+    argParser.setVersionHandler(new DirectoryServerVersionHandler());
 
     try
     {
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDIFDiff.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDIFDiff.java
index 4cb3db6..83aa77b 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDIFDiff.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDIFDiff.java
@@ -22,7 +22,7 @@
  *
  *
  *      Copyright 2006-2009 Sun Microsystems, Inc.
- *      Portions Copyright 2013-2014 ForgeRock AS.
+ *      Portions Copyright 2013-2015 ForgeRock AS.
  */
 package org.opends.server.tools;
 import java.io.BufferedReader;
@@ -41,6 +41,7 @@
 
 import org.forgerock.i18n.LocalizableMessage;
 import org.opends.server.core.DirectoryServer;
+import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.opends.server.extensions.ConfigFileHandler;
 import org.opends.server.loggers.JDKLogging;
 import org.opends.server.types.Attribute;
@@ -168,6 +169,7 @@
     LocalizableMessage toolDescription = INFO_LDIFDIFF_TOOL_DESCRIPTION.get();
     ArgumentParser argParser = new ArgumentParser(CLASS_NAME, toolDescription,
                                                   false);
+    argParser.setVersionHandler(new DirectoryServerVersionHandler());
     try
     {
       sourceLDIF = new StringArgument(
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDIFModify.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDIFModify.java
index 6874800..3db057d 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDIFModify.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDIFModify.java
@@ -22,7 +22,7 @@
  *
  *
  *      Copyright 2006-2008 Sun Microsystems, Inc.
- *      Portions Copyright 2012-2014 ForgeRock AS
+ *      Portions Copyright 2012-2015 ForgeRock AS
  */
 package org.opends.server.tools;
 
@@ -40,6 +40,7 @@
 import org.forgerock.i18n.LocalizableMessage;
 import org.forgerock.opendj.ldap.ByteString;
 import org.opends.server.core.DirectoryServer;
+import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.opends.server.extensions.ConfigFileHandler;
 import org.opends.server.loggers.JDKLogging;
 import org.opends.server.protocols.ldap.LDAPResultCode;
@@ -437,6 +438,7 @@
     LocalizableMessage toolDescription = INFO_LDIFMODIFY_TOOL_DESCRIPTION.get();
     ArgumentParser argParser = new ArgumentParser(CLASS_NAME, toolDescription,
                                                   false);
+    argParser.setVersionHandler(new DirectoryServerVersionHandler());
 
     try
     {
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDIFSearch.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDIFSearch.java
index 4d6b67d..1284277 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDIFSearch.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDIFSearch.java
@@ -22,7 +22,7 @@
  *
  *
  *      Copyright 2006-2008 Sun Microsystems, Inc.
- *      Portions Copyright 2013-2014 ForgeRock AS
+ *      Portions Copyright 2013-2015 ForgeRock AS
  */
 package org.opends.server.tools;
 
@@ -38,6 +38,7 @@
 import org.forgerock.i18n.LocalizableMessage;
 import org.forgerock.opendj.ldap.SearchScope;
 import org.opends.server.core.DirectoryServer;
+import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.opends.server.extensions.ConfigFileHandler;
 import org.opends.server.loggers.JDKLogging;
 import org.opends.server.protocols.ldap.LDAPResultCode;
@@ -66,41 +67,18 @@
  */
 public class LDIFSearch
 {
-  /**
-   * The fully-qualified name of this class.
-   */
+  /** The fully-qualified name of this class. */
   private static final String CLASS_NAME = "org.opends.server.tools.LDIFSearch";
 
-
-
-  /**
-   * The search scope string that will be used for baseObject searches.
-   */
+  /** The search scope string that will be used for baseObject searches. */
   private static final String SCOPE_STRING_BASE = "base";
-
-
-
-  /**
-   * The search scope string that will be used for singleLevel searches.
-   */
+  /** The search scope string that will be used for singleLevel searches. */
   private static final String SCOPE_STRING_ONE = "one";
-
-
-
-  /**
-   * The search scope string that will be used for wholeSubtree searches.
-   */
+  /** The search scope string that will be used for wholeSubtree searches. */
   private static final String SCOPE_STRING_SUB = "sub";
-
-
-
-  /**
-   * The search scope string that will be used for subordinateSubtree searches.
-   */
+  /** The search scope string that will be used for subordinateSubtree searches. */
   private static final String SCOPE_STRING_SUBORDINATE = "subordinate";
 
-
-
   /**
    * Provides the command line arguments to the <CODE>mainSearch</CODE> method
    * so that they can be processed.
@@ -166,6 +144,7 @@
     ArgumentParser argParser = new ArgumentParser(CLASS_NAME, toolDescription,
                                                   false, true, 0, 0,
                                                   "[filter] [attributes ...]");
+    argParser.setVersionHandler(new DirectoryServerVersionHandler());
 
     try
     {
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/ListBackends.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/ListBackends.java
index 964dc15..5918246 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/ListBackends.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/ListBackends.java
@@ -22,14 +22,9 @@
  *
  *
  *      Copyright 2006-2008 Sun Microsystems, Inc.
- *      Portions Copyright 2012-2014 ForgeRock AS
+ *      Portions Copyright 2012-2015 ForgeRock AS
  */
 package org.opends.server.tools;
-import org.forgerock.i18n.LocalizableMessage;
-
-
-
-
 
 import java.io.OutputStream;
 import java.io.PrintStream;
@@ -39,10 +34,12 @@
 import java.util.TreeSet;
 
 import org.opends.server.config.ConfigEntry;
+import org.forgerock.i18n.LocalizableMessage;
 import org.forgerock.opendj.config.server.ConfigException;
 import org.opends.server.config.DNConfigAttribute;
 import org.opends.server.config.StringConfigAttribute;
 import org.opends.server.core.DirectoryServer;
+import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.opends.server.extensions.ConfigFileHandler;
 import org.opends.server.loggers.JDKLogging;
 import org.opends.server.types.DirectoryException;
@@ -68,9 +65,6 @@
 import static com.forgerock.opendj.cli.Utils.wrapText;
 import static com.forgerock.opendj.cli.Utils.filterExitCode;
 
-
-
-
 /**
  * This program provides a utility that may be used to list the backends in the
  * server, as well as to determine which backend holds a given entry.
@@ -146,7 +140,7 @@
     ArgumentParser argParser =
          new ArgumentParser("org.opends.server.tools.ListBackends",
                             toolDescription, false);
-
+    argParser.setVersionHandler(new DirectoryServerVersionHandler());
 
     // Initialize all the command-line argument types and register them with the
     // parser.
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/ManageAccount.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/ManageAccount.java
index 921143a..f984b86 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/ManageAccount.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/ManageAccount.java
@@ -23,30 +23,44 @@
  *
  *
  *      Copyright 2006-2009 Sun Microsystems, Inc.
- *      Portions Copyright 2011-2014 ForgeRock AS
+ *      Portions Copyright 2011-2015 ForgeRock AS
  */
 package org.opends.server.tools;
 
+import static com.forgerock.opendj.cli.ArgumentConstants.*;
+import static com.forgerock.opendj.cli.Utils.wrapText;
+import static com.forgerock.opendj.cli.Utils.filterExitCode;
+
+import static org.opends.messages.ToolMessages.*;
+import static org.opends.server.extensions.PasswordPolicyStateExtendedOperation.*;
+import static org.opends.server.util.ServerConstants.*;
+import static org.opends.server.util.StaticUtils.*;
+
+import java.io.IOException;
 import java.io.OutputStream;
 import java.io.PrintStream;
-import java.io.IOException;
 import java.util.ArrayList;
-import java.util.LinkedList;
 import java.util.HashSet;
+import java.util.LinkedList;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import javax.net.ssl.SSLException;
 
 import org.forgerock.i18n.LocalizableMessage;
+import org.forgerock.opendj.io.ASN1;
+import org.forgerock.opendj.io.ASN1Reader;
+import org.forgerock.opendj.io.ASN1Writer;
+import org.forgerock.opendj.ldap.ByteStringBuilder;
 import org.opends.server.admin.AdministrationConnector;
-import org.forgerock.opendj.io.*;
+import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.opends.server.loggers.JDKLogging;
 import org.opends.server.protocols.ldap.ExtendedRequestProtocolOp;
 import org.opends.server.protocols.ldap.ExtendedResponseProtocolOp;
 import org.opends.server.protocols.ldap.LDAPMessage;
 import org.opends.server.protocols.ldap.LDAPResultCode;
 import org.opends.server.types.NullOutputStream;
-import org.forgerock.opendj.ldap.ByteStringBuilder;
+import org.opends.server.util.EmbeddedUtils;
+import org.opends.server.util.args.LDAPConnectionArgumentParser;
 
 import com.forgerock.opendj.cli.Argument;
 import com.forgerock.opendj.cli.ArgumentException;
@@ -59,31 +73,13 @@
 import com.forgerock.opendj.cli.SubCommand;
 import com.forgerock.opendj.cli.SubCommandArgumentParser;
 
-import org.opends.server.util.args.LDAPConnectionArgumentParser;
-
-import static org.opends.server.extensions.
-                   PasswordPolicyStateExtendedOperation.*;
-import static org.opends.messages.ToolMessages.*;
-import static com.forgerock.opendj.cli.ArgumentConstants.*;
-
-import org.opends.server.util.EmbeddedUtils;
-
-import static org.opends.server.util.ServerConstants.*;
-import static org.opends.server.util.StaticUtils.*;
-import static com.forgerock.opendj.cli.Utils.wrapText;
-import static com.forgerock.opendj.cli.Utils.filterExitCode;
-
-
-
 /**
  * This class provides a tool that can be used to perform various kinds of
  * account management using the password policy state extended operation.
  */
 public class ManageAccount
 {
-  /**
-   * The fully-qualified name of this class.
-   */
+  /** The fully-qualified name of this class. */
   private static final String CLASS_NAME =
        "org.opends.server.tools.ManageAccount";
 
@@ -832,6 +828,7 @@
     argParser = new SubCommandArgumentParser(
             CLASS_NAME, INFO_PWPSTATE_TOOL_DESCRIPTION.get(),
             false);
+    argParser.setVersionHandler(new DirectoryServerVersionHandler());
 
     BooleanArgument   showUsage;
     BooleanArgument   trustAll;
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/StopDS.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/StopDS.java
index 744e623..e689ae7 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/StopDS.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/StopDS.java
@@ -22,7 +22,7 @@
  *
  *
  *      Copyright 2006-2010 Sun Microsystems, Inc.
- *      Portions Copyright 2011-2014 ForgeRock AS
+ *      Portions Copyright 2011-2015 ForgeRock AS
  */
 package org.opends.server.tools;
 
@@ -46,6 +46,7 @@
 import org.opends.server.controls.ProxiedAuthV2Control;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.core.LockFileManager;
+import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.opends.server.loggers.JDKLogging;
 import org.opends.server.protocols.ldap.AddRequestProtocolOp;
 import org.opends.server.protocols.ldap.AddResponseProtocolOp;
@@ -83,9 +84,7 @@
  */
 public class StopDS
 {
-  /**
-   * The fully-qualified name of this class.
-   */
+  /** The fully-qualified name of this class. */
   private static final String CLASS_NAME = "org.opends.server.tools.StopDS";
 
   /**
@@ -94,42 +93,23 @@
    * a lot of memory for the JVM (Using -Xms and -Xmx options) as there might
    * be calls to Runtime.exec.
    */
-  /**
-   * The server is already stopped.
-   */
+  /** The server is already stopped. */
   private static int SERVER_ALREADY_STOPPED = 98;
-  /**
-   * The server must be started.
-   */
+  /** The server must be started. */
   private static int START_SERVER = 99;
-  /**
-   * The server must be stopped using a system call.
-   */
+  /** The server must be stopped using a system call. */
   private static int STOP_USING_SYSTEM_CALL = 100;
-  /**
-   * The server must be restarted using system calls.
-   */
+  /** The server must be restarted using system calls. */
   private static int RESTART_USING_SYSTEM_CALL = 101;
-  /**
-   * The server must be stopped using protocol.
-   */
+  /** The server must be stopped using protocol. */
   private static int STOP_USING_PROTOCOL = 102;
-  /**
-   * The server must be stopped as a window service.
-   */
+  /** The server must be stopped as a window service. */
   private static int STOP_AS_WINDOW_SERVICE = 103;
-  /**
-   * The server must be restarted as a window service.
-   */
+  /** The server must be restarted as a window service. */
   private static int RESTART_AS_WINDOW_SERVICE = 104;
-  /**
-   * The server must be started and it should use quiet mode.
-   */
+  /** The server must be started and it should use quiet mode. */
   private static int START_SERVER_QUIET = 105;
-  /**
-   * The server must be restarted using system calls and it should use quiet
-   * mode.
-   */
+  /** The server must be restarted using system calls and it should use quiet mode. */
   private static int RESTART_USING_SYSTEM_CALL_QUIET = 106;
 
   /**
@@ -193,6 +173,7 @@
     LocalizableMessage toolDescription = INFO_STOPDS_TOOL_DESCRIPTION.get();
     ArgumentParser    argParser = new ArgumentParser(CLASS_NAME,
                                                      toolDescription, false);
+    argParser.setVersionHandler(new DirectoryServerVersionHandler());
     BooleanArgument   checkStoppability;
     BooleanArgument   quietMode;
     BooleanArgument   windowsNetStop;
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/VerifyIndex.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/VerifyIndex.java
index 4adae60..47efd1a 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/VerifyIndex.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/VerifyIndex.java
@@ -46,6 +46,7 @@
 import org.opends.server.core.CoreConfigManager;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.core.LockFileManager;
+import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.opends.server.extensions.ConfigFileHandler;
 import org.opends.server.loggers.JDKLogging;
 import org.opends.server.types.DN;
@@ -119,7 +120,7 @@
     ArgumentParser argParser =
          new ArgumentParser("org.opends.server.tools.VerifyIndex",
                             toolDescription, false);
-
+    argParser.setVersionHandler(new DirectoryServerVersionHandler());
 
     // Initialize all the command-line argument types and register them with the
     // parser.
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsreplication/ReplicationCliArgumentParser.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsreplication/ReplicationCliArgumentParser.java
index 832ba33..f9544d2 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsreplication/ReplicationCliArgumentParser.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsreplication/ReplicationCliArgumentParser.java
@@ -22,17 +22,15 @@
  *
  *
  *      Copyright 2007-2010 Sun Microsystems, Inc.
- *      Portions Copyright 2012-2014 ForgeRock AS
+ *      Portions Copyright 2012-2015 ForgeRock AS
  */
-
 package org.opends.server.tools.dsreplication;
 
+import static com.forgerock.opendj.cli.ArgumentConstants.*;
+import static com.forgerock.opendj.cli.Utils.*;
+
 import static org.opends.messages.AdminToolMessages.*;
 import static org.opends.messages.ToolMessages.*;
-import static com.forgerock.opendj.cli.ArgumentConstants.*;
-import static com.forgerock.opendj.cli.Utils.canWrite;
-import static com.forgerock.opendj.cli.Utils.LINE_SEPARATOR;
-import static com.forgerock.opendj.cli.Utils.isDN;
 
 import java.io.File;
 import java.io.OutputStream;
@@ -47,6 +45,7 @@
 import org.opends.server.admin.client.cli.SecureConnectionCliArgs;
 import org.opends.server.admin.client.cli.SecureConnectionCliParser;
 import org.opends.server.admin.client.cli.TaskScheduleArgs;
+import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.opends.server.extensions.ConfigFileHandler;
 import org.opends.server.tasks.PurgeConflictsHistoricalTask;
 
@@ -78,256 +77,124 @@
   private SubCommand statusReplicationSubCmd;
   private SubCommand purgeHistoricalSubCmd;
 
-  int defaultAdminPort =
+  private int defaultAdminPort =
     AdministrationConnector.DEFAULT_ADMINISTRATION_CONNECTOR_PORT;
 
-  /**
-   * No-prompt argument.
-   */
+  /** No-prompt argument. */
   BooleanArgument noPromptArg;
-
   private String defaultLocalHostValue;
-
-  /**
-   * The 'hostName' argument for the first server.
-   */
-  private StringArgument hostName1Arg = null;
-
-  /**
-   * The 'port' argument for the first server.
-   */
-  private IntegerArgument port1Arg = null;
-
-  /**
-   * The 'bindDN' argument for the first server.
-   */
-  private StringArgument bindDn1Arg = null;
-
-  /**
-   * The 'bindPasswordFile' argument for the first server.
-   */
-  FileBasedArgument bindPasswordFile1Arg = null;
-
-  /**
-   * The 'bindPassword' argument for the first server.
-   */
-  StringArgument bindPassword1Arg = null;
-
-  /**
-   * The 'replicationPort' argument for the first server.
-   */
-  IntegerArgument replicationPort1Arg = null;
-
-  /**
-   * The 'noReplicationServer' argument for the first server.
-   */
-  BooleanArgument noReplicationServer1Arg = null;
-
-  /**
-   * The 'onlyReplicationServer' argument for the first server.
-   */
-  BooleanArgument onlyReplicationServer1Arg = null;
-
-  /**
-   * The 'secureReplication' argument for the first server.
-   */
-  BooleanArgument secureReplication1Arg = null;
-
-  /**
-   * The 'hostName' argument for the second server.
-   */
-  private StringArgument hostName2Arg = null;
-
-  /**
-   * The 'port' argument for the second server.
-   */
-  private IntegerArgument port2Arg = null;
-
-  /**
-   * The 'binDN' argument for the second server.
-   */
-  private StringArgument bindDn2Arg = null;
-
-  /**
-   * The 'bindPasswordFile' argument for the second server.
-   */
-  FileBasedArgument bindPasswordFile2Arg = null;
-
-  /**
-   * The 'bindPassword' argument for the second server.
-   */
-  StringArgument bindPassword2Arg = null;
-
-  /**
-   * The 'replicationPort' argument for the second server.
-   */
-  IntegerArgument replicationPort2Arg = null;
-
-  /**
-   * The 'noReplicationServer' argument for the second server.
-   */
-  BooleanArgument noReplicationServer2Arg = null;
-
-  /**
-   * The 'onlyReplicationServer' argument for the second server.
-   */
-  BooleanArgument onlyReplicationServer2Arg = null;
-
-  /**
-   * The 'secureReplication' argument for the second server.
-   */
-  private BooleanArgument secureReplication2Arg = null;
-
-  /**
-   * The 'skipPortCheckArg' argument to not check replication ports.
-   */
+  /** The 'hostName' argument for the first server. */
+  private StringArgument hostName1Arg;
+  /** The 'port' argument for the first server. */
+  private IntegerArgument port1Arg;
+  /** The 'bindDN' argument for the first server. */
+  private StringArgument bindDn1Arg;
+  /** The 'bindPasswordFile' argument for the first server. */
+  FileBasedArgument bindPasswordFile1Arg;
+  /** The 'bindPassword' argument for the first server. */
+  StringArgument bindPassword1Arg;
+  /** The 'replicationPort' argument for the first server. */
+  IntegerArgument replicationPort1Arg;
+  /** The 'noReplicationServer' argument for the first server. */
+  BooleanArgument noReplicationServer1Arg;
+  /** The 'onlyReplicationServer' argument for the first server. */
+  BooleanArgument onlyReplicationServer1Arg;
+  /** The 'secureReplication' argument for the first server. */
+  private BooleanArgument secureReplication1Arg;
+  /** The 'hostName' argument for the second server. */
+  private StringArgument hostName2Arg;
+  /** The 'port' argument for the second server. */
+  private IntegerArgument port2Arg;
+  /** The 'binDN' argument for the second server. */
+  private StringArgument bindDn2Arg;
+  /** The 'bindPasswordFile' argument for the second server. */
+  FileBasedArgument bindPasswordFile2Arg;
+  /** The 'bindPassword' argument for the second server. */
+  StringArgument bindPassword2Arg;
+  /** The 'replicationPort' argument for the second server. */
+  IntegerArgument replicationPort2Arg;
+  /** The 'noReplicationServer' argument for the second server. */
+  BooleanArgument noReplicationServer2Arg;
+  /** The 'onlyReplicationServer' argument for the second server. */
+  BooleanArgument onlyReplicationServer2Arg;
+  /** The 'secureReplication' argument for the second server. */
+  private BooleanArgument secureReplication2Arg;
+  /** The 'skipPortCheckArg' argument to not check replication ports. */
   private BooleanArgument skipPortCheckArg;
-
-  /**
-   * The 'noSchemaReplication' argument to not replicate schema.
-   */
+  /** The 'noSchemaReplication' argument to not replicate schema. */
   BooleanArgument noSchemaReplicationArg;
-
-  /**
-   * The 'useSecondServerAsSchemaSource' argument to not replicate schema.
-   */
+  /** The 'useSecondServerAsSchemaSource' argument to not replicate schema. */
   private BooleanArgument useSecondServerAsSchemaSourceArg;
-
-  /**
-   * The 'disableAll' argument to disable all the replication configuration of
-   * server.
-   */
+  /** The 'disableAll' argument to disable all the replication configuration of server. */
   BooleanArgument disableAllArg;
-
-  /**
-   * The 'disableReplicationServer' argument to disable the replication
-   * server.
-   */
+  /** The 'disableReplicationServer' argument to disable the replication server. */
   BooleanArgument disableReplicationServerArg;
-
-  /**
-   * The 'hostName' argument for the source server.
-   */
-  private StringArgument hostNameSourceArg = null;
-
-  /**
-   * The 'port' argument for the source server.
-   */
-  private IntegerArgument portSourceArg = null;
-
-  /**
-   * The 'hostName' argument for the destination server.
-   */
-  private StringArgument hostNameDestinationArg = null;
-
-  /**
-   * The 'port' argument for the destination server.
-   */
-  private IntegerArgument portDestinationArg = null;
-
-  /**
-   * The 'suffixes' global argument.
-   */
-  StringArgument baseDNsArg = null;
-
-  /**
-   * The 'quiet' argument.
-   */
-  BooleanArgument quietArg;
-
-  /**
-   * The 'scriptFriendly' argument.
-   */
+  /** The 'hostName' argument for the source server. */
+  private StringArgument hostNameSourceArg;
+  /** The 'port' argument for the source server. */
+  private IntegerArgument portSourceArg;
+  /** The 'hostName' argument for the destination server. */
+  private StringArgument hostNameDestinationArg;
+  /** The 'port' argument for the destination server. */
+  private IntegerArgument portDestinationArg;
+  /** The 'suffixes' global argument. */
+  StringArgument baseDNsArg;
+  /**The 'quiet' argument.   */
+  private BooleanArgument quietArg;
+  /**The 'scriptFriendly' argument.   */
   BooleanArgument scriptFriendlyArg;
-
-  /**
-   * Properties file argument.
-   */
+  /**Properties file argument.   */
   StringArgument propertiesFileArgument;
-
-  /**
-   * No-properties file argument.
-   */
+  /**No-properties file argument.   */
   BooleanArgument noPropertiesFileArgument;
-
   /**
    * The argument that the user must set to display the equivalent
    * non-interactive mode argument.
    */
   BooleanArgument displayEquivalentArgument;
-
   /**
    * The argument that allows the user to dump the equivalent non-interactive
    * command to a file.
    */
   StringArgument equivalentCommandFileArgument;
-
-  /**
-   * The argument that the user must set to have advanced options in interactive
-   * mode.
-   */
+  /** The argument that the user must set to have advanced options in interactive mode. */
   BooleanArgument advancedArg;
 
-  // The argument set by the user to specify the configuration class
-  // (useful when dsreplication purge-historical runs locally)
+  /**
+   * The argument set by the user to specify the configuration class
+   * (useful when dsreplication purge-historical runs locally).
+   */
   private StringArgument  configClassArg;
 
-  // The argument set by the user to specify the configuration file
-  // (useful when dsreplication purge-historical runs locally)
+  /**
+   * The argument set by the user to specify the configuration file
+   * (useful when dsreplication purge-historical runs locally).
+   */
   private StringArgument  configFileArg;
 
   TaskScheduleArgs taskArgs;
 
-
-  /**
-   * The 'maximumDuration' argument for the purge of historical.
-   */
+  /** The 'maximumDuration' argument for the purge of historical. */
   IntegerArgument maximumDurationArg;
 
-  /**
-   * The text of the enable replication subcommand.
-   */
-  public static final String ENABLE_REPLICATION_SUBCMD_NAME = "enable";
+  /** The text of the enable replication subcommand. */
+  static final String ENABLE_REPLICATION_SUBCMD_NAME = "enable";
+  /** The text of the disable replication subcommand. */
+  static final String DISABLE_REPLICATION_SUBCMD_NAME = "disable";
+  /** The text of the initialize replication subcommand. */
+  static final String INITIALIZE_REPLICATION_SUBCMD_NAME = "initialize";
+  /** The text of the initialize all replication subcommand. */
+  public static final String INITIALIZE_ALL_REPLICATION_SUBCMD_NAME = "initialize-all";
+  /** The text of the pre external initialization subcommand. */
+  static final String PRE_EXTERNAL_INITIALIZATION_SUBCMD_NAME = "pre-external-initialization";
+  /** The text of the initialize all replication subcommand. */
+  static final String POST_EXTERNAL_INITIALIZATION_SUBCMD_NAME = "post-external-initialization";
 
-  /**
-   * The text of the disable replication subcommand.
-   */
-  public static final String DISABLE_REPLICATION_SUBCMD_NAME = "disable";
-
-  /**
-   * The text of the initialize replication subcommand.
-   */
-  public static final String INITIALIZE_REPLICATION_SUBCMD_NAME = "initialize";
-
-  /**
-   * The text of the initialize all replication subcommand.
-   */
-  public static final String INITIALIZE_ALL_REPLICATION_SUBCMD_NAME =
-    "initialize-all";
-
-  /**
-   * The text of the pre external initialization subcommand.
-   */
-  public static final String PRE_EXTERNAL_INITIALIZATION_SUBCMD_NAME =
-    "pre-external-initialization";
-
-  /**
-   * The text of the initialize all replication subcommand.
-   */
-  public static final String POST_EXTERNAL_INITIALIZATION_SUBCMD_NAME =
-    "post-external-initialization";
-
-  /**
-   * The text of the status replication subcommand.
-   */
-  public static final String STATUS_REPLICATION_SUBCMD_NAME = "status";
-
-  /**
-   * The text of the purge historical subcommand.
-   */
-  public static final String PURGE_HISTORICAL_SUBCMD_NAME = "purge-historical";
-
-  // This CLI is always using the administration connector with SSL
+  /** The text of the status replication subcommand. */
+  static final String STATUS_REPLICATION_SUBCMD_NAME = "status";
+  /** The text of the purge historical subcommand. */
+  static final String PURGE_HISTORICAL_SUBCMD_NAME = "purge-historical";
+  /** This CLI is always using the administration connector with SSL. */
   private static final boolean alwaysSSL = true;
 
   /**
@@ -344,6 +211,7 @@
         INFO_REPLICATION_TOOL_DESCRIPTION.get(ENABLE_REPLICATION_SUBCMD_NAME,
             INITIALIZE_REPLICATION_SUBCMD_NAME),
             false);
+    setVersionHandler(new DirectoryServerVersionHandler());
   }
 
   /**
@@ -394,9 +262,7 @@
     validateSubcommandOptions(buf);
   }
 
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override
   public int validateGlobalOptions(LocalizableMessageBuilder buf)
   {
@@ -513,9 +379,9 @@
       secureArgsList.bindPasswordArg
     };
 
-    for (int i=0; i<argsToRemove.length; i++)
+    for (Argument arg : argsToRemove)
     {
-      defaultArgs.remove(argsToRemove[i]);
+      defaultArgs.remove(arg);
     }
     defaultArgs.remove(super.noPropertiesFileArg);
     defaultArgs.remove(super.propertiesFileArg);
@@ -758,10 +624,10 @@
         skipPortCheckArg, noSchemaReplicationArg,
         useSecondServerAsSchemaSourceArg
     };
-    for (int i=0; i<argsToAdd.length; i++)
+    for (Argument arg : argsToAdd)
     {
-      argsToAdd[i].setPropertyName(argsToAdd[i].getLongIdentifier());
-      enableReplicationSubCmd.addArgument(argsToAdd[i]);
+      arg.setPropertyName(arg.getLongIdentifier());
+      enableReplicationSubCmd.addArgument(arg);
     }
   }
 
@@ -793,9 +659,9 @@
     Argument[] argsToAdd = { secureArgsList.hostNameArg,
         secureArgsList.portArg, secureArgsList.bindDnArg,
         disableReplicationServerArg, disableAllArg};
-    for (int i=0; i<argsToAdd.length; i++)
+    for (Argument arg : argsToAdd)
     {
-      disableReplicationSubCmd.addArgument(argsToAdd[i]);
+      disableReplicationSubCmd.addArgument(arg);
     }
   }
 
@@ -840,10 +706,10 @@
         hostNameSourceArg, portSourceArg, hostNameDestinationArg,
         portDestinationArg
     };
-    for (int i=0; i<argsToAdd.length; i++)
+    for (Argument arg : argsToAdd)
     {
-      argsToAdd[i].setPropertyName(argsToAdd[i].getLongIdentifier());
-      initializeReplicationSubCmd.addArgument(argsToAdd[i]);
+      arg.setPropertyName(arg.getLongIdentifier());
+      initializeReplicationSubCmd.addArgument(arg);
     }
   }
 
@@ -863,9 +729,9 @@
     secureArgsList.hostNameArg.setDefaultValue(getDefaultHostValue());
     Argument[] argsToAdd = { secureArgsList.hostNameArg,
         secureArgsList.portArg };
-    for (int i=0; i<argsToAdd.length; i++)
+    for (Argument arg : argsToAdd)
     {
-      initializeAllReplicationSubCmd.addArgument(argsToAdd[i]);
+      initializeAllReplicationSubCmd.addArgument(arg);
     }
   }
 
@@ -895,9 +761,9 @@
         secureArgsList.portArg,
         externalInitializationLocalOnlyArg};
 
-    for (int i=0; i<argsToAdd.length; i++)
+    for (Argument arg : argsToAdd)
     {
-      preExternalInitializationSubCmd.addArgument(argsToAdd[i]);
+      preExternalInitializationSubCmd.addArgument(arg);
     }
   }
 
@@ -918,9 +784,9 @@
     secureArgsList.hostNameArg.setDefaultValue(getDefaultHostValue());
     Argument[] argsToAdd = { secureArgsList.hostNameArg,
         secureArgsList.portArg };
-    for (int i=0; i<argsToAdd.length; i++)
+    for (Argument arg : argsToAdd)
     {
-      postExternalInitializationSubCmd.addArgument(argsToAdd[i]);
+      postExternalInitializationSubCmd.addArgument(arg);
     }
   }
 
@@ -944,9 +810,9 @@
     secureArgsList.hostNameArg.setDefaultValue(getDefaultHostValue());
     Argument[] argsToAdd = { secureArgsList.hostNameArg,
         secureArgsList.portArg, scriptFriendlyArg };
-    for (int i=0; i<argsToAdd.length; i++)
+    for (Argument arg : argsToAdd)
     {
-      statusReplicationSubCmd.addArgument(argsToAdd[i]);
+      statusReplicationSubCmd.addArgument(arg);
     }
   }
 
@@ -983,10 +849,10 @@
         secureArgsList.portArg,
         maximumDurationArg};
 
-    for (int i=0; i<argsToAdd.length; i++)
+    for (Argument arg : argsToAdd)
     {
-      argsToAdd[i].setPropertyName(argsToAdd[i].getLongIdentifier());
-      purgeHistoricalSubCmd.addArgument(argsToAdd[i]);
+      arg.setPropertyName(arg.getLongIdentifier());
+      purgeHistoricalSubCmd.addArgument(arg);
     }
     for (Argument arg : taskArgs.getArguments())
     {
@@ -1071,72 +937,6 @@
   }
 
   /**
-   * Get the password of the first server which has to be used in the
-   * enable replication subcommand.
-   *
-   * @param dn
-   *          The user DN for which to password could be asked.
-   * @param out
-   *          The input stream to used if we have to prompt to the
-   *          user.
-   * @param err
-   *          The error stream to used if we have to prompt to the
-   *          user.
-   * @return the password of the first server which has to be used n the
-   *          enable replication subcommand.
-   */
-  public String getBindPassword1(
-      String dn, OutputStream out, OutputStream err)
-  {
-    return getBindPassword(dn, out, err, bindPassword1Arg,
-        bindPasswordFile1Arg);
-  }
-
-  /**
-   * Get the password of the second server which has to be used in the
-   * enable replication subcommand.
-   *
-   * @param dn
-   *          The user DN for which to password could be asked.
-   * @param out
-   *          The input stream to used if we have to prompt to the
-   *          user.
-   * @param err
-   *          The error stream to used if we have to prompt to the
-   *          user.
-   * @return the password of the second server which has to be used in the
-   *          enable replication subcommand.
-   */
-  public String getBindPassword2(
-      String dn, OutputStream out, OutputStream err)
-  {
-    return getBindPassword(dn, out, err, bindPassword2Arg,
-        bindPasswordFile2Arg);
-  }
-
-  /**
-   * Get the password of the global administrator which has to be used for the
-   * command.
-   *
-   * @param dn
-   *          The user DN for which to password could be asked.
-   * @param out
-   *          The input stream to used if we have to prompt to the
-   *          user.
-   * @param err
-   *          The error stream to used if we have to prompt to the
-   *          user.
-   * @return the password of the global administrator which has to be used for
-   *          the command.
-   */
-  public String getBindPasswordAdmin(
-      String dn, OutputStream out, OutputStream err)
-  {
-    return getBindPassword(dn, out, err, secureArgsList.bindPasswordArg,
-        secureArgsList.bindPasswordFileArg);
-  }
-
-  /**
    * Returns the Administrator UID explicitly provided in the command-line.
    * @return the Administrator UID explicitly provided in the command-line.
    */
@@ -1752,12 +1552,11 @@
    */
   private String getValue(StringArgument arg)
   {
-    String v = null;
     if (arg.isPresent())
     {
-      v = arg.getValue();
+      return arg.getValue();
     }
-    return v;
+    return null;
   }
 
   /**
@@ -1779,12 +1578,11 @@
    */
   private int getValue(IntegerArgument arg)
   {
-    int v = -1;
     if (arg.isPresent())
     {
       try
       {
-        v = arg.getIntValue();
+        return arg.getIntValue();
       }
       catch (ArgumentException ae)
       {
@@ -1796,7 +1594,7 @@
             "parseArguments which should result in an error.", ae);
       }
     }
-    return v;
+    return -1;
   }
 
   /**
@@ -1806,13 +1604,12 @@
    */
   private int getDefaultValue(IntegerArgument arg)
   {
-    int returnValue = -1;
     String defaultValue = arg.getDefaultValue();
     if (defaultValue != null)
     {
-      returnValue = Integer.parseInt(arg.getDefaultValue());
+      return Integer.parseInt(arg.getDefaultValue());
     }
-    return returnValue;
+    return -1;
   }
 
   /**
@@ -1824,7 +1621,7 @@
    * @param buf the LocalizableMessageBuilder object where we add the error messages
    * describing the errors encountered.
    */
-  public void validateSubcommandOptions(LocalizableMessageBuilder buf)
+  private void validateSubcommandOptions(LocalizableMessageBuilder buf)
   {
     if (isEnableReplicationSubcommand())
     {
@@ -1858,7 +1655,6 @@
     {
       validatePurgeHistoricalOptions(buf);
     }
-
     else
     {
       // This can occur if the user did not provide any subcommand.  We assume
@@ -1997,13 +1793,12 @@
    */
   private boolean isSubcommand(String name)
   {
-    boolean isSubcommand = false;
     SubCommand subCommand = getSubCommand();
     if (subCommand != null)
     {
-      isSubcommand = subCommand.getName().equalsIgnoreCase(name);
+      return subCommand.getName().equalsIgnoreCase(name);
     }
-    return isSubcommand;
+    return false;
   }
 
   /**
@@ -2029,10 +1824,10 @@
         {noSchemaReplicationArg, useSecondServerAsSchemaSourceArg}
     };
 
-    for (int i=0; i< conflictingPairs.length; i++)
+    for (Argument[] conflictingPair : conflictingPairs)
     {
-      Argument arg1 = conflictingPairs[i][0];
-      Argument arg2 = conflictingPairs[i][1];
+      Argument arg1 = conflictingPair[0];
+      Argument arg2 = conflictingPair[1];
       if (arg1.isPresent() && arg2.isPresent())
       {
         LocalizableMessage message = ERR_TOOL_CONFLICTING_ARGS.get(
@@ -2041,15 +1836,13 @@
       }
     }
 
-    if (hostName1Arg.getValue().equalsIgnoreCase(hostName2Arg.getValue()) &&
-        !isInteractive())
+    if (hostName1Arg.getValue().equalsIgnoreCase(hostName2Arg.getValue())
+        && !isInteractive()
+        && port1Arg.getValue().equals(port2Arg.getValue()))
     {
-      if (port1Arg.getValue().equals(port2Arg.getValue()))
-      {
-        LocalizableMessage message = ERR_REPLICATION_ENABLE_SAME_SERVER_PORT.get(
-            hostName1Arg.getValue(), port1Arg.getValue());
-        addMessage(buf, message);
-      }
+      LocalizableMessage message = ERR_REPLICATION_ENABLE_SAME_SERVER_PORT.get(
+          hostName1Arg.getValue(), port1Arg.getValue());
+      addMessage(buf, message);
     }
   }
 
@@ -2072,10 +1865,10 @@
         {disableAllArg, baseDNsArg}
     };
 
-    for (int i=0; i< conflictingPairs.length; i++)
+    for (Argument[] conflictingPair : conflictingPairs)
     {
-      Argument arg1 = conflictingPairs[i][0];
-      Argument arg2 = conflictingPairs[i][1];
+      Argument arg1 = conflictingPair[0];
+      Argument arg2 = conflictingPair[1];
       if (arg1.isPresent() && arg2.isPresent())
       {
         LocalizableMessage message = ERR_TOOL_CONFLICTING_ARGS.get(
@@ -2161,15 +1954,13 @@
    */
   private void validateInitializeReplicationOptions(LocalizableMessageBuilder buf)
   {
-    if (hostNameSourceArg.getValue().equalsIgnoreCase(
-        hostNameDestinationArg.getValue()) && !isInteractive())
+    if (hostNameSourceArg.getValue().equalsIgnoreCase(hostNameDestinationArg.getValue())
+        && !isInteractive()
+        && portSourceArg.getValue().equals(portDestinationArg.getValue()))
     {
-      if (portSourceArg.getValue().equals(portDestinationArg.getValue()))
-      {
-        LocalizableMessage message = ERR_REPLICATION_INITIALIZE_SAME_SERVER_PORT.get(
-            hostNameSourceArg.getValue(), portSourceArg.getValue());
-        addMessage(buf, message);
-      }
+      LocalizableMessage message = ERR_REPLICATION_INITIALIZE_SAME_SERVER_PORT.get(
+          hostNameSourceArg.getValue(), portSourceArg.getValue());
+      addMessage(buf, message);
     }
   }
 
@@ -2250,10 +2041,7 @@
       secureArgsList.bindPasswordFileArg.isPresent();
       return secureArgsPresent || adminArgsPresent;
     }
-    else
-    {
-      return true;
-    }
+    return true;
   }
 
   /**
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/makeldif/MakeLDIF.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/makeldif/MakeLDIF.java
index eb86e29..0aa9ad8 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/makeldif/MakeLDIF.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/makeldif/MakeLDIF.java
@@ -22,7 +22,7 @@
  *
  *
  *      Copyright 2006-2010 Sun Microsystems, Inc.
- *      Portions Copyright 2013-2014 ForgeRock AS
+ *      Portions Copyright 2013-2015 ForgeRock AS
  */
 package org.opends.server.tools.makeldif;
 
@@ -35,6 +35,7 @@
 
 import org.forgerock.i18n.LocalizableMessage;
 import org.opends.server.core.DirectoryServer;
+import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.opends.server.types.AttributeType;
 import org.opends.server.types.ExistingFileBehavior;
 import org.opends.server.types.InitializationException;
@@ -134,6 +135,8 @@
     LocalizableMessage toolDescription = INFO_MAKELDIF_TOOL_DESCRIPTION.get();
     ArgumentParser  argParser = new ArgumentParser(CLASS_NAME, toolDescription,
                                                    false);
+    argParser.setVersionHandler(new DirectoryServerVersionHandler());
+
     BooleanArgument showUsage;
     IntegerArgument randomSeed;
     StringArgument  configClass;
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/status/StatusCliArgumentParser.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/status/StatusCliArgumentParser.java
index 1e3aac7..0de4a76 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/status/StatusCliArgumentParser.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/status/StatusCliArgumentParser.java
@@ -22,9 +22,8 @@
  *
  *
  *      Copyright 2008-2009 Sun Microsystems, Inc.
- *      Portions Copyright 2012-2014 ForgeRock AS
+ *      Portions Copyright 2012-2015 ForgeRock AS
  */
-
 package org.opends.server.tools.status;
 
 import static org.opends.messages.AdminToolMessages.*;
@@ -35,6 +34,7 @@
 
 import org.opends.server.admin.client.cli.SecureConnectionCliArgs;
 import org.opends.server.admin.client.cli.SecureConnectionCliParser;
+import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 
 import com.forgerock.opendj.cli.Argument;
 import com.forgerock.opendj.cli.ArgumentException;
@@ -46,23 +46,16 @@
 /**
  * The class that is used to parse the arguments provided in the status command
  * line.
- *
  */
 public class StatusCliArgumentParser extends SecureConnectionCliParser
 {
   private BooleanArgument noPromptArg;
-
-  // This CLI is always using the administration connector with SSL
+  /** This CLI is always using the administration connector with SSL. */
   private static final boolean alwaysSSL = true;
 
-
-  /**
-   * The 'refresh' argument.
-   */
+  /** The 'refresh' argument. */
   private IntegerArgument refreshArg;
-  /**
-   * The 'scriptFriendly' argument.
-   */
+  /** The 'scriptFriendly' argument. */
   private BooleanArgument scriptFriendlyArg;
 
   /**
@@ -76,6 +69,7 @@
   public StatusCliArgumentParser(String mainClassName)
   {
     super(mainClassName, INFO_STATUS_CLI_USAGE_DESCRIPTION.get(), false);
+    setVersionHandler(new DirectoryServerVersionHandler());
   }
 
   /**
@@ -133,6 +127,7 @@
   {
     return secureArgsList;
   }
+
   /**
    * Tells whether the user specified to have an interactive status CLI or not.
    * This method must be called after calling parseArguments.
@@ -176,10 +171,7 @@
             "should be called after parsing the attributes: "+ae, ae);
       }
     }
-    else
-    {
-      return -1;
-    }
+    return -1;
   }
 
   /**
@@ -189,12 +181,11 @@
    */
   public String getExplicitBindDn()
   {
-    String dn = null;
     if (secureArgsList.bindDnArg.isPresent())
     {
-      dn = secureArgsList.bindDnArg.getValue();
+      return secureArgsList.bindDnArg.getValue();
     }
-    return dn;
+    return null;
   }
 
   /**
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/upgrade/UpgradeCli.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/upgrade/UpgradeCli.java
index d65e1cc..2ca43cb 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/upgrade/UpgradeCli.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/upgrade/UpgradeCli.java
@@ -21,17 +21,17 @@
  * CDDL HEADER END
  *
  *
- *      Portions Copyright 2013-2014 ForgeRock AS
+ *      Portions Copyright 2013-2015 ForgeRock AS
  */
 package org.opends.server.tools.upgrade;
 
-import static org.opends.messages.ToolMessages.*;
-import static com.forgerock.opendj.cli.Utils.filterExitCode;
-import static org.opends.server.tools.upgrade.FormattedNotificationCallback.*;
-import static org.opends.server.tools.upgrade.Upgrade.EXIT_CODE_ERROR;
-import static org.opends.server.tools.upgrade.Upgrade.EXIT_CODE_SUCCESS;
 import static com.forgerock.opendj.cli.ArgumentConstants.*;
-import static com.forgerock.opendj.cli.Utils.wrapText;
+import static com.forgerock.opendj.cli.Utils.*;
+import static javax.security.auth.callback.TextOutputCallback.*;
+
+import static org.opends.messages.ToolMessages.*;
+import static org.opends.server.tools.upgrade.FormattedNotificationCallback.*;
+import static org.opends.server.tools.upgrade.Upgrade.*;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -40,26 +40,26 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.forgerock.i18n.LocalizableMessage;
-import org.forgerock.i18n.slf4j.LocalizedLogger;
-
 import javax.security.auth.callback.Callback;
 import javax.security.auth.callback.CallbackHandler;
 import javax.security.auth.callback.ConfirmationCallback;
 import javax.security.auth.callback.TextOutputCallback;
 import javax.security.auth.callback.UnsupportedCallbackException;
 
+import org.forgerock.i18n.LocalizableMessage;
+import org.forgerock.i18n.slf4j.LocalizedLogger;
+import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.opends.server.extensions.ConfigFileHandler;
 import org.opends.server.util.ServerConstants;
 import org.opends.server.util.StaticUtils;
 
 import com.forgerock.opendj.cli.ArgumentException;
 import com.forgerock.opendj.cli.BooleanArgument;
+import com.forgerock.opendj.cli.ClientException;
 import com.forgerock.opendj.cli.CommonArguments;
+import com.forgerock.opendj.cli.ConsoleApplication;
 import com.forgerock.opendj.cli.StringArgument;
 import com.forgerock.opendj.cli.SubCommandArgumentParser;
-import com.forgerock.opendj.cli.ClientException;
-import com.forgerock.opendj.cli.ConsoleApplication;
 
 /**
  * This class provides the CLI used for upgrading the OpenDJ product.
@@ -67,21 +67,18 @@
 public final class UpgradeCli extends ConsoleApplication implements
     CallbackHandler
 {
-  /**
-   * Upgrade's logger.
-   */
+  /** Upgrade's logger. */
   private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
 
-  // The command-line argument parser.
+  /** The command-line argument parser. */
   private final SubCommandArgumentParser parser;
 
-  // The argument which should be used to specify the config class.
+  /** The argument which should be used to specify the config class. */
   private StringArgument configClass;
-
-  // The argument which should be used to specify the config file.
+  /** The argument which should be used to specify the config file. */
   private StringArgument configFile;
 
-  //The argument which should be used to specify non interactive mode.
+  /** The argument which should be used to specify non interactive mode. */
   private BooleanArgument noPrompt;
   private BooleanArgument ignoreErrors;
   private BooleanArgument force;
@@ -90,20 +87,22 @@
   private BooleanArgument acceptLicense;
 
 
-  // The argument which should be used to request usage information.
+  /** The argument which should be used to request usage information. */
   private BooleanArgument showUsageArgument;
 
-  // Flag indicating whether or not the global arguments have
-  // already been initialized.
-  private boolean globalArgumentsInitialized = false;
+  /**
+   * Flag indicating whether or not the global arguments have
+   * already been initialized.
+   */
+  private boolean globalArgumentsInitialized;
 
   private UpgradeCli(InputStream in, OutputStream out, OutputStream err)
   {
     super(new PrintStream(out), new PrintStream(err));
     this.parser =
-        new SubCommandArgumentParser(this.getClass().getName(),
+        new SubCommandArgumentParser(getClass().getName(),
             INFO_UPGRADE_DESCRIPTION_CLI.get(), false);
-
+    this.parser.setVersionHandler(new DirectoryServerVersionHandler());
   }
 
   /**
@@ -219,7 +218,7 @@
     return acceptLicense.isPresent();
   }
 
-  // Displays the provided message followed by a help usage reference.
+  /** Displays the provided message followed by a help usage reference. */
   private void displayMessageAndUsageReference(final LocalizableMessage message)
   {
     println(message);
@@ -227,20 +226,15 @@
     println(parser.getHelpUsageReference());
   }
 
-  // Initialize arguments provided by the command line.
+  /** Initialize arguments provided by the command line. */
   private void initializeGlobalArguments() throws ArgumentException
   {
     if (!globalArgumentsInitialized)
     {
-      configClass =
-          CommonArguments.getConfigClass(ConfigFileHandler.class.getName());
-
+      configClass = CommonArguments.getConfigClass(ConfigFileHandler.class.getName());
       configFile = CommonArguments.getConfigFile();
-
       noPrompt = CommonArguments.getNoPrompt();
-
       verbose = CommonArguments.getVerbose();
-
       quietMode = CommonArguments.getQuiet();
 
       ignoreErrors =
@@ -253,13 +247,12 @@
           INFO_UPGRADE_OPTION_FORCE.get(OPTION_LONG_NO_PROMPT));
 
       acceptLicense = CommonArguments.getAcceptLicense();
-
       showUsageArgument = CommonArguments.getShowUsage();
 
 
       // Register the global arguments.
       parser.addGlobalArgument(showUsageArgument);
-      parser.setUsageArgument(showUsageArgument, this.getOutputStream());
+      parser.setUsageArgument(showUsageArgument, getOutputStream());
       parser.addGlobalArgument(configClass);
       parser.addGlobalArgument(configFile);
       parser.addGlobalArgument(noPrompt);
@@ -283,7 +276,7 @@
     catch (ArgumentException e)
     {
       final LocalizableMessage message = ERR_CANNOT_INITIALIZE_ARGS.get(e.getMessage());
-      this.getOutputStream().print(message);
+      getOutputStream().print(message);
       return EXIT_CODE_ERROR;
     }
 
@@ -296,7 +289,7 @@
         final LocalizableMessage message =
             ERR_UPGRADE_INCOMPATIBLE_ARGS.get(OPTION_LONG_QUIET,
                 "interactive mode");
-        this.getOutputStream().println(message);
+        getOutputStream().println(message);
         return EXIT_CODE_ERROR;
       }
       if (isInteractive() && isForceUpgrade())
@@ -304,7 +297,7 @@
         final LocalizableMessage message =
             ERR_UPGRADE_INCOMPATIBLE_ARGS.get(OPTION_LONG_FORCE_UPGRADE,
                 "interactive mode");
-        this.getOutputStream().println(message);
+        getOutputStream().println(message);
         return EXIT_CODE_ERROR;
       }
       if (isQuiet() && isVerbose())
@@ -312,7 +305,7 @@
         final LocalizableMessage message =
             ERR_UPGRADE_INCOMPATIBLE_ARGS.get(OPTION_LONG_QUIET,
                 OPTION_LONG_VERBOSE);
-        this.getOutputStream().println(message);
+        getOutputStream().println(message);
         return EXIT_CODE_ERROR;
       }
     }
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/util/Base64.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/util/Base64.java
index bc59e55..4b9dcf6 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/util/Base64.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/util/Base64.java
@@ -22,11 +22,14 @@
  *
  *
  *      Copyright 2006-2009 Sun Microsystems, Inc.
- *      Portions Copyright 2014 ForgeRock AS
+ *      Portions Copyright 2014-2015 ForgeRock AS
  */
 package org.opends.server.util;
 
-
+import static org.forgerock.util.Reject.*;
+import static org.opends.messages.ToolMessages.*;
+import static org.opends.messages.UtilityMessages.*;
+import static org.opends.server.util.StaticUtils.*;
 
 import java.io.BufferedReader;
 import java.io.BufferedWriter;
@@ -45,9 +48,9 @@
 
 import org.forgerock.i18n.LocalizableMessage;
 import org.forgerock.i18n.LocalizableMessageBuilder;
-import org.opends.server.core.DirectoryServer;
-import org.opends.server.types.NullOutputStream;
 import org.forgerock.opendj.ldap.ByteSequence;
+import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
+import org.opends.server.types.NullOutputStream;
 
 import com.forgerock.opendj.cli.ArgumentException;
 import com.forgerock.opendj.cli.BooleanArgument;
@@ -56,13 +59,6 @@
 import com.forgerock.opendj.cli.SubCommand;
 import com.forgerock.opendj.cli.SubCommandArgumentParser;
 
-import static org.opends.messages.UtilityMessages.*;
-import static org.opends.messages.ToolMessages.*;
-import static org.opends.server.util.StaticUtils.*;
-import static org.forgerock.util.Reject.*;
-
-
-
 /**
  * This class provides methods for performing base64 encoding and decoding.
  * Base64 is a mechanism for encoding binary data in ASCII form by converting
@@ -76,16 +72,11 @@
      mayInvoke=true)
 public final class Base64
 {
-  /**
-   * The set of characters that may be used in base64-encoded values.
-   */
+  /** The set of characters that may be used in base64-encoded values. */
   private static final char[] BASE64_ALPHABET =
-       ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" +
-        "0123456789+/").toCharArray();
+      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
 
-  /**
-   * Prevent instance creation.
-   */
+  /** Prevent instance creation. */
   private Base64() {
     // No implementation required.
   }
@@ -476,6 +467,7 @@
     SubCommandArgumentParser argParser =
          new SubCommandArgumentParser(Base64.class.getName(), description,
                                       false);
+    argParser.setVersionHandler(new DirectoryServerVersionHandler());
 
     BooleanArgument showUsage        = null;
     StringArgument  encodedData      = null;
@@ -583,19 +575,8 @@
 
     if (argParser.isVersionArgumentPresent())
     {
-      // We have to print the version since we have set a NullOutputStream on
-      // the parser
-      try
-      {
-        DirectoryServer.printVersion(System.out);
-        System.exit(0);
-      }
-      catch (Throwable t)
-      {
-        // Bug
-        System.err.println(ERR_UNEXPECTED.get(t));
-        System.exit(1);
-      }
+      // version has already been printed
+      System.exit(0);
     }
 
     if (subCommand == null)
@@ -785,4 +766,3 @@
     }
   }
 }
-
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/util/args/LDAPConnectionArgumentParser.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/util/args/LDAPConnectionArgumentParser.java
index 4de6c39..ebe09ef 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/util/args/LDAPConnectionArgumentParser.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/util/args/LDAPConnectionArgumentParser.java
@@ -22,11 +22,14 @@
  *
  *
  *      Copyright 2008-2010 Sun Microsystems, Inc.
- *      Portions Copyright 2011-2014 ForgeRock AS
+ *      Portions Copyright 2011-2015 ForgeRock AS
  */
-
 package org.opends.server.util.args;
 
+import static com.forgerock.opendj.cli.Utils.*;
+
+import static org.opends.messages.ToolMessages.*;
+
 import java.io.PrintStream;
 import java.util.LinkedHashSet;
 import java.util.LinkedList;
@@ -36,28 +39,24 @@
 
 import org.forgerock.i18n.LocalizableMessage;
 import org.opends.server.admin.client.cli.SecureConnectionCliArgs;
-
+import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.opends.server.tools.LDAPConnection;
-import org.opends.server.tools.LDAPConnectionOptions;
-import org.opends.server.tools.SSLConnectionFactory;
-import org.opends.server.tools.SSLConnectionException;
 import org.opends.server.tools.LDAPConnectionException;
+import org.opends.server.tools.LDAPConnectionOptions;
+import org.opends.server.tools.SSLConnectionException;
+import org.opends.server.tools.SSLConnectionFactory;
 import org.opends.server.types.OpenDsException;
 import org.opends.server.util.cli.LDAPConnectionConsoleInteraction;
 
 import com.forgerock.opendj.cli.Argument;
 import com.forgerock.opendj.cli.ArgumentException;
-import com.forgerock.opendj.cli.ArgumentParser;
 import com.forgerock.opendj.cli.ArgumentGroup;
+import com.forgerock.opendj.cli.ArgumentParser;
 import com.forgerock.opendj.cli.ClientException;
 import com.forgerock.opendj.cli.ConsoleApplication;
 import com.forgerock.opendj.cli.FileBasedArgument;
 import com.forgerock.opendj.cli.StringArgument;
 
-import static org.opends.messages.ToolMessages.*;
-import static org.opends.server.util.ServerConstants.*;
-import static com.forgerock.opendj.cli.Utils.wrapText;
-
 /**
  * Creates an argument parser pre-populated with arguments for specifying
  * information for opening and LDAPConnection an LDAP connection.
@@ -92,6 +91,7 @@
                                       boolean alwaysSSL) {
     super(mainClassName, toolDescription, longArgumentsCaseSensitive);
     addLdapConnectionArguments(argumentGroup, alwaysSSL);
+    setVersionHandler(new DirectoryServerVersionHandler());
   }
 
   /**

--
Gitblit v1.10.0