From 8f434776744e26ae11fe4d7e395837f62461dc59 Mon Sep 17 00:00:00 2001
From: Violette Roche-Montane <violette.roche-montane@forgerock.com>
Date: Wed, 29 Jan 2014 11:57:22 +0000
Subject: [PATCH] OPENDJ-1303 Split out CLI support from opendj-ldap-toolkit into a separate Maven module, "opendj-cli" - Add dependency to opendj-cli module. - Classes modified in order to take into account this change. - Fixed comments.
---
opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFSearch.java | 38
opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/AuthRate.java | 53 +-
opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/DataSource.java | 5
opendj-ldap-toolkit/src/test/java/com/forgerock/opendj/ldap/tools/MakeLDIFTestCase.java | 6
opendj-ldap-toolkit/src/test/java/com/forgerock/opendj/ldap/tools/ConnectionFactoryProviderTest.java | 5
opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ConnectionFactoryProvider.java | 31
opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/MakeLDIF.java | 15
opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PerformanceRunner.java | 12
opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/SearchRate.java | 41
/dev/null | 625 ------------------------
opendj-ldap-toolkit/pom.xml | 5
opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFModify.java | 32
opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPCompare.java | 57 -
opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPSearch.java | 75 +-
opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFDiff.java | 29
opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PromptingTrustManager.java | 3
opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPPasswordModify.java | 44
opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPModify.java | 58 -
opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/Utils.java | 329 ------------
opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ModRate.java | 44
20 files changed, 293 insertions(+), 1,214 deletions(-)
diff --git a/opendj-ldap-toolkit/pom.xml b/opendj-ldap-toolkit/pom.xml
index f96b6aa..c1bbb87 100644
--- a/opendj-ldap-toolkit/pom.xml
+++ b/opendj-ldap-toolkit/pom.xml
@@ -57,6 +57,11 @@
<artifactId>i18n-core</artifactId>
</dependency>
<dependency>
+ <groupId>org.forgerock.opendj</groupId>
+ <artifactId>opendj-cli</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.forgerock</groupId>
<artifactId>forgerock-build-tools</artifactId>
<version>${forgerockBuildToolsVersion}</version>
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/Argument.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/Argument.java
deleted file mode 100644
index 11c5a55..0000000
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/Argument.java
+++ /dev/null
@@ -1,650 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at legal-notices/CDDLv1_0.txt.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Copyright 2006-2008 Sun Microsystems, Inc.
- */
-package com.forgerock.opendj.ldap.tools;
-
-import static com.forgerock.opendj.ldap.tools.ToolsMessages.*;
-import static com.forgerock.opendj.util.StaticUtils.toLowerCase;
-
-import java.util.Iterator;
-import java.util.LinkedList;
-
-import org.forgerock.i18n.LocalizableMessage;
-import org.forgerock.i18n.LocalizableMessageBuilder;
-
-/**
- * This class defines a generic argument that may be used in the argument list
- * for an application. This is an abstract class that must be subclassed in
- * order to provide specific functionality.
- */
-abstract class Argument {
- // Indicates whether this argument should be hidden in the usage
- // information.
- private boolean isHidden;
-
- // Indicates whether this argument may be specified more than once for
- // multiple values.
- private boolean isMultiValued;
-
- // Indicates whether this argument was provided in the set of
- // command-line
- // arguments.
- private boolean isPresent;
-
- // Indicates whether this argument is required to have a value.
- private boolean isRequired;
-
- // Indicates whether this argument requires a value.
- private boolean needsValue;
-
- // The single-character identifier for this argument.
- private final Character shortIdentifier;
-
- // The unique ID of the description for this argument.
- private final LocalizableMessage description;
-
- // The set of values for this argument.
- private final LinkedList<String> values;
-
- // The default value for the argument if none other is provided.
- private String defaultValue;
-
- // The long identifier for this argument.
- private final String longIdentifier;
-
- // The generic name that will be used to refer to this argument.
- private final String name;
-
- // The name of the property that can be used to set the default value.
- private String propertyName;
-
- // The value placeholder for this argument, which will be used in
- // usage
- // information.
- private LocalizableMessage valuePlaceholder;
-
- // Indicates whether this argument was provided in the set of
- // properties
- // found is a properties file.
- private boolean isValueSetByProperty;
-
- /**
- * Creates a new argument with the provided information.
- *
- * @param name
- * The generic name that should be used to refer to this
- * argument.
- * @param shortIdentifier
- * The single-character identifier for this argument, or
- * <CODE>null</CODE> if there is none.
- * @param longIdentifier
- * The long identifier for this argument, or <CODE>null</CODE> if
- * there is none.
- * @param isRequired
- * Indicates whether this argument must be specified on the
- * command line.
- * @param isMultiValued
- * Indicates whether this argument may be specified more than
- * once to provide multiple values.
- * @param needsValue
- * Indicates whether this argument requires a value.
- * @param valuePlaceholder
- * The placeholder for the argument value that will be displayed
- * in usage information, or <CODE>null</CODE> if this argument
- * does not require a value.
- * @param defaultValue
- * The default value that should be used for this argument if
- * none is provided in a properties file or on the command line.
- * This may be <CODE>null</CODE> if there is no generic default.
- * @param propertyName
- * The name of the property in a property file that may be used
- * to override the default value but will be overridden by a
- * command-line argument.
- * @param description
- * LocalizableMessage for the description of this argument.
- * @throws ArgumentException
- * If there is a problem with any of the parameters used to
- * create this argument.
- */
- protected Argument(final String name, final Character shortIdentifier,
- final String longIdentifier, final boolean isRequired, final boolean isMultiValued,
- final boolean needsValue, final LocalizableMessage valuePlaceholder,
- final String defaultValue, final String propertyName,
- final LocalizableMessage description) throws ArgumentException {
- this.name = name;
- this.shortIdentifier = shortIdentifier;
- this.longIdentifier = longIdentifier;
- this.isRequired = isRequired;
- this.isMultiValued = isMultiValued;
- this.needsValue = needsValue;
- this.valuePlaceholder = valuePlaceholder;
- this.defaultValue = defaultValue;
- this.propertyName = propertyName;
- this.description = description;
- this.isValueSetByProperty = false;
-
- if ((shortIdentifier == null) && (longIdentifier == null)) {
- final LocalizableMessage message = ERR_ARG_NO_IDENTIFIER.get(name);
- throw new ArgumentException(message);
- }
-
- if (needsValue && (valuePlaceholder == null)) {
- final LocalizableMessage message = ERR_ARG_NO_VALUE_PLACEHOLDER.get(name);
- throw new ArgumentException(message);
- }
-
- values = new LinkedList<String>();
- isPresent = false;
- isHidden = false;
- }
-
- /**
- * Adds a value to the set of values for this argument. This should only be
- * called if the value is allowed by the <CODE>valueIsAcceptable</CODE>
- * method.
- *
- * @param valueString
- * The string representation of the value to add to this
- * argument.
- */
- public void addValue(final String valueString) {
- values.add(valueString);
- }
-
- /**
- * Clears the set of values assigned to this argument.
- */
- public void clearValues() {
- values.clear();
- }
-
- /**
- * Retrieves the value of this argument as a <CODE>Boolean</CODE>.
- *
- * @return The value of this argument as a <CODE>Boolean</CODE>.
- * @throws ArgumentException
- * If this argument cannot be interpreted as a Boolean value.
- */
- public boolean getBooleanValue() throws ArgumentException {
- if (values.isEmpty()) {
- final LocalizableMessage message = ERR_ARG_NO_BOOLEAN_VALUE.get(name);
- throw new ArgumentException(message);
- }
-
- final Iterator<String> iterator = values.iterator();
- final String valueString = toLowerCase(iterator.next());
-
- boolean booleanValue;
- if (valueString.equals("true") || valueString.equals("yes") || valueString.equals("on")
- || valueString.equals("1")) {
- booleanValue = true;
- } else if (valueString.equals("false") || valueString.equals("no")
- || valueString.equals("off") || valueString.equals("0")) {
- booleanValue = false;
- } else {
- final LocalizableMessage message =
- ERR_ARG_CANNOT_DECODE_AS_BOOLEAN.get(valueString, name);
- throw new ArgumentException(message);
- }
-
- if (iterator.hasNext()) {
- final LocalizableMessage message = ERR_ARG_BOOLEAN_MULTIPLE_VALUES.get(name);
- throw new ArgumentException(message);
- } else {
- return booleanValue;
- }
- }
-
- /**
- * Retrieves the default value that will be used for this argument if it is
- * not specified on the command line and it is not set from a properties
- * file.
- *
- * @return The default value that will be used for this argument if it is
- * not specified on the command line and it is not set from a
- * properties file, or <CODE>null</CODE> if there is no default
- * value.
- */
- public String getDefaultValue() {
- return defaultValue;
- }
-
- /**
- * Retrieves the human-readable description for this argument.
- *
- * @return The human-readable description for this argument.
- */
- public LocalizableMessage getDescription() {
- return description != null ? description : LocalizableMessage.EMPTY;
- }
-
- /**
- * Retrieves the value of this argument as an integer.
- *
- * @return The value of this argument as an integer.
- * @throws ArgumentException
- * If there are multiple values, or the value cannot be parsed
- * as an integer.
- */
- public double getDoubleValue() throws ArgumentException {
- if (values.isEmpty()) {
- final LocalizableMessage message = ERR_ARG_NO_INT_VALUE.get(name);
- throw new ArgumentException(message);
- }
-
- final Iterator<String> iterator = values.iterator();
- final String valueString = iterator.next();
-
- double intValue;
- try {
- intValue = Double.parseDouble(valueString);
- } catch (final Exception e) {
- final LocalizableMessage message = ERR_ARG_CANNOT_DECODE_AS_INT.get(valueString, name);
- throw new ArgumentException(message, e);
- }
-
- if (iterator.hasNext()) {
- final LocalizableMessage message = ERR_ARG_INT_MULTIPLE_VALUES.get(name);
- throw new ArgumentException(message);
- } else {
- return intValue;
- }
- }
-
- /**
- * Retrieves the set of values for this argument as a list of integers.
- *
- * @return A list of the integer representations of the values for this
- * argument.
- * @throws ArgumentException
- * If any of the values cannot be parsed as an integer.
- */
- public LinkedList<Double> getDoubleValues() throws ArgumentException {
- final LinkedList<Double> intList = new LinkedList<Double>();
-
- final Iterator<String> iterator = values.iterator();
- while (iterator.hasNext()) {
- final String valueString = iterator.next();
-
- try {
- intList.add(Double.valueOf(valueString));
- } catch (final Exception e) {
- final LocalizableMessage message =
- ERR_ARG_CANNOT_DECODE_AS_INT.get(valueString, name);
- throw new ArgumentException(message, e);
- }
- }
-
- return intList;
- }
-
- /**
- * Retrieves the value of this argument as an integer.
- *
- * @return The value of this argument as an integer.
- * @throws ArgumentException
- * If there are multiple values, or the value cannot be parsed
- * as an integer.
- */
- public int getIntValue() throws ArgumentException {
- if (values.isEmpty()) {
- final LocalizableMessage message = ERR_ARG_NO_INT_VALUE.get(name);
- throw new ArgumentException(message);
- }
-
- final Iterator<String> iterator = values.iterator();
- final String valueString = iterator.next();
-
- int intValue;
- try {
- intValue = Integer.parseInt(valueString);
- } catch (final Exception e) {
- final LocalizableMessage message = ERR_ARG_CANNOT_DECODE_AS_INT.get(valueString, name);
- throw new ArgumentException(message, e);
- }
-
- if (iterator.hasNext()) {
- final LocalizableMessage message = ERR_ARG_INT_MULTIPLE_VALUES.get(name);
- throw new ArgumentException(message);
- } else {
- return intValue;
- }
- }
-
- /**
- * Retrieves the set of values for this argument as a list of integers.
- *
- * @return A list of the integer representations of the values for this
- * argument.
- * @throws ArgumentException
- * If any of the values cannot be parsed as an integer.
- */
- public LinkedList<Integer> getIntValues() throws ArgumentException {
- final LinkedList<Integer> intList = new LinkedList<Integer>();
-
- final Iterator<String> iterator = values.iterator();
- while (iterator.hasNext()) {
- final String valueString = iterator.next();
-
- try {
- intList.add(Integer.valueOf(valueString));
- } catch (final Exception e) {
- final LocalizableMessage message =
- ERR_ARG_CANNOT_DECODE_AS_INT.get(valueString, name);
- throw new ArgumentException(message, e);
- }
- }
-
- return intList;
- }
-
- /**
- * Retrieves the long (multi-character) identifier that may be used to
- * specify the value of this argument.
- *
- * @return The long (multi-character) identifier that may be used to specify
- * the value of this argument.
- */
- public String getLongIdentifier() {
- return longIdentifier;
- }
-
- /**
- * Retrieves the generic name that will be used to refer to this argument.
- *
- * @return The generic name that will be used to refer to this argument.
- */
- public String getName() {
- return name;
- }
-
- /**
- * Retrieves the name of a property in a properties file that may be used to
- * set the default value for this argument if it is present. A value read
- * from a properties file will override the default value returned from the
- * <CODE>getDefaultValue</CODE>, but the properties file value will be
- * overridden by a value supplied on the command line.
- *
- * @return The name of a property in a properties file that may be used to
- * set the default value for this argument if it is present.
- */
- public String getPropertyName() {
- return propertyName;
- }
-
- /**
- * Retrieves the single-character identifier that may be used to specify the
- * value of this argument.
- *
- * @return The single-character identifier that may be used to specify the
- * value of this argument, or <CODE>null</CODE> if there is none.
- */
- public Character getShortIdentifier() {
- return shortIdentifier;
- }
-
- /**
- * Retrieves the string vale for this argument. If it has multiple values,
- * then the first will be returned. If it does not have any values, then the
- * default value will be returned.
- *
- * @return The string value for this argument, or <CODE>null</CODE> if there
- * are no values and no default value has been given.
- */
- public String getValue() {
- if (values.isEmpty()) {
- return defaultValue;
- }
-
- return values.getFirst();
- }
-
- /**
- * Retrieves the value placeholder that will be displayed for this argument
- * in the generated usage information.
- *
- * @return The value placeholder that will be displayed for this argument in
- * the generated usage information, or <CODE>null</CODE> if there is
- * none.
- */
- public LocalizableMessage getValuePlaceholder() {
- return valuePlaceholder;
- }
-
- /**
- * Retrieves the set of string values for this argument.
- *
- * @return The set of string values for this argument.
- */
- public LinkedList<String> getValues() {
- return values;
- }
-
- /**
- * Indicates whether this argument has at least one value.
- *
- * @return <CODE>true</CODE> if this argument has at least one value, or
- * <CODE>false</CODE> if it does not have any values.
- */
- public boolean hasValue() {
- return (!values.isEmpty());
- }
-
- /**
- * Indicates whether this argument should be hidden from the usage
- * information.
- *
- * @return <CODE>true</CODE> if this argument should be hidden from the
- * usage information, or <CODE>false</CODE> if not.
- */
- public boolean isHidden() {
- return isHidden;
- }
-
- /**
- * Indicates whether this argument may be provided more than once on the
- * command line to specify multiple values.
- *
- * @return <CODE>true</CODE> if this argument may be provided more than once
- * on the command line to specify multiple values, or
- * <CODE>false</CODE> if it may have at most one value.
- */
- public boolean isMultiValued() {
- return isMultiValued;
- }
-
- /**
- * Indicates whether this argument is present in the parsed set of
- * command-line arguments.
- *
- * @return <CODE>true</CODE> if this argument is present in the parsed set
- * of command-line arguments, or <CODE>false</CODE> if not.
- */
- public boolean isPresent() {
- return isPresent;
- }
-
- /**
- * Indicates whether this argument is required to have at least one value.
- *
- * @return <CODE>true</CODE> if this argument is required to have at least
- * one value, or <CODE>false</CODE> if it does not need to have a
- * value.
- */
- public boolean isRequired() {
- return isRequired;
- }
-
- /**
- * Indicates whether this argument was provided in the set of properties
- * found is a properties file.
- *
- * @return <CODE>true</CODE> if this argument was provided in the set of
- * properties found is a properties file, or <CODE>false</CODE> if
- * not.
- */
- public boolean isValueSetByProperty() {
- return isValueSetByProperty;
- }
-
- /**
- * Indicates whether a value must be provided with this argument if it is
- * present.
- *
- * @return <CODE>true</CODE> if a value must be provided with the argument
- * if it is present, or <CODE>false</CODE> if the argument does not
- * take a value and the presence of the argument identifier itself
- * is sufficient to convey the necessary information.
- */
- public boolean needsValue() {
- return needsValue;
- }
-
- /**
- * Specifies the default value that will be used for this argument if it is
- * not specified on the command line and it is not set from a properties
- * file.
- *
- * @param defaultValue
- * The default value that will be used for this argument if it is
- * not specified on the command line and it is not set from a
- * properties file.
- */
- public void setDefaultValue(final String defaultValue) {
- this.defaultValue = defaultValue;
- }
-
- /**
- * Specifies whether this argument should be hidden from the usage
- * information.
- *
- * @param isHidden
- * Indicates whether this argument should be hidden from the
- * usage information.
- */
- public void setHidden(final boolean isHidden) {
- this.isHidden = isHidden;
- }
-
- /**
- * Specifies whether this argument may be provided more than once on the
- * command line to specify multiple values.
- *
- * @param isMultiValued
- * Indicates whether this argument may be provided more than once
- * on the command line to specify multiple values.
- */
- public void setMultiValued(final boolean isMultiValued) {
- this.isMultiValued = isMultiValued;
- }
-
- /**
- * Specifies whether a value must be provided with this argument if it is
- * present. If this is changed from <CODE>false</CODE> to <CODE>true</CODE>,
- * then a value placeholder must also be provided.
- *
- * @param needsValue
- * Indicates whether a value must be provided with this argument
- * if it is present.
- */
- public void setNeedsValue(final boolean needsValue) {
- this.needsValue = needsValue;
- }
-
- /**
- * Specifies whether this argument is present in the parsed set of
- * command-line arguments.
- *
- * @param isPresent
- * Indicates whether this argument is present in the set of
- * command-line arguments.
- */
- public void setPresent(final boolean isPresent) {
- this.isPresent = isPresent;
- }
-
- /**
- * Specifies the name of a property in a properties file that may be used to
- * set the default value for this argument if it is present.
- *
- * @param propertyName
- * The name of a property in a properties file that may be used
- * to set the default value for this argument if it is present.
- */
- public void setPropertyName(final String propertyName) {
- this.propertyName = propertyName;
- }
-
- /**
- * Specifies whether this argument is required to have at least one value.
- *
- * @param isRequired
- * Indicates whether this argument is required to have at least
- * one value.
- */
- public void setRequired(final boolean isRequired) {
- this.isRequired = isRequired;
- }
-
- /**
- * Specifies the value placeholder that will be displayed for this argument
- * in the generated usage information. It may be <CODE>null</CODE> only if
- * <CODE>needsValue()</CODE> returns <CODE>false</CODE>.
- *
- * @param valuePlaceholder
- * The value placeholder that will be displayed for this argument
- * in the generated usage information.
- */
- public void setValuePlaceholder(final LocalizableMessage valuePlaceholder) {
- this.valuePlaceholder = valuePlaceholder;
- }
-
- /**
- * Specifies whether this argument was provided in the set of properties
- * found is a properties file.
- *
- * @param isValueSetByProperty
- * Specify whether this argument was provided in the set of
- * properties found is a properties file.
- */
- public void setValueSetByProperty(final boolean isValueSetByProperty) {
- this.isValueSetByProperty = isValueSetByProperty;
- }
-
- /**
- * Indicates whether the provided value is acceptable for use in this
- * argument.
- *
- * @param valueString
- * The value for which to make the determination.
- * @param invalidReason
- * A buffer into which the invalid reason may be written if the
- * value is not acceptable.
- * @return <CODE>true</CODE> if the value is acceptable, or
- * <CODE>false</CODE> if it is not.
- */
- public abstract boolean valueIsAcceptable(String valueString,
- LocalizableMessageBuilder invalidReason);
-}
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ArgumentException.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ArgumentException.java
deleted file mode 100644
index 2a9590f..0000000
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ArgumentException.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at legal-notices/CDDLv1_0.txt.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Copyright 2006-2008 Sun Microsystems, Inc.
- */
-package com.forgerock.opendj.ldap.tools;
-
-import org.forgerock.i18n.LocalizableException;
-import org.forgerock.i18n.LocalizableMessage;
-
-/**
- * This class defines an exception that may be thrown if there is a problem with
- * an argument definition.
- */
-@SuppressWarnings("serial")
-final class ArgumentException extends Exception implements LocalizableException {
- // The I18N message associated with this exception.
- private final LocalizableMessage message;
-
- /**
- * Creates a new argument exception with the provided message.
- *
- * @param message
- * The message that explains the problem that occurred.
- */
- ArgumentException(final LocalizableMessage message) {
- super(String.valueOf(message));
- this.message = message;
- }
-
- /**
- * Creates a new argument exception with the provided message and root
- * cause.
- *
- * @param message
- * The message that explains the problem that occurred.
- * @param cause
- * The exception that was caught to trigger this exception.
- */
- ArgumentException(final LocalizableMessage message, final Throwable cause) {
- super(String.valueOf(message), cause);
- this.message = message;
- }
-
- /**
- * {@inheritDoc}
- */
- public LocalizableMessage getMessageObject() {
- return this.message;
- }
-
-}
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ArgumentGroup.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ArgumentGroup.java
deleted file mode 100644
index f981732..0000000
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ArgumentGroup.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at legal-notices/CDDLv1_0.txt.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Copyright 2008 Sun Microsystems, Inc.
- * Portions copyright 2012 ForgeRock AS.
- */
-
-package com.forgerock.opendj.ldap.tools;
-
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.forgerock.i18n.LocalizableMessage;
-
-/**
- * Class for organizing options into logical groups when arguement usage is
- * printed. To use an argument group, create an instance and use
- * {@code ArgumentParser#addArgument(Argument, ArgumentGroup)}
- * when adding arguments for to the parser.
- */
-final class ArgumentGroup implements Comparable<ArgumentGroup> {
-
- // Description for this group of arguments
- private LocalizableMessage description = null;
-
- // List of arguments belonging to this group
- private List<Argument> args = null;
-
- // Governs groups position within usage statement
- private final Integer priority;
-
- /**
- * Creates a parameterized instance.
- *
- * @param description
- * for options in this group that is printed before argument
- * descriptions in usage output
- * @param priority
- * number governing the position of this group within the usage
- * statement. Groups with higher priority values appear before
- * groups with lower priority.
- */
- ArgumentGroup(final LocalizableMessage description, final int priority) {
- this.description = description;
- this.priority = priority;
- this.args = new LinkedList<Argument>();
- }
-
- /**
- * {@inheritDoc}
- */
- public int compareTo(final ArgumentGroup o) {
- // Groups with higher priority numbers appear before
- // those with lower priority in the usage output
- return -1 * priority.compareTo(o.priority);
- }
-
- /**
- * Adds an argument to this group.
- *
- * @param arg
- * to add
- * @return boolean where true indicates the add was successful
- */
- boolean addArgument(final Argument arg) {
- boolean success = false;
- if (arg != null) {
- final Character newShort = arg.getShortIdentifier();
- final String newLong = arg.getLongIdentifier();
-
- // See if there is already an argument in this group that the
- // new argument should replace
- for (final Iterator<Argument> it = this.args.iterator(); it.hasNext();) {
- final Argument a = it.next();
- if (newShort != null && newShort.equals(a.getShortIdentifier()) || newLong != null
- && newLong.equals(a.getLongIdentifier())) {
- it.remove();
- break;
- }
- }
-
- success = this.args.add(arg);
- }
- return success;
- }
-
- /**
- * Indicates whether this group contains any members.
- *
- * @return boolean where true means this group contains members
- */
- boolean containsArguments() {
- return this.args.size() > 0;
- }
-
- /**
- * Indicates whether this group contains any non-hidden members.
- *
- * @return boolean where true means this group contains non-hidden members
- */
- boolean containsNonHiddenArguments() {
- for (final Argument arg : args) {
- if (!arg.isHidden()) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Gets the list of arguments associated with this group.
- *
- * @return list of associated arguments
- */
- List<Argument> getArguments() {
- return Collections.unmodifiableList(args);
- }
-
- /**
- * Gets the description for this group of arguments.
- *
- * @return description for this argument group
- */
- LocalizableMessage getDescription() {
- return this.description;
- }
-
- /**
- * Removes an argument from this group.
- *
- * @param arg
- * to remove
- * @return boolean where true indicates the remove was successful
- */
- boolean removeArgument(final Argument arg) {
- return this.args.remove(arg);
- }
-
- /**
- * Sets the description for this group of arguments.
- *
- * @param description
- * for this argument group
- */
- void setDescription(final LocalizableMessage description) {
- this.description = description;
- }
-
-}
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ArgumentParser.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ArgumentParser.java
deleted file mode 100644
index c1207f6..0000000
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ArgumentParser.java
+++ /dev/null
@@ -1,1598 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at legal-notices/CDDLv1_0.txt.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Copyright 2006-2010 Sun Microsystems, Inc.
- * Portions copyright 2012 ForgeRock AS.
- */
-package com.forgerock.opendj.ldap.tools;
-
-import static com.forgerock.opendj.ldap.tools.ToolConstants.*;
-import static com.forgerock.opendj.ldap.tools.ToolsMessages.*;
-import static com.forgerock.opendj.ldap.tools.Utils.PROPERTY_SCRIPT_NAME;
-import static com.forgerock.opendj.ldap.tools.Utils.wrapText;
-import static com.forgerock.opendj.util.StaticUtils.EOL;
-import static com.forgerock.opendj.util.StaticUtils.getBytes;
-import static com.forgerock.opendj.util.StaticUtils.getExceptionMessage;
-import static com.forgerock.opendj.util.StaticUtils.toLowerCase;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.Properties;
-import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeSet;
-
-import org.forgerock.i18n.LocalizableMessage;
-import org.forgerock.i18n.LocalizableMessageBuilder;
-
-/**
- * This class defines a utility that can be used to deal with command-line
- * arguments for applications in a CLIP-compliant manner using either short
- * one-character or longer word-based arguments. It is also integrated with the
- * Directory Server message catalog so that it can display messages in an
- * internationalizeable format, can automatically generate usage information,
- * can detect conflicts between arguments, and can interact with a properties
- * file to obtain default values for arguments there if they are not specified
- * on the command-line.
- */
-final class ArgumentParser {
- /**
- * The argument that will be used to indicate the file properties.
- */
- private StringArgument filePropertiesPathArgument;
-
- /**
- * The argument that will be used to indicate that we'll not look for
- * default properties file.
- */
- private BooleanArgument noPropertiesFileArgument;
-
- // The argument that will be used to trigger the display of usage
- // information.
- private Argument usageArgument;
-
- // The argument that will be used to trigger the display of the OpenDJ
- // version.
- private Argument versionArgument;
-
- // The set of unnamed trailing arguments that were provided for this
- // parser.
- private final ArrayList<String> trailingArguments;
-
- // Indicates whether this parser will allow additional unnamed
- // arguments at the end of the list.
- private final boolean allowsTrailingArguments;
-
- // Indicates whether long arguments should be treated in a
- // case-sensitive manner.
- private final boolean longArgumentsCaseSensitive;
-
- // Indicates whether the usage or version information has been
- // displayed.
- private boolean usageOrVersionDisplayed;
-
- // Indicates whether the version argument was provided.
- private boolean versionPresent;
-
- // The set of arguments defined for this parser, referenced by short
- // ID.
- private final HashMap<Character, Argument> shortIDMap;
-
- // The set of arguments defined for this parser, referenced by
- // argument name.
- private final HashMap<String, Argument> argumentMap;
-
- // The set of arguments defined for this parser, referenced by long
- // ID.
- private final HashMap<String, Argument> longIDMap;
-
- // The maximum number of unnamed trailing arguments that may be
- // provided.
- private final int maxTrailingArguments;
-
- // The minimum number of unnamed trailing arguments that may be
- // provided.
- private final int minTrailingArguments;
-
- // The total set of arguments defined for this parser.
- private final LinkedList<Argument> argumentList;
-
- // 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 display name that will be used for the trailing arguments in
- // the usage information.
- private final String trailingArgsDisplayName;
-
- // The raw set of command-line arguments that were provided.
- private String[] rawArguments;
-
- /** Set of argument groups. */
- private Set<ArgumentGroup> argumentGroups;
-
- /**
- * 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);
-
- /**
- * 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(
- INFO_DESCRIPTION_LDAP_CONNECTION_ARGS.get(), Integer.MIN_VALUE + 2);
-
- /**
- * Group for arguments that are related to utility input/output like
- * properties file, no-prompt etc. These will appear toward the bottom of
- * the usage statement.
- */
- 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 static String INDENT = " ";
-
- private final static int MAX_LENGTH = 80;
-
- /**
- * Creates a new instance of this argument parser with no arguments. Unnamed
- * trailing arguments will not be allowed.
- *
- * @param mainClassName
- * The fully-qualified name of the Java class that should be
- * invoked to launch the program with which this argument parser
- * is associated.
- * @param toolDescription
- * A human-readable description for the tool, which will be
- * included when displaying usage information.
- * @param longArgumentsCaseSensitive
- * Indicates whether long arguments should be treated in a
- * case-sensitive manner.
- */
- ArgumentParser(final String mainClassName, final LocalizableMessage toolDescription,
- final boolean longArgumentsCaseSensitive) {
- this.mainClassName = mainClassName;
- this.toolDescription = toolDescription;
- this.longArgumentsCaseSensitive = longArgumentsCaseSensitive;
-
- argumentList = new LinkedList<Argument>();
- argumentMap = new HashMap<String, Argument>();
- shortIDMap = new HashMap<Character, Argument>();
- longIDMap = new HashMap<String, Argument>();
- allowsTrailingArguments = false;
- usageOrVersionDisplayed = false;
- versionPresent = false;
- trailingArgsDisplayName = null;
- maxTrailingArguments = 0;
- minTrailingArguments = 0;
- trailingArguments = new ArrayList<String>();
- rawArguments = null;
- usageArgument = null;
- filePropertiesPathArgument = null;
- noPropertiesFileArgument = null;
- usageOutputStream = System.out;
- initGroups();
- }
-
- /**
- * Creates a new instance of this argument parser with no arguments that may
- * or may not be allowed to have unnamed trailing arguments.
- *
- * @param mainClassName
- * The fully-qualified name of the Java class that should be
- * invoked to launch the program with which this argument parser
- * is associated.
- * @param toolDescription
- * A human-readable description for the tool, which will be
- * included when displaying usage information.
- * @param longArgumentsCaseSensitive
- * Indicates whether long arguments should be treated in a
- * case-sensitive manner.
- * @param allowsTrailingArguments
- * Indicates whether this parser allows unnamed trailing
- * arguments to be provided.
- * @param minTrailingArguments
- * The minimum number of unnamed trailing arguments that must be
- * provided. A value less than or equal to zero indicates that no
- * minimum will be enforced.
- * @param maxTrailingArguments
- * The maximum number of unnamed trailing arguments that may be
- * provided. A value less than or equal to zero indicates that no
- * maximum will be enforced.
- * @param trailingArgsDisplayName
- * The display name that should be used as a placeholder for
- * unnamed trailing arguments in the generated usage information.
- */
- ArgumentParser(final String mainClassName, final LocalizableMessage toolDescription,
- final boolean longArgumentsCaseSensitive, final boolean allowsTrailingArguments,
- final int minTrailingArguments, final int maxTrailingArguments,
- final String trailingArgsDisplayName) {
- this.mainClassName = mainClassName;
- this.toolDescription = toolDescription;
- this.longArgumentsCaseSensitive = longArgumentsCaseSensitive;
- this.allowsTrailingArguments = allowsTrailingArguments;
- this.minTrailingArguments = minTrailingArguments;
- this.maxTrailingArguments = maxTrailingArguments;
- this.trailingArgsDisplayName = trailingArgsDisplayName;
-
- argumentList = new LinkedList<Argument>();
- argumentMap = new HashMap<String, Argument>();
- shortIDMap = new HashMap<Character, Argument>();
- longIDMap = new HashMap<String, Argument>();
- trailingArguments = new ArrayList<String>();
- usageOrVersionDisplayed = false;
- versionPresent = false;
- rawArguments = null;
- usageArgument = null;
- usageOutputStream = System.out;
- initGroups();
- }
-
- /**
- * Adds the provided argument to the set of arguments handled by this
- * parser.
- *
- * @param argument
- * The argument to be added.
- * @throws ArgumentException
- * If the provided argument conflicts with another argument that
- * has already been defined.
- */
- 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.
- */
- 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();
-
- final LocalizableMessage message =
- ERR_ARGPARSER_DUPLICATE_SHORT_ID.get(argument.getName(), String
- .valueOf(shortID), conflictingName);
- throw new ArgumentException(message);
- }
-
- if (versionArgument != null) {
- if (shortID != null && shortID.equals(versionArgument.getShortIdentifier())) {
- // Update the version argument to not display its short
- // identifier.
- try {
- versionArgument =
- new BooleanArgument(OPTION_LONG_PRODUCT_VERSION, null,
- OPTION_LONG_PRODUCT_VERSION, INFO_DESCRIPTION_PRODUCT_VERSION
- .get());
- this.generalArgGroup.addArgument(versionArgument);
- } catch (final ArgumentException e) {
- // ignore
- }
- }
- }
-
- String longID = argument.getLongIdentifier();
- if (longID != null) {
- if (!longArgumentsCaseSensitive) {
- longID = toLowerCase(longID);
- }
- if (longIDMap.containsKey(longID)) {
- final String conflictingName = longIDMap.get(longID).getName();
-
- final LocalizableMessage message =
- ERR_ARGPARSER_DUPLICATE_LONG_ID.get(argument.getName(), argument
- .getLongIdentifier(), conflictingName);
- throw new ArgumentException(message);
- }
- }
-
- if (shortID != null) {
- shortIDMap.put(shortID, argument);
- }
-
- if (longID != null) {
- longIDMap.put(longID, argument);
- }
-
- argumentList.add(argument);
-
- if (group == null) {
- group = getStandardGroup(argument);
- }
- group.addArgument(argument);
- argumentGroups.add(group);
- }
-
- /**
- * Adds the provided argument to the set of arguments handled by this parser
- * and puts the arguement 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.
- */
- 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 arguement 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.
- */
- 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.
- */
- 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
- * the application using this parser. Note that once an unnamed trailing
- * argument has been identified, all remaining arguments will be classified
- * as such.
- *
- * @return <CODE>true</CODE> if this parser allows unnamed trailing
- * arguments, or <CODE>false</CODE> if it does not.
- */
- boolean allowsTrailingArguments() {
- return allowsTrailingArguments;
- }
-
- /**
- * Check if we have a properties file.
- *
- * @return The properties found in the properties file or null.
- * @throws ArgumentException
- * If a problem was encountered while parsing the provided
- * arguments.
- */
- Properties checkExternalProperties() throws ArgumentException {
- // We don't look for properties file.
- if ((noPropertiesFileArgument != null) && (noPropertiesFileArgument.isPresent())) {
- return null;
- }
-
- // Check if we have a properties file argument
- if (filePropertiesPathArgument == null) {
- return null;
- }
-
- // check if the properties file argument has been set. If not
- // look for default location.
- String propertiesFilePath = null;
- if (filePropertiesPathArgument.isPresent()) {
- propertiesFilePath = filePropertiesPathArgument.getValue();
- } else {
- // Check in "user home"/.opendj directory
- final String userDir = System.getProperty("user.home");
- propertiesFilePath =
- findPropertiesFile(userDir + File.separator + DEFAULT_OPENDJ_CONFIG_DIR);
- }
-
- // We don't have a properties file location
- if (propertiesFilePath == null) {
- return null;
- }
-
- // We have a location for the properties file.
- final Properties argumentProperties = new Properties();
- final String scriptName = System.getProperty(Utils.PROPERTY_SCRIPT_NAME);
- try {
- final Properties p = new Properties();
- final FileInputStream fis = new FileInputStream(propertiesFilePath);
- p.load(fis);
- fis.close();
-
- for (final Enumeration<?> e = p.propertyNames(); e.hasMoreElements();) {
- final String currentPropertyName = (String) e.nextElement();
- String propertyName = currentPropertyName;
-
- // Property name form <script name>.<property name> has the
- // precedence to <property name>
- if (scriptName != null) {
- if (currentPropertyName.startsWith(scriptName)) {
- propertyName = currentPropertyName.substring(scriptName.length() + 1);
- } else {
- if (p.containsKey(scriptName + "." + currentPropertyName)) {
- continue;
- }
- }
- }
- argumentProperties.setProperty(propertyName.toLowerCase(), p
- .getProperty(currentPropertyName));
- }
- } catch (final Exception e) {
- final LocalizableMessage message =
- ERR_ARGPARSER_CANNOT_READ_PROPERTIES_FILE.get(String
- .valueOf(propertiesFilePath), getExceptionMessage(e));
- throw new ArgumentException(message, e);
- }
- return argumentProperties;
- }
-
- /**
- * Retrieves the argument with the specified name.
- *
- * @param name
- * The name of the argument to retrieve.
- * @return The argument with the specified name, or <CODE>null</CODE> if
- * there is no such argument.
- */
- Argument getArgument(final String name) {
- return argumentMap.get(name);
- }
-
- /**
- * Retrieves the argument with the specified long identifier.
- *
- * @param longID
- * The long identifier of the argument to retrieve.
- * @return The argument with the specified long identifier, or
- * <CODE>null</CODE> if there is no such argument.
- */
- Argument getArgumentForLongID(final String longID) {
- return longIDMap.get(longID);
- }
-
- /**
- * Retrieves the argument with the specified short identifier.
- *
- * @param shortID
- * The short ID for the argument to retrieve.
- * @return The argument with the specified short identifier, or
- * <CODE>null</CODE> if there is no such argument.
- */
- Argument getArgumentForShortID(final Character shortID) {
- return shortIDMap.get(shortID);
- }
-
- /**
- * Retrieves the list of all arguments that have been defined for this
- * argument parser.
- *
- * @return The list of all arguments that have been defined for this
- * argument parser.
- */
- LinkedList<Argument> getArgumentList() {
- return argumentList;
- }
-
- /**
- * Retrieves the set of arguments mapped by the long identifier that may be
- * used to reference them. Note that arguments that do not have a long
- * identifier will not be present in this list.
- *
- * @return The set of arguments mapped by the long identifier that may be
- * used to reference them.
- */
- HashMap<String, Argument> getArgumentsByLongID() {
- return longIDMap;
- }
-
- /**
- * Retrieves the set of arguments mapped by the short identifier that may be
- * used to reference them. Note that arguments that do not have a short
- * identifier will not be present in this list.
- *
- * @return The set of arguments mapped by the short identifier that may be
- * used to reference them.
- */
- HashMap<Character, Argument> getArgumentsByShortID() {
- return shortIDMap;
- }
-
- /**
- * 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.
- */
- String getMainClassName() {
- return mainClassName;
- }
-
- /**
- * Retrieves the maximum number of unnamed trailing arguments that may be
- * provided.
- *
- * @return The maximum number of unnamed trailing arguments that may be
- * provided, or a value less than or equal to zero if no maximum
- * will be enforced.
- */
- int getMaxTrailingArguments() {
- return maxTrailingArguments;
- }
-
- /**
- * Retrieves the minimum number of unnamed trailing arguments that must be
- * provided.
- *
- * @return The minimum number of unnamed trailing arguments that must be
- * provided, or a value less than or equal to zero if no minimum
- * will be enforced.
- */
- int getMinTrailingArguments() {
- return minTrailingArguments;
- }
-
- /**
- * Retrieves the raw set of arguments that were provided.
- *
- * @return The raw set of arguments that were provided, or <CODE>null</CODE>
- * if the argument list has not yet been parsed.
- */
- String[] getRawArguments() {
- return rawArguments;
- }
-
- /**
- * Given an argument, returns an appropriate group. Arguments may be part of
- * one of the special groups or the default group.
- *
- * @param argument
- * for which a group is requested
- * @return argument group appropriate for <code>argument</code>
- */
- ArgumentGroup getStandardGroup(final Argument argument) {
- ArgumentGroup group;
- if (isInputOutputArgument(argument)) {
- group = ioArgGroup;
- } else if (isGeneralArgument(argument)) {
- group = generalArgGroup;
- } else if (isLdapConnectionArgument(argument)) {
- group = ldapArgGroup;
- } else {
- group = defaultArgGroup;
- }
- return group;
- }
-
- /**
- * 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.
- */
- LocalizableMessage getToolDescription() {
- return toolDescription;
- }
-
- /**
- * Retrieves the set of unnamed trailing arguments that were provided on the
- * command line.
- *
- * @return The set of unnamed trailing arguments that were provided on the
- * command line.
- */
- ArrayList<String> getTrailingArguments() {
- return trailingArguments;
- }
-
- /**
- * Retrieves a string containing usage information based on the defined
- * arguments.
- *
- * @return A string containing usage information based on the defined
- * arguments.
- */
- String getUsage() {
- final StringBuilder buffer = new StringBuilder();
- getUsage(buffer);
-
- return buffer.toString();
- }
-
- /**
- * Writes usage information based on the defined arguments to the provided
- * 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.
- */
- void getUsage(final OutputStream outputStream) throws IOException {
- final StringBuilder buffer = new StringBuilder();
- getUsage(buffer);
-
- outputStream.write(getBytes(buffer.toString()));
- }
-
- /**
- * Appends usage information based on the defined arguments to the provided
- * buffer.
- *
- * @param buffer
- * The buffer to which the usage information should be appended.
- */
- void getUsage(final StringBuilder buffer) {
- usageOrVersionDisplayed = true;
- final String scriptName = System.getProperty(PROPERTY_SCRIPT_NAME);
- if ((scriptName == null) || (scriptName.length() == 0)) {
- buffer.append(INFO_ARGPARSER_USAGE_JAVA_CLASSNAME.get(mainClassName));
- } else {
- buffer.append(INFO_ARGPARSER_USAGE_JAVA_SCRIPTNAME.get(scriptName));
- }
-
- if (allowsTrailingArguments) {
- if (trailingArgsDisplayName == null) {
- buffer.append(" " + INFO_ARGPARSER_USAGE_TRAILINGARGS.get());
- } else {
- buffer.append(" ");
- buffer.append(trailingArgsDisplayName);
- }
- }
- buffer.append(EOL);
- buffer.append(EOL);
- if ((toolDescription != null) && (toolDescription.length() > 0)) {
- buffer.append(wrapText(toolDescription.toString(), MAX_LENGTH - 1));
- buffer.append(EOL);
- buffer.append(EOL);
- }
- buffer.append(INFO_SUBCMDPARSER_WHERE_OPTIONS_INCLUDE.get());
- buffer.append(EOL);
- buffer.append(EOL);
-
- Argument helpArgument = null;
-
- final boolean printHeaders = printUsageGroupHeaders();
- for (final ArgumentGroup argGroup : argumentGroups) {
- if (argGroup.containsArguments() && printHeaders) {
- // Print the groups description if any
- final LocalizableMessage groupDesc = argGroup.getDescription();
- if (groupDesc != null && !LocalizableMessage.EMPTY.equals(groupDesc)) {
- buffer.append(EOL);
- buffer.append(wrapText(groupDesc.toString(), MAX_LENGTH - 1));
- buffer.append(EOL);
- buffer.append(EOL);
- }
- }
-
- final SortedSet<Argument> args = new TreeSet<Argument>(new Comparator<Argument>() {
-
- /**
- * {@inheritDoc}
- */
- public int compare(final Argument o1, final Argument o2) {
- final String s1;
- final String s2;
-
- if (o1.getShortIdentifier() != null) {
- s1 = o1.getShortIdentifier().toString();
- } else {
- s1 = o1.getLongIdentifier();
- }
-
- if (o2.getShortIdentifier() != null) {
- s2 = o2.getShortIdentifier().toString();
- } else {
- s2 = o2.getLongIdentifier();
- }
-
- final int res = s1.compareToIgnoreCase(s2);
- if (res != 0) {
- return res;
- } else {
- // Lowercase options first then uppercase.
- return -s1.compareTo(s2);
- }
- }
-
- });
- args.addAll(argGroup.getArguments());
-
- for (final Argument a : args) {
- // If this argument is hidden, then skip it.
- if (a.isHidden()) {
- continue;
- }
-
- // Help argument should be printed at the end
- if ((usageArgument != null) && usageArgument.getName().equals(a.getName())) {
- helpArgument = a;
- continue;
- }
- printArgumentUsage(a, buffer);
- }
- }
- if (helpArgument != null) {
- printArgumentUsage(helpArgument, buffer);
- } else {
- buffer.append(EOL);
- buffer.append("-?");
- buffer.append(EOL);
- }
- }
-
- /**
- * Retrieves a message containing usage information based on the defined
- * arguments.
- *
- * @return A string containing usage information based on the defined
- * arguments.
- */
- LocalizableMessage getUsageMessage() {
- final StringBuilder buffer = new StringBuilder();
- getUsage(buffer);
-
- // TODO: rework getUsage(OutputStream) to work with messages
- // framework
- return LocalizableMessage.raw(buffer.toString());
- }
-
- /**
- * 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.
- */
- boolean isUsageArgumentPresent() {
- boolean isUsageArgumentPresent = false;
- if (usageArgument != null) {
- isUsageArgumentPresent = usageArgument.isPresent();
- }
- return isUsageArgumentPresent;
- }
-
- /**
- * 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.
- */
- boolean isVersionArgumentPresent() {
- return versionPresent;
- }
-
- /**
- * Parses the provided set of arguments and updates the information
- * associated with this parser accordingly.
- *
- * @param rawArguments
- * The raw set of arguments to parse.
- * @throws ArgumentException
- * If a problem was encountered while parsing the provided
- * arguments.
- */
- void parseArguments(final String[] rawArguments) throws ArgumentException {
- parseArguments(rawArguments, null);
- }
-
- /**
- * Parses the provided set of arguments and updates the information
- * associated with this parser accordingly. Default values for unspecified
- * arguments may be read from the specified properties if any are provided.
- *
- * @param rawArguments
- * The set of raw arguments to parse.
- * @param argumentProperties
- * A set of properties that may be used to provide default values
- * for arguments not included in the given raw arguments.
- * @throws ArgumentException
- * If a problem was encountered while parsing the provided
- * arguments.
- */
- void parseArguments(final String[] rawArguments, Properties argumentProperties)
- throws ArgumentException {
- this.rawArguments = rawArguments;
-
- boolean inTrailingArgs = false;
-
- final int numArguments = rawArguments.length;
- for (int i = 0; i < numArguments; i++) {
- final String arg = rawArguments[i];
-
- if (inTrailingArgs) {
- trailingArguments.add(arg);
- if ((maxTrailingArguments > 0) && (trailingArguments.size() > maxTrailingArguments)) {
- final LocalizableMessage message =
- ERR_ARGPARSER_TOO_MANY_TRAILING_ARGS.get(maxTrailingArguments);
- throw new ArgumentException(message);
- }
-
- continue;
- }
-
- if (arg.equals("--")) {
- // This is a special indicator that we have reached the end of
- // the named arguments and that everything that follows after
- // this
- // should be considered trailing arguments.
- inTrailingArgs = true;
- } else if (arg.startsWith("--")) {
- // This indicates that we are using the long name to reference
- // the argument. It may be in any of the following forms:
- // --name
- // --name value
- // --name=value
-
- String argName = arg.substring(2);
- String argValue = null;
- final int equalPos = argName.indexOf('=');
- if (equalPos < 0) {
- // This is fine. The value is not part of the argument name
- // 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);
- } else {
- // The argument is in the form --name=value, so parse them
- // both out.
- argValue = argName.substring(equalPos + 1);
- argName = argName.substring(0, equalPos);
- }
-
- // If we're not case-sensitive, then convert the name to
- // lowercase.
- final String origArgName = argName;
- if (!longArgumentsCaseSensitive) {
- argName = toLowerCase(argName);
- }
-
- // Get the argument with the specified name.
- final Argument a = longIDMap.get(argName);
- if (a == null) {
- if (argName.equals(OPTION_LONG_HELP)) {
- // "--help" will always be interpreted as requesting
- // usage
- // information.
- try {
- getUsage(usageOutputStream);
- } catch (final Exception e) {
- // Ignored.
- }
-
- return;
- } else if (argName.equals(OPTION_LONG_PRODUCT_VERSION)) {
- // "--version" will always be interpreted as requesting
- // version information.
- usageOrVersionDisplayed = true;
- versionPresent = true;
- try {
- // TODO
- // DirectoryServer.printVersion(usageOutputStream);
- } catch (final Exception e) {
- // Ignored.
- }
-
- return;
- } else {
- // There is no such argument registered.
- final LocalizableMessage message =
- ERR_ARGPARSER_NO_ARGUMENT_WITH_LONG_ID.get(origArgName);
- throw new ArgumentException(message);
- }
- } else {
- a.setPresent(true);
-
- // If this is the usage argument, then immediately stop and
- // print usage information.
- if ((usageArgument != null) && usageArgument.getName().equals(a.getName())) {
- try {
- getUsage(usageOutputStream);
- } catch (final Exception e) {
- // Ignored.
- }
-
- return;
- }
- }
-
- // See if the argument takes a value. If so, then make sure one
- // was provided. If not, then make sure none was provided.
- if (a.needsValue()) {
- if (argValue == null) {
- if ((i + 1) == numArguments) {
- final LocalizableMessage message =
- ERR_ARGPARSER_NO_VALUE_FOR_ARGUMENT_WITH_LONG_ID
- .get(origArgName);
- throw new ArgumentException(message);
- }
-
- argValue = rawArguments[++i];
- }
-
- final LocalizableMessageBuilder invalidReason = new LocalizableMessageBuilder();
- if (!a.valueIsAcceptable(argValue, invalidReason)) {
- final LocalizableMessage message =
- ERR_ARGPARSER_VALUE_UNACCEPTABLE_FOR_LONG_ID.get(argValue,
- origArgName, invalidReason.toString());
- throw new ArgumentException(message);
- }
-
- // If the argument already has a value, then make sure it is
- // acceptable to have more than one.
- if (a.hasValue() && (!a.isMultiValued())) {
- final LocalizableMessage message =
- ERR_ARGPARSER_NOT_MULTIVALUED_FOR_LONG_ID.get(origArgName);
- throw new ArgumentException(message);
- }
-
- a.addValue(argValue);
- } else {
- if (argValue != null) {
- final LocalizableMessage message =
- ERR_ARGPARSER_ARG_FOR_LONG_ID_DOESNT_TAKE_VALUE.get(origArgName);
- throw new ArgumentException(message);
- }
- }
- } else if (arg.startsWith("-")) {
- // This indicates that we are using the 1-character name to
- // reference the argument. It may be in any of the following
- // forms:
- // -n
- // -nvalue
- // -n value
- if (arg.equals("-")) {
- final LocalizableMessage message = ERR_ARGPARSER_INVALID_DASH_AS_ARGUMENT.get();
- throw new ArgumentException(message);
- }
-
- final char argCharacter = arg.charAt(1);
- String argValue;
- if (arg.length() > 2) {
- argValue = arg.substring(2);
- } else {
- argValue = null;
- }
-
- // Get the argument with the specified short ID.
- final Argument a = shortIDMap.get(argCharacter);
- if (a == null) {
- if (argCharacter == '?') {
- // "-?" will always be interpreted as requesting usage
- // information.
- try {
- getUsage(usageOutputStream);
- } catch (final Exception e) {
- // Ignored.
- }
-
- return;
- } else if ((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;
- try {
- // TODO
- // DirectoryServer.printVersion(usageOutputStream);
- } catch (final Exception e) {
- // Ignored.
- }
- return;
- } else {
- // There is no such argument registered.
- final LocalizableMessage message =
- ERR_ARGPARSER_NO_ARGUMENT_WITH_SHORT_ID.get(String
- .valueOf(argCharacter));
- throw new ArgumentException(message);
- }
- } else {
- a.setPresent(true);
-
- // If this is the usage argument, then immediately stop and
- // print usage information.
- if ((usageArgument != null) && usageArgument.getName().equals(a.getName())) {
- try {
- getUsage(usageOutputStream);
- } catch (final Exception e) {
- // Ignored.
- }
-
- return;
- }
- }
-
- // See if the argument takes a value. If so, then make sure one
- // was provided. If not, then make sure none was provided.
- if (a.needsValue()) {
- if (argValue == null) {
- if ((i + 1) == numArguments) {
- final LocalizableMessage message =
- ERR_ARGPARSER_NO_VALUE_FOR_ARGUMENT_WITH_SHORT_ID.get(String
- .valueOf(argCharacter));
- throw new ArgumentException(message);
- }
-
- argValue = rawArguments[++i];
- }
-
- final LocalizableMessageBuilder invalidReason = new LocalizableMessageBuilder();
- if (!a.valueIsAcceptable(argValue, invalidReason)) {
- final LocalizableMessage message =
- ERR_ARGPARSER_VALUE_UNACCEPTABLE_FOR_SHORT_ID.get(argValue, String
- .valueOf(argCharacter), invalidReason.toString());
- throw new ArgumentException(message);
- }
-
- // If the argument already has a value, then make sure it is
- // acceptable to have more than one.
- if (a.hasValue() && (!a.isMultiValued())) {
- final LocalizableMessage message =
- ERR_ARGPARSER_NOT_MULTIVALUED_FOR_SHORT_ID.get(String
- .valueOf(argCharacter));
- throw new ArgumentException(message);
- }
-
- a.addValue(argValue);
- } else {
- if (argValue != null) {
- // If we've gotten here, then it means that we're in a
- // scenario like
- // "-abc" where "a" is a valid argument that doesn't
- // take a
- // value. However, this could still be valid if all
- // remaining
- // characters in the value are also valid argument
- // characters that
- // don't take values.
- final int valueLength = argValue.length();
- for (int j = 0; j < valueLength; j++) {
- final char c = argValue.charAt(j);
- final Argument b = shortIDMap.get(c);
- if (b == null) {
- // There is no such argument registered.
- final LocalizableMessage message =
- ERR_ARGPARSER_NO_ARGUMENT_WITH_SHORT_ID.get(String
- .valueOf(argCharacter));
- throw new ArgumentException(message);
- } else if (b.needsValue()) {
- // This means we're in a scenario like "-abc"
- // where b is
- // a valid argument that takes a value. We don't
- // support
- // that.
- final LocalizableMessage message =
- ERR_ARGPARSER_CANT_MIX_ARGS_WITH_VALUES
- .get(String.valueOf(argCharacter), argValue, String
- .valueOf(c));
- throw new ArgumentException(message);
- } else {
- b.setPresent(true);
-
- // If this is the usage argument, then
- // immediately stop
- // and print usage information.
- if ((usageArgument != null)
- && usageArgument.getName().equals(b.getName())) {
- try {
- getUsage(usageOutputStream);
- } catch (final Exception e) {
- // Ignored.
- }
-
- return;
- }
- }
- }
- }
- }
- } else if (allowsTrailingArguments) {
- // It doesn't start with a dash, so it must be a trailing
- // argument if that is acceptable.
- inTrailingArgs = true;
- trailingArguments.add(arg);
- } else {
- // It doesn't start with a dash and we don't allow trailing
- // arguments, so this is illegal.
- final LocalizableMessage message =
- ERR_ARGPARSER_DISALLOWED_TRAILING_ARGUMENT.get(arg);
- throw new ArgumentException(message);
- }
- }
-
- // If we allow trailing arguments and there is a minimum number,
- // then make sure at least that many were provided.
- if (allowsTrailingArguments && (minTrailingArguments > 0)) {
- if (trailingArguments.size() < minTrailingArguments) {
- final LocalizableMessage message =
- ERR_ARGPARSER_TOO_FEW_TRAILING_ARGUMENTS.get(minTrailingArguments);
- throw new ArgumentException(message);
- }
- }
-
- // If we don't have the argumentProperties, try to load a properties
- // file.
- if (argumentProperties == null) {
- argumentProperties = checkExternalProperties();
- }
-
- // Iterate through all of the arguments. For any that were not
- // provided on the command line, see if there is an alternate default
- // that
- // can be used. For cases where there is not, see that argument is
- // required.
- for (final Argument a : argumentList) {
- if (!a.isPresent()) {
- // See if there is a value in the properties that can be used
- if ((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);
- }
- if (addValue) {
- a.addValue(value);
- if (a.needsValue()) {
- a.setPresent(true);
- }
- a.setValueSetByProperty(true);
- }
- }
- }
- }
-
- if ((!a.isPresent()) && a.needsValue()) {
- // See if the argument defines a default.
- if (a.getDefaultValue() != null) {
- a.addValue(a.getDefaultValue());
- }
-
- // If there is still no value and the argument is required, then
- // that's a problem.
- if ((!a.hasValue()) && a.isRequired()) {
- final LocalizableMessage message =
- ERR_ARGPARSER_NO_VALUE_FOR_REQUIRED_ARG.get(a.getName());
- throw new ArgumentException(message);
- }
- }
- }
- }
-
- /**
- * Parses the provided set of arguments and updates the information
- * associated with this parser accordingly. Default values for unspecified
- * arguments may be read from the specified properties file.
- *
- * @param rawArguments
- * The set of raw arguments to parse.
- * @param propertiesFile
- * The path to the properties file to use to obtain default
- * values for unspecified properties.
- * @param requirePropertiesFile
- * Indicates whether the parsing should fail if the provided
- * properties file does not exist or is not accessible.
- * @throws ArgumentException
- * If a problem was encountered while parsing the provided
- * arguments or interacting with the properties file.
- */
- void parseArguments(final String[] rawArguments, final String propertiesFile,
- final boolean requirePropertiesFile) throws ArgumentException {
- this.rawArguments = rawArguments;
-
- Properties argumentProperties = null;
-
- try {
- final Properties p = new Properties();
- final FileInputStream fis = new FileInputStream(propertiesFile);
- p.load(fis);
- fis.close();
- argumentProperties = p;
- } catch (final Exception e) {
- if (requirePropertiesFile) {
- final LocalizableMessage message =
- ERR_ARGPARSER_CANNOT_READ_PROPERTIES_FILE.get(String
- .valueOf(propertiesFile), getExceptionMessage(e));
- throw new ArgumentException(message, e);
- }
- }
-
- parseArguments(rawArguments, argumentProperties);
- }
-
- /**
- * Indicates whether or not argument group description headers should be
- * printed.
- *
- * @return boolean where true means print the descriptions
- */
- boolean printUsageGroupHeaders() {
- // If there is only a single group then we won't print them.
- int groupsContainingArgs = 0;
- for (final ArgumentGroup argGroup : argumentGroups) {
- if (argGroup.containsNonHiddenArguments()) {
- groupsContainingArgs++;
- }
- }
- return groupsContainingArgs > 1;
- }
-
- /**
- * Sets the usage group description for the default argument group.
- *
- * @param description
- * for the default group
- */
- void setDefaultArgumentGroupDescription(final LocalizableMessage description) {
- this.defaultArgGroup.setDescription(description);
- }
-
- /**
- * Sets the provided argument which will be used to identify the file
- * properties.
- *
- * @param argument
- * The argument which will be used to identify the file
- * properties.
- */
- void setFilePropertiesArgument(final StringArgument argument) {
- filePropertiesPathArgument = argument;
- }
-
- /**
- * Sets the usage group description for the general argument group.
- *
- * @param description
- * for the general group
- */
- void setGeneralArgumentGroupDescription(final LocalizableMessage description) {
- this.generalArgGroup.setDescription(description);
- }
-
- /**
- * Sets the usage group description for the input/output argument group.
- *
- * @param description
- * for the input/output group
- */
- void setInputOutputArgumentGroupDescription(final LocalizableMessage description) {
- this.ioArgGroup.setDescription(description);
- }
-
- /**
- * Sets the usage group description for the LDAP argument group.
- *
- * @param description
- * for the LDAP group
- */
- void setLdapArgumentGroupDescription(final LocalizableMessage description) {
- this.ldapArgGroup.setDescription(description);
- }
-
- /**
- * Sets the provided argument which will be used to identify the file
- * properties.
- *
- * @param argument
- * The argument which will be used to indicate if we have to look
- * for properties file.
- */
- void setNoPropertiesFileArgument(final BooleanArgument argument) {
- noPropertiesFileArgument = argument;
- }
-
- /**
- * Sets the provided argument as one which will automatically trigger the
- * output of usage information if it is provided on the command line and no
- * further argument validation will be performed. Note that the caller will
- * still need to add this argument to the parser with the
- * <CODE>addArgument</CODE> method, and the argument should not be required
- * and should not take a value. Also, the caller will still need to check
- * for the presence of the usage argument after calling
- * <CODE>parseArguments</CODE> to know that no further processing will be
- * required.
- *
- * @param argument
- * The argument whose presence should automatically trigger the
- * display of usage information.
- */
- void setUsageArgument(final Argument argument) {
- usageArgument = argument;
- usageOutputStream = System.out;
- }
-
- /**
- * Sets the provided argument as one which will automatically trigger the
- * output of usage information if it is provided on the command line and no
- * further argument validation will be performed. Note that the caller will
- * still need to add this argument to the parser with the
- * <CODE>addArgument</CODE> method, and the argument should not be required
- * and should not take a value. Also, the caller will still need to check
- * for the presence of the usage argument after calling
- * <CODE>parseArguments</CODE> to know that no further processing will be
- * required.
- *
- * @param argument
- * The argument whose presence should automatically trigger the
- * display of usage information.
- * @param outputStream
- * The output stream to which the usage information should be
- * written.
- */
- void setUsageArgument(final Argument argument, final OutputStream outputStream) {
- usageArgument = argument;
- usageOutputStream = outputStream;
- }
-
- /**
- * Indicates whether the version or the usage information has been displayed
- * to the end user either by an explicit argument like "-H" or "--help", or
- * by a built-in argument like "-?".
- *
- * @return {@code true} if the usage information has been displayed, or
- * {@code false} if not.
- */
- boolean usageOrVersionDisplayed() {
- return usageOrVersionDisplayed;
- }
-
- /**
- * Get the absolute path of the properties file.
- *
- * @param directory
- * The location in which we should look for properties file
- * @return The absolute path of the properties file or null
- */
- private String findPropertiesFile(final String directory) {
- // Look for the tools properties file
- final File f =
- new File(directory, DEFAULT_OPENDJ_PROPERTIES_FILE_NAME
- + DEFAULT_OPENDJ_PROPERTIES_FILE_EXTENSION);
- if (f.exists() && f.canRead()) {
- return f.getAbsolutePath();
- } else {
- return null;
- }
- }
-
- private void initGroups() {
- this.argumentGroups = new TreeSet<ArgumentGroup>();
- this.argumentGroups.add(defaultArgGroup);
- this.argumentGroups.add(ldapArgGroup);
- this.argumentGroups.add(generalArgGroup);
- this.argumentGroups.add(ioArgGroup);
-
- try {
- versionArgument =
- new BooleanArgument(OPTION_LONG_PRODUCT_VERSION, OPTION_SHORT_PRODUCT_VERSION,
- OPTION_LONG_PRODUCT_VERSION, INFO_DESCRIPTION_PRODUCT_VERSION.get());
- this.generalArgGroup.addArgument(versionArgument);
- } catch (final ArgumentException e) {
- // ignore
- }
- }
-
- private boolean isGeneralArgument(final Argument arg) {
- boolean general = false;
- if (arg != null) {
- final String longId = arg.getLongIdentifier();
- general = OPTION_LONG_HELP.equals(longId) || OPTION_LONG_PRODUCT_VERSION.equals(longId);
- }
- return general;
- }
-
- private boolean isInputOutputArgument(final Argument arg) {
- boolean io = false;
- if (arg != null) {
- final String longId = arg.getLongIdentifier();
- io =
- OPTION_LONG_VERBOSE.equals(longId) || OPTION_LONG_QUIET.equals(longId)
- || OPTION_LONG_NO_PROMPT.equals(longId)
- || OPTION_LONG_PROP_FILE_PATH.equals(longId)
- || OPTION_LONG_NO_PROP_FILE.equals(longId)
- || OPTION_LONG_SCRIPT_FRIENDLY.equals(longId)
- || OPTION_LONG_DONT_WRAP.equals(longId)
- || OPTION_LONG_ENCODING.equals(longId)
- || OPTION_LONG_BATCH_FILE_PATH.equals(longId);
- }
- return io;
- }
-
- private boolean isLdapConnectionArgument(final Argument arg) {
- boolean ldap = false;
- if (arg != null) {
- final String longId = arg.getLongIdentifier();
- ldap =
- OPTION_LONG_USE_SSL.equals(longId) || OPTION_LONG_START_TLS.equals(longId)
- || OPTION_LONG_HOST.equals(longId) || OPTION_LONG_PORT.equals(longId)
- || OPTION_LONG_BINDDN.equals(longId)
- || OPTION_LONG_BINDPWD.equals(longId)
- || OPTION_LONG_BINDPWD_FILE.equals(longId)
- || OPTION_LONG_SASLOPTION.equals(longId)
- || OPTION_LONG_TRUSTALL.equals(longId)
- || OPTION_LONG_TRUSTSTOREPATH.equals(longId)
- || OPTION_LONG_TRUSTSTORE_PWD.equals(longId)
- || OPTION_LONG_TRUSTSTORE_PWD_FILE.equals(longId)
- || OPTION_LONG_KEYSTOREPATH.equals(longId)
- || OPTION_LONG_KEYSTORE_PWD.equals(longId)
- || OPTION_LONG_KEYSTORE_PWD_FILE.equals(longId)
- || OPTION_LONG_CERT_NICKNAME.equals(longId)
- || OPTION_LONG_REFERENCED_HOST_NAME.equals(longId)
- || OPTION_LONG_ADMIN_UID.equals(longId)
- || OPTION_LONG_REPORT_AUTHZ_ID.equals(longId)
- || OPTION_LONG_USE_PW_POLICY_CTL.equals(longId)
- || OPTION_LONG_USE_SASL_EXTERNAL.equals(longId)
- || OPTION_LONG_PROTOCOL_VERSION.equals(longId);
- }
- return ldap;
- }
-
- /**
- * Appends argument usage information to the provided buffer.
- *
- * @param a
- * The argument to handle.
- * @param buffer
- * 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.
- final int indentLength = INDENT.length();
- final Character shortID = a.getShortIdentifier();
- final String longID = a.getLongIdentifier();
- if (shortID != null) {
- final int currentLength = buffer.length();
-
- if (usageArgument.getName().equals(a.getName())) {
- buffer.append("-?, ");
- }
-
- buffer.append("-");
- buffer.append(shortID.charValue());
-
- if (a.needsValue() && longID == null) {
- buffer.append(" ");
- buffer.append(a.getValuePlaceholder());
- }
-
- if (longID != null) {
- final StringBuilder newBuffer = new StringBuilder();
- newBuffer.append(", --");
- newBuffer.append(longID);
-
- if (a.needsValue()) {
- newBuffer.append(" ");
- newBuffer.append(a.getValuePlaceholder());
- }
-
- final int lineLength = (buffer.length() - currentLength) + newBuffer.length();
- if (lineLength > MAX_LENGTH) {
- buffer.append(EOL);
- buffer.append(newBuffer.toString());
- } else {
- buffer.append(newBuffer.toString());
- }
- }
-
- buffer.append(EOL);
- } else {
- if (longID != null) {
- if (usageArgument.getName().equals(a.getName())) {
- buffer.append("-?, ");
- }
- buffer.append("--");
- buffer.append(longID);
-
- if (a.needsValue()) {
- buffer.append(" ");
- buffer.append(a.getValuePlaceholder());
- }
-
- 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(Utils.wrapText(a.getDescription(), MAX_LENGTH, 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()).toString());
- buffer.append(EOL);
- }
- }
-}
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/AuthRate.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/AuthRate.java
index 63aa356..bfe2b17 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/AuthRate.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/AuthRate.java
@@ -22,14 +22,14 @@
*
*
* Copyright 2010 Sun Microsystems, Inc.
- * Portions copyright 2011 ForgeRock AS
+ * Portions copyright 2011-2014 ForgeRock AS
*/
-
package com.forgerock.opendj.ldap.tools;
-import static com.forgerock.opendj.ldap.tools.ToolConstants.*;
+import static com.forgerock.opendj.cli.CliConstants.*;
import static com.forgerock.opendj.ldap.tools.ToolsMessages.*;
-import static com.forgerock.opendj.ldap.tools.Utils.filterExitCode;
+import static com.forgerock.opendj.ldap.tools.Utils.setDefaultPerfToolProperties;
+import static com.forgerock.opendj.cli.Utils.filterExitCode;
import java.util.ArrayList;
import java.util.LinkedList;
@@ -39,6 +39,16 @@
import java.util.concurrent.atomic.AtomicLong;
import org.forgerock.i18n.LocalizableMessage;
+
+import com.forgerock.opendj.cli.BooleanArgument;
+import com.forgerock.opendj.cli.CommonArguments;
+import com.forgerock.opendj.cli.ConsoleApplication;
+import com.forgerock.opendj.cli.ArgumentParser;
+import com.forgerock.opendj.cli.ArgumentException;
+import com.forgerock.opendj.cli.IntegerArgument;
+import com.forgerock.opendj.cli.MultiChoiceArgument;
+import com.forgerock.opendj.cli.StringArgument;
+
import org.forgerock.opendj.ldap.Connection;
import org.forgerock.opendj.ldap.ConnectionFactory;
import org.forgerock.opendj.ldap.DereferenceAliasesPolicy;
@@ -362,8 +372,7 @@
}
private int run(final String[] args) {
- // Create the command-line argument parser for use with this
- // program.
+ // Create the command-line argument parser for use with this program.
final LocalizableMessage toolDescription = INFO_AUTHRATE_TOOL_DESCRIPTION.get();
final ArgumentParser argParser =
new ArgumentParser(AuthRate.class.getName(), toolDescription, false, true, 0, 0,
@@ -382,27 +391,20 @@
IntegerArgument invalidCredPercent;
try {
- Utils.setDefaultPerfToolProperties();
+ setDefaultPerfToolProperties();
connectionFactoryProvider = new ConnectionFactoryProvider(argParser, this);
runner = new BindPerformanceRunner(argParser, this);
- propertiesFileArgument =
- new StringArgument("propertiesFilePath", null, OPTION_LONG_PROP_FILE_PATH,
- false, false, true, INFO_PROP_FILE_PATH_PLACEHOLDER.get(), null, null,
- INFO_DESCRIPTION_PROP_FILE_PATH.get());
+ propertiesFileArgument = CommonArguments.getPropertiesFileArgument();
argParser.addArgument(propertiesFileArgument);
argParser.setFilePropertiesArgument(propertiesFileArgument);
- noPropertiesFileArgument =
- new BooleanArgument("noPropertiesFileArgument", null, OPTION_LONG_NO_PROP_FILE,
- INFO_DESCRIPTION_NO_PROP_FILE.get());
+ noPropertiesFileArgument = CommonArguments.getNoPropertiesFileArgument();
argParser.addArgument(noPropertiesFileArgument);
argParser.setNoPropertiesFileArgument(noPropertiesFileArgument);
- showUsage =
- new BooleanArgument("showUsage", OPTION_SHORT_HELP, OPTION_LONG_HELP,
- INFO_DESCRIPTION_SHOWUSAGE.get());
+ showUsage = CommonArguments.getShowUsage();
argParser.addArgument(showUsage);
argParser.setUsageArgument(showUsage, getOutputStream());
@@ -439,9 +441,7 @@
invalidCredPercent.setPropertyName("invalidPassword");
argParser.addArgument(invalidCredPercent);
- verbose =
- new BooleanArgument("verbose", 'v', "verbose", INFO_DESCRIPTION_VERBOSE.get());
- verbose.setPropertyName("verbose");
+ verbose = CommonArguments.getVerbose();
argParser.addArgument(verbose);
scriptFriendly =
@@ -459,8 +459,8 @@
try {
argParser.parseArguments(args);
- // If we should just display usage or version information,
- // then print it and exit.
+ /* If we should just display usage or version information,
+ then print it and exit.*/
if (argParser.usageOrVersionDisplayed()) {
return 0;
}
@@ -482,9 +482,9 @@
final List<String> attributes = new LinkedList<String>();
final ArrayList<String> filterAndAttributeStrings = argParser.getTrailingArguments();
if (filterAndAttributeStrings.size() > 0) {
- // the list of trailing arguments should be structured as follow:
- // the first trailing argument is considered the filter, the other
- // as attributes.
+ /*The list of trailing arguments should be structured as follow:
+ the first trailing argument is considered the filter, the other
+ as attributes.*/
runner.filter = filterAndAttributeStrings.remove(0);
// The rest are attributes
@@ -503,8 +503,7 @@
return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue();
}
- // Try it out to make sure the format string and data sources
- // match.
+ // Try it out to make sure the format string and data sources match.
final Object[] data = DataSource.generateData(runner.getDataSources(), null);
try {
if (runner.baseDN != null && runner.filter != null) {
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/BooleanArgument.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/BooleanArgument.java
deleted file mode 100644
index eee0a46..0000000
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/BooleanArgument.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at legal-notices/CDDLv1_0.txt.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Copyright 2006-2008 Sun Microsystems, Inc.
- */
-package com.forgerock.opendj.ldap.tools;
-
-import static com.forgerock.opendj.ldap.tools.ToolsMessages.ERR_BOOLEANARG_NO_VALUE_ALLOWED;
-
-import org.forgerock.i18n.LocalizableMessage;
-import org.forgerock.i18n.LocalizableMessageBuilder;
-
-/**
- * This class defines an argument type that will be used to represent Boolean
- * values. These arguments will never take values from the command line but and
- * will never be required. If the argument is provided, then it will be
- * considered true, and if not then it will be considered false. As such, the
- * default value will always be "false".
- */
-final class BooleanArgument extends Argument {
- /**
- * Creates a new Boolean argument with the provided information.
- *
- * @param name
- * The generic name that should be used to refer to this
- * argument.
- * @param shortIdentifier
- * The single-character identifier for this argument, or
- * <CODE>null</CODE> if there is none.
- * @param longIdentifier
- * The long identifier for this argument, or <CODE>null</CODE> if
- * there is none.
- * @param description
- * LocalizableMessage for the description of this argument.
- * @throws ArgumentException
- * If there is a problem with any of the parameters used to
- * create this argument.
- */
- public BooleanArgument(final String name, final Character shortIdentifier,
- final String longIdentifier, final LocalizableMessage description)
- throws ArgumentException {
- super(name, shortIdentifier, longIdentifier, false, false, false, null, String
- .valueOf(false), null, description);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- final public void addValue(final String valueString) {
- if (valueString != null) {
- clearValues();
- super.addValue(valueString);
- super.setPresent(Boolean.valueOf(valueString));
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- final public void setPresent(final boolean isPresent) {
- addValue(String.valueOf(isPresent));
- }
-
- /**
- * Indicates whether the provided value is acceptable for use in this
- * argument.
- *
- * @param valueString
- * The value for which to make the determination.
- * @param invalidReason
- * A buffer into which the invalid reason may be written if the
- * value is not acceptable.
- * @return <CODE>true</CODE> if the value is acceptable, or
- * <CODE>false</CODE> if it is not.
- */
- @Override
- public boolean valueIsAcceptable(final String valueString,
- final LocalizableMessageBuilder invalidReason) {
- // This argument type should never have a value, so any value
- // provided will
- // be unacceptable.
-
- invalidReason.append(ERR_BOOLEANARG_NO_VALUE_ALLOWED.get(getName()));
-
- return false;
- }
-
-}
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/CLIException.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/CLIException.java
deleted file mode 100755
index ab2b4dd..0000000
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/CLIException.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at legal-notices/CDDLv1_0.txt.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Copyright 2008 Sun Microsystems, Inc.
- */
-package com.forgerock.opendj.ldap.tools;
-
-import static com.forgerock.opendj.ldap.tools.ToolsMessages.ERR_CONSOLE_INPUT_ERROR;
-
-import org.forgerock.i18n.LocalizableException;
-import org.forgerock.i18n.LocalizableMessage;
-
-/**
- * Thrown to indicate that a problem occurred when interacting with the client.
- * For example, if input provided by the client was invalid.
- */
-@SuppressWarnings("serial")
-final class CLIException extends Exception implements LocalizableException {
-
- /**
- * Adapts any exception that may have occurred whilst reading input from the
- * console.
- *
- * @param cause
- * The exception that occurred whilst reading input from the
- * console.
- * @return Returns a new CLI exception describing a problem that occurred
- * whilst reading input from the console.
- */
- static CLIException adaptInputException(final Throwable cause) {
- return new CLIException(ERR_CONSOLE_INPUT_ERROR.get(cause.getMessage()), cause);
- }
-
- private final LocalizableMessage message;
-
- /**
- * Creates a new CLI exception with the provided message.
- *
- * @param message
- * The message explaining the problem that occurred.
- */
- CLIException(final LocalizableMessage message) {
- super(message.toString());
- this.message = message;
- }
-
- /**
- * Creates a new CLI exception with the provided message and cause.
- *
- * @param message
- * The message explaining the problem that occurred.
- * @param cause
- * The cause of this exception.
- */
- CLIException(final LocalizableMessage message, final Throwable cause) {
- super(message.toString(), cause);
- this.message = message;
- }
-
- public LocalizableMessage getMessageObject() {
- return message;
- }
-
-}
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ConnectionFactoryProvider.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ConnectionFactoryProvider.java
index 45ea5b3..1088b61 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ConnectionFactoryProvider.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ConnectionFactoryProvider.java
@@ -22,12 +22,11 @@
*
*
* Copyright 2010 Sun Microsystems, Inc.
- * Portions copyright 2011-2013 ForgeRock AS
+ * Portions copyright 2011-2014 ForgeRock AS
*/
-
package com.forgerock.opendj.ldap.tools;
-import static com.forgerock.opendj.ldap.tools.ToolConstants.*;
+import static com.forgerock.opendj.cli.CliConstants.*;
import static com.forgerock.opendj.ldap.tools.ToolsMessages.*;
import java.io.File;
@@ -47,6 +46,16 @@
import javax.net.ssl.X509TrustManager;
import org.forgerock.i18n.LocalizableMessage;
+
+import com.forgerock.opendj.cli.ArgumentException;
+import com.forgerock.opendj.cli.ArgumentParser;
+import com.forgerock.opendj.cli.BooleanArgument;
+import com.forgerock.opendj.cli.CLIException;
+import com.forgerock.opendj.cli.ConsoleApplication;
+import com.forgerock.opendj.cli.FileBasedArgument;
+import com.forgerock.opendj.cli.IntegerArgument;
+import com.forgerock.opendj.cli.StringArgument;
+
import org.forgerock.opendj.ldap.ConnectionFactory;
import org.forgerock.opendj.ldap.KeyManagers;
import org.forgerock.opendj.ldap.LDAPConnectionFactory;
@@ -68,11 +77,6 @@
*/
final class ConnectionFactoryProvider {
/**
- * End Of Line.
- */
- static final String EOL = System.getProperty("line.separator");
-
- /**
* The Logger.
*/
static final Logger LOG = Logger.getLogger(ConnectionFactoryProvider.class.getName());
@@ -353,8 +357,8 @@
throw new ArgumentException(message);
}
- // Couldn't have at the same time trustAll and
- // trustStore related arg
+ /* Couldn't have at the same time trustAll and
+ trustStore related arg*/
if (trustAllArg.isPresent() && trustStorePathArg.isPresent()) {
final LocalizableMessage message =
ERR_TOOL_CONFLICTING_ARGS.get(trustAllArg.getLongIdentifier(),
@@ -374,8 +378,8 @@
throw new ArgumentException(message);
}
- // Couldn't have at the same time trustStorePasswordArg and
- // trustStorePasswordFileArg
+ /* Couldn't have at the same time trustStorePasswordArg and
+ trustStorePasswordFileArg*/
if (trustStorePasswordArg.isPresent() && trustStorePasswordFileArg.isPresent()) {
final LocalizableMessage message =
ERR_TOOL_CONFLICTING_ARGS.get(trustStorePasswordArg.getLongIdentifier(),
@@ -401,8 +405,7 @@
}
}
- // Couldn't have at the same time startTLSArg and
- // useSSLArg
+ // Couldn't have at the same time startTLSArg and useSSLArg
if (useStartTLSArg.isPresent() && useSSLArg.isPresent()) {
final LocalizableMessage message =
ERR_TOOL_CONFLICTING_ARGS.get(useStartTLSArg.getLongIdentifier(), useSSLArg
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ConsoleApplication.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ConsoleApplication.java
deleted file mode 100755
index a1d38f6..0000000
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ConsoleApplication.java
+++ /dev/null
@@ -1,324 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at legal-notices/CDDLv1_0.txt.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Copyright 2008-2009 Sun Microsystems, Inc.
- * Portions copyright 2011-2013 ForgeRock AS
- * Portions copyright 2011 Nemanja Lukić
- */
-package com.forgerock.opendj.ldap.tools;
-
-import static com.forgerock.opendj.ldap.tools.ToolsMessages.INFO_ERROR_EMPTY_RESPONSE;
-import static com.forgerock.opendj.ldap.tools.ToolsMessages.INFO_MENU_PROMPT_RETURN_TO_CONTINUE;
-import static com.forgerock.opendj.ldap.tools.ToolsMessages.INFO_PROMPT_SINGLE_DEFAULT;
-import static com.forgerock.opendj.ldap.tools.Utils.MAX_LINE_WIDTH;
-import static com.forgerock.opendj.ldap.tools.Utils.wrapText;
-
-import java.io.BufferedReader;
-import java.io.Closeable;
-import java.io.Console;
-import java.io.EOFException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.PrintStream;
-
-import org.forgerock.i18n.LocalizableMessage;
-
-/**
- * This class provides an abstract base class which can be used as the basis of
- * a console-based application.
- */
-abstract class ConsoleApplication {
- private final PrintStream err;
-
- private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
-
- private final InputStream in = System.in;
-
- private final PrintStream out;
-
- private final Console console = System.console();
-
- /**
- * Creates a new console application instance.
- */
- ConsoleApplication() {
- this(System.out, System.err);
- }
-
- /**
- * Creates a new console application instance with
- * provided standard and error out streams.
- */
- ConsoleApplication(PrintStream out, PrintStream err) {
- this.out = out;
- this.err = err;
- }
-
- /**
- * Closes the provided {@code Closeable}s if they are not {@code null}.
- *
- * @param closeables
- * The closeables to be closed.
- */
- final void closeIfNotNull(Closeable... closeables) {
- if (closeables == null) {
- return;
- }
- for (Closeable closeable : closeables) {
- if (closeable != null) {
- try {
- closeable.close();
- } catch (Exception ignored) {
- // Do nothing.
- }
- }
- }
- }
-
- /**
- * Returns the application error stream.
- *
- * @return The application error stream.
- */
- final PrintStream getErrorStream() {
- return err;
- }
-
- /**
- * Returns the application input stream.
- *
- * @return The application input stream.
- */
- final InputStream getInputStream() {
- return in;
- }
-
- /**
- * Returns the application output stream.
- *
- * @return The application output stream.
- */
- final PrintStream getOutputStream() {
- return out;
- }
-
- /**
- * Indicates whether or not the user has requested interactive behavior. The
- * default implementation returns {@code true}.
- *
- * @return {@code true} if the user has requested interactive behavior.
- */
- boolean isInteractive() {
- return true;
- }
-
- /**
- * Indicates whether or not the user has requested quiet output. The default
- * implementation returns {@code false}.
- *
- * @return {@code true} if the user has requested quiet output.
- */
- boolean isQuiet() {
- return false;
- }
-
- /**
- * Indicates whether or not the user has requested script-friendly output.
- * The default implementation returns {@code false}.
- *
- * @return {@code true} if the user has requested script-friendly output.
- */
- boolean isScriptFriendly() {
- return false;
- }
-
- /**
- * Indicates whether or not the user has requested verbose output. The
- * default implementation returns {@code false}.
- *
- * @return {@code true} if the user has requested verbose output.
- */
- boolean isVerbose() {
- return false;
- }
-
- /**
- * Interactively prompts the user to press return to continue. This method
- * should be called in situations where a user needs to be given a chance to
- * read some documentation before continuing (continuing may cause the
- * documentation to be scrolled out of view).
- */
- final void pressReturnToContinue() {
- final LocalizableMessage msg = INFO_MENU_PROMPT_RETURN_TO_CONTINUE.get();
- try {
- readLineOfInput(msg);
- } catch (final CLIException e) {
- // Ignore the exception - applications don't care.
- }
- }
-
- /**
- * Displays a message to the error stream.
- *
- * @param msg
- * The message.
- */
- final void print(final LocalizableMessage msg) {
- err.print(wrapText(msg, MAX_LINE_WIDTH));
- }
-
- /**
- * Displays a blank line to the error stream.
- */
- final void println() {
- err.println();
- }
-
- /**
- * Displays a message to the error stream.
- *
- * @param msg
- * The message.
- */
- final void println(final LocalizableMessage msg) {
- err.println(wrapText(msg, MAX_LINE_WIDTH));
- }
-
- /**
- * Displays a message to the error stream indented by the specified number
- * of columns.
- *
- * @param msg
- * The message.
- * @param indent
- * The number of columns to indent.
- */
- final void println(final LocalizableMessage msg, final int indent) {
- err.println(wrapText(msg, MAX_LINE_WIDTH, indent));
- }
-
- /**
- * Displays a message to the error stream if verbose mode is enabled.
- *
- * @param msg
- * The verbose message.
- */
- final void printVerboseMessage(final LocalizableMessage msg) {
- if (isVerbose() || isInteractive()) {
- err.println(wrapText(msg, MAX_LINE_WIDTH));
- }
- }
-
- /**
- * Interactively prompts (on error output) the user to provide a string
- * value. Any non-empty string will be allowed (the empty string will
- * indicate that the default should be used, if there is one).
- *
- * @param prompt
- * The prompt to present to the user.
- * @param defaultValue
- * The default value to assume if the user presses ENTER without
- * typing anything, or {@code null} if there should not be a
- * default and the user must explicitly provide a value.
- * @throws CLIException
- * If the line of input could not be retrieved for some reason.
- * @return The string value read from the user.
- */
- final String readInput(LocalizableMessage prompt, final String defaultValue)
- throws CLIException {
- while (true) {
- if (defaultValue != null) {
- prompt = INFO_PROMPT_SINGLE_DEFAULT.get(prompt.toString(), defaultValue);
- }
- final String response = readLineOfInput(prompt);
-
- if ("".equals(response)) {
- if (defaultValue == null) {
- print(INFO_ERROR_EMPTY_RESPONSE.get());
- } else {
- return defaultValue;
- }
- } else {
- return response;
- }
- }
- }
-
- /**
- * Interactively reads a password from the console.
- *
- * @param prompt
- * The password prompt.
- * @return The password.
- * @throws CLIException
- * If the password could not be retrieved for some reason.
- */
- final char[] readPassword(final LocalizableMessage prompt) throws CLIException {
- if (console != null) {
- if (prompt != null) {
- err.print(wrapText(prompt, MAX_LINE_WIDTH));
- err.print(" ");
- }
- try {
- final char[] password = console.readPassword();
- if (password == null) {
- throw new EOFException("End of input");
- }
- return password;
- } catch (final Throwable e) {
- throw CLIException.adaptInputException(e);
- }
- } else {
- // FIXME: should go direct to char[] and avoid the String.
- return readLineOfInput(prompt).toCharArray();
- }
- }
-
- /**
- * Interactively retrieves a line of input from the console.
- *
- * @param prompt
- * The prompt.
- * @return The line of input.
- * @throws CLIException
- * If the line of input could not be retrieved for some reason.
- */
- private final String readLineOfInput(final LocalizableMessage prompt) throws CLIException {
- if (prompt != null) {
- err.print(wrapText(prompt, MAX_LINE_WIDTH));
- err.print(" ");
- }
- try {
- final String s = reader.readLine();
- if (s == null) {
- throw CLIException.adaptInputException(new EOFException("End of input"));
- } else {
- return s;
- }
- } catch (final IOException e) {
- throw CLIException.adaptInputException(e);
- }
- }
-
-}
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/DataSource.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/DataSource.java
index b405a67..1f7f65a 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/DataSource.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/DataSource.java
@@ -22,6 +22,7 @@
*
*
* Copyright 2009-2010 Sun Microsystems, Inc.
+ * Portions copyright 2014 ForgeRock AS
*/
package com.forgerock.opendj.ldap.tools;
@@ -37,7 +38,9 @@
import org.forgerock.i18n.LocalizableMessage;
+import com.forgerock.opendj.cli.ArgumentException;
import com.forgerock.opendj.util.StaticUtils;
+
import org.forgerock.util.Reject;
/**
@@ -249,7 +252,7 @@
* Data sources that will generate arguments referenced by the
* format specifiers in the format string.
* @param data
- * The array where genereated data will be placed to format the
+ * The array where generated data will be placed to format the
* string.
* @return A formatted string
*/
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/FileBasedArgument.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/FileBasedArgument.java
deleted file mode 100644
index 816f891..0000000
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/FileBasedArgument.java
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at legal-notices/CDDLv1_0.txt.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Copyright 2006-2008 Sun Microsystems, Inc.
- */
-package com.forgerock.opendj.ldap.tools;
-
-import static com.forgerock.opendj.ldap.tools.ToolsMessages.*;
-import static com.forgerock.opendj.util.StaticUtils.getExceptionMessage;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.util.LinkedHashMap;
-
-import org.forgerock.i18n.LocalizableMessage;
-import org.forgerock.i18n.LocalizableMessageBuilder;
-
-/**
- * This class defines an argument whose value will be read from a file rather
- * than actually specified on the command-line. When a value is specified on the
- * command line, it will be treated as the path to the file containing the
- * actual value rather than the value itself. <BR>
- * <BR>
- * Note that if if no filename is provided on the command line but a default
- * value is specified programatically or if the default value is read from a
- * specified property, then that default value will be taken as the actual value
- * rather than a filename. <BR>
- * <BR>
- * Also note that this argument type assumes that the entire value for the
- * argument is on a single line in the specified file. If the file contains
- * multiple lines, then only the first line will be read.
- */
-final class FileBasedArgument extends Argument {
- // The mapping between filenames specified and the first lines read
- // from those
- // files.
- private final LinkedHashMap<String, String> namesToValues;
-
- /**
- * Creates a new file-based argument with the provided information.
- *
- * @param name
- * The generic name that should be used to refer to this
- * argument.
- * @param shortIdentifier
- * The single-character identifier for this argument, or
- * <CODE>null</CODE> if there is none.
- * @param longIdentifier
- * The long identifier for this argument, or <CODE>null</CODE> if
- * there is none.
- * @param isRequired
- * Indicates whether this argument must be specified on the
- * command line.
- * @param isMultiValued
- * Indicates whether this argument may be specified more than
- * once to provide multiple values.
- * @param valuePlaceholder
- * The placeholder for the argument value that will be displayed
- * in usage information, or <CODE>null</CODE> if this argument
- * does not require a value.
- * @param defaultValue
- * The default value that should be used for this argument if
- * none is provided in a properties file or on the command line.
- * This may be <CODE>null</CODE> if there is no generic default.
- * @param propertyName
- * The name of the property in a property file that may be used
- * to override the default value but will be overridden by a
- * command-line argument.
- * @param description
- * LocalizableMessage for the description of this argument.
- * @throws ArgumentException
- * If there is a problem with any of the parameters used to
- * create this argument.
- */
- public FileBasedArgument(final String name, final Character shortIdentifier,
- final String longIdentifier, final boolean isRequired, final boolean isMultiValued,
- final LocalizableMessage valuePlaceholder, final String defaultValue,
- final String propertyName, final LocalizableMessage description)
- throws ArgumentException {
- super(name, shortIdentifier, longIdentifier, isRequired, isMultiValued, true,
- valuePlaceholder, defaultValue, propertyName, description);
-
- namesToValues = new LinkedHashMap<String, String>();
- }
-
- /**
- * Creates a new file-based argument with the provided information.
- *
- * @param name
- * The generic name that should be used to refer to this
- * argument.
- * @param shortIdentifier
- * The single-character identifier for this argument, or
- * <CODE>null</CODE> if there is none.
- * @param longIdentifier
- * The long identifier for this argument, or <CODE>null</CODE> if
- * there is none.
- * @param isRequired
- * Indicates whether this argument must be specified on the
- * command line.
- * @param valuePlaceholder
- * The placeholder for the argument value that will be displayed
- * in usage information, or <CODE>null</CODE> if this argument
- * does not require a value.
- * @param description
- * LocalizableMessage for the description of this argument.
- * @throws ArgumentException
- * If there is a problem with any of the parameters used to
- * create this argument.
- */
- public FileBasedArgument(final String name, final Character shortIdentifier,
- final String longIdentifier, final boolean isRequired,
- final LocalizableMessage valuePlaceholder, final LocalizableMessage description)
- throws ArgumentException {
- super(name, shortIdentifier, longIdentifier, isRequired, false, true, valuePlaceholder,
- null, null, description);
-
- namesToValues = new LinkedHashMap<String, String>();
- }
-
- /**
- * Adds a value to the set of values for this argument. This should only be
- * called if the value is allowed by the <CODE>valueIsAcceptable</CODE>
- * method. Note that in this case, correct behavior depends on a previous
- * successful call to <CODE>valueIsAcceptable</CODE> so that the value read
- * from the file may be stored in the name-to-value hash and used in place
- * of the filename here.
- *
- * @param valueString
- * The string representation of the value to add to this
- * argument.
- */
- @Override
- public void addValue(final String valueString) {
- final String actualValue = namesToValues.get(valueString);
- if (actualValue != null) {
- super.addValue(actualValue);
- }
- }
-
- /**
- * Retrieves a map between the filenames specified on the command line and
- * the first lines read from those files.
- *
- * @return A map between the filenames specified on the command line and the
- * first lines read from those files.
- */
- public LinkedHashMap<String, String> getNameToValueMap() {
- return namesToValues;
- }
-
- /**
- * Indicates whether the provided value is acceptable for use in this
- * argument.
- *
- * @param valueString
- * The value for which to make the determination.
- * @param invalidReason
- * A buffer into which the invalid reason may be written if the
- * value is not acceptable.
- * @return <CODE>true</CODE> if the value is acceptable, or
- * <CODE>false</CODE> if it is not.
- */
- @Override
- public boolean valueIsAcceptable(final String valueString,
- final LocalizableMessageBuilder invalidReason) {
- // First, make sure that the specified file exists.
- File valueFile;
- try {
- valueFile = new File(valueString);
- if (!valueFile.exists()) {
- invalidReason.append(ERR_FILEARG_NO_SUCH_FILE.get(valueString, getName()));
- return false;
- }
- } catch (final Exception e) {
- invalidReason.append(ERR_FILEARG_CANNOT_VERIFY_FILE_EXISTENCE.get(valueString,
- getName(), getExceptionMessage(e)));
- return false;
- }
-
- // Open the file for reading.
- BufferedReader reader;
- try {
- reader = new BufferedReader(new FileReader(valueFile));
- } catch (final Exception e) {
- invalidReason.append(ERR_FILEARG_CANNOT_OPEN_FILE.get(valueString, getName(),
- getExceptionMessage(e)));
- return false;
- }
-
- // Read the first line and close the file.
- String line;
- try {
- line = reader.readLine();
- } catch (final Exception e) {
- invalidReason.append(ERR_FILEARG_CANNOT_READ_FILE.get(valueString, getName(),
- getExceptionMessage(e)));
- return false;
- } finally {
- try {
- reader.close();
- } catch (final Exception e) {
- // Ignored.
- }
- }
-
- // If the line read is null, then that means the file was empty.
- if (line == null) {
-
- invalidReason.append(ERR_FILEARG_EMPTY_FILE.get(valueString, getName()));
- return false;
- }
-
- // Store the value in the hash so it will be available for addValue.
- // We
- // won't do any validation on the value itself, so anything that we
- // read
- // will be considered acceptable.
- namesToValues.put(valueString, line);
- return true;
- }
-}
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/IntegerArgument.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/IntegerArgument.java
deleted file mode 100644
index 3effa04..0000000
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/IntegerArgument.java
+++ /dev/null
@@ -1,485 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at legal-notices/CDDLv1_0.txt.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Copyright 2006-2010 Sun Microsystems, Inc.
- */
-package com.forgerock.opendj.ldap.tools;
-
-import static com.forgerock.opendj.ldap.tools.ToolsMessages.ERR_ARG_CANNOT_DECODE_AS_INT;
-import static com.forgerock.opendj.ldap.tools.ToolsMessages.ERR_INTARG_LOWER_BOUND_ABOVE_UPPER_BOUND;
-import static com.forgerock.opendj.ldap.tools.ToolsMessages.ERR_INTARG_VALUE_ABOVE_UPPER_BOUND;
-import static com.forgerock.opendj.ldap.tools.ToolsMessages.ERR_INTARG_VALUE_BELOW_LOWER_BOUND;
-
-import org.forgerock.i18n.LocalizableMessage;
-import org.forgerock.i18n.LocalizableMessageBuilder;
-
-/**
- * This class defines an argument type that will only accept integer values, and
- * potentially only those in a given range.
- */
-final class IntegerArgument extends Argument {
- // Indicates whether a lower bound will be enforced for this argument.
- private final boolean hasLowerBound;
-
- // Indicates whether an upper bound will be enforced for this
- // argument.
- private final boolean hasUpperBound;
-
- // The lower bound that will be enforced for this argument.
- private final double lowerBound;
-
- // The upper bound that will be enforced for this argument.
- private final double upperBound;
-
- /**
- * Creates a new integer argument with the provided information.
- *
- * @param name
- * The generic name that should be used to refer to this
- * argument.
- * @param shortIdentifier
- * The single-character identifier for this argument, or
- * <CODE>null</CODE> if there is none.
- * @param longIdentifier
- * The long identifier for this argument, or <CODE>null</CODE> if
- * there is none.
- * @param isRequired
- * Indicates whether this argument must be specified on the
- * command line.
- * @param isMultiValued
- * Indicates whether this argument may be specified more than
- * once to provide multiple values.
- * @param needsValue
- * Indicates whether this argument requires a value.
- * @param valuePlaceholder
- * The placeholder for the argument value that will be displayed
- * in usage information, or <CODE>null</CODE> if this argument
- * does not require a value.
- * @param defaultValue
- * The default value that should be used for this argument if
- * none is provided in a properties file or on the command line.
- * This may be <CODE>null</CODE> if there is no generic default.
- * @param propertyName
- * The name of the property in a property file that may be used
- * to override the default value but will be overridden by a
- * command-line argument.
- * @param hasLowerBound
- * Indicates whether a lower bound should be enforced for values
- * of this argument.
- * @param lowerBound
- * The lower bound that should be enforced for values of this
- * argument.
- * @param hasUpperBound
- * Indicates whether an upperbound should be enforced for values
- * of this argument.
- * @param upperBound
- * The upper bound that should be enforced for values of this
- * argument.
- * @param description
- * LocalizableMessage for the description of this argument.
- * @throws ArgumentException
- * If there is a problem with any of the parameters used to
- * create this argument.
- */
- public IntegerArgument(final String name, final Character shortIdentifier,
- final String longIdentifier, final boolean isRequired, final boolean isMultiValued,
- final boolean needsValue, final LocalizableMessage valuePlaceholder,
- final double defaultValue, final String propertyName, final boolean hasLowerBound,
- final double lowerBound, final boolean hasUpperBound, final double upperBound,
- final LocalizableMessage description) throws ArgumentException {
- super(name, shortIdentifier, longIdentifier, isRequired, isMultiValued, needsValue,
- valuePlaceholder, String.valueOf(defaultValue), propertyName, description);
-
- this.hasLowerBound = hasLowerBound;
- this.hasUpperBound = hasUpperBound;
- this.lowerBound = lowerBound;
- this.upperBound = upperBound;
-
- if (hasLowerBound && hasUpperBound && (lowerBound > upperBound)) {
- final LocalizableMessage message =
- ERR_INTARG_LOWER_BOUND_ABOVE_UPPER_BOUND.get(name, lowerBound, upperBound);
- throw new ArgumentException(message);
- }
- }
-
- /**
- * Creates a new integer argument with the provided information.
- *
- * @param name
- * The generic name that should be used to refer to this
- * argument.
- * @param shortIdentifier
- * The single-character identifier for this argument, or
- * <CODE>null</CODE> if there is none.
- * @param longIdentifier
- * The long identifier for this argument, or <CODE>null</CODE> if
- * there is none.
- * @param isRequired
- * Indicates whether this argument must be specified on the
- * command line.
- * @param isMultiValued
- * Indicates whether this argument may be specified more than
- * once to provide multiple values.
- * @param needsValue
- * Indicates whether this argument requires a value.
- * @param valuePlaceholder
- * The placeholder for the argument value that will be displayed
- * in usage information, or <CODE>null</CODE> if this argument
- * does not require a value.
- * @param defaultValue
- * The default value that should be used for this argument if
- * none is provided in a properties file or on the command line.
- * This may be <CODE>null</CODE> if there is no generic default.
- * @param propertyName
- * The name of the property in a property file that may be used
- * to override the default value but will be overridden by a
- * command-line argument.
- * @param description
- * LocalizableMessage for the description of this argument.
- * @throws ArgumentException
- * If there is a problem with any of the parameters used to
- * create this argument.
- */
- public IntegerArgument(final String name, final Character shortIdentifier,
- final String longIdentifier, final boolean isRequired, final boolean isMultiValued,
- final boolean needsValue, final LocalizableMessage valuePlaceholder,
- final double defaultValue, final String propertyName,
- final LocalizableMessage description) throws ArgumentException {
- super(name, shortIdentifier, longIdentifier, isRequired, isMultiValued, needsValue,
- valuePlaceholder, String.format("%f", defaultValue), propertyName, description);
-
- hasLowerBound = false;
- hasUpperBound = false;
- lowerBound = Integer.MIN_VALUE;
- upperBound = Integer.MAX_VALUE;
- }
-
- /**
- * Creates a new integer argument with the provided information.
- *
- * @param name
- * The generic name that should be used to refer to this
- * argument.
- * @param shortIdentifier
- * The single-character identifier for this argument, or
- * <CODE>null</CODE> if there is none.
- * @param longIdentifier
- * The long identifier for this argument, or <CODE>null</CODE> if
- * there is none.
- * @param isRequired
- * Indicates whether this argument must be specified on the
- * command line.
- * @param isMultiValued
- * Indicates whether this argument may be specified more than
- * once to provide multiple values.
- * @param needsValue
- * Indicates whether this argument requires a value.
- * @param valuePlaceholder
- * The placeholder for the argument value that will be displayed
- * in usage information, or <CODE>null</CODE> if this argument
- * does not require a value.
- * @param defaultValue
- * The default value that should be used for this argument if
- * none is provided in a properties file or on the command line.
- * This may be <CODE>null</CODE> if there is no generic default.
- * @param propertyName
- * The name of the property in a property file that may be used
- * to override the default value but will be overridden by a
- * command-line argument.
- * @param hasLowerBound
- * Indicates whether a lower bound should be enforced for values
- * of this argument.
- * @param lowerBound
- * The lower bound that should be enforced for values of this
- * argument.
- * @param hasUpperBound
- * Indicates whether an upperbound should be enforced for values
- * of this argument.
- * @param upperBound
- * The upper bound that should be enforced for values of this
- * argument.
- * @param description
- * LocalizableMessage for the description of this argument.
- * @throws ArgumentException
- * If there is a problem with any of the parameters used to
- * create this argument.
- */
- public IntegerArgument(final String name, final Character shortIdentifier,
- final String longIdentifier, final boolean isRequired, final boolean isMultiValued,
- final boolean needsValue, final LocalizableMessage valuePlaceholder,
- final int defaultValue, final String propertyName, final boolean hasLowerBound,
- final double lowerBound, final boolean hasUpperBound, final double upperBound,
- final LocalizableMessage description) throws ArgumentException {
- super(name, shortIdentifier, longIdentifier, isRequired, isMultiValued, needsValue,
- valuePlaceholder, String.valueOf(defaultValue), propertyName, description);
-
- this.hasLowerBound = hasLowerBound;
- this.hasUpperBound = hasUpperBound;
- this.lowerBound = lowerBound;
- this.upperBound = upperBound;
-
- if (hasLowerBound && hasUpperBound && (lowerBound > upperBound)) {
- final LocalizableMessage message =
- ERR_INTARG_LOWER_BOUND_ABOVE_UPPER_BOUND.get(name, lowerBound, upperBound);
- throw new ArgumentException(message);
- }
- }
-
- /**
- * Creates a new integer argument with the provided information.
- *
- * @param name
- * The generic name that should be used to refer to this
- * argument.
- * @param shortIdentifier
- * The single-character identifier for this argument, or
- * <CODE>null</CODE> if there is none.
- * @param longIdentifier
- * The long identifier for this argument, or <CODE>null</CODE> if
- * there is none.
- * @param isRequired
- * Indicates whether this argument must be specified on the
- * command line.
- * @param isMultiValued
- * Indicates whether this argument may be specified more than
- * once to provide multiple values.
- * @param needsValue
- * Indicates whether this argument requires a value.
- * @param valuePlaceholder
- * The placeholder for the argument value that will be displayed
- * in usage information, or <CODE>null</CODE> if this argument
- * does not require a value.
- * @param defaultValue
- * The default value that should be used for this argument if
- * none is provided in a properties file or on the command line.
- * This may be <CODE>null</CODE> if there is no generic default.
- * @param propertyName
- * The name of the property in a property file that may be used
- * to override the default value but will be overridden by a
- * command-line argument.
- * @param description
- * LocalizableMessage for the description of this argument.
- * @throws ArgumentException
- * If there is a problem with any of the parameters used to
- * create this argument.
- */
- public IntegerArgument(final String name, final Character shortIdentifier,
- final String longIdentifier, final boolean isRequired, final boolean isMultiValued,
- final boolean needsValue, final LocalizableMessage valuePlaceholder,
- final int defaultValue, final String propertyName, final LocalizableMessage description)
- throws ArgumentException {
- super(name, shortIdentifier, longIdentifier, isRequired, isMultiValued, needsValue,
- valuePlaceholder, String.valueOf(defaultValue), propertyName, description);
-
- hasLowerBound = false;
- hasUpperBound = false;
- lowerBound = Integer.MIN_VALUE;
- upperBound = Integer.MAX_VALUE;
- }
-
- /**
- * Creates a new integer argument with the provided information.
- *
- * @param name
- * The generic name that should be used to refer to this
- * argument.
- * @param shortIdentifier
- * The single-character identifier for this argument, or
- * <CODE>null</CODE> if there is none.
- * @param longIdentifier
- * The long identifier for this argument, or <CODE>null</CODE> if
- * there is none.
- * @param isRequired
- * Indicates whether this argument must be specified on the
- * command line.
- * @param needsValue
- * Indicates whether this argument requires a value.
- * @param valuePlaceholder
- * The placeholder for the argument value that will be displayed
- * in usage information, or <CODE>null</CODE> if this argument
- * does not require a value.
- * @param hasLowerBound
- * Indicates whether a lower bound should be enforced for values
- * of this argument.
- * @param lowerBound
- * The lower bound that should be enforced for values of this
- * argument.
- * @param hasUpperBound
- * Indicates whether an upperbound should be enforced for values
- * of this argument.
- * @param upperBound
- * The upper bound that should be enforced for values of this
- * argument.
- * @param description
- * LocalizableMessage for the description of this argument.
- * @throws ArgumentException
- * If there is a problem with any of the parameters used to
- * create this argument.
- */
- public IntegerArgument(final String name, final Character shortIdentifier,
- final String longIdentifier, final boolean isRequired, final boolean needsValue,
- final LocalizableMessage valuePlaceholder, final boolean hasLowerBound,
- final double lowerBound, final boolean hasUpperBound, final double upperBound,
- final LocalizableMessage description) throws ArgumentException {
- super(name, shortIdentifier, longIdentifier, isRequired, false, needsValue,
- valuePlaceholder, null, null, description);
-
- this.hasLowerBound = hasLowerBound;
- this.hasUpperBound = hasUpperBound;
- this.lowerBound = lowerBound;
- this.upperBound = upperBound;
-
- if (hasLowerBound && hasUpperBound && (lowerBound > upperBound)) {
- final LocalizableMessage message =
- ERR_INTARG_LOWER_BOUND_ABOVE_UPPER_BOUND.get(name, lowerBound, upperBound);
- throw new ArgumentException(message);
- }
- }
-
- /**
- * Creates a new integer argument with the provided information.
- *
- * @param name
- * The generic name that should be used to refer to this
- * argument.
- * @param shortIdentifier
- * The single-character identifier for this argument, or
- * <CODE>null</CODE> if there is none.
- * @param longIdentifier
- * The long identifier for this argument, or <CODE>null</CODE> if
- * there is none.
- * @param isRequired
- * Indicates whether this argument must be specified on the
- * command line.
- * @param needsValue
- * Indicates whether this argument requires a value.
- * @param valuePlaceholder
- * The placeholder for the argument value that will be displayed
- * in usage information, or <CODE>null</CODE> if this argument
- * does not require a value.
- * @param description
- * LocalizableMessage for the description of this argument.
- * @throws ArgumentException
- * If there is a problem with any of the parameters used to
- * create this argument.
- */
- public IntegerArgument(final String name, final Character shortIdentifier,
- final String longIdentifier, final boolean isRequired, final boolean needsValue,
- final LocalizableMessage valuePlaceholder, final LocalizableMessage description)
- throws ArgumentException {
- super(name, shortIdentifier, longIdentifier, isRequired, false, needsValue,
- valuePlaceholder, null, null, description);
-
- hasLowerBound = false;
- hasUpperBound = false;
- lowerBound = Double.MIN_VALUE;
- upperBound = Double.MAX_VALUE;
- }
-
- /**
- * Retrieves the lower bound that may be enforced for values of this
- * argument.
- *
- * @return The lower bound that may be enforced for values of this argument.
- */
- public double getLowerBound() {
- return lowerBound;
- }
-
- /**
- * Retrieves the upper bound that may be enforced for values of this
- * argument.
- *
- * @return The upper bound that may be enforced for values of this argument.
- */
- public double getUpperBound() {
- return upperBound;
- }
-
- /**
- * Indicates whether a lower bound should be enforced for values of this
- * argument.
- *
- * @return <CODE>true</CODE> if a lower bound should be enforced for values
- * of this argument, or <CODE>false</CODE> if not.
- */
- public boolean hasLowerBound() {
- return hasLowerBound;
- }
-
- /**
- * Indicates whether a upper bound should be enforced for values of this
- * argument.
- *
- * @return <CODE>true</CODE> if a upper bound should be enforced for values
- * of this argument, or <CODE>false</CODE> if not.
- */
- public boolean hasUpperBound() {
- return hasUpperBound;
- }
-
- /**
- * Indicates whether the provided value is acceptable for use in this
- * argument.
- *
- * @param valueString
- * The value for which to make the determination.
- * @param invalidReason
- * A buffer into which the invalid reason may be written if the
- * value is not acceptable.
- * @return <CODE>true</CODE> if the value is acceptable, or
- * <CODE>false</CODE> if it is not.
- */
- @Override
- public boolean valueIsAcceptable(final String valueString,
- final LocalizableMessageBuilder invalidReason) {
- // First, the value must be decodable as an integer.
- double intValue;
- try {
- intValue = Double.parseDouble(valueString);
- } catch (final Exception e) {
- invalidReason.append(ERR_ARG_CANNOT_DECODE_AS_INT.get(valueString, getName()));
- return false;
- }
-
- // If there is a lower bound, then the value must be greater than or
- // equal to it.
- if (hasLowerBound && (intValue < lowerBound)) {
- invalidReason.append(ERR_INTARG_VALUE_BELOW_LOWER_BOUND.get(getName(), intValue,
- lowerBound));
- return false;
- }
-
- // If there is an upper bound, then the value must be less than or
- // equal to it.
- if (hasUpperBound && (intValue > upperBound)) {
-
- invalidReason.append(ERR_INTARG_VALUE_ABOVE_UPPER_BOUND.get(getName(), intValue,
- upperBound));
- return false;
- }
-
- // At this point, the value should be acceptable.
- return true;
- }
-}
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPCompare.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPCompare.java
index 910d652..a00f1b0 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPCompare.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPCompare.java
@@ -22,14 +22,14 @@
*
*
* Copyright 2010 Sun Microsystems, Inc.
- * Portions copyright 2011-2012 ForgeRock AS
+ * Portions copyright 2011-2014 ForgeRock AS
*/
-
package com.forgerock.opendj.ldap.tools;
-import static com.forgerock.opendj.ldap.tools.ToolConstants.*;
+import static com.forgerock.opendj.cli.CliConstants.*;
import static com.forgerock.opendj.ldap.tools.ToolsMessages.*;
-import static com.forgerock.opendj.ldap.tools.Utils.filterExitCode;
+import static com.forgerock.opendj.cli.Utils.filterExitCode;
+import static com.forgerock.opendj.cli.Utils.readBytesFromFile;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
@@ -54,6 +54,14 @@
import org.forgerock.opendj.ldap.requests.Requests;
import org.forgerock.opendj.ldap.responses.Result;
+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.ConsoleApplication;
+import com.forgerock.opendj.cli.IntegerArgument;
+import com.forgerock.opendj.cli.StringArgument;
+
/**
* A tool that can be used to issue Compare requests to the Directory Server.
*/
@@ -138,16 +146,12 @@
try {
connectionFactoryProvider = new ConnectionFactoryProvider(argParser, this);
- propertiesFileArgument =
- new StringArgument("propertiesFilePath", null, OPTION_LONG_PROP_FILE_PATH,
- false, false, true, INFO_PROP_FILE_PATH_PLACEHOLDER.get(), null, null,
- INFO_DESCRIPTION_PROP_FILE_PATH.get());
+
+ propertiesFileArgument = CommonArguments.getPropertiesFileArgument();
argParser.addArgument(propertiesFileArgument);
argParser.setFilePropertiesArgument(propertiesFileArgument);
- noPropertiesFileArgument =
- new BooleanArgument("noPropertiesFileArgument", null, OPTION_LONG_NO_PROP_FILE,
- INFO_DESCRIPTION_NO_PROP_FILE.get());
+ noPropertiesFileArgument = CommonArguments.getNoPropertiesFileArgument();
argParser.addArgument(noPropertiesFileArgument);
argParser.setNoPropertiesFileArgument(noPropertiesFileArgument);
@@ -180,12 +184,7 @@
controlStr.setPropertyName("control");
argParser.addArgument(controlStr);
- version =
- new IntegerArgument("version", OPTION_SHORT_PROTOCOL_VERSION,
- OPTION_LONG_PROTOCOL_VERSION, false, false, true,
- INFO_PROTOCOL_VERSION_PLACEHOLDER.get(), 3, null,
- INFO_DESCRIPTION_VERSION.get());
- version.setPropertyName(OPTION_LONG_PROTOCOL_VERSION);
+ version = CommonArguments.getVersionArgument();
argParser.addArgument(version);
encodingStr =
@@ -195,10 +194,7 @@
encodingStr.setPropertyName("encoding");
argParser.addArgument(encodingStr);
- continueOnError =
- new BooleanArgument("continueOnError", 'c', "continueOnError",
- INFO_DESCRIPTION_CONTINUE_ON_ERROR.get());
- continueOnError.setPropertyName("continueOnError");
+ continueOnError = CommonArguments.getContinueOnErrorArgument();
argParser.addArgument(continueOnError);
noop =
@@ -207,16 +203,13 @@
noop.setPropertyName(OPTION_LONG_DRYRUN);
argParser.addArgument(noop);
- verbose =
- new BooleanArgument("verbose", 'v', "verbose", INFO_DESCRIPTION_VERBOSE.get());
- verbose.setPropertyName("verbose");
+ verbose = CommonArguments.getVerbose();
argParser.addArgument(verbose);
- showUsage =
- new BooleanArgument("showUsage", OPTION_SHORT_HELP, OPTION_LONG_HELP,
- INFO_DESCRIPTION_SHOWUSAGE.get());
+ showUsage = CommonArguments.getShowUsage();
argParser.addArgument(showUsage);
argParser.setUsageArgument(showUsage, getOutputStream());
+
} catch (final ArgumentException ae) {
final LocalizableMessage message = ERR_CANNOT_INITIALIZE_ARGS.get(ae.getMessage());
println(message);
@@ -227,8 +220,8 @@
try {
argParser.parseArguments(args);
- // If we should just display usage or version information,
- // then print it and exit.
+ /* If we should just display usage or version information,
+ then print it and exit.*/
if (argParser.usageOrVersionDisplayed()) {
return 0;
}
@@ -274,8 +267,8 @@
return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue();
}
- // If trailing DNs were provided and the filename argument was also
- // provided, exit with an error.
+ /* If trailing DNs were provided and the filename argument was also
+ provided, exit with an error.*/
if (!dnStrings.isEmpty() && filename.isPresent()) {
println(ERR_LDAPCOMPARE_FILENAME_AND_DNS.get());
return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue();
@@ -305,7 +298,7 @@
} else if (nextChar == '<') {
try {
final String filePath = remainder.substring(1, remainder.length());
- attributeVal = ByteString.wrap(Utils.readBytesFromFile(filePath));
+ attributeVal = ByteString.wrap(readBytesFromFile(filePath));
} catch (final Exception e) {
println(INFO_COMPARE_CANNOT_READ_ASSERTION_VALUE_FROM_FILE.get(String
.valueOf(e)));
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPModify.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPModify.java
index 5665ca3..b6e68dd 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPModify.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPModify.java
@@ -22,14 +22,15 @@
*
*
* Copyright 2010 Sun Microsystems, Inc.
- * Portions copyright 2011-2012 ForgeRock AS
+ * Portions copyright 2011-2014 ForgeRock AS
*/
-
package com.forgerock.opendj.ldap.tools;
-import static com.forgerock.opendj.ldap.tools.ToolConstants.*;
+import static com.forgerock.opendj.cli.CliConstants.*;
import static com.forgerock.opendj.ldap.tools.ToolsMessages.*;
-import static com.forgerock.opendj.ldap.tools.Utils.filterExitCode;
+import static com.forgerock.opendj.cli.Utils.filterExitCode;
+import static com.forgerock.opendj.ldap.tools.Utils.printErrorMessage;
+import static org.forgerock.util.Utils.closeSilently;
import java.io.FileInputStream;
import java.io.IOException;
@@ -66,6 +67,14 @@
import org.forgerock.opendj.ldif.LDIFChangeRecordReader;
import org.forgerock.opendj.ldif.LDIFEntryWriter;
+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.ConsoleApplication;
+import com.forgerock.opendj.cli.IntegerArgument;
+import com.forgerock.opendj.cli.StringArgument;
+
/**
* A tool that can be used to issue update (Add/Delete/Modify/ModifyDN) requests
* to the Directory Server.
@@ -102,7 +111,7 @@
printResult(opType, change.getName().toString(), r);
return r.getResultCode().intValue();
} catch (final ErrorResultException ere) {
- return Utils.printErrorMessage(LDAPModify.this, ere);
+ return printErrorMessage(LDAPModify.this, ere);
}
}
return ResultCode.SUCCESS.intValue();
@@ -232,8 +241,7 @@
}
private int run(final String[] args) {
- // Create the command-line argument parser for use with this
- // program.
+ // Create the command-line argument parser for use with this program.
final LocalizableMessage toolDescription = INFO_LDAPMODIFY_TOOL_DESCRIPTION.get();
final ArgumentParser argParser =
new ArgumentParser(LDAPModify.class.getName(), toolDescription, false);
@@ -258,16 +266,12 @@
try {
connectionFactoryProvider = new ConnectionFactoryProvider(argParser, this);
- propertiesFileArgument =
- new StringArgument("propertiesFilePath", null, OPTION_LONG_PROP_FILE_PATH,
- false, false, true, INFO_PROP_FILE_PATH_PLACEHOLDER.get(), null, null,
- INFO_DESCRIPTION_PROP_FILE_PATH.get());
+
+ propertiesFileArgument = CommonArguments.getPropertiesFileArgument();
argParser.addArgument(propertiesFileArgument);
argParser.setFilePropertiesArgument(propertiesFileArgument);
- noPropertiesFileArgument =
- new BooleanArgument("noPropertiesFileArgument", null, OPTION_LONG_NO_PROP_FILE,
- INFO_DESCRIPTION_NO_PROP_FILE.get());
+ noPropertiesFileArgument = CommonArguments.getNoPropertiesFileArgument();
argParser.addArgument(noPropertiesFileArgument);
argParser.setNoPropertiesFileArgument(noPropertiesFileArgument);
@@ -319,12 +323,7 @@
controlStr.setPropertyName("control");
argParser.addArgument(controlStr);
- version =
- new IntegerArgument("version", OPTION_SHORT_PROTOCOL_VERSION,
- OPTION_LONG_PROTOCOL_VERSION, false, false, true,
- INFO_PROTOCOL_VERSION_PLACEHOLDER.get(), 3, null,
- INFO_DESCRIPTION_VERSION.get());
- version.setPropertyName(OPTION_LONG_PROTOCOL_VERSION);
+ version = CommonArguments.getVersionArgument();
argParser.addArgument(version);
encodingStr =
@@ -334,10 +333,7 @@
encodingStr.setPropertyName("encoding");
argParser.addArgument(encodingStr);
- continueOnError =
- new BooleanArgument("continueOnError", 'c', "continueOnError",
- INFO_DESCRIPTION_CONTINUE_ON_ERROR.get());
- continueOnError.setPropertyName("continueOnError");
+ continueOnError = CommonArguments.getContinueOnErrorArgument();
argParser.addArgument(continueOnError);
noop =
@@ -346,14 +342,10 @@
noop.setPropertyName(OPTION_LONG_DRYRUN);
argParser.addArgument(noop);
- verbose =
- new BooleanArgument("verbose", 'v', "verbose", INFO_DESCRIPTION_VERBOSE.get());
- verbose.setPropertyName("verbose");
+ verbose = CommonArguments.getVerbose();
argParser.addArgument(verbose);
- showUsage =
- new BooleanArgument("showUsage", OPTION_SHORT_HELP, OPTION_LONG_HELP,
- INFO_DESCRIPTION_SHOWUSAGE.get());
+ showUsage = CommonArguments.getShowUsage();
argParser.addArgument(showUsage);
argParser.setUsageArgument(showUsage, getOutputStream());
} catch (final ArgumentException ae) {
@@ -366,8 +358,8 @@
try {
argParser.parseArguments(args);
- // If we should just display usage or version information,
- // then print it and exit.
+ /* If we should just display usage or version information,
+ then print it and exit.*/
if (argParser.usageOrVersionDisplayed()) {
return 0;
}
@@ -503,7 +495,7 @@
return ResultCode.CLIENT_SIDE_LOCAL_ERROR.intValue();
}
} finally {
- org.forgerock.util.Utils.closeSilently(reader, connection);
+ closeSilently(reader, connection);
}
return ResultCode.SUCCESS.intValue();
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPPasswordModify.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPPasswordModify.java
index 9dd1ee7..b73f82b 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPPasswordModify.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPPasswordModify.java
@@ -22,14 +22,12 @@
*
*
* Copyright 2010 Sun Microsystems, Inc.
- * Portions copyright 2011-2013 ForgeRock AS
+ * Portions copyright 2011-2014 ForgeRock AS
*/
-
package com.forgerock.opendj.ldap.tools;
-import static com.forgerock.opendj.ldap.tools.ToolConstants.*;
import static com.forgerock.opendj.ldap.tools.ToolsMessages.*;
-import static com.forgerock.opendj.ldap.tools.Utils.filterExitCode;
+import static com.forgerock.opendj.cli.Utils.filterExitCode;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.ByteString;
@@ -43,6 +41,15 @@
import org.forgerock.opendj.ldap.requests.Requests;
import org.forgerock.opendj.ldap.responses.PasswordModifyExtendedResult;
+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.ConsoleApplication;
+import com.forgerock.opendj.cli.FileBasedArgument;
+import com.forgerock.opendj.cli.IntegerArgument;
+import com.forgerock.opendj.cli.StringArgument;
+
/**
* A tool that can be used to issue LDAP password modify extended requests to
* the Directory Server. It exposes the three primary options available for this
@@ -105,16 +112,12 @@
try {
connectionFactoryProvider = new ConnectionFactoryProvider(argParser, this);
- propertiesFileArgument =
- new StringArgument("propertiesFilePath", null, OPTION_LONG_PROP_FILE_PATH,
- false, false, true, INFO_PROP_FILE_PATH_PLACEHOLDER.get(), null, null,
- INFO_DESCRIPTION_PROP_FILE_PATH.get());
+
+ propertiesFileArgument = CommonArguments.getPropertiesFileArgument();
argParser.addArgument(propertiesFileArgument);
argParser.setFilePropertiesArgument(propertiesFileArgument);
- noPropertiesFileArgument =
- new BooleanArgument("noPropertiesFileArgument", null, OPTION_LONG_NO_PROP_FILE,
- INFO_DESCRIPTION_NO_PROP_FILE.get());
+ noPropertiesFileArgument = CommonArguments.getNoPropertiesFileArgument();
argParser.addArgument(noPropertiesFileArgument);
argParser.setNoPropertiesFileArgument(noPropertiesFileArgument);
@@ -160,22 +163,13 @@
controlStr.setPropertyName("control");
argParser.addArgument(controlStr);
- version =
- new IntegerArgument("version", OPTION_SHORT_PROTOCOL_VERSION,
- OPTION_LONG_PROTOCOL_VERSION, false, false, true,
- INFO_PROTOCOL_VERSION_PLACEHOLDER.get(), 3, null,
- INFO_DESCRIPTION_VERSION.get());
- version.setPropertyName(OPTION_LONG_PROTOCOL_VERSION);
+ version = CommonArguments.getVersionArgument();
argParser.addArgument(version);
- verbose =
- new BooleanArgument("verbose", 'v', "verbose", INFO_DESCRIPTION_VERBOSE.get());
- verbose.setPropertyName("verbose");
+ verbose = CommonArguments.getVerbose();
argParser.addArgument(verbose);
- showUsage =
- new BooleanArgument("showUsage", OPTION_SHORT_HELP, OPTION_LONG_HELP,
- INFO_DESCRIPTION_SHOWUSAGE.get());
+ showUsage = CommonArguments.getShowUsage();
argParser.addArgument(showUsage);
argParser.setUsageArgument(showUsage, getOutputStream());
} catch (final ArgumentException ae) {
@@ -188,8 +182,8 @@
try {
argParser.parseArguments(args);
- // If we should just display usage or version information,
- // then print it and exit.
+ /* If we should just display usage or version information,
+ then print it and exit.*/
if (argParser.usageOrVersionDisplayed()) {
return 0;
}
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPSearch.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPSearch.java
index a2eb8f8..ec7a642 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPSearch.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPSearch.java
@@ -22,14 +22,15 @@
*
*
* Copyright 2010 Sun Microsystems, Inc.
- * Portions copyright 2011-2012 ForgeRock AS
+ * Portions copyright 2011-2014 ForgeRock AS
*/
-
package com.forgerock.opendj.ldap.tools;
-import static com.forgerock.opendj.ldap.tools.ToolConstants.*;
+import static com.forgerock.opendj.cli.CliConstants.*;
import static com.forgerock.opendj.ldap.tools.ToolsMessages.*;
-import static com.forgerock.opendj.ldap.tools.Utils.filterExitCode;
+import static com.forgerock.opendj.cli.Utils.filterExitCode;
+import static com.forgerock.opendj.cli.Utils.secondsToTimeString;
+import static org.forgerock.util.Utils.closeSilently;
import java.io.BufferedReader;
import java.io.FileReader;
@@ -75,6 +76,14 @@
import org.forgerock.opendj.ldif.EntryWriter;
import org.forgerock.opendj.ldif.LDIFEntryWriter;
+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.ConsoleApplication;
+import com.forgerock.opendj.cli.IntegerArgument;
+import com.forgerock.opendj.cli.MultiChoiceArgument;
+import com.forgerock.opendj.cli.StringArgument;
import com.forgerock.opendj.ldap.controls.AccountUsabilityResponseControl;
import com.forgerock.opendj.util.StaticUtils;
@@ -120,7 +129,7 @@
if (control.getSecondsBeforeExpiration() > 0) {
final int timeToExp = control.getSecondsBeforeExpiration();
final LocalizableMessage timeToExpStr =
- Utils.secondsToTimeString(timeToExp);
+ secondsToTimeString(timeToExp);
println(INFO_LDAPSEARCH_ACCTUSABLE_TIME_UNTIL_EXPIRATION
.get(timeToExpStr));
@@ -147,7 +156,7 @@
if (control.getSecondsBeforeUnlock() > 0) {
final int timeToUnlock = control.getSecondsBeforeUnlock();
final LocalizableMessage timeToUnlockStr =
- Utils.secondsToTimeString(timeToUnlock);
+ secondsToTimeString(timeToUnlock);
println(INFO_LDAPSEARCH_ACCTUSABLE_TIME_UNTIL_UNLOCK
.get(timeToUnlockStr));
@@ -221,8 +230,8 @@
}
private int run(final String[] args, final boolean returnMatchingEntries) {
- // Create the command-line argument parser for use with this
- // program.
+ /* Create the command-line argument parser for use with this
+ program.*/
final LocalizableMessage toolDescription = INFO_LDAPSEARCH_TOOL_DESCRIPTION.get();
final ArgumentParser argParser =
new ArgumentParser(LDAPSearch.class.getName(), toolDescription, false, true, 0, 0,
@@ -254,15 +263,11 @@
try {
connectionFactoryProvider = new ConnectionFactoryProvider(argParser, this);
final StringArgument propertiesFileArgument =
- new StringArgument("propertiesFilePath", null, OPTION_LONG_PROP_FILE_PATH,
- false, false, true, INFO_PROP_FILE_PATH_PLACEHOLDER.get(), null, null,
- INFO_DESCRIPTION_PROP_FILE_PATH.get());
+ CommonArguments.getPropertiesFileArgument();
argParser.addArgument(propertiesFileArgument);
argParser.setFilePropertiesArgument(propertiesFileArgument);
- final BooleanArgument noPropertiesFileArgument =
- new BooleanArgument("noPropertiesFileArgument", null, OPTION_LONG_NO_PROP_FILE,
- INFO_DESCRIPTION_NO_PROP_FILE.get());
+ final BooleanArgument noPropertiesFileArgument = CommonArguments.getNoPropertiesFileArgument();
argParser.addArgument(noPropertiesFileArgument);
argParser.setNoPropertiesFileArgument(noPropertiesFileArgument);
@@ -360,12 +365,7 @@
effectiveRightsAttrs.setPropertyName(OPTION_LONG_EFFECTIVERIGHTSATTR);
argParser.addArgument(effectiveRightsAttrs);
- version =
- new IntegerArgument("version", OPTION_SHORT_PROTOCOL_VERSION,
- OPTION_LONG_PROTOCOL_VERSION, false, false, true,
- INFO_PROTOCOL_VERSION_PLACEHOLDER.get(), 3, null,
- INFO_DESCRIPTION_VERSION.get());
- version.setPropertyName(OPTION_LONG_PROTOCOL_VERSION);
+ version = CommonArguments.getVersionArgument();
argParser.addArgument(version);
final StringArgument encodingStr =
@@ -416,10 +416,7 @@
countEntries.setPropertyName("countEntries");
argParser.addArgument(countEntries);
- final BooleanArgument continueOnError =
- new BooleanArgument("continueOnError", 'c', "continueOnError",
- INFO_DESCRIPTION_CONTINUE_ON_ERROR.get());
- continueOnError.setPropertyName("continueOnError");
+ final BooleanArgument continueOnError = CommonArguments.getContinueOnErrorArgument();
argParser.addArgument(continueOnError);
noop =
@@ -428,14 +425,10 @@
noop.setPropertyName(OPTION_LONG_DRYRUN);
argParser.addArgument(noop);
- verbose =
- new BooleanArgument("verbose", 'v', "verbose", INFO_DESCRIPTION_VERBOSE.get());
- verbose.setPropertyName("verbose");
+ verbose = CommonArguments.getVerbose();
argParser.addArgument(verbose);
- final BooleanArgument showUsage =
- new BooleanArgument("showUsage", OPTION_SHORT_HELP, OPTION_LONG_HELP,
- INFO_DESCRIPTION_SHOWUSAGE.get());
+ final BooleanArgument showUsage = CommonArguments.getShowUsage();
argParser.addArgument(showUsage);
argParser.setUsageArgument(showUsage, getOutputStream());
} catch (final ArgumentException ae) {
@@ -465,11 +458,11 @@
final List<String> attributes = new LinkedList<String>();
final ArrayList<String> filterAndAttributeStrings = argParser.getTrailingArguments();
if (filterAndAttributeStrings.size() > 0) {
- // the list of trailing arguments should be structured as follow:
- // - If a filter file is present, trailing arguments are
- // considered as attributes
- // - If filter file is not present, the first trailing argument is
- // considered the filter, the other as attributes.
+ /* The list of trailing arguments should be structured as follow:
+ - If a filter file is present, trailing arguments are
+ considered as attributes
+ - If filter file is not present, the first trailing argument is
+ considered the filter, the other as attributes.*/
if (!filename.isPresent()) {
final String filterString = filterAndAttributeStrings.remove(0);
@@ -830,11 +823,11 @@
}
if (noop.isPresent()) {
- // We don't actually need to open a connection or perform the
- // search, so we're done. We should return 0 to either mean that the
- // processing was successful or that there were no matching entries,
- // based on countEntries.isPresent() (but in either case the return value
- // should be zero).
+ /* We don't actually need to open a connection or perform the
+ search, so we're done. We should return 0 to either mean that the
+ processing was successful or that there were no matching entries,
+ based on countEntries.isPresent() (but in either case the return value
+ should be zero).*/
return 0;
}
@@ -944,7 +937,7 @@
} catch (final ErrorResultException ere) {
return Utils.printErrorMessage(this, ere);
} finally {
- org.forgerock.util.Utils.closeSilently(ldifWriter, connection);
+ closeSilently(ldifWriter, connection);
}
return 0;
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFDiff.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFDiff.java
index 31e5567..22bcf03 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFDiff.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFDiff.java
@@ -22,16 +22,14 @@
*
*
* Copyright 2012-2013 ForgeRock AS
+ * Portions copyright 2014 ForgeRock AS
*/
-
package com.forgerock.opendj.ldap.tools;
-import static com.forgerock.opendj.ldap.tools.ToolConstants.OPTION_LONG_HELP;
-import static com.forgerock.opendj.ldap.tools.ToolConstants.OPTION_LONG_OUTPUT_LDIF_FILENAME;
-import static com.forgerock.opendj.ldap.tools.ToolConstants.OPTION_SHORT_HELP;
-import static com.forgerock.opendj.ldap.tools.ToolConstants.OPTION_SHORT_OUTPUT_LDIF_FILENAME;
+import static com.forgerock.opendj.cli.CliConstants.OPTION_LONG_OUTPUT_LDIF_FILENAME;
+import static com.forgerock.opendj.cli.CliConstants.OPTION_SHORT_OUTPUT_LDIF_FILENAME;
import static com.forgerock.opendj.ldap.tools.ToolsMessages.*;
-import static com.forgerock.opendj.ldap.tools.Utils.filterExitCode;
+import static com.forgerock.opendj.cli.Utils.filterExitCode;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -48,6 +46,13 @@
import org.forgerock.opendj.ldif.LDIFChangeRecordWriter;
import org.forgerock.opendj.ldif.LDIFEntryReader;
+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.ConsoleApplication;
+import com.forgerock.opendj.cli.StringArgument;
+
/**
* This utility can be used to compare two LDIF files and report the differences
* in LDIF format.
@@ -90,9 +95,7 @@
.get(INFO_OUTPUT_LDIF_FILE_PLACEHOLDER.get()));
argParser.addArgument(outputFilename);
- showUsage =
- new BooleanArgument("showUsage", OPTION_SHORT_HELP, OPTION_LONG_HELP,
- INFO_DESCRIPTION_SHOWUSAGE.get());
+ showUsage = CommonArguments.getShowUsage();
argParser.addArgument(showUsage);
argParser.setUsageArgument(showUsage, getOutputStream());
} catch (final ArgumentException ae) {
@@ -105,8 +108,8 @@
try {
argParser.parseArguments(args);
- // If we should just display usage or version information,
- // then print it and exit.
+ /* If we should just display usage or version information,
+ then print it and exit.*/
if (argParser.usageOrVersionDisplayed()) {
return ResultCode.SUCCESS.intValue();
}
@@ -178,8 +181,8 @@
outputStream = System.out;
}
- // Check that we are not attempting to read both the source and
- // target from stdin.
+ /* Check that we are not attempting to read both the source and
+ target from stdin.*/
if (sourceInputStream == targetInputStream) {
final LocalizableMessage message = ERR_LDIFDIFF_MULTIPLE_USES_OF_STDIN.get();
println(message);
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFModify.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFModify.java
index e3fe2f6..758ece9 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFModify.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFModify.java
@@ -21,17 +21,14 @@
* CDDL HEADER END
*
*
- * Copyright 2012-2013 ForgeRock AS
+ * Copyright 2012-2014 ForgeRock AS
*/
-
package com.forgerock.opendj.ldap.tools;
-import static com.forgerock.opendj.ldap.tools.ToolConstants.OPTION_LONG_HELP;
-import static com.forgerock.opendj.ldap.tools.ToolConstants.OPTION_LONG_OUTPUT_LDIF_FILENAME;
-import static com.forgerock.opendj.ldap.tools.ToolConstants.OPTION_SHORT_HELP;
-import static com.forgerock.opendj.ldap.tools.ToolConstants.OPTION_SHORT_OUTPUT_LDIF_FILENAME;
+import static com.forgerock.opendj.cli.CliConstants.OPTION_LONG_OUTPUT_LDIF_FILENAME;
+import static com.forgerock.opendj.cli.CliConstants.OPTION_SHORT_OUTPUT_LDIF_FILENAME;
import static com.forgerock.opendj.ldap.tools.ToolsMessages.*;
-import static com.forgerock.opendj.ldap.tools.Utils.filterExitCode;
+import static com.forgerock.opendj.cli.Utils.filterExitCode;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -56,6 +53,13 @@
import org.forgerock.opendj.ldif.LDIFEntryWriter;
import org.forgerock.opendj.ldif.RejectedChangeRecordListener;
+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.ConsoleApplication;
+import com.forgerock.opendj.cli.StringArgument;
+
/**
* A tool that can be used to issue update (Add/Delete/Modify/ModifyDN) requests
* to a set of entries contained in an LDIF file.
@@ -99,15 +103,10 @@
.get(INFO_OUTPUT_LDIF_FILE_PLACEHOLDER.get()));
argParser.addArgument(outputFilename);
- continueOnError =
- new BooleanArgument("continueOnError", 'c', "continueOnError",
- INFO_DESCRIPTION_CONTINUE_ON_ERROR.get());
- continueOnError.setPropertyName("continueOnError");
+ continueOnError = CommonArguments.getContinueOnErrorArgument();
argParser.addArgument(continueOnError);
- showUsage =
- new BooleanArgument("showUsage", OPTION_SHORT_HELP, OPTION_LONG_HELP,
- INFO_DESCRIPTION_SHOWUSAGE.get());
+ showUsage = CommonArguments.getShowUsage();
argParser.addArgument(showUsage);
argParser.setUsageArgument(showUsage, getOutputStream());
} catch (final ArgumentException ae) {
@@ -193,9 +192,8 @@
outputStream = System.out;
}
- // Check that we are not attempting to read both the source and
- // changes
- // from stdin.
+ /* Check that we are not attempting to read both the source and
+ changes from stdin.*/
if (sourceInputStream == changesInputStream) {
final LocalizableMessage message = ERR_LDIFMODIFY_MULTIPLE_USES_OF_STDIN.get();
println(message);
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFSearch.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFSearch.java
index edfacb8..091c644 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFSearch.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFSearch.java
@@ -21,14 +21,13 @@
* CDDL HEADER END
*
*
- * Copyright 2012-2013 ForgeRock AS
+ * Copyright 2012-2014 ForgeRock AS
*/
-
package com.forgerock.opendj.ldap.tools;
-import static com.forgerock.opendj.ldap.tools.ToolConstants.*;
+import static com.forgerock.opendj.cli.CliConstants.*;
import static com.forgerock.opendj.ldap.tools.ToolsMessages.*;
-import static com.forgerock.opendj.ldap.tools.Utils.filterExitCode;
+import static com.forgerock.opendj.cli.Utils.filterExitCode;
import java.io.BufferedReader;
import java.io.FileInputStream;
@@ -54,6 +53,15 @@
import org.forgerock.opendj.ldif.LDIFEntryReader;
import org.forgerock.opendj.ldif.LDIFEntryWriter;
+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.ConsoleApplication;
+import com.forgerock.opendj.cli.IntegerArgument;
+import com.forgerock.opendj.cli.MultiChoiceArgument;
+import com.forgerock.opendj.cli.StringArgument;
+
/**
* This utility can be used to perform search operations against data in an LDIF
* file.
@@ -76,8 +84,8 @@
}
private int run(final String[] args) {
- // Create the command-line argument parser for use with this
- // program.
+ /* Create the command-line argument parser for use with this
+ program.*/
final LocalizableMessage toolDescription = INFO_LDIFSEARCH_TOOL_DESCRIPTION.get();
final ArgumentParser argParser =
@@ -144,9 +152,7 @@
timeLimit.setPropertyName("timeLimit");
argParser.addArgument(timeLimit);
- showUsage =
- new BooleanArgument("showUsage", OPTION_SHORT_HELP, OPTION_LONG_HELP,
- INFO_DESCRIPTION_SHOWUSAGE.get());
+ showUsage = CommonArguments.getShowUsage();
argParser.addArgument(showUsage);
argParser.setUsageArgument(showUsage, getOutputStream());
} catch (final ArgumentException ae) {
@@ -159,8 +165,8 @@
try {
argParser.parseArguments(args);
- // If we should just display usage or version information,
- // then print it and exit.
+ /* If we should just display usage or version information,
+ then print it and exit.*/
if (argParser.usageOrVersionDisplayed()) {
return ResultCode.SUCCESS.intValue();
}
@@ -177,11 +183,11 @@
final List<String> filterAndAttributeStrings =
trailingArguments.subList(1, trailingArguments.size());
- // the list of trailing arguments should be structured as follow:
- // - If a filter file is present, trailing arguments are
- // considered as attributes
- // - If filter file is not present, the first trailing argument is
- // considered the filter, the other as attributes.
+ /* The list of trailing arguments should be structured as follow:
+ - If a filter file is present, trailing arguments are
+ considered as attributes
+ - If filter file is not present, the first trailing argument is
+ considered the filter, the other as attributes.*/
if (!filename.isPresent()) {
final String filterString = filterAndAttributeStrings.remove(0);
try {
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/MakeLDIF.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/MakeLDIF.java
index 8f96964..00f65dd 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/MakeLDIF.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/MakeLDIF.java
@@ -22,20 +22,29 @@
*
*
* Copyright 2006-2010 Sun Microsystems, Inc.
- * Portions Copyright 2013 ForgeRock AS
+ * Portions Copyright 2013-2014 ForgeRock AS
*/
package com.forgerock.opendj.ldap.tools;
-import static com.forgerock.opendj.ldap.tools.ToolConstants.*;
+import static com.forgerock.opendj.cli.CliConstants.*;
import static com.forgerock.opendj.ldap.tools.ToolsMessages.*;
-import static com.forgerock.opendj.ldap.tools.Utils.*;
+import static com.forgerock.opendj.cli.Utils.filterExitCode;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
+
import org.forgerock.i18n.LocalizableMessage;
+
+import com.forgerock.opendj.cli.ArgumentException;
+import com.forgerock.opendj.cli.ArgumentParser;
+import com.forgerock.opendj.cli.BooleanArgument;
+import com.forgerock.opendj.cli.ConsoleApplication;
+import com.forgerock.opendj.cli.IntegerArgument;
+import com.forgerock.opendj.cli.StringArgument;
+
import org.forgerock.opendj.ldap.Entry;
import org.forgerock.opendj.ldif.EntryGenerator;
import org.forgerock.opendj.ldif.LDIFEntryWriter;
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ModRate.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ModRate.java
index 9be618a..cedb49e 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ModRate.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ModRate.java
@@ -22,14 +22,13 @@
*
*
* Copyright 2010 Sun Microsystems, Inc.
- * Portions copyright 2011 ForgeRock AS
+ * Portions copyright 2011-2014 ForgeRock AS
*/
-
package com.forgerock.opendj.ldap.tools;
-import static com.forgerock.opendj.ldap.tools.ToolConstants.*;
+import static com.forgerock.opendj.cli.CliConstants.*;
import static com.forgerock.opendj.ldap.tools.ToolsMessages.*;
-import static com.forgerock.opendj.ldap.tools.Utils.filterExitCode;
+import static com.forgerock.opendj.cli.Utils.filterExitCode;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.Connection;
@@ -41,6 +40,13 @@
import org.forgerock.opendj.ldap.requests.Requests;
import org.forgerock.opendj.ldap.responses.Result;
+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.ConsoleApplication;
+import com.forgerock.opendj.cli.StringArgument;
+
/**
* A load generation tool that can be used to load a Directory Server with
* Modify requests using one or more LDAP connections.
@@ -148,8 +154,8 @@
}
private int run(final String[] args) {
- // Create the command-line argument parser for use with this
- // program.
+ /* Creates the command-line argument parser for use with this
+ program*/
final LocalizableMessage toolDescription = INFO_MODRATE_TOOL_DESCRIPTION.get();
final ArgumentParser argParser =
new ArgumentParser(ModRate.class.getName(), toolDescription, false, true, 1, 0,
@@ -168,16 +174,12 @@
connectionFactoryProvider = new ConnectionFactoryProvider(argParser, this);
runner = new ModifyPerformanceRunner(argParser, this);
- propertiesFileArgument =
- new StringArgument("propertiesFilePath", null, OPTION_LONG_PROP_FILE_PATH,
- false, false, true, INFO_PROP_FILE_PATH_PLACEHOLDER.get(), null, null,
- INFO_DESCRIPTION_PROP_FILE_PATH.get());
+
+ propertiesFileArgument = CommonArguments.getPropertiesFileArgument();
argParser.addArgument(propertiesFileArgument);
argParser.setFilePropertiesArgument(propertiesFileArgument);
- noPropertiesFileArgument =
- new BooleanArgument("noPropertiesFileArgument", null, OPTION_LONG_NO_PROP_FILE,
- INFO_DESCRIPTION_NO_PROP_FILE.get());
+ noPropertiesFileArgument = CommonArguments.getNoPropertiesFileArgument();
argParser.addArgument(noPropertiesFileArgument);
argParser.setNoPropertiesFileArgument(noPropertiesFileArgument);
@@ -188,14 +190,10 @@
baseDN.setPropertyName(OPTION_LONG_BASEDN);
argParser.addArgument(baseDN);
- verbose =
- new BooleanArgument("verbose", 'v', "verbose", INFO_DESCRIPTION_VERBOSE.get());
- verbose.setPropertyName("verbose");
+ verbose = CommonArguments.getVerbose();
argParser.addArgument(verbose);
- showUsage =
- new BooleanArgument("showUsage", OPTION_SHORT_HELP, OPTION_LONG_HELP,
- INFO_DESCRIPTION_SHOWUSAGE.get());
+ showUsage = CommonArguments.getShowUsage();
argParser.addArgument(showUsage);
argParser.setUsageArgument(showUsage, getOutputStream());
@@ -214,8 +212,8 @@
try {
argParser.parseArguments(args);
- // If we should just display usage or version information,
- // then print it and exit.
+ /* If we should just display usage or version information,
+ then print it and exit.*/
if (argParser.usageOrVersionDisplayed()) {
return 0;
}
@@ -235,8 +233,8 @@
try {
- // Try it out to make sure the format string and data sources
- // match.
+ /* Try it out to make sure the format string and data sources
+ match.*/
final Object[] data = DataSource.generateData(runner.getDataSources(), null);
for (final String modString : runner.modStrings) {
String.format(modString, data);
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/MultiChoiceArgument.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/MultiChoiceArgument.java
deleted file mode 100644
index 6d0e92d..0000000
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/MultiChoiceArgument.java
+++ /dev/null
@@ -1,238 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at legal-notices/CDDLv1_0.txt.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Copyright 2006-2008 Sun Microsystems, Inc.
- */
-package com.forgerock.opendj.ldap.tools;
-
-import static com.forgerock.opendj.ldap.tools.ToolsMessages.ERR_MCARG_VALUE_NOT_ALLOWED;
-
-import java.util.Collection;
-
-import org.forgerock.i18n.LocalizableMessage;
-import org.forgerock.i18n.LocalizableMessageBuilder;
-
-/**
- * This class defines an argument type that will only accept one or more of a
- * specific set of string values.
- *
- * @param <T>
- * The type of values returned by this argument.
- */
-final class MultiChoiceArgument<T> extends Argument {
- // Indicates whether argument values should be treated in a
- // case-sensitive manner.
- private final boolean caseSensitive;
-
- // The set of values that will be allowed for use with this argument.
- private final Collection<T> allowedValues;
-
- /**
- * Creates a new string argument with the provided information.
- *
- * @param name
- * The generic name that should be used to refer to this
- * argument.
- * @param shortIdentifier
- * The single-character identifier for this argument, or
- * <CODE>null</CODE> if there is none.
- * @param longIdentifier
- * The long identifier for this argument, or <CODE>null</CODE> if
- * there is none.
- * @param isRequired
- * Indicates whether this argument must be specified on the
- * command line.
- * @param isMultiValued
- * Indicates whether this argument may be specified more than
- * once to provide multiple values.
- * @param needsValue
- * Indicates whether this argument requires a value.
- * @param valuePlaceholder
- * The placeholder for the argument value that will be displayed
- * in usage information, or <CODE>null</CODE> if this argument
- * does not require a value.
- * @param defaultValue
- * The default value that should be used for this argument if
- * none is provided in a properties file or on the command line.
- * This may be <CODE>null</CODE> if there is no generic default.
- * @param propertyName
- * The name of the property in a property file that may be used
- * to override the default value but will be overridden by a
- * command-line argument.
- * @param allowedValues
- * The set of values that are allowed for use for this argument.
- * If they are not to be treated in a case-sensitive value then
- * they should all be formatted in lowercase.
- * @param caseSensitive
- * Indicates whether the set of allowed values should be treated
- * in a case-sensitive manner.
- * @param description
- * LocalizableMessage for the description of this argument.
- * @throws ArgumentException
- * If there is a problem with any of the parameters used to
- * create this argument.
- */
- public MultiChoiceArgument(final String name, final Character shortIdentifier,
- final String longIdentifier, final boolean isRequired, final boolean isMultiValued,
- final boolean needsValue, final LocalizableMessage valuePlaceholder,
- final String defaultValue, final String propertyName,
- final Collection<T> allowedValues, final boolean caseSensitive,
- final LocalizableMessage description) throws ArgumentException {
- super(name, shortIdentifier, longIdentifier, isRequired, isMultiValued, needsValue,
- valuePlaceholder, defaultValue, propertyName, description);
-
- this.allowedValues = allowedValues;
- this.caseSensitive = caseSensitive;
- }
-
- /**
- * Creates a new string argument with the provided information.
- *
- * @param name
- * The generic name that should be used to refer to this
- * argument.
- * @param shortIdentifier
- * The single-character identifier for this argument, or
- * <CODE>null</CODE> if there is none.
- * @param longIdentifier
- * The long identifier for this argument, or <CODE>null</CODE> if
- * there is none.
- * @param isRequired
- * Indicates whether this argument must be specified on the
- * command line.
- * @param needsValue
- * Indicates whether this argument requires a value.
- * @param valuePlaceholder
- * The placeholder for the argument value that will be displayed
- * in usage information, or <CODE>null</CODE> if this argument
- * does not require a value.
- * @param allowedValues
- * The set of values that are allowed for use for this argument.
- * If they are not to be treated in a case-sensitive value then
- * they should all be formatted in lowercase.
- * @param caseSensitive
- * Indicates whether the set of allowed values should be treated
- * in a case-sensitive manner.
- * @param description
- * LocalizableMessage for the description of this argument.
- * @throws ArgumentException
- * If there is a problem with any of the parameters used to
- * create this argument.
- */
- public MultiChoiceArgument(final String name, final Character shortIdentifier,
- final String longIdentifier, final boolean isRequired, final boolean needsValue,
- final LocalizableMessage valuePlaceholder, final Collection<T> allowedValues,
- final boolean caseSensitive, final LocalizableMessage description)
- throws ArgumentException {
- super(name, shortIdentifier, longIdentifier, isRequired, false, needsValue,
- valuePlaceholder, null, null, description);
-
- this.allowedValues = allowedValues;
- this.caseSensitive = caseSensitive;
- }
-
- /**
- * Retrieves the set of allowed values for this argument. The contents of
- * this set must not be altered by the caller.
- *
- * @return The set of allowed values for this argument.
- */
- public Collection<T> getAllowedValues() {
- return allowedValues;
- }
-
- /**
- * Retrieves the string vale for this argument. If it has multiple values,
- * then the first will be returned. If it does not have any values, then the
- * default value will be returned.
- *
- * @return The string value for this argument, or <CODE>null</CODE> if there
- * are no values and no default value has been given.
- * @throws ArgumentException
- * The value cannot be parsed.
- */
- public T getTypedValue() throws ArgumentException {
- final String v = super.getValue();
- if (v == null) {
- return null;
- }
- for (final T o : allowedValues) {
- if ((caseSensitive && o.toString().equals(v)) || o.toString().equalsIgnoreCase(v)) {
- return o;
- }
- }
- // TODO: Some message
- throw new ArgumentException(null);
- }
-
- /**
- * Indicates whether the set of allowed values for this argument should be
- * treated in a case-sensitive manner.
- *
- * @return <CODE>true</CODE> if the values are to be treated in a
- * case-sensitive manner, or <CODE>false</CODE> if not.
- */
- public boolean isCaseSensitive() {
- return caseSensitive;
- }
-
- /**
- * Specifies the default value that will be used for this argument if it is
- * not specified on the command line and it is not set from a properties
- * file.
- *
- * @param defaultValue
- * The default value that will be used for this argument if it is
- * not specified on the command line and it is not set from a
- * properties file.
- */
- public void setDefaultValue(final T defaultValue) {
- super.setDefaultValue(defaultValue.toString());
- }
-
- /**
- * Indicates whether the provided value is acceptable for use in this
- * argument.
- *
- * @param valueString
- * The value for which to make the determination.
- * @param invalidReason
- * A buffer into which the invalid reason may be written if the
- * value is not acceptable.
- * @return <CODE>true</CODE> if the value is acceptable, or
- * <CODE>false</CODE> if it is not.
- */
- @Override
- public boolean valueIsAcceptable(final String valueString,
- final LocalizableMessageBuilder invalidReason) {
- for (final T o : allowedValues) {
- if ((caseSensitive && o.toString().equals(valueString))
- || o.toString().equalsIgnoreCase(valueString)) {
- return true;
- }
- }
- invalidReason.append(ERR_MCARG_VALUE_NOT_ALLOWED.get(getName(), valueString));
-
- return false;
- }
-}
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/MultiColumnPrinter.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/MultiColumnPrinter.java
deleted file mode 100644
index a1518f3..0000000
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/MultiColumnPrinter.java
+++ /dev/null
@@ -1,475 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at legal-notices/CDDLv1_0.txt.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Copyright 2010 Sun Microsystems, Inc.
- * Portions copyright 2012-2013 ForgeRock AS.
- */
-
-package com.forgerock.opendj.ldap.tools;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.Vector;
-
-/**
- * Utility class for printing aligned columns of text.
- * <P>
- * This class allows you to specify:
- * <UL>
- * <LI>The number of columns in the output. This will determine the dimension of
- * the string arrays passed to add(String[]) or addTitle(String[]).
- * <LI>spacing/gap between columns
- * <LI>character to use for title border (null means no border)
- * <LI>column alignment. Only LEFT/CENTER is supported for now.
- * </UL>
- * <P>
- * Example usage:
- *
- * <PRE>
- * MyPrinter mp = new MyPrinter(3, 2, "-");
- * String oneRow[] = new String[3];
- * oneRow[0] = "User Name";
- * oneRow[1] = "Email Address";
- * oneRow[2] = "Phone Number";
- * mp.addTitle(oneRow);
- * oneRow[0] = "Bob";
- * oneRow[1] = "bob@foo.com";
- * oneRow[2] = "123-4567";
- * mp.add(oneRow);
- * oneRow[0] = "John";
- * oneRow[1] = "john@foo.com";
- * oneRow[2] = "456-7890";
- * mp.add(oneRow);
- * mp.print();
- * </PRE>
- * <P>
- * The above would print:
- * <P>
- *
- * <PRE>
- * --------------------------------------
- * User Name Email Address Phone Number
- * --------------------------------------
- * Bob bob@foo.com 123-4567
- * John john@foo.com 456-7890
- * </PRE>
- * <P>
- * This class also supports multi-row titles and having title strings spanning
- * multiple columns. Example usage:
- *
- * <PRE>
- * TestPrinter tp = new TestPrinter(4, 2, "-");
- * String oneRow[] = new String[4];
- * int[] span = new int[4];
- * span[0] = 2; // spans 2 columns
- * span[1] = 0; // spans 0 columns
- * span[2] = 2; // spans 2 columns
- * span[3] = 0; // spans 0 columns
- * tp.setTitleAlign(CENTER);
- * oneRow[0] = "Name";
- * oneRow[1] = "";
- * oneRow[2] = "Contact";
- * oneRow[3] = "";
- * tp.addTitle(oneRow, span);
- * oneRow[0] = "First";
- * oneRow[1] = "Last";
- * oneRow[2] = "Email";
- * oneRow[3] = "Phone";
- * tp.addTitle(oneRow);
- * oneRow[0] = "Bob";
- * oneRow[1] = "Jones";
- * oneRow[2] = "bob@foo.com";
- * oneRow[3] = "123-4567";
- * tp.add(oneRow);
- * oneRow[0] = "John";
- * oneRow[1] = "Doe";
- * oneRow[2] = "john@foo.com";
- * oneRow[3] = "456-7890";
- * tp.add(oneRow);
- * tp.println();
- * </PRE>
- * <P>
- * The above would print:
- * <P>
- *
- * <PRE>
- * ------------------------------------
- * Name Contact
- * First Last Email Phone
- * ------------------------------------
- * Bob Jones bob@foo.com 123-4567
- * John Doe john@foo.com 456-7890
- * </PRE>
- */
-final class MultiColumnPrinter {
-
- static final int LEFT = 0;
-
- static final int CENTER = 1;
-
- static final int RIGHT = 2;
-
- private int numCol = 2;
-
- private int gap = 4;
-
- private int align = CENTER;
-
- private int titleAlign = CENTER;
-
- private String border = null;
-
- private List<String[]> titleTable = null;
-
- private List<int[]> titleSpanTable = null;
-
- private final int[] curLength;
-
- private final ConsoleApplication app;
-
- /**
- * Creates a sorted new MultiColumnPrinter class using LEFT alignment and
- * with no title border.
- *
- * @param numCol
- * number of columns
- * @param gap
- * gap between each column
- * @param app
- * the console application to use for outputting data
- */
- MultiColumnPrinter(final int numCol, final int gap, final ConsoleApplication app) {
- this(numCol, gap, null, LEFT, app);
- }
-
- /**
- * Creates a sorted new MultiColumnPrinter class using LEFT alignment.
- *
- * @param numCol
- * number of columns
- * @param gap
- * gap between each column
- * @param border
- * character used to frame the titles
- * @param app
- * the console application to use for outputting data
- */
- MultiColumnPrinter(final int numCol, final int gap, final String border,
- final ConsoleApplication app) {
- this(numCol, gap, border, LEFT, app);
- }
-
- /**
- * Creates a new MultiColumnPrinter class.
- *
- * @param numCol
- * number of columns
- * @param gap
- * gap between each column
- * @param border
- * character used to frame the titles
- * @param align
- * type of alignment within columns
- * @param app
- * the console application to use for outputting data
- */
- MultiColumnPrinter(final int numCol, final int gap, final String border, final int align,
- final ConsoleApplication app) {
-
- titleTable = new Vector<String[]>();
- titleSpanTable = new Vector<int[]>();
- curLength = new int[numCol];
-
- this.numCol = numCol;
- this.gap = gap;
- this.border = border;
- this.align = align;
- this.titleAlign = LEFT;
-
- this.app = app;
- }
-
- /**
- * Adds to the row of strings to be used as the title for the table.
- *
- * @param row
- * Array of strings to print in one row of title.
- */
- void addTitle(final String[] row) {
- if (row == null) {
- return;
- }
-
- final int[] span = new int[row.length];
- for (int i = 0; i < row.length; i++) {
- span[i] = 1;
- }
-
- addTitle(row, span);
- }
-
- /**
- * Adds to the row of strings to be used as the title for the table. Also
- * allows for certain title strings to span multiple columns The span
- * parameter is an array of integers which indicate how many columns the
- * corresponding title string will occupy. For a row that is 4 columns
- * wide, it is possible to have some title strings in a row to 'span'
- * multiple columns:
- * <P>
- *
- * <PRE>
- * ------------------------------------
- * Name Contact
- * First Last Email Phone
- * ------------------------------------
- * Bob Jones bob@foo.com 123-4567
- * John Doe john@foo.com 456-7890
- * </PRE>
- *
- * In the example above, the title row has a string 'Name' that spans 2
- * columns. The string 'Contact' also spans 2 columns. The above is done
- * by passing in to addTitle() an array that contains:
- *
- * <PRE>
- * span[0] = 2; // spans 2 columns
- * span[1] = 0; // spans 0 columns, ignore
- * span[2] = 2; // spans 2 columns
- * span[3] = 0; // spans 0 columns, ignore
- * </PRE>
- * <P>
- * A span value of 1 is the default. The method addTitle(String[] row)
- * basically does:
- *
- * <PRE>
- * int[] span = new int[row.length];
- * for (int i = 0; i < row.length; i++) {
- * span[i] = 1;
- * }
- * addTitle(row, span);
- * </PRE>
- *
- * @param row
- * Array of strings to print in one row of title.
- * @param span
- * Array of integers that reflect the number of columns the
- * corresponding title string will occupy.
- */
- void addTitle(final String[] row, final int[] span) {
- // Need to create a new instance of it, otherwise the new values
- // will always overwrite the old values.
-
- final String[] rowInstance = new String[row.length];
- for (int i = 0; i < row.length; i++) {
- rowInstance[i] = row[i];
- }
- titleTable.add(rowInstance);
-
- titleSpanTable.add(span);
- }
-
- /**
- * Clears title strings.
- */
- void clearTitle() {
- titleTable.clear();
- titleSpanTable.clear();
- }
-
- /**
- * Adds one row of text to output.
- *
- * @param row
- * Array of strings to print in one row.
- */
- void printRow(final String... row) {
- for (int i = 0; i < numCol; i++) {
- if (titleAlign == RIGHT) {
- final int spaceBefore = curLength[i] - row[i].length();
- printSpaces(spaceBefore);
- app.getOutputStream().print(row[i]);
- if (i < numCol - 1) {
- printSpaces(gap);
- }
- } else if (align == CENTER) {
- int space1, space2;
- space1 = (curLength[i] - row[i].length()) / 2;
- space2 = curLength[i] - row[i].length() - space1;
-
- printSpaces(space1);
- app.getOutputStream().print(row[i]);
- printSpaces(space2);
- if (i < numCol - 1) {
- printSpaces(gap);
- }
- } else {
- app.getOutputStream().print(row[i]);
- if (i < numCol - 1) {
- printSpaces(curLength[i] - row[i].length() + gap);
- }
- }
- }
- app.getOutputStream().println("");
- }
-
- /**
- * Prints the table title.
- */
- void printTitle() {
- // Get the longest string for each column and store in curLength[]
-
- // Scan through title rows
- Iterator<int[]> spanEnum = titleSpanTable.iterator();
- for (String[] row : titleTable) {
- final int[] curSpan = spanEnum.next();
-
- for (int i = 0; i < numCol; i++) {
- // None of the fields should be null, but if it
- // happens to be so, replace it with "-".
- if (row[i] == null) {
- row[i] = "-";
- }
-
- int len = row[i].length();
-
- /*
- * If a title string spans multiple columns, then the space it
- * occupies in each column is at most len/span (since we have
- * gap to take into account as well).
- */
- final int span = curSpan[i];
- int rem = 0;
- if (span > 1) {
- rem = len % span;
- len = len / span;
- }
-
- if (curLength[i] < len) {
- curLength[i] = len;
-
- if ((span > 1) && ((i + span) <= numCol)) {
- for (int j = i + 1; j < (i + span); ++j) {
- curLength[j] = len;
- }
-
- /*
- * Add remainder to last column in span to avoid
- * round-off errors.
- */
- curLength[(i + span) - 1] += rem;
- }
- }
- }
- }
-
- printBorder();
-
- spanEnum = titleSpanTable.iterator();
- for (String[] row : titleTable) {
- final int[] curSpan = spanEnum.next();
-
- for (int i = 0; i < numCol; i++) {
- int availableSpace = 0;
- final int span = curSpan[i];
-
- if (span == 0) {
- continue;
- }
-
- availableSpace = curLength[i];
-
- if ((span > 1) && ((i + span) <= numCol)) {
- for (int j = i + 1; j < (i + span); ++j) {
- availableSpace += gap;
- availableSpace += curLength[j];
- }
- }
-
- if (titleAlign == RIGHT) {
- final int spaceBefore = availableSpace - row[i].length();
- printSpaces(spaceBefore);
- app.getOutputStream().print(row[i]);
- if (i < numCol - 1) {
- printSpaces(gap);
- }
- } else if (titleAlign == CENTER) {
- int spaceBefore, spaceAfter;
- spaceBefore = (availableSpace - row[i].length()) / 2;
- spaceAfter = availableSpace - row[i].length() - spaceBefore;
-
- printSpaces(spaceBefore);
- app.getOutputStream().print(row[i]);
- printSpaces(spaceAfter);
- if (i < numCol - 1) {
- printSpaces(gap);
- }
- } else {
- app.getOutputStream().print(row[i]);
- if (i < numCol - 1) {
- printSpaces(availableSpace - row[i].length() + gap);
- }
- }
-
- }
- app.getOutputStream().println("");
- }
- printBorder();
- }
-
- /**
- * Set alignment for title strings.
- *
- * @param titleAlign
- * The alignment which should be one of {@code LEFT},
- * {@code RIGHT}, or {@code CENTER}.
- */
- void setTitleAlign(final int titleAlign) {
- this.titleAlign = titleAlign;
- }
-
- private void printBorder() {
- if (border == null) {
- return;
- }
-
- // For the value in each column
- for (int i = 0; i < numCol; i++) {
- for (int j = 0; j < curLength[i]; j++) {
- app.getOutputStream().print(border);
- }
- }
-
- // For the gap between each column
- for (int i = 0; i < numCol - 1; i++) {
- for (int j = 0; j < gap; j++) {
- app.getOutputStream().print(border);
- }
- }
- app.getOutputStream().println("");
- }
-
- private void printSpaces(final int count) {
- for (int i = 0; i < count; ++i) {
- app.getOutputStream().print(" ");
- }
- }
-}
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PerformanceRunner.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PerformanceRunner.java
index 7704b16..fb70b6c 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PerformanceRunner.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PerformanceRunner.java
@@ -27,6 +27,8 @@
package com.forgerock.opendj.ldap.tools;
+import static org.forgerock.util.Utils.closeSilently;
+
import java.io.IOException;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
@@ -48,8 +50,14 @@
import org.forgerock.opendj.ldap.ResultHandler;
import org.forgerock.opendj.ldap.responses.ExtendedResult;
import org.forgerock.opendj.ldap.responses.Result;
-import org.forgerock.util.Utils;
+import com.forgerock.opendj.cli.ArgumentException;
+import com.forgerock.opendj.cli.ArgumentParser;
+import com.forgerock.opendj.cli.BooleanArgument;
+import com.forgerock.opendj.cli.ConsoleApplication;
+import com.forgerock.opendj.cli.IntegerArgument;
+import com.forgerock.opendj.cli.MultiColumnPrinter;
+import com.forgerock.opendj.cli.StringArgument;
import com.forgerock.opendj.ldap.tools.AuthenticatedConnectionFactory.AuthenticatedConnection;
import com.forgerock.opendj.util.StaticUtils;
@@ -859,7 +867,7 @@
stopRequested = true;
app.println(LocalizableMessage.raw(e.getResult().getDiagnosticMessage()));
} finally {
- Utils.closeSilently(connections);
+ closeSilently(connections);
}
return 0;
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PromptingTrustManager.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PromptingTrustManager.java
index 182fcd7..5692f63 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PromptingTrustManager.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PromptingTrustManager.java
@@ -50,6 +50,9 @@
import org.forgerock.i18n.LocalizableMessageBuilder;
import org.forgerock.util.Reject;
+import com.forgerock.opendj.cli.CLIException;
+import com.forgerock.opendj.cli.ConsoleApplication;
+
/**
* A trust manager which prompts the user for the length of time that they would
* like to trust a server certificate.
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/SearchRate.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/SearchRate.java
index a90d11d..32eb1b0 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/SearchRate.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/SearchRate.java
@@ -22,14 +22,13 @@
*
*
* Copyright 2010 Sun Microsystems, Inc.
- * Portions copyright 2011 ForgeRock AS
+ * Portions copyright 2011-2014 ForgeRock AS
*/
-
package com.forgerock.opendj.ldap.tools;
-import static com.forgerock.opendj.ldap.tools.ToolConstants.*;
+import static com.forgerock.opendj.cli.CliConstants.*;
import static com.forgerock.opendj.ldap.tools.ToolsMessages.*;
-import static com.forgerock.opendj.ldap.tools.Utils.filterExitCode;
+import static com.forgerock.opendj.cli.Utils.filterExitCode;
import java.util.ArrayList;
import java.util.LinkedList;
@@ -50,6 +49,14 @@
import org.forgerock.opendj.ldap.responses.SearchResultEntry;
import org.forgerock.opendj.ldap.responses.SearchResultReference;
+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.ConsoleApplication;
+import com.forgerock.opendj.cli.MultiChoiceArgument;
+import com.forgerock.opendj.cli.StringArgument;
+
/**
* A load generation tool that can be used to load a Directory Server with
* Search requests using one or more LDAP connections.
@@ -211,22 +218,15 @@
connectionFactoryProvider = new ConnectionFactoryProvider(argParser, this);
runner = new SearchPerformanceRunner(argParser, this);
- propertiesFileArgument =
- new StringArgument("propertiesFilePath", null, OPTION_LONG_PROP_FILE_PATH,
- false, false, true, INFO_PROP_FILE_PATH_PLACEHOLDER.get(), null, null,
- INFO_DESCRIPTION_PROP_FILE_PATH.get());
+ propertiesFileArgument = CommonArguments.getPropertiesFileArgument();
argParser.addArgument(propertiesFileArgument);
argParser.setFilePropertiesArgument(propertiesFileArgument);
- noPropertiesFileArgument =
- new BooleanArgument("noPropertiesFileArgument", null, OPTION_LONG_NO_PROP_FILE,
- INFO_DESCRIPTION_NO_PROP_FILE.get());
+ noPropertiesFileArgument = CommonArguments.getNoPropertiesFileArgument();
argParser.addArgument(noPropertiesFileArgument);
argParser.setNoPropertiesFileArgument(noPropertiesFileArgument);
- showUsage =
- new BooleanArgument("showUsage", OPTION_SHORT_HELP, OPTION_LONG_HELP,
- INFO_DESCRIPTION_SHOWUSAGE.get());
+ showUsage = CommonArguments.getShowUsage();
argParser.addArgument(showUsage);
argParser.setUsageArgument(showUsage, getOutputStream());
@@ -254,9 +254,7 @@
dereferencePolicy.setDefaultValue(DereferenceAliasesPolicy.NEVER);
argParser.addArgument(dereferencePolicy);
- verbose =
- new BooleanArgument("verbose", 'v', "verbose", INFO_DESCRIPTION_VERBOSE.get());
- verbose.setPropertyName("verbose");
+ verbose = CommonArguments.getVerbose();
argParser.addArgument(verbose);
scriptFriendly =
@@ -291,9 +289,8 @@
final List<String> attributes = new LinkedList<String>();
final ArrayList<String> filterAndAttributeStrings = argParser.getTrailingArguments();
if (filterAndAttributeStrings.size() > 0) {
- // the list of trailing arguments should be structured as follow:
- // the first trailing argument is
- // considered the filter, the other as attributes.
+ /* The list of trailing arguments should be structured as follow:
+ the first trailing argument is considered the filter, the other as attributes.*/
runner.filter = filterAndAttributeStrings.remove(0);
// The rest are attributes
for (final String s : filterAndAttributeStrings) {
@@ -311,8 +308,8 @@
}
try {
- // Try it out to make sure the format string and data sources
- // match.
+ /* Try it out to make sure the format string and data sources
+ match.*/
final Object[] data = DataSource.generateData(runner.getDataSources(), null);
String.format(runner.filter, data);
String.format(runner.baseDN, data);
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/StringArgument.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/StringArgument.java
deleted file mode 100644
index 1fc8e4e..0000000
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/StringArgument.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at legal-notices/CDDLv1_0.txt.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Copyright 2006-2008 Sun Microsystems, Inc.
- */
-package com.forgerock.opendj.ldap.tools;
-
-import org.forgerock.i18n.LocalizableMessage;
-import org.forgerock.i18n.LocalizableMessageBuilder;
-
-/**
- * This class defines an argument type that will accept any string value.
- */
-final class StringArgument extends Argument {
- /**
- * Creates a new string argument with the provided information.
- *
- * @param name
- * The generic name that should be used to refer to this
- * argument.
- * @param shortIdentifier
- * The single-character identifier for this argument, or
- * <CODE>null</CODE> if there is none.
- * @param longIdentifier
- * The long identifier for this argument, or <CODE>null</CODE> if
- * there is none.
- * @param isRequired
- * Indicates whether this argument must be specified on the
- * command line.
- * @param isMultiValued
- * Indicates whether this argument may be specified more than
- * once to provide multiple values.
- * @param needsValue
- * Indicates whether this argument requires a value.
- * @param valuePlaceholder
- * The placeholder for the argument value that will be displayed
- * in usage information, or <CODE>null</CODE> if this argument
- * does not require a value.
- * @param defaultValue
- * The default value that should be used for this argument if
- * none is provided in a properties file or on the command line.
- * This may be <CODE>null</CODE> if there is no generic default.
- * @param propertyName
- * The name of the property in a property file that may be used
- * to override the default value but will be overridden by a
- * command-line argument.
- * @param description
- * LocalizableMessage for the description of this argument.
- * @throws ArgumentException
- * If there is a problem with any of the parameters used to
- * create this argument.
- */
- public StringArgument(final String name, final Character shortIdentifier,
- final String longIdentifier, final boolean isRequired, final boolean isMultiValued,
- final boolean needsValue, final LocalizableMessage valuePlaceholder,
- final String defaultValue, final String propertyName,
- final LocalizableMessage description) throws ArgumentException {
- super(name, shortIdentifier, longIdentifier, isRequired, isMultiValued, needsValue,
- valuePlaceholder, defaultValue, propertyName, description);
- }
-
- /**
- * Creates a new string argument with the provided information.
- *
- * @param name
- * The generic name that should be used to refer to this
- * argument.
- * @param shortIdentifier
- * The single-character identifier for this argument, or
- * <CODE>null</CODE> if there is none.
- * @param longIdentifier
- * The long identifier for this argument, or <CODE>null</CODE> if
- * there is none.
- * @param isRequired
- * Indicates whether this argument must be specified on the
- * command line.
- * @param needsValue
- * Indicates whether this argument requires a value.
- * @param valuePlaceholder
- * The placeholder for the argument value that will be displayed
- * in usage information, or <CODE>null</CODE> if this argument
- * does not require a value.
- * @param description
- * LocalizableMessage for the description of this argument.
- * @throws ArgumentException
- * If there is a problem with any of the parameters used to
- * create this argument.
- */
- public StringArgument(final String name, final Character shortIdentifier,
- final String longIdentifier, final boolean isRequired, final boolean needsValue,
- final LocalizableMessage valuePlaceholder, final LocalizableMessage description)
- throws ArgumentException {
- super(name, shortIdentifier, longIdentifier, isRequired, false, needsValue,
- valuePlaceholder, null, null, description);
- }
-
- /**
- * Indicates whether the provided value is acceptable for use in this
- * argument.
- *
- * @param valueString
- * The value for which to make the determination.
- * @param invalidReason
- * A buffer into which the invalid reason may be written if the
- * value is not acceptable.
- * @return <CODE>true</CODE> if the value is acceptable, or
- * <CODE>false</CODE> if it is not.
- */
- @Override
- public boolean valueIsAcceptable(final String valueString,
- final LocalizableMessageBuilder invalidReason) {
- // All values will be acceptable for this argument.
- return true;
- }
-}
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ToolConstants.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ToolConstants.java
deleted file mode 100755
index cdb9837..0000000
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ToolConstants.java
+++ /dev/null
@@ -1,625 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at legal-notices/CDDLv1_0.txt.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Copyright 2006-2010 Sun Microsystems, Inc.
- * Portions copyright 2012 ForgeRock AS.
- */
-package com.forgerock.opendj.ldap.tools;
-
-/**
- * This class defines a number of constants used in one or more Directory Server
- * tools.
- */
-final class ToolConstants {
- /**
- * The name of the SASL property that can be used to provide the
- * authentication ID for the bind.
- */
- static final String SASL_PROPERTY_AUTHID = "authid";
-
- /**
- * The name of the SASL property that can be used to provide the
- * authorization ID for the bind.
- */
- static final String SASL_PROPERTY_AUTHZID = "authzid";
-
- /**
- * The name of the SASL property that can be used to provide the digest URI
- * for the bind.
- */
- static final String SASL_PROPERTY_DIGEST_URI = "digest-uri";
-
- /**
- * The name of the SASL property that can be used to provide the KDC for use
- * in Kerberos authentication.
- */
- static final String SASL_PROPERTY_KDC = "kdc";
-
- /**
- * The name of the SASL property that can be used to provide the quality of
- * protection for the bind.
- */
- static final String SASL_PROPERTY_QOP = "qop";
-
- /**
- * The name of the SASL property that can be used to provide the realm for
- * the bind.
- */
- static final String SASL_PROPERTY_REALM = "realm";
-
- /**
- * The name of the SASL property that can be used to provide trace
- * information for a SASL ANONYMOUS request.
- */
- static final String SASL_PROPERTY_TRACE = "trace";
-
- /**
- * The name of the SASL property that can be used to provide the SASL
- * mechanism to use.
- */
- static final String SASL_PROPERTY_MECH = "mech";
-
- /**
- * The name of the opendj configuration direction in the user home
- * directory.
- */
- static final String DEFAULT_OPENDJ_CONFIG_DIR = ".opendj";
-
- /**
- * The default properties file name.
- */
- static final String DEFAULT_OPENDJ_PROPERTIES_FILE_NAME = "tools";
-
- /**
- * The default properties file extension.
- */
- static final String DEFAULT_OPENDJ_PROPERTIES_FILE_EXTENSION = ".properties";
-
- /**
- * The value for the short option batchFilePath.
- */
- static final char OPTION_SHORT_BATCH_FILE_PATH = 'F';
-
- /**
- * The value for the long option batchFilePath .
- */
- static final String OPTION_LONG_BATCH_FILE_PATH = "batchFilePath";
-
- /**
- * The value for the short option hostname.
- */
- static final char OPTION_SHORT_HOST = 'h';
-
- /**
- * The value for the long option hostname.
- */
- static final String OPTION_LONG_HOST = "hostname";
-
- /**
- * The value for the short option port.
- */
- static final char OPTION_SHORT_PORT = 'p';
-
- /**
- * The value for the long option port.
- */
- static final String OPTION_LONG_PORT = "port";
-
- /**
- * The value for the short option useSSL.
- */
- static final char OPTION_SHORT_USE_SSL = 'Z';
-
- /**
- * The value for the long option useSSL.
- */
- static final String OPTION_LONG_USE_SSL = "useSSL";
-
- /**
- * The value for the short option baseDN.
- */
- static final char OPTION_SHORT_BASEDN = 'b';
-
- /**
- * The value for the long option baseDN.
- */
- static final String OPTION_LONG_BASEDN = "baseDN";
-
- /**
- * The value for the short option bindDN.
- */
- static final char OPTION_SHORT_BINDDN = 'D';
-
- /**
- * The value for the long option bindDN.
- */
- static final String OPTION_LONG_BINDDN = "bindDN";
-
- /**
- * The value for the short option bindPassword.
- */
- static final char OPTION_SHORT_BINDPWD = 'w';
-
- /**
- * The value for the long option bindPassword.
- */
- static final String OPTION_LONG_BINDPWD = "bindPassword";
-
- /**
- * The value for the short option bindPasswordFile.
- */
- static final char OPTION_SHORT_BINDPWD_FILE = 'j';
-
- /**
- * The value for the long option bindPasswordFile.
- */
- static final String OPTION_LONG_BINDPWD_FILE = "bindPasswordFile";
-
- /**
- * The value for the short option compress.
- */
- static final char OPTION_SHORT_COMPRESS = 'c';
-
- /**
- * The value for the long option compress.
- */
- static final String OPTION_LONG_COMPRESS = "compress";
-
- /**
- * The value for the short option filename.
- */
- static final char OPTION_SHORT_FILENAME = 'f';
-
- /**
- * The value for the long option filename.
- */
- static final String OPTION_LONG_FILENAME = "filename";
-
- /**
- * The value for the short option ldifFile.
- */
- static final char OPTION_SHORT_LDIF_FILE = 'l';
-
- /**
- * The value for the long option ldifFile.
- */
- static final String OPTION_LONG_LDIF_FILE = "ldifFile";
-
- /**
- * The value for the short option useStartTLS.
- */
- static final char OPTION_SHORT_START_TLS = 'q';
-
- /**
- * The value for the long option useStartTLS.
- */
- static final String OPTION_LONG_START_TLS = "useStartTLS";
-
- /**
- * The value for the short option randomSeed.
- */
- static final char OPTION_SHORT_RANDOM_SEED = 's';
-
- /**
- * The value for the long option randomSeed.
- */
- static final String OPTION_LONG_RANDOM_SEED = "randomSeed";
-
- /**
- * The value for the short option keyStorePath.
- */
- static final char OPTION_SHORT_KEYSTOREPATH = 'K';
-
- /**
- * The value for the long option keyStorePath.
- */
- static final String OPTION_LONG_KEYSTOREPATH = "keyStorePath";
-
- /**
- * The value for the short option trustStorePath.
- */
- static final char OPTION_SHORT_TRUSTSTOREPATH = 'P';
-
- /**
- * The value for the long option trustStorePath.
- */
- static final String OPTION_LONG_TRUSTSTOREPATH = "trustStorePath";
-
- /**
- * The value for the short option keyStorePassword.
- */
- static final char OPTION_SHORT_KEYSTORE_PWD = 'W';
-
- /**
- * The value for the long option keyStorePassword.
- */
- static final String OPTION_LONG_KEYSTORE_PWD = "keyStorePassword";
-
- /**
- * The value for the short option trustStorePassword.
- */
- static final char OPTION_SHORT_TRUSTSTORE_PWD = 'T';
-
- /**
- * The value for the long option trustStorePassword.
- */
- static final String OPTION_LONG_TRUSTSTORE_PWD = "trustStorePassword";
-
- /**
- * The value for the short option keyStorePasswordFile .
- */
- static final char OPTION_SHORT_KEYSTORE_PWD_FILE = 'u';
-
- /**
- * The value for the long option keyStorePasswordFile .
- */
- static final String OPTION_LONG_KEYSTORE_PWD_FILE = "keyStorePasswordFile";
-
- /**
- * The value for the short option keyStorePasswordFile .
- */
- static final char OPTION_SHORT_TRUSTSTORE_PWD_FILE = 'U';
-
- /**
- * The value for the long option keyStorePasswordFile .
- */
- static final String OPTION_LONG_TRUSTSTORE_PWD_FILE = "trustStorePasswordFile";
-
- /**
- * The value for the short option trustAll .
- */
- static final char OPTION_SHORT_TRUSTALL = 'X';
-
- /**
- * The value for the long option trustAll .
- */
- static final String OPTION_LONG_TRUSTALL = "trustAll";
-
- /**
- * The value for the short option certNickname .
- */
- static final char OPTION_SHORT_CERT_NICKNAME = 'N';
-
- /**
- * The value for the long option certNickname .
- */
- static final String OPTION_LONG_CERT_NICKNAME = "certNickname";
-
- /**
- * The value for the long option assertionFilter .
- */
- static final String OPTION_LONG_ASSERTION_FILE = "assertionFilter";
-
- /**
- * The value for the short option dry-run.
- */
- static final char OPTION_SHORT_DRYRUN = 'n';
-
- /**
- * The value for the long option dry-run.
- */
- static final String OPTION_LONG_DRYRUN = "dry-run";
-
- /**
- * The value for the short option help.
- */
- static final char OPTION_SHORT_HELP = 'H';
-
- /**
- * The value for the long option help.
- */
- static final String OPTION_LONG_HELP = "help";
-
- /**
- * The value for the long option cli.
- */
- static final String OPTION_LONG_CLI = "cli";
-
- /**
- * The value for the short option cli.
- */
- static final char OPTION_SHORT_CLI = 'i';
-
- /**
- * The value for the short option proxyAs.
- */
- static final char OPTION_SHORT_PROXYAUTHID = 'Y';
-
- /**
- * The value for the long option proxyAs.
- */
- static final String OPTION_LONG_PROXYAUTHID = "proxyAs";
-
- /**
- * The value for the short option saslOption.
- */
- static final char OPTION_SHORT_SASLOPTION = 'o';
-
- /**
- * The value for the long option saslOption.
- */
- static final String OPTION_LONG_SASLOPTION = "saslOption";
-
- /**
- * The value for the short option geteffectiverights control authzid.
- */
- static final char OPTION_SHORT_EFFECTIVERIGHTSUSER = 'g';
-
- /**
- * The value for the long option geteffectiverights control authzid.
- */
- static final String OPTION_LONG_EFFECTIVERIGHTSUSER = "getEffectiveRightsAuthzid";
-
- /**
- * The value for the short option geteffectiveights control attributes.
- */
- static final char OPTION_SHORT_EFFECTIVERIGHTSATTR = 'e';
-
- /**
- * The value for the long option geteffectiverights control specific
- * attribute list.
- */
- static final String OPTION_LONG_EFFECTIVERIGHTSATTR = "getEffectiveRightsAttribute";
-
- /**
- * The value for the short option protocol version attributes.
- */
- static final char OPTION_SHORT_PROTOCOL_VERSION = 'V';
-
- /**
- * The value for the long option protocol version attribute.
- */
- static final String OPTION_LONG_PROTOCOL_VERSION = "ldapVersion";
-
- /**
- * The value for the long option version.
- */
- static final char OPTION_SHORT_PRODUCT_VERSION = 'V';
-
- /**
- * The value for the long option version.
- */
- static final String OPTION_LONG_PRODUCT_VERSION = "version";
-
- /**
- * The value for the short option description attributes.
- */
- static final char OPTION_SHORT_DESCRIPTION = 'd';
-
- /**
- * The value for the long option description attribute.
- */
- static final String OPTION_LONG_DESCRIPTION = "description";
-
- /**
- * The value for the short option groupName attributes.
- */
- static final char OPTION_SHORT_GROUPNAME = 'g';
-
- /**
- * The value for the long option groupName attribute.
- */
- static final String OPTION_LONG_GROUPNAME = "groupName";
-
- /**
- * The value for the short option newGroupName attribute.
- */
- static final char OPTION_SHORT_NEWGROUPNAME = 'n';
-
- /**
- * The value for the long option groupName attribute.
- */
- static final String OPTION_LONG_NEWGROUPNAME = "newGroupName";
-
- /**
- * The value for the short option member-name attributes.
- */
- static final char OPTION_SHORT_MEMBERNAME = 'm';
-
- /**
- * The value for the long member-name version attribute.
- */
- static final String OPTION_LONG_MEMBERNAME = "memberName";
-
- /**
- * The value for the short option serverID attributes.
- */
- static final String OPTION_SHORT_SERVERID = null;
-
- /**
- * The value for the long option serverID attribute.
- */
- static final String OPTION_LONG_SERVERID = "serverID";
-
- /**
- * The value for the short option userID attributes.
- */
- static final String OPTION_SHORT_USERID = null;
-
- /**
- * The value for the long option userID attribute.
- */
- static final String OPTION_LONG_USERID = "userID";
-
- /**
- * The value for the short option set.
- */
- static final Character OPTION_SHORT_SET = null;
-
- /**
- * The value for the long option set.
- */
- static final String OPTION_LONG_SET = "set";
-
- /**
- * Value for the quiet option short form.
- */
- static final Character OPTION_SHORT_QUIET = 'Q';
-
- /**
- * Value for the quiet option long form.
- */
- static final String OPTION_LONG_QUIET = "quiet";
-
- /**
- * Value for noninteractive session short form.
- */
- static final Character OPTION_SHORT_NO_PROMPT = 'n';
-
- /**
- * Value for noninteractive session long form.
- */
- static final String OPTION_LONG_NO_PROMPT = "no-prompt";
-
- /**
- * Long form of script friendly option.
- */
- static final String OPTION_LONG_SCRIPT_FRIENDLY = "script-friendly";
-
- /**
- * Short form of script friendly option.
- */
- static final Character OPTION_SHORT_SCRIPT_FRIENDLY = 's';
-
- /**
- * Value for verbose option short form.
- */
- static final Character OPTION_SHORT_VERBOSE = 'v';
-
- /**
- * Value for verbose option long form.
- */
- static final String OPTION_LONG_VERBOSE = "verbose";
-
- /**
- * The value for the long option propertiesFilePAth .
- */
- static final String OPTION_LONG_PROP_FILE_PATH = "propertiesFilePath";
-
- /**
- * The value for the long option propertiesFilePAth .
- */
- static final String OPTION_LONG_NO_PROP_FILE = "noPropertiesFile";
-
- /**
- * Long form of referenced host name.
- */
- static final String OPTION_LONG_REFERENCED_HOST_NAME = "referencedHostName";
-
- /**
- * Long form of admin UID.
- */
- static final String OPTION_LONG_ADMIN_UID = "adminUID";
-
- /**
- * Long form of report authorization ID connection option.
- */
- static final String OPTION_LONG_REPORT_AUTHZ_ID = "reportAuthzID";
-
- /**
- * Long form of use password policy control connection option.
- */
- static final String OPTION_LONG_USE_PW_POLICY_CTL = "usePasswordPolicyControl";
-
- /**
- * Long form of use SASL external connection option.
- */
- static final String OPTION_LONG_USE_SASL_EXTERNAL = "useSASLExternal";
-
- /**
- * Long form of option for the command-line encoding option.
- */
- static final String OPTION_LONG_ENCODING = "encoding";
-
- /**
- * Long form of option specifying no wrapping of the command-line.
- */
- static final String OPTION_LONG_DONT_WRAP = "dontWrap";
-
- /**
- * The value for the long option targetDN.
- */
- static final String OPTION_LONG_TARGETDN = "targetDN";
-
- /**
- * Long form of email notification upon completion option.
- */
- static final String OPTION_LONG_COMPLETION_NOTIFICATION_EMAIL = "completionNotify";
-
- /**
- * Short form of email notification upon completion option.
- */
- static final Character OPTION_SHORT_COMPLETION_NOTIFICATION_EMAIL = null;
-
- /**
- * Long form of email notification upon error option.
- */
- static final String OPTION_LONG_ERROR_NOTIFICATION_EMAIL = "errorNotify";
-
- /**
- * Short form of email notification upon error option.
- */
- static final Character OPTION_SHORT_ERROR_NOTIFICATION_EMAIL = null;
-
- /**
- * Long form of dependency option.
- */
- static final String OPTION_LONG_DEPENDENCY = "dependency";
-
- /**
- * Short form of dependency option.
- */
- static final Character OPTION_SHORT_DEPENDENCY = null;
-
- /**
- * Long form of failed dependency action option.
- */
- static final String OPTION_LONG_FAILED_DEPENDENCY_ACTION = "failedDependencyAction";
-
- /**
- * Short form of failed dependency action option.
- */
- static final Character OPTION_SHORT_FAILED_DEPENDENCY_ACTION = null;
-
- /**
- * The default separator to be used in tables.
- */
- static final String LIST_TABLE_SEPARATOR = ":";
-
- /**
- *
- * The value for the short option output LDIF filename.
- */
- static final char OPTION_SHORT_OUTPUT_LDIF_FILENAME = 'o';
-
- /**
- * The value for the long option output LDIF filename.
- */
- static final String OPTION_LONG_OUTPUT_LDIF_FILENAME = "outputLDIF";
-
- // Prevent instantiation.
- private ToolConstants() {
-
- }
-
-}
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/Utils.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/Utils.java
index 51c711c..bceb305 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/Utils.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/Utils.java
@@ -22,16 +22,13 @@
*
*
* Copyright 2006-2010 Sun Microsystems, Inc.
+ * Portions copyright 2014 ForgeRock AS
*/
package com.forgerock.opendj.ldap.tools;
import static com.forgerock.opendj.ldap.tools.ToolsMessages.*;
-import static com.forgerock.opendj.util.StaticUtils.EOL;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.StringTokenizer;
+import static com.forgerock.opendj.cli.Utils.readBytesFromFile;
+import static com.forgerock.opendj.cli.Utils.secondsToTimeString;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.ByteString;
@@ -52,6 +49,7 @@
import org.forgerock.opendj.ldap.controls.SubtreeDeleteRequestControl;
import org.forgerock.opendj.ldap.responses.BindResult;
+import com.forgerock.opendj.cli.ConsoleApplication;
import com.forgerock.opendj.ldap.controls.AccountUsabilityRequestControl;
import com.forgerock.opendj.ldap.tools.AuthenticatedConnectionFactory.AuthenticatedConnection;
import com.forgerock.opendj.util.StaticUtils;
@@ -60,52 +58,6 @@
* This class provides utility functions for all the client side tools.
*/
final class Utils {
- /**
- * The name of a command-line script used to launch a tool.
- */
- static final String PROPERTY_SCRIPT_NAME = "com.forgerock.opendj.ldap.tools.scriptName";
-
- /**
- * The column at which to wrap long lines of output in the command-line
- * tools.
- */
- static final int MAX_LINE_WIDTH;
-
- static {
- int columns = 80;
- try {
- final String s = System.getenv("COLUMNS");
- if (s != null) {
- columns = Integer.parseInt(s);
- }
- } catch (final Exception e) {
- // Do nothing.
- }
- MAX_LINE_WIDTH = columns - 1;
- }
-
- /**
- * Filters the provided value to ensure that it is appropriate for use as an
- * exit code. Exit code values are generally only allowed to be between 0
- * and 255, so any value outside of this range will be converted to 255,
- * which is the typical exit code used to indicate an overflow value.
- *
- * @param exitCode
- * The exit code value to be processed.
- * @return An integer value between 0 and 255, inclusive. If the provided
- * exit code was already between 0 and 255, then the original value
- * will be returned. If the provided value was out of this range,
- * then 255 will be returned.
- */
- static int filterExitCode(final int exitCode) {
- if (exitCode < 0) {
- return 255;
- } else if (exitCode > 255) {
- return 255;
- } else {
- return exitCode;
- }
- }
/**
* Parse the specified command line argument to create the appropriate
@@ -219,11 +171,9 @@
* @return The error code.
*/
static int printErrorMessage(final ConsoleApplication app, final ErrorResultException ere) {
- // if ((ere.getMessage() != null) && (ere.getMessage().length() >
- // 0))
- // {
- // app.println(LocalizableMessage.raw(ere.getMessage()));
- // }
+ /* if ((ere.getMessage() != null) && (ere.getMessage().length() > 0)) {
+ app.println(LocalizableMessage.raw(ere.getMessage()));
+ }*/
if (ere.getResult().getResultCode().intValue() >= 0) {
app.println(ERR_TOOL_RESULT_CODE.get(ere.getResult().getResultCode().intValue(), ere
@@ -282,7 +232,7 @@
new DecodeOptions());
if (control != null) {
final LocalizableMessage timeString =
- Utils.secondsToTimeString(control.getSecondsUntilExpiration());
+ secondsToTimeString(control.getSecondsUntilExpiration());
final LocalizableMessage message = INFO_BIND_PASSWORD_EXPIRING.get(timeString);
app.println(message);
}
@@ -311,7 +261,7 @@
final PasswordPolicyWarningType warningType = control.getWarningType();
if (warningType == PasswordPolicyWarningType.TIME_BEFORE_EXPIRATION) {
final LocalizableMessage timeString =
- Utils.secondsToTimeString(control.getWarningValue());
+ secondsToTimeString(control.getWarningValue());
final LocalizableMessage message =
INFO_BIND_PASSWORD_EXPIRING.get(timeString);
app.println(message);
@@ -328,79 +278,6 @@
}
/**
- * Read the data from the specified file and return it in a byte array.
- *
- * @param filePath
- * The path to the file that should be read.
- * @return A byte array containing the contents of the requested file.
- * @throws IOException
- * If a problem occurs while trying to read the specified file.
- */
- static byte[] readBytesFromFile(final String filePath) throws IOException {
- byte[] val = null;
- FileInputStream fis = null;
- try {
- final File file = new File(filePath);
- fis = new FileInputStream(file);
- final long length = file.length();
- val = new byte[(int) length];
- // Read in the bytes
- int offset = 0;
- int numRead = 0;
- while (offset < val.length
- && (numRead = fis.read(val, offset, val.length - offset)) >= 0) {
- offset += numRead;
- }
-
- // Ensure all the bytes have been read in
- if (offset < val.length) {
- throw new IOException("Could not completely read file " + filePath);
- }
-
- return val;
- } finally {
- if (fis != null) {
- fis.close();
- }
- }
- }
-
- /**
- * Retrieves a user-friendly string that indicates the length of time (in
- * days, hours, minutes, and seconds) in the specified number of seconds.
- *
- * @param numSeconds
- * The number of seconds to be converted to a more user-friendly
- * value.
- * @return The user-friendly representation of the specified number of
- * seconds.
- */
- static LocalizableMessage secondsToTimeString(final int numSeconds) {
- if (numSeconds < 60) {
- // We can express it in seconds.
- return INFO_TIME_IN_SECONDS.get(numSeconds);
- } else if (numSeconds < 3600) {
- // We can express it in minutes and seconds.
- final int m = numSeconds / 60;
- final int s = numSeconds % 60;
- return INFO_TIME_IN_MINUTES_SECONDS.get(m, s);
- } else if (numSeconds < 86400) {
- // We can express it in hours, minutes, and seconds.
- final int h = numSeconds / 3600;
- final int m = (numSeconds % 3600) / 60;
- final int s = numSeconds % 3600 % 60;
- return INFO_TIME_IN_HOURS_MINUTES_SECONDS.get(h, m, s);
- } else {
- // We can express it in days, hours, minutes, and seconds.
- final int d = numSeconds / 86400;
- final int h = (numSeconds % 86400) / 3600;
- final int m = (numSeconds % 86400 % 3600) / 60;
- final int s = numSeconds % 86400 % 3600 % 60;
- return INFO_TIME_IN_DAYS_HOURS_MINUTES_SECONDS.get(d, h, m, s);
- }
- }
-
- /**
* Sets default system property settings for the xxxrate performance tools.
*/
static void setDefaultPerfToolProperties() {
@@ -409,196 +286,14 @@
System.setProperty("org.forgerock.opendj.transport.useWorkerThreads", "false");
}
- // Configure connections to be terminate immediately after closing (this
- // prevents port exhaustion in xxxrate tools when
- // connecting/disconnecting).
+ /* Configure connections to be terminate immediately after closing (this
+ prevents port exhaustion in xxxrate tools when
+ connecting/disconnecting).*/
if (System.getProperty("org.forgerock.opendj.transport.linger") == null) {
System.setProperty("org.forgerock.opendj.transport.linger", "0");
}
}
- /**
- * Inserts line breaks into the provided buffer to wrap text at no more than
- * the specified column width. Wrapping will only be done at space
- * boundaries and if there are no spaces within the specified width, then
- * wrapping will be performed at the first space after the specified column.
- *
- * @param message
- * The message to be wrapped.
- * @param width
- * The maximum number of characters to allow on a line if there
- * is a suitable breaking point.
- * @return The wrapped text.
- */
- static String wrapText(final LocalizableMessage message, final int width) {
- return wrapText(message.toString(), width, 0);
- }
-
- /**
- * Inserts line breaks into the provided buffer to wrap text at no more than
- * the specified column width. Wrapping will only be done at space
- * boundaries and if there are no spaces within the specified width, then
- * wrapping will be performed at the first space after the specified column.
- * In addition each line will be indented by the specified amount.
- *
- * @param message
- * The message to be wrapped.
- * @param width
- * The maximum number of characters to allow on a line if there
- * is a suitable breaking point (including any indentation).
- * @param indent
- * The number of columns to indent each line.
- * @return The wrapped text.
- */
- static String wrapText(final LocalizableMessage message, final int width, final int indent) {
- return wrapText(message.toString(), width, indent);
- }
-
- /**
- * Inserts line breaks into the provided buffer to wrap text at no more than
- * the specified column width. Wrapping will only be done at space
- * boundaries and if there are no spaces within the specified width, then
- * wrapping will be performed at the first space after the specified column.
- *
- * @param text
- * The text to be wrapped.
- * @param width
- * The maximum number of characters to allow on a line if there
- * is a suitable breaking point.
- * @return The wrapped text.
- */
- static String wrapText(final String text, final int width) {
- return wrapText(text, width, 0);
- }
-
- /**
- * Inserts line breaks into the provided buffer to wrap text at no more than
- * the specified column width. Wrapping will only be done at space
- * boundaries and if there are no spaces within the specified width, then
- * wrapping will be performed at the first space after the specified column.
- * In addition each line will be indented by the specified amount.
- *
- * @param text
- * The text to be wrapped.
- * @param width
- * The maximum number of characters to allow on a line if there
- * is a suitable breaking point (including any indentation).
- * @param indent
- * The number of columns to indent each line.
- * @return The wrapped text.
- */
- static String wrapText(final String text, int width, final int indent) {
- // Calculate the real width and indentation padding.
- width -= indent;
- final StringBuilder pb = new StringBuilder();
- for (int i = 0; i < indent; i++) {
- pb.append(' ');
- }
- final String padding = pb.toString();
-
- final StringBuilder buffer = new StringBuilder();
- if (text != null) {
- final StringTokenizer lineTokenizer = new StringTokenizer(text, "\r\n", true);
- while (lineTokenizer.hasMoreTokens()) {
- final String line = lineTokenizer.nextToken();
- if (line.equals("\r") || line.equals("\n")) {
- // It's an end-of-line character, so append it as-is.
- buffer.append(line);
- } else if (line.length() <= width) {
- // The line fits in the specified width, so append it as-is.
- buffer.append(padding);
- buffer.append(line);
- } else {
- // The line doesn't fit in the specified width, so it needs
- // to
- // be
- // wrapped. Do so at space boundaries.
- StringBuilder lineBuffer = new StringBuilder();
- StringBuilder delimBuffer = new StringBuilder();
- final StringTokenizer wordTokenizer = new StringTokenizer(line, " ", true);
- while (wordTokenizer.hasMoreTokens()) {
- final String word = wordTokenizer.nextToken();
- if (word.equals(" ")) {
- // It's a space, so add it to the delim buffer only
- // if the
- // line
- // buffer is not empty.
- if (lineBuffer.length() > 0) {
- delimBuffer.append(word);
- }
- } else if (word.length() > width) {
- // This is a long word that can't be wrapped, so
- // we'll
- // just have
- // to make do.
- if (lineBuffer.length() > 0) {
- buffer.append(padding);
- buffer.append(lineBuffer);
- buffer.append(EOL);
- lineBuffer = new StringBuilder();
- }
- buffer.append(padding);
- buffer.append(word);
-
- if (wordTokenizer.hasMoreTokens()) {
- // The next token must be a space, so remove it.
- // If
- // there are
- // still more tokens after that, then append an
- // EOL.
- wordTokenizer.nextToken();
- if (wordTokenizer.hasMoreTokens()) {
- buffer.append(EOL);
- }
- }
-
- if (delimBuffer.length() > 0) {
- delimBuffer = new StringBuilder();
- }
- } else {
- // It's not a space, so see if we can fit it on the
- // curent
- // line.
- final int newLineLength =
- lineBuffer.length() + delimBuffer.length() + word.length();
- if (newLineLength < width) {
- // It does fit on the line, so add it.
- lineBuffer.append(delimBuffer).append(word);
-
- if (delimBuffer.length() > 0) {
- delimBuffer = new StringBuilder();
- }
- } else {
- // It doesn't fit on the line, so end the
- // current line
- // and start
- // a new one.
- buffer.append(padding);
- buffer.append(lineBuffer);
- buffer.append(EOL);
-
- lineBuffer = new StringBuilder();
- lineBuffer.append(word);
-
- if (delimBuffer.length() > 0) {
- delimBuffer = new StringBuilder();
- }
- }
- }
- }
-
- // If there's anything left in the line buffer, then add it
- // to
- // the
- // final buffer.
- buffer.append(padding);
- buffer.append(lineBuffer);
- }
- }
- }
- return buffer.toString();
- }
-
// Prevent instantiation.
private Utils() {
// Do nothing.
diff --git a/opendj-ldap-toolkit/src/test/java/com/forgerock/opendj/ldap/tools/ConnectionFactoryProviderTest.java b/opendj-ldap-toolkit/src/test/java/com/forgerock/opendj/ldap/tools/ConnectionFactoryProviderTest.java
index afcc9df..6f2ca88 100644
--- a/opendj-ldap-toolkit/src/test/java/com/forgerock/opendj/ldap/tools/ConnectionFactoryProviderTest.java
+++ b/opendj-ldap-toolkit/src/test/java/com/forgerock/opendj/ldap/tools/ConnectionFactoryProviderTest.java
@@ -21,7 +21,7 @@
* CDDL HEADER END
*
*
- * Copyright 2013 ForgeRock AS.
+ * Copyright 2013-2014 ForgeRock AS.
*/
package com.forgerock.opendj.ldap.tools;
@@ -36,6 +36,9 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import com.forgerock.opendj.cli.ArgumentParser;
+import com.forgerock.opendj.cli.ConsoleApplication;
+
@SuppressWarnings("javadoc")
public class ConnectionFactoryProviderTest extends ToolsTestCase {
diff --git a/opendj-ldap-toolkit/src/test/java/com/forgerock/opendj/ldap/tools/MakeLDIFTestCase.java b/opendj-ldap-toolkit/src/test/java/com/forgerock/opendj/ldap/tools/MakeLDIFTestCase.java
index 1b0328b..a8b6fe9 100644
--- a/opendj-ldap-toolkit/src/test/java/com/forgerock/opendj/ldap/tools/MakeLDIFTestCase.java
+++ b/opendj-ldap-toolkit/src/test/java/com/forgerock/opendj/ldap/tools/MakeLDIFTestCase.java
@@ -21,12 +21,14 @@
* CDDL HEADER END
*
*
- * Copyright 2013 ForgeRock AS.
+ * Copyright 2013-2014 ForgeRock AS.
*/
package com.forgerock.opendj.ldap.tools;
import static org.fest.assertions.Assertions.*;
import static com.forgerock.opendj.ldap.tools.ToolsMessages.*;
+import static com.forgerock.opendj.cli.Utils.MAX_LINE_WIDTH;
+import static com.forgerock.opendj.cli.Utils.wrapText;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
@@ -107,7 +109,7 @@
assertThat(out.size()).isEqualTo(0);
}
- assertThat(err.toString("UTF-8")).contains(Utils.wrapText(expectedErrOutput, Utils.MAX_LINE_WIDTH));
+ assertThat(err.toString("UTF-8")).contains(wrapText(expectedErrOutput, MAX_LINE_WIDTH));
} finally {
org.forgerock.util.Utils.closeSilently(outStream, errStream);
}
--
Gitblit v1.10.0