mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noel Rouvignac
20.17.2015 dfcb1b5674ba90e20a12c34c45016920531b1a44
More code cleanup


ArgumentParser.java:
- removed unnecessary exposed add*Argument() methods.
- extracted methods
- factorized code with sub class SubCommandArgumentParser with printLineForShortLongArgument()

SubCommandArgumentParser.java:
- Preferred using StringBuilder instead of LocalizedMessageBuilder
5 files modified
348 ■■■■■ changed files
opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java 166 ●●●●● patch | view | raw | blame | history
opendj-cli/src/main/java/com/forgerock/opendj/cli/ConnectionFactoryProvider.java 51 ●●●●● patch | view | raw | blame | history
opendj-cli/src/main/java/com/forgerock/opendj/cli/SubCommandArgumentParser.java 108 ●●●● patch | view | raw | blame | history
opendj-cli/src/test/java/com/forgerock/opendj/cli/TestSubCommandArgumentParserTestCase.java 20 ●●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/util/Base64.java 3 ●●●● patch | view | raw | blame | history
opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java
@@ -157,20 +157,20 @@
    private String[] rawArguments;
    /** Set of argument groups. */
    protected Set<ArgumentGroup> argumentGroups;
    protected final Set<ArgumentGroup> argumentGroups = new TreeSet<ArgumentGroup>();
    /**
     * Group for arguments that have not been explicitly grouped. These will
     * appear at the top of the usage statement without a header.
     */
    private final ArgumentGroup defaultArgGroup = new ArgumentGroup(LocalizableMessage.EMPTY,
            Integer.MAX_VALUE);
    private final ArgumentGroup defaultArgGroup = new ArgumentGroup(
            LocalizableMessage.EMPTY, Integer.MAX_VALUE);
    /**
     * Group for arguments that are related to connection through LDAP. This
     * includes options like the bind DN, the port, etc.
     */
    private final ArgumentGroup ldapArgGroup = new ArgumentGroup(
    final ArgumentGroup ldapArgGroup = new ArgumentGroup(
            INFO_DESCRIPTION_LDAP_CONNECTION_ARGS.get(), Integer.MIN_VALUE + 2);
    /**
@@ -178,15 +178,15 @@
     * properties file, no-prompt etc. These will appear toward the bottom of
     * the usage statement.
     */
    protected final ArgumentGroup ioArgGroup = new ArgumentGroup(INFO_DESCRIPTION_IO_ARGS.get(),
            Integer.MIN_VALUE + 1);
    private final ArgumentGroup ioArgGroup = new ArgumentGroup(
            INFO_DESCRIPTION_IO_ARGS.get(), Integer.MIN_VALUE + 1);
    /**
     * Group for arguments that are general like help, version etc. These will
     * appear at the end of the usage statement.
     */
    private final ArgumentGroup generalArgGroup = new ArgumentGroup(INFO_DESCRIPTION_GENERAL_ARGS
            .get(), Integer.MIN_VALUE);
    private final ArgumentGroup generalArgGroup = new ArgumentGroup(
            INFO_DESCRIPTION_GENERAL_ARGS.get(), Integer.MIN_VALUE);
    private static final String INDENT = "    ";
@@ -273,22 +273,6 @@
     *             has already been defined.
     */
    public void addArgument(final Argument argument) throws ArgumentException {
        addArgument(argument, null);
    }
    /**
     * Adds the provided argument to the set of arguments handled by this
     * parser.
     *
     * @param argument
     *            The argument to be added.
     * @param group
     *            The argument group to which the argument belongs.
     * @throws ArgumentException
     *             If the provided argument conflicts with another argument that
     *             has already been defined.
     */
    public void addArgument(final Argument argument, ArgumentGroup group) throws ArgumentException {
        final Character shortID = argument.getShortIdentifier();
        if (shortID != null && shortIDMap.containsKey(shortID)) {
            final String conflictingName = shortIDMap.get(shortID).getName();
@@ -332,9 +316,7 @@
        argumentList.add(argument);
        if (group == null) {
            group = getStandardGroup(argument);
        }
        final ArgumentGroup group = getStandardGroup(argument);
        group.addArgument(argument);
        argumentGroups.add(group);
    }
@@ -345,62 +327,6 @@
    }
    /**
     * Adds the provided argument to the set of arguments handled by this parser
     * and puts the argument in the default group.
     *
     * @param argument
     *            The argument to be added.
     * @throws ArgumentException
     *             If the provided argument conflicts with another argument that
     *             has already been defined.
     */
    protected void addDefaultArgument(final Argument argument) throws ArgumentException {
        addArgument(argument, defaultArgGroup);
    }
    /**
     * Adds the provided argument to the set of arguments handled by this parser
     * and puts the argument in the general group.
     *
     * @param argument
     *            The argument to be added.
     * @throws ArgumentException
     *             If the provided argument conflicts with another argument that
     *             has already been defined.
     */
    void addGeneralArgument(final Argument argument) throws ArgumentException {
        addArgument(argument, generalArgGroup);
    }
    /**
     * Adds the provided argument to the set of arguments handled by this parser
     * and puts the argument in the input/output group.
     *
     * @param argument
     *            The argument to be added.
     * @throws ArgumentException
     *             If the provided argument conflicts with another argument that
     *             has already been defined.
     */
    public void addInputOutputArgument(final Argument argument) throws ArgumentException {
        addArgument(argument, ioArgGroup);
    }
    /**
     * Adds the provided argument to the set of arguments handled by this parser
     * and puts the argument in the LDAP connection group.
     *
     * @param argument
     *            The argument to be added.
     * @throws ArgumentException
     *             If the provided argument conflicts with another argument that
     *             has already been defined.
     */
    public void addLdapConnectionArgument(final Argument argument) throws ArgumentException {
        addArgument(argument, ldapArgGroup);
    }
    /**
     * Indicates whether this parser will allow unnamed trailing arguments.
     * These will be arguments at the end of the list that are not preceded by
     * either a long or short identifier and will need to be manually parsed by
@@ -752,7 +678,7 @@
                }
                // Help argument should be printed at the end
                if (usageArgument != null && usageArgument.getName().equals(a.getName())) {
                if (isUsageArgument(a)) {
                    helpArgument = a;
                    continue;
                }
@@ -778,6 +704,16 @@
    }
    /**
     * Returns whether the provided argument is the usage argument.
     *
     * @param a the argument to test
     * @return true if the provided argument is the usage argument, false otherwise
     */
    boolean isUsageArgument(final Argument a) {
        return usageArgument != null && usageArgument.getName().equals(a.getName());
    }
    /**
     * Retrieves a message containing usage information based on the defined
     * arguments.
     *
@@ -906,8 +842,7 @@
                    // token.
                } else if (equalPos == 0) {
                    // The argument starts with "--=", which is not acceptable.
                    final LocalizableMessage message = ERR_ARGPARSER_LONG_ARG_WITHOUT_NAME.get(arg);
                    throw new ArgumentException(message);
                    throw new ArgumentException(ERR_ARGPARSER_LONG_ARG_WITHOUT_NAME.get(arg));
                } else {
                    // The argument is in the form --name=value, so parse them
                    // both out.
@@ -931,8 +866,7 @@
                        writeToUsageOutputStream(getUsage());
                        return;
                    } else if (versionHandler != null && OPTION_LONG_PRODUCT_VERSION.equals(argName)) {
                        // "--version" will always be interpreted as requesting
                        // version information.
                        // "--version" will always be interpreted as requesting version information.
                        printVersion();
                        return;
                    } else {
@@ -945,7 +879,7 @@
                    // If this is the usage argument, then immediately stop and
                    // print usage information.
                    if (usageArgument != null && usageArgument.getName().equals(a.getName())) {
                    if (isUsageArgument(a)) {
                        writeToUsageOutputStream(getUsage());
                        return;
                    }
@@ -1019,7 +953,7 @@
                    // If this is the usage argument, then immediately stop and
                    // print usage information.
                    if (usageArgument != null && usageArgument.getName().equals(a.getName())) {
                    if (isUsageArgument(a)) {
                        writeToUsageOutputStream(getUsage());
                        return;
                    }
@@ -1074,7 +1008,7 @@
                            // If this is the usage argument,
                            // then immediately stop and print usage information.
                            if (usageArgument != null && usageArgument.getName().equals(b.getName())) {
                            if (isUsageArgument(b)) {
                                writeToUsageOutputStream(getUsage());
                                return;
                            }
@@ -1338,7 +1272,6 @@
    }
    private void initGroups() {
        this.argumentGroups = new TreeSet<ArgumentGroup>();
        this.argumentGroups.add(defaultArgGroup);
        this.argumentGroups.add(ldapArgGroup);
        this.argumentGroups.add(generalArgGroup);
@@ -1415,15 +1348,36 @@
     *            The buffer to which the usage information should be appended.
     */
    private void printArgumentUsage(final Argument a, final StringBuilder buffer) {
        // Write a line with the short and/or long identifiers that may be
        // used for the argument.
        printLineForShortLongArgument(a, buffer);
        // Write one or more lines with the description of the argument.
        // We will indent the description five characters and try our best to wrap
        // at or before column 79 so it will be friendly to 80-column displays.
        final int indentLength = INDENT.length();
        buffer.append(wrapText(a.getDescription(), MAX_LINE_WIDTH, indentLength));
        buffer.append(EOL);
        if (a.needsValue() && a.getDefaultValue() != null && a.getDefaultValue().length() > 0) {
            buffer.append(INDENT);
            buffer.append(INFO_ARGPARSER_USAGE_DEFAULT_VALUE.get(a.getDefaultValue()));
            buffer.append(EOL);
        }
    }
    /**
     * Appends a line with the short and/or long identifiers that may be used for the argument to the provided string
     * builder.
     *
     * @param a the argument for which to print a line
     * @param buffer the string builder where to append the line
     */
    void printLineForShortLongArgument(final Argument a, final StringBuilder buffer) {
        final Character shortID = a.getShortIdentifier();
        final String longID = a.getLongIdentifier();
        if (shortID != null) {
            final int currentLength = buffer.length();
            if (usageArgument.getName().equals(a.getName())) {
            if (isUsageArgument(a)) {
                buffer.append("-?, ");
            }
@@ -1454,7 +1408,7 @@
            buffer.append(EOL);
        } else if (longID != null) {
            if (usageArgument.getName().equals(a.getName())) {
            if (isUsageArgument(a)) {
                buffer.append("-?, ");
            }
            buffer.append("--");
@@ -1467,33 +1421,19 @@
            buffer.append(EOL);
        }
        // Write one or more lines with the description of the argument.
        // We will indent the description five characters and try our best to wrap
        // at or before column 79 so it will be friendly to 80-column displays.
        buffer.append(wrapText(a.getDescription(), MAX_LINE_WIDTH, indentLength));
        buffer.append(EOL);
        if (a.needsValue() && a.getDefaultValue() != null && a.getDefaultValue().length() > 0) {
            buffer.append(INDENT);
            buffer.append(INFO_ARGPARSER_USAGE_DEFAULT_VALUE.get(a.getDefaultValue()));
            buffer.append(EOL);
        }
    }
    void normalizeArguments(final Properties argumentProperties, final List<Argument> arguments)
            throws ArgumentException {
        for (final Argument a : arguments) {
            if (!a.isPresent()
            // See if there is a value in the properties that can be used
                    // See if there is a value in the properties that can be used
                    && argumentProperties != null && a.getPropertyName() != null) {
                final String value = argumentProperties.getProperty(a.getPropertyName().toLowerCase());
                final LocalizableMessageBuilder invalidReason = new LocalizableMessageBuilder();
                if (value != null) {
                    Boolean addValue = true;
                    if (!(a instanceof BooleanArgument)) {
                        addValue = a.valueIsAcceptable(value, invalidReason);
                    }
                    boolean addValue = !(a instanceof BooleanArgument)
                            && a.valueIsAcceptable(value, invalidReason);
                    if (addValue) {
                        a.addValue(value);
                        if (a.needsValue()) {
opendj-cli/src/main/java/com/forgerock/opendj/cli/ConnectionFactoryProvider.java
@@ -22,7 +22,7 @@
 *
 *
 *      Copyright 2010 Sun Microsystems, Inc.
 *      Portions copyright 2011-2014 ForgeRock AS
 *      Portions copyright 2011-2015 ForgeRock AS
 */
package com.forgerock.opendj.cli;
@@ -74,19 +74,16 @@
    /** The 'hostName' global argument. */
    private StringArgument hostNameArg;
    /** The 'port' global argument. */
    private IntegerArgument portArg;
    /** The 'bindDN' global argument. */
    private StringArgument bindNameArg;
    /** The 'bindPasswordFile' global argument. */
    private FileBasedArgument bindPasswordFileArg;
    /** The 'password' value. */
    private char[] password;
    /** The 'bindPassword' global argument. */
    private StringArgument bindPasswordArg;
@@ -95,22 +92,17 @@
    /** The 'trustAllArg' global argument. */
    private BooleanArgument trustAllArg;
    /** The 'trustStore' global argument. */
    private StringArgument trustStorePathArg;
    /** The 'trustStorePassword' global argument. */
    private StringArgument trustStorePasswordArg;
    /** The 'trustStorePasswordFile' global argument. */
    private FileBasedArgument trustStorePasswordFileArg;
    /** The 'keyStore' global argument. */
    private StringArgument keyStorePathArg;
    /** The 'keyStorePassword' global argument. */
    private StringArgument keyStorePasswordArg;
    /** The 'keyStorePasswordFile' global argument. */
    private FileBasedArgument keyStorePasswordFileArg;
@@ -119,10 +111,8 @@
    /** The 'useSSLArg' global argument. */
    private BooleanArgument useSSLArg;
    /** The 'useStartTLSArg' global argument. */
    private BooleanArgument useStartTLSArg;
    /** Argument indicating a SASL option. */
    private StringArgument saslOptionArg;
@@ -132,9 +122,7 @@
     */
    private final BooleanArgument reportAuthzIDArg;
    /**
     * Whether to use the password policy control in the bind request.
     */
    /** Whether to use the password policy control in the bind request. */
    private final BooleanArgument usePasswordPolicyControlArg;
    /** The port number to used to connect. */
@@ -145,7 +133,6 @@
    /**  The basic connection factory. */
    private ConnectionFactory connFactory;
    /** The authenticated connection factory. */
    protected ConnectionFactory authenticatedConnFactory;
@@ -195,10 +182,10 @@
            final ConsoleApplication app, final String defaultBindDN, final int defaultPort,
            final boolean alwaysSSL) throws ArgumentException {
        this.app = app;
        useSSLArg = CommonArguments.getUseSSL();
        useSSLArg = CommonArguments.getUseSSL();
        if (!alwaysSSL) {
            argumentParser.addLdapConnectionArgument(useSSLArg);
            argumentParser.addArgument(useSSLArg);
        } else {
            // simulate that the useSSL arg has been given in the CLI
            useSSLArg.setPresent(true);
@@ -206,7 +193,7 @@
        useStartTLSArg = CommonArguments.getStartTLS();
        if (!alwaysSSL) {
            argumentParser.addLdapConnectionArgument(useStartTLSArg);
            argumentParser.addArgument(useStartTLSArg);
        }
        String defaultHostName;
@@ -216,7 +203,7 @@
            defaultHostName = "Unknown (" + e + ")";
        }
        hostNameArg = CommonArguments.getHostName(defaultHostName);
        argumentParser.addLdapConnectionArgument(hostNameArg);
        argumentParser.addArgument(hostNameArg);
        LocalizableMessage portDescription = INFO_DESCRIPTION_PORT.get();
        if (alwaysSSL) {
@@ -224,43 +211,43 @@
        }
        portArg = CommonArguments.getPort(defaultPort, portDescription);
        argumentParser.addLdapConnectionArgument(portArg);
        argumentParser.addArgument(portArg);
        bindNameArg = CommonArguments.getBindDN(defaultBindDN);
        argumentParser.addLdapConnectionArgument(bindNameArg);
        argumentParser.addArgument(bindNameArg);
        bindPasswordArg = CommonArguments.getBindPassword();
        argumentParser.addLdapConnectionArgument(bindPasswordArg);
        argumentParser.addArgument(bindPasswordArg);
        bindPasswordFileArg = CommonArguments.getBindPasswordFile();
        argumentParser.addLdapConnectionArgument(bindPasswordFileArg);
        argumentParser.addArgument(bindPasswordFileArg);
        saslOptionArg = CommonArguments.getSASL();
        argumentParser.addLdapConnectionArgument(saslOptionArg);
        argumentParser.addArgument(saslOptionArg);
        trustAllArg = CommonArguments.getTrustAll();
        argumentParser.addLdapConnectionArgument(trustAllArg);
        argumentParser.addArgument(trustAllArg);
        trustStorePathArg = CommonArguments.getTrustStorePath();
        argumentParser.addLdapConnectionArgument(trustStorePathArg);
        argumentParser.addArgument(trustStorePathArg);
        trustStorePasswordArg = CommonArguments.getTrustStorePassword();
        argumentParser.addLdapConnectionArgument(trustStorePasswordArg);
        argumentParser.addArgument(trustStorePasswordArg);
        trustStorePasswordFileArg = CommonArguments.getTrustStorePasswordFile();
        argumentParser.addLdapConnectionArgument(trustStorePasswordFileArg);
        argumentParser.addArgument(trustStorePasswordFileArg);
        keyStorePathArg = CommonArguments.getKeyStorePath();
        argumentParser.addLdapConnectionArgument(keyStorePathArg);
        argumentParser.addArgument(keyStorePathArg);
        keyStorePasswordArg = CommonArguments.getKeyStorePassword();
        argumentParser.addLdapConnectionArgument(keyStorePasswordArg);
        argumentParser.addArgument(keyStorePasswordArg);
        keyStorePasswordFileArg = CommonArguments.getKeyStorePasswordFile();
        argumentParser.addLdapConnectionArgument(keyStorePasswordFileArg);
        argumentParser.addArgument(keyStorePasswordFileArg);
        certNicknameArg = CommonArguments.getCertNickName();
        argumentParser.addLdapConnectionArgument(certNicknameArg);
        argumentParser.addArgument(certNicknameArg);
        reportAuthzIDArg = CommonArguments.getReportAuthzId();
        argumentParser.addArgument(reportAuthzIDArg);
opendj-cli/src/main/java/com/forgerock/opendj/cli/SubCommandArgumentParser.java
@@ -244,20 +244,15 @@
        addGlobalArgument(argument, null);
    }
    /**
     * Adds the provided argument to the set of arguments handled by this parser and puts the argument in the LDAP
     * connection group.
     *
     * @param argument
     *            The argument to add to this sub command.
     * @throws ArgumentException
     *             If the provided argument conflicts with another global or subcommand argument that has already been
     *             defined.
     */
    /** {@inheritDoc} */
    @Override
    public void addLdapConnectionArgument(final Argument argument) throws ArgumentException {
        addGlobalArgument(argument, null);
    public void addArgument(Argument argument) throws ArgumentException {
        final ArgumentGroup group = getStandardGroup(argument);
        if (group == ldapArgGroup) {
            addGlobalArgument(argument);
        } else {
            super.addArgument(argument);
        }
    }
    /**
@@ -501,8 +496,7 @@
                            writeToUsageOutputStream(getUsage());
                            return;
                        } else if (OPTION_LONG_PRODUCT_VERSION.equals(argName) && getVersionHandler() != null) {
                            // "--version" will always be interpreted as requesting usage
                            // information.
                            // "--version" will always be interpreted as requesting usage information.
                            printVersion();
                            return;
                        } else if (subCommand != null) {
@@ -765,7 +759,7 @@
     * @param subCommand
     *            The subcommand for which to display the usage information.
     */
    public void getSubCommandUsage(LocalizableMessageBuilder buffer, SubCommand subCommand) {
    public void getSubCommandUsage(StringBuilder buffer, SubCommand subCommand) {
        setUsageOrVersionDisplayed(true);
        String scriptName = System.getProperty(PROPERTY_SCRIPT_NAME);
        if (scriptName == null || scriptName.length() == 0) {
@@ -801,64 +795,13 @@
            buffer.append(EOL);
        }
        final Argument usageArgument = getUsageArgument();
        for (Argument a : subCommand.getArguments()) {
            // If this argument is hidden, then skip it.
            if (a.isHidden()) {
                continue;
            }
            // Write a line with the short and/or long identifiers that may be used
            // for the argument.
            Character shortID = a.getShortIdentifier();
            String longID = a.getLongIdentifier();
            if (shortID != null) {
                int currentLength = buffer.length();
                if (a.equals(usageArgument)) {
                    buffer.append("-?, ");
                }
                buffer.append("-");
                buffer.append(shortID.charValue());
                if (a.needsValue() && longID == null) {
                    buffer.append(" ");
                    buffer.append(a.getValuePlaceholder());
                }
                if (longID != null) {
                    StringBuilder newBuffer = new StringBuilder();
                    newBuffer.append(", --");
                    newBuffer.append(longID);
                    if (a.needsValue()) {
                        newBuffer.append(" ");
                        newBuffer.append(a.getValuePlaceholder());
                    }
                    int lineLength = (buffer.length() - currentLength) + newBuffer.length();
                    if (lineLength > MAX_LINE_WIDTH) {
                        buffer.append(EOL);
                    }
                    buffer.append(newBuffer);
                }
                buffer.append(EOL);
            } else if (longID != null) {
                if (a.equals(usageArgument)) {
                    buffer.append("-?, ");
                }
                buffer.append("--");
                buffer.append(longID);
                if (a.needsValue()) {
                    buffer.append(" ");
                    buffer.append(a.getValuePlaceholder());
                }
                buffer.append(EOL);
            }
            printLineForShortLongArgument(a, buffer);
            indentAndWrap2(INDENT, a.getDescription(), buffer);
            if (a.needsValue() && a.getDefaultValue() != null && a.getDefaultValue().length() > 0) {
@@ -873,7 +816,7 @@
     * <p>
     * FIXME Try to merge with #indentAndWrap(LocalizableMessage, LocalizableMessage, LocalizableMessageBuilder).
     */
    private void indentAndWrap2(String indent, LocalizableMessage text, LocalizableMessageBuilder buffer) {
    private void indentAndWrap2(String indent, LocalizableMessage text, StringBuilder buffer) {
        int actualSize = MAX_LINE_WIDTH - indent.length() - 1;
        indentAndWrap(indent, actualSize, text, buffer);
    }
@@ -885,7 +828,7 @@
     */
    @Override
    public String getUsage() {
        LocalizableMessageBuilder buffer = new LocalizableMessageBuilder();
        final StringBuilder buffer = new StringBuilder();
        if (subCommand == null) {
            if (System.getProperty("org.forgerock.opendj.gendoc") != null) {
@@ -905,7 +848,7 @@
            getSubCommandUsage(buffer, subCommand);
        }
        return buffer.toMessage().toString();
        return buffer.toString();
    }
    /**
@@ -940,15 +883,15 @@
    /** Get usage for a specific usage argument. */
    private void getUsage(Argument a) {
        LocalizableMessageBuilder buffer = new LocalizableMessageBuilder();
        final StringBuilder buffer = new StringBuilder();
        final Argument usageArgument = getUsageArgument();
        if (a.equals(usageArgument) && subCommand != null) {
        final boolean isUsageArgument = isUsageArgument(a);
        if (isUsageArgument && subCommand != null) {
            getSubCommandUsage(buffer, subCommand);
        } else if (a.equals(usageArgument) && usageGroupArguments.size() <= 1) {
        } else if (isUsageArgument && usageGroupArguments.size() <= 1) {
            // No groups - so display all sub-commands.
            getFullUsage(subCommands.values(), true, buffer);
        } else if (a.equals(usageArgument)) {
        } else if (isUsageArgument) {
            // Using groups - so display all sub-commands group help.
            getFullUsage(Collections.<SubCommand> emptySet(), true, buffer);
        } else {
@@ -962,7 +905,7 @@
    /**
     * Appends complete usage information for the specified set of sub-commands.
     */
    private void getFullUsage(Collection<SubCommand> c, boolean showGlobalOptions, LocalizableMessageBuilder buffer) {
    private void getFullUsage(Collection<SubCommand> c, boolean showGlobalOptions, StringBuilder buffer) {
        setUsageOrVersionDisplayed(true);
        final LocalizableMessage toolDescription = getToolDescription();
@@ -996,7 +939,6 @@
            buffer.append(EOL);
        }
        final Argument usageArgument = getUsageArgument();
        if (c.isEmpty()) {
            // Display usage arguments (except the default one).
            for (Argument a : globalArgumentList) {
@@ -1004,7 +946,7 @@
                    continue;
                }
                if (usageGroupArguments.containsKey(a) && !a.equals(usageArgument)) {
                if (usageGroupArguments.containsKey(a) && !isUsageArgument(a)) {
                    printArgumentUsage(a, buffer);
                }
            }
@@ -1061,6 +1003,7 @@
            }
            // Finally print default usage argument.
            final Argument usageArgument = getUsageArgument();
            if (usageArgument != null) {
                printArgumentUsage(usageArgument, buffer);
            } else {
@@ -1078,7 +1021,7 @@
     * @param buffer
     *            The buffer to which the usage information should be appended.
     */
    private void printArgumentUsage(Argument a, LocalizableMessageBuilder buffer) {
    private void printArgumentUsage(Argument a, StringBuilder buffer) {
        String value;
        if (a.needsValue()) {
            LocalizableMessage pHolder = a.getValuePlaceholder();
@@ -1130,13 +1073,12 @@
     * Write one or more lines with the description of the argument. We will indent the description five characters and
     * try our best to wrap at or before column 79 so it will be friendly to 80-column displays.
     */
    private void indentAndWrap(String indent, LocalizableMessage text, LocalizableMessageBuilder buffer) {
    private void indentAndWrap(String indent, LocalizableMessage text, StringBuilder buffer) {
        int actualSize = MAX_LINE_WIDTH - indent.length();
        indentAndWrap(indent, actualSize, text, buffer);
    }
    static void indentAndWrap(String indent, int actualSize, LocalizableMessage text,
            LocalizableMessageBuilder buffer) {
    static void indentAndWrap(String indent, int actualSize, LocalizableMessage text, StringBuilder buffer) {
        if (text.length() <= actualSize) {
            buffer.append(indent);
            buffer.append(text);
opendj-cli/src/test/java/com/forgerock/opendj/cli/TestSubCommandArgumentParserTestCase.java
@@ -22,23 +22,22 @@
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 *      Portions Copyright 2014 ForgeRock AS
 *      Portions Copyright 2014-2015 ForgeRock AS
 */
package com.forgerock.opendj.cli;
import static com.forgerock.opendj.cli.CliMessages.*;
import java.util.ArrayList;
import java.util.List;
import org.fest.assertions.Assertions;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.LocalizableMessageBuilder;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static com.forgerock.opendj.cli.CliMessages.*;
/**
 * Unit tests for the SubCommand class.
 */
@@ -49,7 +48,6 @@
    /** First sub-command. */
    private SubCommand sc1;
    /** Second sub-command. */
    private SubCommand sc2;
@@ -88,7 +86,9 @@
     */
    @DataProvider(name = "validCommandLineArgs")
    public Object[][] createValidCommandLineArgs() {
        return new Object[][] { { new String[] {}, null }, { new String[] { "sub-command1" }, sc1 },
        return new Object[][] {
            { new String[] {}, null },
            { new String[] { "sub-command1" }, sc1 },
            { new String[] { "sub-command2", "one", "two" }, sc2 },
            { new String[] { "sub-command2", "one", "two", "three" }, sc2 },
            { new String[] { "sub-command2", "one", "two", "three", "four" }, sc2 }, };
@@ -131,8 +131,10 @@
     */
    @DataProvider(name = "invalidCommandLineArgs")
    public Object[][] createInvalidCommandLineArgs() {
        return new Object[][] { { new String[] { "sub-command1", "one" } },
            { new String[] { "sub-command1", "one", "two" } }, { new String[] { "sub-command2" } },
        return new Object[][] {
            { new String[] { "sub-command1", "one" } },
            { new String[] { "sub-command1", "one", "two" } },
            { new String[] { "sub-command2" } },
            { new String[] { "sub-command2", "one" } },
            { new String[] { "sub-command2", "one", "two", "three", "four", "five" } }, };
    }
@@ -162,7 +164,7 @@
    @Test(dataProvider = "indentAndWrapProvider")
    public void testIndentAndWrap(String text, int wrapColumn, String indent, String expected) {
        final LocalizableMessageBuilder buffer = new LocalizableMessageBuilder();
        final StringBuilder buffer = new StringBuilder();
        SubCommandArgumentParser.indentAndWrap(indent, wrapColumn, LocalizableMessage.raw(text), buffer);
        Assertions.assertThat(buffer.toString()).isEqualTo(expected);
    }
opendj3-server-dev/src/server/org/opends/server/util/Base64.java
@@ -47,7 +47,6 @@
import java.util.StringTokenizer;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.LocalizableMessageBuilder;
import org.forgerock.opendj.ldap.ByteSequence;
import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
import org.opends.server.types.NullOutputStream;
@@ -565,7 +564,7 @@
      }
      else
      {
        LocalizableMessageBuilder messageBuilder = new LocalizableMessageBuilder();
        final StringBuilder messageBuilder = new StringBuilder();
        argParser.getSubCommandUsage(messageBuilder, subCommand);
        System.out.println(messageBuilder.toString());
      }