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.
13 files deleted
19 files modified
| | |
| | | <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> |
| | |
| | | * |
| | | * |
| | | * 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; |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | 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, |
| | |
| | | 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()); |
| | | |
| | |
| | | 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 = |
| | |
| | | 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; |
| | | } |
| | |
| | | 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 |
| | |
| | | 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) { |
| | |
| | | * |
| | | * |
| | | * 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; |
| | |
| | | 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; |
| | |
| | | */ |
| | | 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()); |
| | |
| | | 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(), |
| | |
| | | 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(), |
| | |
| | | } |
| | | } |
| | | |
| | | // 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 |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2014 ForgeRock AS |
| | | */ |
| | | |
| | | package com.forgerock.opendj.ldap.tools; |
| | |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | |
| | | import com.forgerock.opendj.cli.ArgumentException; |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | |
| | | import org.forgerock.util.Reject; |
| | | |
| | | /** |
| | |
| | | * 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 |
| | | */ |
| | |
| | | * |
| | | * |
| | | * 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; |
| | |
| | | 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. |
| | | */ |
| | |
| | | |
| | | 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); |
| | | |
| | |
| | | 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 = |
| | |
| | | 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 = |
| | |
| | | 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); |
| | |
| | | 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; |
| | | } |
| | |
| | | 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(); |
| | |
| | | } 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))); |
| | |
| | | * |
| | | * |
| | | * 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; |
| | |
| | | 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. |
| | |
| | | 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(); |
| | |
| | | } |
| | | |
| | | 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); |
| | |
| | | |
| | | 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); |
| | | |
| | |
| | | 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 = |
| | |
| | | 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 = |
| | |
| | | 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) { |
| | |
| | | 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; |
| | | } |
| | |
| | | return ResultCode.CLIENT_SIDE_LOCAL_ERROR.intValue(); |
| | | } |
| | | } finally { |
| | | org.forgerock.util.Utils.closeSilently(reader, connection); |
| | | closeSilently(reader, connection); |
| | | } |
| | | |
| | | return ResultCode.SUCCESS.intValue(); |
| | |
| | | * |
| | | * |
| | | * 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; |
| | |
| | | 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 |
| | |
| | | |
| | | 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); |
| | | |
| | |
| | | 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) { |
| | |
| | | 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; |
| | | } |
| | |
| | | * |
| | | * |
| | | * 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; |
| | |
| | | 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; |
| | | |
| | |
| | | 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)); |
| | |
| | | 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)); |
| | |
| | | } |
| | | |
| | | 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, |
| | |
| | | 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); |
| | | |
| | |
| | | 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 = |
| | |
| | | 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 = |
| | |
| | | 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) { |
| | |
| | | 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); |
| | | |
| | |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | |
| | |
| | | } catch (final ErrorResultException ere) { |
| | | return Utils.printErrorMessage(this, ere); |
| | | } finally { |
| | | org.forgerock.util.Utils.closeSilently(ldifWriter, connection); |
| | | closeSilently(ldifWriter, connection); |
| | | } |
| | | |
| | | return 0; |
| | |
| | | * |
| | | * |
| | | * 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; |
| | |
| | | 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. |
| | |
| | | .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) { |
| | |
| | | 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(); |
| | | } |
| | |
| | | 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); |
| | |
| | | * 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; |
| | |
| | | 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. |
| | |
| | | .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) { |
| | |
| | | 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); |
| | |
| | | * 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; |
| | |
| | | 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. |
| | |
| | | } |
| | | |
| | | 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 = |
| | |
| | | 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) { |
| | |
| | | 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(); |
| | | } |
| | |
| | | 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 { |
| | |
| | | * |
| | | * |
| | | * 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; |
| | |
| | | * |
| | | * |
| | | * 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; |
| | |
| | | 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. |
| | |
| | | } |
| | | |
| | | 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, |
| | |
| | | |
| | | 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); |
| | | |
| | |
| | | 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()); |
| | | |
| | |
| | | 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; |
| | | } |
| | |
| | | |
| | | 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); |
| | |
| | | |
| | | 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; |
| | |
| | | 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; |
| | | |
| | |
| | | stopRequested = true; |
| | | app.println(LocalizableMessage.raw(e.getResult().getDiagnosticMessage())); |
| | | } finally { |
| | | Utils.closeSilently(connections); |
| | | closeSilently(connections); |
| | | } |
| | | |
| | | return 0; |
| | |
| | | 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. |
| | |
| | | * |
| | | * |
| | | * 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; |
| | |
| | | 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. |
| | |
| | | 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()); |
| | | |
| | |
| | | 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 = |
| | |
| | | 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) { |
| | |
| | | } |
| | | |
| | | 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); |
| | |
| | | * |
| | | * |
| | | * 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; |
| | |
| | | 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; |
| | |
| | | * 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 |
| | |
| | | * @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 |
| | |
| | | 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); |
| | | } |
| | |
| | | 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); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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() { |
| | |
| | | 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. |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2013 ForgeRock AS. |
| | | * Copyright 2013-2014 ForgeRock AS. |
| | | */ |
| | | package com.forgerock.opendj.ldap.tools; |
| | | |
| | |
| | | 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 { |
| | | |
| | |
| | | * 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; |
| | |
| | | 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); |
| | | } |