| | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.OutputStream; |
| | | import java.io.PrintStream; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Comparator; |
| | |
| | | } |
| | | |
| | | /** |
| | | * Displays the provided message on the provided stream followed by a help usage reference. |
| | | * |
| | | * @param printStream |
| | | * The stream to print error message and help reference message. |
| | | * @param message |
| | | * The error message to print. |
| | | */ |
| | | public void displayMessageAndUsageReference(final PrintStream printStream, final LocalizableMessage message) { |
| | | printWrappedText(printStream, message); |
| | | printStream.println(); |
| | | printWrappedText(printStream, getHelpUsageReference()); |
| | | } |
| | | |
| | | /** |
| | | * Retrieves a string describing how the user can get more help. |
| | | * |
| | | * @return A string describing how the user can get more help. |
| | | */ |
| | | public LocalizableMessage getHelpUsageReference() { |
| | | setUsageOrVersionDisplayed(true); |
| | | |
| | | LocalizableMessageBuilder buffer = new LocalizableMessageBuilder(); |
| | | buffer.append(INFO_GLOBAL_HELP_REFERENCE.get(getScriptNameOrJava())); |
| | | buffer.append(EOL); |
| | | return buffer.toMessage(); |
| | | } |
| | | |
| | | /** |
| | | * Get the password which has to be used for the command without prompting the user. If no password was specified, |
| | | * return null. |
| | | * |
| | |
| | | * |
| | | * @return The error stream that should be used with this application. |
| | | */ |
| | | private PrintStream getErrStream() { |
| | | protected PrintStream getErrStream() { |
| | | if (isInteractive()) { |
| | | return out; |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * Retrieves a string describing how the user can get more help. |
| | | * |
| | | * @return A string describing how the user can get more help. |
| | | */ |
| | | public LocalizableMessage getHelpUsageReference() { |
| | | setUsageOrVersionDisplayed(true); |
| | | |
| | | LocalizableMessageBuilder buffer = new LocalizableMessageBuilder(); |
| | | buffer.append(INFO_GLOBAL_HELP_REFERENCE.get(getScriptNameOrJava())); |
| | | buffer.append(EOL); |
| | | return buffer.toMessage(); |
| | | } |
| | | |
| | | /** |
| | | * Adds the provided subcommand to this argument parser. This is only intended for use by the |
| | | * <CODE>SubCommand</CODE> constructor and does not do any validation of its own to ensure that there are no |
| | | * conflicts with the subcommand or any of its arguments. |
| | |
| | | return verboseArgument.isPresent(); |
| | | } |
| | | |
| | | /** Displays the provided error message followed by a help usage reference. */ |
| | | private void displayErrorMessageAndUsageReference(LocalizableMessage message) { |
| | | errPrintln(message); |
| | | errPrintln(); |
| | | errPrintln(parser.getHelpUsageReference()); |
| | | } |
| | | |
| | | /** |
| | | * Registers the global arguments with the argument parser. |
| | | * |
| | |
| | | parser.parseArguments(args); |
| | | checkForConflictingArguments(); |
| | | } catch (ArgumentException ae) { |
| | | displayErrorMessageAndUsageReference(ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | parser.displayMessageAndUsageReference(getErrStream(), ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return ReturnCode.CONFLICTING_ARGS.get(); |
| | | } |
| | | |
| | |
| | | try { |
| | | factory = new LDAPManagementContextFactory(cfp); |
| | | } catch (ArgumentException e) { |
| | | displayErrorMessageAndUsageReference(ERR_ERROR_PARSING_ARGS.get(e.getMessage())); |
| | | parser.displayMessageAndUsageReference(getErrStream(), ERR_ERROR_PARSING_ARGS.get(e.getMessage())); |
| | | return ReturnCode.CONFLICTING_ARGS.get(); |
| | | } |
| | | |
| | |
| | | // Top-level interactive mode. |
| | | retCode = runInteractiveMode(); |
| | | } else { |
| | | displayErrorMessageAndUsageReference( |
| | | ERR_ERROR_PARSING_ARGS.get(ERR_DSCFG_ERROR_MISSING_SUBCOMMAND.get())); |
| | | parser.displayMessageAndUsageReference( |
| | | getErrStream(), ERR_ERROR_PARSING_ARGS.get(ERR_DSCFG_ERROR_MISSING_SUBCOMMAND.get())); |
| | | retCode = ReturnCode.ERROR_USER_DATA.get(); |
| | | } |
| | | } else { |
| | |
| | | try { |
| | | // Force retrieval of management context. |
| | | factory.getManagementContext(app); |
| | | } catch (ArgumentException | ClientException e) { |
| | | } catch (ArgumentException e) { |
| | | parser.displayMessageAndUsageReference(getErrStream(), e.getMessageObject()); |
| | | return ReturnCode.ERROR_USER_DATA.get(); |
| | | } catch (ClientException e) { |
| | | app.errPrintln(e.getMessageObject()); |
| | | return ReturnCode.ERROR_UNEXPECTED.get(); |
| | | } |
| | |
| | | connectionFactory = connectionFactoryProvider.getAuthenticatedConnectionFactory(); |
| | | runner.validate(deleteMode, deleteSizeThreshold, deleteAgeThreshold, noPurgeArgument); |
| | | } catch (final ArgumentException ae) { |
| | | errPrintln(ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | errPrintln(argParser.getUsageMessage()); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue(); |
| | | } |
| | | |
| | |
| | | .raw("Authentication information must be provided to use this tool")); |
| | | } |
| | | } catch (final ArgumentException ae) { |
| | | final LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage()); |
| | | errPrintln(message); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue(); |
| | | } |
| | | |
| | |
| | | |
| | | connectionFactory = connectionFactoryProvider.getAuthenticatedConnectionFactory(); |
| | | } catch (final ArgumentException ae) { |
| | | final LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage()); |
| | | errPrintln(message); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue(); |
| | | } |
| | | |
| | | try { |
| | | final int versionNumber = version.getIntValue(); |
| | | if (versionNumber != 2 && versionNumber != 3) { |
| | | errPrintln(ERR_DESCRIPTION_INVALID_VERSION.get(String.valueOf(versionNumber))); |
| | | argParser.displayMessageAndUsageReference( |
| | | getErrStream(), ERR_DESCRIPTION_INVALID_VERSION.get(String.valueOf(versionNumber))); |
| | | return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue(); |
| | | } |
| | | } catch (final ArgumentException ae) { |
| | | errPrintln(ERR_DESCRIPTION_INVALID_VERSION.get(String.valueOf(version.getValue()))); |
| | | argParser.displayMessageAndUsageReference( |
| | | getErrStream(), ERR_DESCRIPTION_INVALID_VERSION.get(String.valueOf(version.getValue()))); |
| | | return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue(); |
| | | } |
| | | |
| | |
| | | final ArrayList<String> attrAndDNStrings = argParser.getTrailingArguments(); |
| | | |
| | | if (attrAndDNStrings.isEmpty()) { |
| | | final LocalizableMessage message = ERR_LDAPCOMPARE_NO_ATTR.get(); |
| | | errPrintln(message); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ERR_LDAPCOMPARE_NO_ATTR.get()); |
| | | return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue(); |
| | | } |
| | | |
| | |
| | | |
| | | // If no DNs were provided, then exit with an error. |
| | | if (dnStrings.isEmpty() && !filename.isPresent()) { |
| | | errPrintln(ERR_LDAPCOMPARE_NO_DNS.get()); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ERR_LDAPCOMPARE_NO_DNS.get()); |
| | | return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue(); |
| | | } |
| | | |
| | | /* If trailing DNs were provided and the filename argument was also |
| | | provided, exit with an error.*/ |
| | | if (!dnStrings.isEmpty() && filename.isPresent()) { |
| | | errPrintln(ERR_LDAPCOMPARE_FILENAME_AND_DNS.get()); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ERR_LDAPCOMPARE_FILENAME_AND_DNS.get()); |
| | | return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue(); |
| | | } |
| | | |
| | | // parse the attribute string |
| | | final int idx = attributeString.indexOf(":"); |
| | | if (idx == -1) { |
| | | final LocalizableMessage message = |
| | | ERR_LDAPCOMPARE_INVALID_ATTR_STRING.get(attributeString); |
| | | errPrintln(message); |
| | | argParser.displayMessageAndUsageReference( |
| | | getErrStream(), ERR_LDAPCOMPARE_INVALID_ATTR_STRING.get(attributeString)); |
| | | return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue(); |
| | | } |
| | | final String attributeType = attributeString.substring(0, idx); |
| | |
| | | |
| | | connectionFactory = connectionFactoryProvider.getAuthenticatedConnectionFactory(); |
| | | } catch (final ArgumentException ae) { |
| | | final LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage()); |
| | | errPrintln(message); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue(); |
| | | } |
| | | |
| | |
| | | |
| | | connectionFactory = connectionFactoryProvider.getAuthenticatedConnectionFactory(); |
| | | } catch (final ArgumentException ae) { |
| | | final LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage()); |
| | | errPrintln(message); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue(); |
| | | } |
| | | |
| | |
| | | |
| | | connectionFactory = connectionFactoryProvider.getAuthenticatedConnectionFactory(); |
| | | } catch (final ArgumentException ae) { |
| | | final LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage()); |
| | | errPrintln(message); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue(); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | if (filters.isEmpty()) { |
| | | errPrintln(ERR_SEARCH_NO_FILTERS.get()); |
| | | errPrintln(argParser.getUsageMessage()); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ERR_SEARCH_NO_FILTERS.get()); |
| | | return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue(); |
| | | } |
| | | |
| | |
| | | return ResultCode.SUCCESS.intValue(); |
| | | } |
| | | } catch (final ArgumentException ae) { |
| | | final LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage()); |
| | | errPrintln(message); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue(); |
| | | } |
| | | |
| | |
| | | return ResultCode.SUCCESS.intValue(); |
| | | } |
| | | } catch (final ArgumentException ae) { |
| | | final LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage()); |
| | | errPrintln(message); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue(); |
| | | } |
| | | |
| | |
| | | return ResultCode.SUCCESS.intValue(); |
| | | } |
| | | } catch (final ArgumentException ae) { |
| | | final LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage()); |
| | | errPrintln(message); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue(); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | if (filters.isEmpty()) { |
| | | errPrintln(ERR_SEARCH_NO_FILTERS.get()); |
| | | errPrintln(argParser.getUsageMessage()); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ERR_SEARCH_NO_FILTERS.get()); |
| | | return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue(); |
| | | } |
| | | |
| | |
| | | try { |
| | | argParser.parseArguments(args); |
| | | } catch (ArgumentException ae) { |
| | | errPrintln(ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | errPrintln(argParser.getUsageMessage()); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return EXIT_CODE_FAILURE; |
| | | } |
| | | |
| | |
| | | connectionFactory = connectionFactoryProvider.getAuthenticatedConnectionFactory(); |
| | | runner.validate(); |
| | | } catch (final ArgumentException ae) { |
| | | final LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage()); |
| | | errPrintln(message); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue(); |
| | | } |
| | | |
| | |
| | | connectionFactory = connectionFactoryProvider.getAuthenticatedConnectionFactory(); |
| | | runner.validate(); |
| | | } catch (final ArgumentException ae) { |
| | | final LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage()); |
| | | errPrintln(message); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue(); |
| | | } |
| | | |
| | |
| | | import static org.fest.assertions.Assertions.*; |
| | | import static org.forgerock.util.Utils.*; |
| | | |
| | | import static com.forgerock.opendj.cli.CliMessages.*; |
| | | import static com.forgerock.opendj.ldap.tools.ToolsMessages.*; |
| | | |
| | | import java.io.PrintStream; |
| | |
| | | { args("-C", "off", "-s", "30000", TEMPLATE_NAME), ERR_ADDRATE_DELMODE_OFF_THRESHOLD_ON.get() }, |
| | | { args("-C", "fifo", "-a", "3", "-s", "20000", TEMPLATE_NAME), ERR_ADDRATE_THRESHOLD_SIZE_AND_AGE.get() }, |
| | | { args("-C", "random", "-a", "3", TEMPLATE_NAME), ERR_ADDRATE_DELMODE_RAND_THRESHOLD_AGE.get() }, |
| | | { args("-s", "999", TEMPLATE_NAME), ERR_ADDRATE_SIZE_THRESHOLD_LOWER_THAN_ITERATIONS.get() } |
| | | { args("-s", "999", TEMPLATE_NAME), ERR_ADDRATE_SIZE_THRESHOLD_LOWER_THAN_ITERATIONS.get() }, |
| | | { args("-42"), INFO_GLOBAL_HELP_REFERENCE.get("java " + AddRate.class.getCanonicalName()) } |
| | | }; |
| | | } |
| | | |
| | |
| | | */ |
| | | package com.forgerock.opendj.ldap.tools; |
| | | |
| | | import static com.forgerock.opendj.cli.CliMessages.*; |
| | | import static com.forgerock.opendj.ldap.tools.ToolsMessages.ERR_ERROR_PARSING_ARGS; |
| | | import static com.forgerock.opendj.ldap.tools.ToolsMessages.INFO_TOOL_WARMING_UP; |
| | | import static org.fest.assertions.Assertions.assertThat; |
| | |
| | | public Object[][] authRateArgs() throws Exception { |
| | | return new Object[][] { |
| | | { args(""), "", ERR_ERROR_PARSING_ARGS.get("") }, |
| | | { args("-42"), "", INFO_GLOBAL_HELP_REFERENCE.get("java " + AuthRate.class.getCanonicalName()) }, |
| | | // Warm-up test case |
| | | { |
| | | args("-h", TestCaseUtils.getServerSocketAddress().getHostName(), |
| | |
| | | */ |
| | | package com.forgerock.opendj.ldap.tools; |
| | | |
| | | import static com.forgerock.opendj.cli.CliMessages.*; |
| | | import static com.forgerock.opendj.ldap.tools.ToolsMessages.INFO_COMPARE_OPERATION_RESULT_FALSE; |
| | | import static com.forgerock.opendj.ldap.tools.ToolsMessages.INFO_COMPARE_OPERATION_RESULT_TRUE; |
| | | import static com.forgerock.opendj.ldap.tools.ToolsMessages.INFO_LDAPCOMPARE_TOOL_DESCRIPTION; |
| | |
| | | public class LDAPCompareITCase extends ToolsITCase { |
| | | |
| | | private static final int NB_RAND_SIMPLE_COMPARE = 10; |
| | | private static final int NB_OTHER_SIMPLE_SEARCH = 1; |
| | | private static final int NB_OTHER_SIMPLE_SEARCH = 2; |
| | | |
| | | @DataProvider |
| | | public Object[][] ldapCompareArgs() throws Exception { |
| | |
| | | // Check if the help message is correctly prompted |
| | | data[0] = new Object[] { args("--help"), INFO_LDAPCOMPARE_TOOL_DESCRIPTION.get(), "" }; |
| | | |
| | | // Check if the help reference message is prompted if arguments failed to be parsed |
| | | data[1] = new Object[] { |
| | | args("-42"), "", INFO_GLOBAL_HELP_REFERENCE.get("java " + LDAPCompare.class.getCanonicalName()) }; |
| | | |
| | | // Perform some basic comparison on random user from the test server |
| | | for (int i = 0; i < NB_RAND_SIMPLE_COMPARE; i++) { |
| | | randUIDs[i] = Math.round(rand.nextInt(1000)); |
| | |
| | | */ |
| | | package com.forgerock.opendj.ldap.tools; |
| | | |
| | | import static com.forgerock.opendj.cli.CliMessages.*; |
| | | import static com.forgerock.opendj.ldap.tools.ToolsMessages.ERR_ERROR_PARSING_ARGS; |
| | | import static com.forgerock.opendj.ldap.tools.ToolsMessages.ERR_TOOL_RESULT_CODE; |
| | | import static com.forgerock.opendj.ldap.tools.ToolsMessages.INFO_LDAPSEARCH_MATCHING_ENTRY_COUNT; |
| | |
| | | @SuppressWarnings("javadoc") |
| | | public class LDAPSearchITCase extends ToolsITCase { |
| | | private static final int NB_RAND_SIMPLE_SEARCH = 10; |
| | | private static final int NB_OTHER_SIMPLE_SEARCH = 2; |
| | | private static final int NB_OTHER_SIMPLE_SEARCH = 3; |
| | | |
| | | @DataProvider |
| | | public Object[][] ldapSearchArgs() throws Exception { |
| | |
| | | // ldapsearch command |
| | | data[1] = new Object[] { args(""), "", ERR_ERROR_PARSING_ARGS.get("") }; |
| | | |
| | | // Check if the help reference message is prompted if arguments failed to be parsed |
| | | data[2] = new Object[] { |
| | | args("-42"), "", INFO_GLOBAL_HELP_REFERENCE.get("java " + LDAPSearch.class.getCanonicalName()) }; |
| | | |
| | | // Perform some basic ldapsearch for random user in the test server |
| | | for (int i = 0; i < NB_RAND_SIMPLE_SEARCH; i++) { |
| | | long userID = new Random().nextInt(1000); |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2013-2014 ForgeRock AS. |
| | | * Copyright 2013-2015 ForgeRock AS. |
| | | */ |
| | | package com.forgerock.opendj.ldap.tools; |
| | | |
| | |
| | | import static org.forgerock.util.Utils.*; |
| | | |
| | | import static com.forgerock.opendj.ldap.tools.ToolsMessages.*; |
| | | import static com.forgerock.opendj.cli.CliMessages.INFO_GLOBAL_HELP_REFERENCE; |
| | | |
| | | import java.io.PrintStream; |
| | | |
| | |
| | | return new Object[][] { |
| | | { // check that usage is written to output when arguments are invalid |
| | | args(), |
| | | expectedOutput(INFO_MAKELDIF_TOOL_DESCRIPTION.get()) }, |
| | | expectedOutput(INFO_GLOBAL_HELP_REFERENCE.get("java " + MakeLDIF.class.getCanonicalName())) }, |
| | | |
| | | { // check that there is an argument error when no arg provided |
| | | args(), |
| | | expectedOutput(ERR_ERROR_PARSING_ARGS.get("")) }, |
| | | { // Check if the help reference message is prompted if arguments failed to be parsed |
| | | args("-42"), |
| | | expectedOutput(INFO_GLOBAL_HELP_REFERENCE.get("java " + MakeLDIF.class.getCanonicalName())) }, |
| | | |
| | | { args("-r", "unknown/path" , "example.template"), |
| | | expectedOutput(ERR_LDIF_GEN_TOOL_NO_SUCH_RESOURCE_DIRECTORY.get("unknown/path")) }, |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage()); |
| | | System.err.println(message); |
| | | System.out.println(LocalizableMessage.raw(argParser.getUsage())); |
| | | |
| | | argParser.displayMessageAndUsageReference(System.err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | System.exit(ErrorReturnCode.ERROR_PARSING_ARGS.getReturnCode()); |
| | | } |
| | | |
| | |
| | | */ |
| | | package org.opends.guitools.uninstaller; |
| | | |
| | | import static org.forgerock.util.Utils.*; |
| | | import static org.opends.admin.ads.util.ConnectionUtils.*; |
| | | import static org.opends.messages.AdminToolMessages.*; |
| | | import static org.opends.messages.QuickSetupMessages.*; |
| | | |
| | | import static com.forgerock.opendj.cli.ArgumentConstants.*; |
| | | import static com.forgerock.opendj.cli.Utils.*; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.File; |
| | | import java.io.FileReader; |
| | |
| | | import com.forgerock.opendj.cli.MenuResult; |
| | | import com.forgerock.opendj.cli.ReturnCode; |
| | | |
| | | import static com.forgerock.opendj.cli.ArgumentConstants.*; |
| | | import static com.forgerock.opendj.cli.Utils.*; |
| | | |
| | | import static org.forgerock.util.Utils.*; |
| | | import static org.opends.admin.ads.util.ConnectionUtils.*; |
| | | import static org.opends.messages.AdminToolMessages.*; |
| | | import static org.opends.messages.QuickSetupMessages.*; |
| | | |
| | | /** |
| | | * The class used to provide some CLI interface in the uninstall. |
| | | * |
| | |
| | | userData.setLocalServerUrl(adminConnectorUrl); |
| | | couldConnect = true; |
| | | } |
| | | catch (ArgumentException | ClientException e) { |
| | | catch (ArgumentException e) |
| | | { |
| | | parser.displayMessageAndUsageReference(getErrStream(), e.getMessageObject()); |
| | | } |
| | | catch (ClientException e) { |
| | | printErrorMessage(e.getMessageObject()); |
| | | println(); |
| | | } |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage()); |
| | | System.err.println(message); |
| | | System.err.println(); |
| | | System.err.println(argParser.getUsage()); |
| | | |
| | | argParser.displayMessageAndUsageReference(System.err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | System.exit(ReturnCode.USER_DATA_ERROR.getReturnCode()); |
| | | } |
| | | } |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage()); |
| | | System.err.println(message); |
| | | System.err.println(); |
| | | System.err.println(argParser.getUsage()); |
| | | |
| | | argParser.displayMessageAndUsageReference(System.err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | System.exit(ReturnCode.USER_DATA_ERROR.getReturnCode()); |
| | | } |
| | | catch (IncompatibleVersionException ive) |
| | |
| | | try { |
| | | parser.parseArguments(args); |
| | | } catch (ArgumentException ae) { |
| | | printWrappedText(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | err.println(parser.getUsage()); |
| | | parser.displayMessageAndUsageReference(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | // Make sure that we have a sub-command. |
| | | if (parser.getSubCommand() == null) |
| | | { |
| | | printWrappedText(err, ERR_DBTEST_MISSING_SUBCOMMAND.get()); |
| | | err.println(parser.getUsage()); |
| | | parser.displayMessageAndUsageReference(err, ERR_DBTEST_MISSING_SUBCOMMAND.get()); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | LocalizableMessage message = ERR_DSCORE_ERROR_PARSING_ARGS.get(ae.getMessage()); |
| | | System.err.println(message); |
| | | System.err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(System.err, ERR_DSCORE_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | System.exit(1); |
| | | } |
| | | |
| | |
| | | return; |
| | | } |
| | | else if (noDetach.isPresent() && timeout.isPresent()) { |
| | | LocalizableMessage message = ERR_DSCORE_ERROR_NODETACH_TIMEOUT.get(); |
| | | System.err.println(message); |
| | | System.err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(System.err, ERR_DSCORE_ERROR_NODETACH_TIMEOUT.get()); |
| | | System.exit(1); |
| | | } |
| | | |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | LocalizableMessage message = |
| | | ERR_PROFILEVIEWER_ERROR_PARSING_ARGS.get(ae.getMessage()); |
| | | |
| | | System.err.println(message); |
| | | System.err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(System.err, ERR_PROFILEVIEWER_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | System.exit(1); |
| | | } |
| | | |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | printWrappedText(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return 1; |
| | | } |
| | | catch (ClientException ce) |
| | |
| | | { |
| | | if (backendID.isPresent()) |
| | | { |
| | | printWrappedText(err, ERR_BACKUPDB_CANNOT_MIX_BACKUP_ALL_AND_BACKEND_ID.get( |
| | | backUpAll.getLongIdentifier(), backendID.getLongIdentifier())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_BACKUPDB_CANNOT_MIX_BACKUP_ALL_AND_BACKEND_ID.get( |
| | | backUpAll.getLongIdentifier(), backendID.getLongIdentifier())); |
| | | return 1; |
| | | } |
| | | } |
| | | else if (! backendID.isPresent()) |
| | | { |
| | | printWrappedText(err, ERR_BACKUPDB_NEED_BACKUP_ALL_OR_BACKEND_ID.get( |
| | | backUpAll.getLongIdentifier(), backendID.getLongIdentifier())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_BACKUPDB_NEED_BACKUP_ALL_OR_BACKEND_ID.get( |
| | | backUpAll.getLongIdentifier(), backendID.getLongIdentifier())); |
| | | return 1; |
| | | } |
| | | else |
| | |
| | | } |
| | | if (!repeatedBackendIds.isEmpty()) |
| | | { |
| | | printWrappedText(err, ERR_BACKUPDB_REPEATED_BACKEND_ID.get(Utils.joinAsString(", ", repeatedBackendIds))); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, |
| | | ERR_BACKUPDB_REPEATED_BACKEND_ID.get(Utils.joinAsString(", ", repeatedBackendIds))); |
| | | return 1; |
| | | } |
| | | } |
| | |
| | | // incremental backup. |
| | | if (incrementalBaseID.isPresent() && ! incremental.isPresent()) |
| | | { |
| | | printWrappedText(err, ERR_BACKUPDB_INCREMENTAL_BASE_REQUIRES_INCREMENTAL.get( |
| | | argParser.displayMessageAndUsageReference(err, ERR_BACKUPDB_INCREMENTAL_BASE_REQUIRES_INCREMENTAL.get( |
| | | incrementalBaseID.getLongIdentifier(), incremental.getLongIdentifier())); |
| | | err.println(argParser.getUsage()); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | // are present, infer an offline backup. |
| | | if ((encrypt.isPresent() || signHash.isPresent()) |
| | | && ! argParser.connectionArgumentsPresent()) { |
| | | printWrappedText(err, ERR_BACKUPDB_ENCRYPT_OR_SIGN_REQUIRES_ONLINE.get( |
| | | encrypt.getLongIdentifier(), signHash.getLongIdentifier())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_BACKUPDB_ENCRYPT_OR_SIGN_REQUIRES_ONLINE.get( |
| | | encrypt.getLongIdentifier(), signHash.getLongIdentifier())); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | // was given. |
| | | if (signHash.isPresent() && !hash.isPresent()) |
| | | { |
| | | printWrappedText( |
| | | err, ERR_BACKUPDB_SIGN_REQUIRES_HASH.get(signHash.getLongIdentifier(), hash.getLongIdentifier())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, |
| | | ERR_BACKUPDB_SIGN_REQUIRES_HASH.get(signHash.getLongIdentifier(), hash.getLongIdentifier())); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | { |
| | | if (e.isWrongUsage()) |
| | | { |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, e.getErrorMessage()); |
| | | } |
| | | printWrappedText(err, e.getErrorMessage()); |
| | | else |
| | | { |
| | | printWrappedText(err, e.getErrorMessage()); |
| | | } |
| | | return e.getErrorCode(); |
| | | } |
| | | finally |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | printWrappedText(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return ERROR; |
| | | } |
| | | |
| | |
| | | } |
| | | if (nArgs != 1) |
| | | { |
| | | LocalizableMessage message = nArgs == 0 ? ERR_CONFIGURE_WINDOWS_SERVICE_TOO_FEW_ARGS.get() |
| | | : ERR_CONFIGURE_WINDOWS_SERVICE_TOO_MANY_ARGS.get(); |
| | | printWrappedText(err, message); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, nArgs == 0 ? ERR_CONFIGURE_WINDOWS_SERVICE_TOO_FEW_ARGS.get() |
| | | : ERR_CONFIGURE_WINDOWS_SERVICE_TOO_MANY_ARGS.get()); |
| | | return ERROR; |
| | | } |
| | | } |
| | |
| | | PrintStream err = NullOutputStream.wrapOrNullStream(errStream); |
| | | JDKLogging.disableLogging(); |
| | | |
| | | EmbeddedUtils.initializeForClientUse(); |
| | | |
| | | if (! OperatingSystem.isUnixBased()) |
| | | { |
| | | printWrappedText(err, ERR_CREATERC_ONLY_RUNS_ON_UNIX.get()); |
| | | return 1; |
| | | } |
| | | |
| | | File serverRoot = DirectoryServer.getEnvironmentConfig().getServerRoot(); |
| | | if (serverRoot == null) |
| | | { |
| | | printWrappedText( |
| | | err, ERR_CREATERC_UNABLE_TO_DETERMINE_SERVER_ROOT.get(PROPERTY_SERVER_ROOT, ENV_VAR_INSTALL_ROOT)); |
| | | return 1; |
| | | } |
| | | |
| | | |
| | | LocalizableMessage description = INFO_CREATERC_TOOL_DESCRIPTION.get(); |
| | | ArgumentParser argParser = |
| | | new ArgumentParser(CreateRCScript.class.getName(), description, false); |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | printWrappedText(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | return 0; |
| | | } |
| | | |
| | | EmbeddedUtils.initializeForClientUse(); |
| | | File serverRoot = DirectoryServer.getEnvironmentConfig().getServerRoot(); |
| | | if (serverRoot == null) |
| | | { |
| | | printWrappedText( |
| | | err, ERR_CREATERC_UNABLE_TO_DETERMINE_SERVER_ROOT.get(PROPERTY_SERVER_ROOT, ENV_VAR_INSTALL_ROOT)); |
| | | return 1; |
| | | } |
| | | |
| | | // Determine the path to the Java installation that should be used. |
| | | String javaHomeDir; |
| | | if (javaHome.isPresent()) |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | printWrappedText(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return OPERATIONS_ERROR; |
| | | } |
| | | |
| | |
| | | && !encodedPasswordFile.isPresent() |
| | | && !schemeName.isPresent()) |
| | | { |
| | | printWrappedText(err, ERR_ENCPW_NO_SCHEME.get(schemeName.getLongIdentifier())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_ENCPW_NO_SCHEME.get(schemeName.getLongIdentifier())); |
| | | return OPERATIONS_ERROR; |
| | | } |
| | | |
| | |
| | | } |
| | | else |
| | | { |
| | | printWrappedText(err, ERR_ENCPW_NO_CLEAR_PW.get(clearPassword.getLongIdentifier(), |
| | | clearPasswordFile.getLongIdentifier(), interactivePassword.getLongIdentifier())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_ENCPW_NO_CLEAR_PW.get(clearPassword.getLongIdentifier(), |
| | | clearPasswordFile.getLongIdentifier(), interactivePassword.getLongIdentifier())); |
| | | return null; |
| | | } |
| | | } |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | printWrappedText(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return 1; |
| | | } |
| | | catch (ClientException ce) |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | printWrappedText(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return 1; |
| | | } |
| | | catch (ClientException ce) |
| | |
| | | } |
| | | else if (! templateFile.isPresent()) |
| | | { |
| | | printWrappedText(err, ERR_LDIFIMPORT_MISSING_REQUIRED_ARGUMENT.get( |
| | | argParser.displayMessageAndUsageReference(err, ERR_LDIFIMPORT_MISSING_REQUIRED_ARGUMENT.get( |
| | | ldifFiles.getLongIdentifier(), templateFile.getLongIdentifier())); |
| | | err.println(argParser.getUsage()); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | // "backendID" argument was provided. |
| | | if(!includeBranchStrings.isPresent() && !backendID.isPresent()) |
| | | { |
| | | printWrappedText(err, ERR_LDIFIMPORT_MISSING_BACKEND_ARGUMENT.get( |
| | | argParser.displayMessageAndUsageReference(err, ERR_LDIFIMPORT_MISSING_BACKEND_ARGUMENT.get( |
| | | includeBranchStrings.getLongIdentifier(), backendID.getLongIdentifier())); |
| | | err.println(argParser.getUsage()); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | // the task framework. |
| | | if (countRejects.isPresent() && argParser.connectionArgumentsPresent()) |
| | | { |
| | | printWrappedText(err, ERR_LDIFIMPORT_COUNT_REJECTS_REQUIRES_OFFLINE.get(countRejects.getLongIdentifier())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_LDIFIMPORT_COUNT_REJECTS_REQUIRES_OFFLINE.get( |
| | | countRejects.getLongIdentifier())); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | catch (final ArgumentException ae) |
| | | { |
| | | println(ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | println(); |
| | | println(LocalizableMessage.raw(argParser.getUsage())); |
| | | |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return InstallReturnCode.ERROR_USER_DATA.getReturnCode(); |
| | | } |
| | | |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage()); |
| | | println(message); |
| | | println(); |
| | | println(LocalizableMessage.raw(argParser.getUsage())); |
| | | |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return ErrorReturnCode.ERROR_USER_DATA.getReturnCode(); |
| | | } |
| | | |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | printWrappedText(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | |
| | |
| | | portNumber = port.getIntValue(); |
| | | } catch (ArgumentException ae) |
| | | { |
| | | printWrappedText(err, ae.getMessage()); |
| | | argParser.displayMessageAndUsageReference(err, ae.getMessageObject()); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | |
| | |
| | | connectionOptions.setVersionNumber(versionNumber); |
| | | } catch(ArgumentException ae) |
| | | { |
| | | printWrappedText(err, ae.getMessage()); |
| | | argParser.displayMessageAndUsageReference(err, ae.getMessageObject()); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | |
| | |
| | | if(ctrl == null) |
| | | { |
| | | printWrappedText(err, ERR_TOOL_INVALID_CONTROL_STRING.get(ctrlString)); |
| | | err.println(argParser.getUsage()); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | compareOptions.getControls().add(ctrl); |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | printWrappedText(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | |
| | |
| | | } catch(ArgumentException ae) |
| | | { |
| | | logger.traceException(ae); |
| | | printWrappedText(err, ae.getMessage()); |
| | | argParser.displayMessageAndUsageReference(err, ae.getMessageObject()); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | |
| | |
| | | } catch(ArgumentException ae) |
| | | { |
| | | logger.traceException(ae); |
| | | printWrappedText(err, ae.getMessage()); |
| | | argParser.displayMessageAndUsageReference(err, ae.getMessageObject()); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | |
| | |
| | | if(ctrl == null) |
| | | { |
| | | printWrappedText(err, ERR_TOOL_INVALID_CONTROL_STRING.get(ctrlString)); |
| | | err.println(argParser.getUsage()); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | deleteOptions.getControls().add(ctrl); |
| | |
| | | lce.getErrorMessage(), |
| | | lce.getMatchedDN()); |
| | | return lce.getResultCode(); |
| | | } catch(Exception e) |
| | | } |
| | | catch(ArgumentException e) |
| | | { |
| | | argParser.displayMessageAndUsageReference(err, e.getMessageObject()); |
| | | return 1; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | logger.traceException(e); |
| | | printWrappedText(err, e.getMessage()); |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | printWrappedText(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | |
| | |
| | | } catch(ArgumentException ae) |
| | | { |
| | | logger.traceException(ae); |
| | | printWrappedText(err, ae.getMessage()); |
| | | argParser.displayMessageAndUsageReference(err, ae.getMessageObject()); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | |
| | |
| | | } catch(ArgumentException ae) |
| | | { |
| | | logger.traceException(ae); |
| | | printWrappedText(err, ae.getMessage()); |
| | | argParser.displayMessageAndUsageReference(err, ae.getMessageObject()); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | |
| | |
| | | if(ctrl == null) |
| | | { |
| | | printWrappedText(err, ERR_TOOL_INVALID_CONTROL_STRING.get(ctrlString)); |
| | | err.println(argParser.getUsage()); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | modifyOptions.getControls().add(ctrl); |
| | |
| | | logger.traceException(fe); |
| | | printWrappedText(err, fe.getMessage()); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } catch(Exception e) |
| | | } |
| | | catch(ArgumentException e) |
| | | { |
| | | argParser.displayMessageAndUsageReference(err, e.getMessageObject()); |
| | | return 1; |
| | | } |
| | | catch(Exception e) |
| | | { |
| | | logger.traceException(e); |
| | | printWrappedText(err, e.getMessage()); |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | printWrappedText(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | |
| | |
| | | { |
| | | if (!bindPW.isPresent() && !bindPWFile.isPresent()) |
| | | { |
| | | printWrappedText(err, ERR_LDAPPWMOD_BIND_DN_AND_PW_MUST_BE_TOGETHER.get()); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_LDAPPWMOD_BIND_DN_AND_PW_MUST_BE_TOGETHER.get()); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | } |
| | | else if (bindPW.isPresent() || bindPWFile.isPresent()) |
| | | { |
| | | printWrappedText(err, ERR_LDAPPWMOD_BIND_DN_AND_PW_MUST_BE_TOGETHER.get()); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_LDAPPWMOD_BIND_DN_AND_PW_MUST_BE_TOGETHER.get()); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | else |
| | | { |
| | | if (provideDNForAuthzID.isPresent()) |
| | | { |
| | | printWrappedText( |
| | | err, ERR_LDAPPWMOD_DEPENDENT_ARGS.get(provideDNForAuthzID.getLongIdentifier(), bindDN.getLongIdentifier())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, |
| | | ERR_LDAPPWMOD_DEPENDENT_ARGS.get(provideDNForAuthzID.getLongIdentifier(), bindDN.getLongIdentifier())); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | |
| | | if (!authzID.isPresent() || (!currentPW.isPresent() && !currentPWFile.isPresent())) |
| | | { |
| | | printWrappedText(err, ERR_LDAPPWMOD_ANON_REQUIRES_AUTHZID_AND_CURRENTPW.get()); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_LDAPPWMOD_ANON_REQUIRES_AUTHZID_AND_CURRENTPW.get()); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | } |
| | |
| | | if(ctrl == null) |
| | | { |
| | | printWrappedText(err, ERR_TOOL_INVALID_CONTROL_STRING.get(ctrlString)); |
| | | err.println(argParser.getUsage()); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | controls.add(ctrl); |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | printWrappedText(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | |
| | |
| | | } catch(ArgumentException ae) |
| | | { |
| | | logger.traceException(ae); |
| | | printWrappedText(err, ae.getMessage()); |
| | | argParser.displayMessageAndUsageReference(err, ae.getMessageObject()); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | |
| | |
| | | } catch(ArgumentException ae) |
| | | { |
| | | logger.traceException(ae); |
| | | printWrappedText(err, ae.getMessage()); |
| | | argParser.displayMessageAndUsageReference(err, ae.getMessageObject()); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | |
| | |
| | | searchOptions.setSizeLimit(sizeLimit.getIntValue()); |
| | | } catch(ArgumentException ex1) |
| | | { |
| | | printWrappedText(err, ex1.getMessage()); |
| | | argParser.displayMessageAndUsageReference(err, ex1.getMessageObject()); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | if (!searchOptions.setSearchScope(searchScope.getValue(), err) |
| | |
| | | if(ctrl == null) |
| | | { |
| | | printWrappedText(err, ERR_TOOL_INVALID_CONTROL_STRING.get(ctrlString)); |
| | | err.println(argParser.getUsage()); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | searchOptions.getControls().add(ctrl); |
| | |
| | | String authzID=effectiveRightsUser.getValue(); |
| | | if (!authzID.startsWith("dn:")) { |
| | | printWrappedText(err, ERR_EFFECTIVERIGHTS_INVALID_AUTHZID.get(authzID)); |
| | | err.println(argParser.getUsage()); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | Control effectiveRightsControl = |
| | |
| | | |
| | | if(filters.isEmpty()) |
| | | { |
| | | printWrappedText(err, ERR_SEARCH_NO_FILTERS.get()); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_SEARCH_NO_FILTERS.get()); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | printWrappedText(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | printWrappedText(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | printWrappedText(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | |
| | |
| | | ArrayList<String> trailingArguments = argParser.getTrailingArguments(); |
| | | if (trailingArguments == null || trailingArguments.isEmpty()) |
| | | { |
| | | printWrappedText(err, ERR_LDIFSEARCH_NO_FILTER.get()); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_LDIFSEARCH_NO_FILTER.get()); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | printWrappedText(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | printWrappedText(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | printWrappedText(err, ERR_PWPSTATE_CANNOT_DETERMINE_PORT.get(port.getLongIdentifier(), ae.getMessage())); |
| | | argParser.displayMessageAndUsageReference( |
| | | err, ERR_PWPSTATE_CANNOT_DETERMINE_PORT.get(port.getLongIdentifier(), ae.getMessage())); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | catch (LDAPConnectionException lce) |
| | |
| | | StaticUtils.checkOnlyOneArgPresent(task, summary, cancel); |
| | | } |
| | | catch (ArgumentException ae) { |
| | | LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage()); |
| | | println(message); |
| | | println(argParser.getUsageMessage()); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | printWrappedText(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | return 0; |
| | | } |
| | | |
| | | // If no arguments were provided, then display usage information and exit. |
| | | final int numArgs = args.length; |
| | | if (numArgs == 0) |
| | | { |
| | | out.println(argParser.getUsage()); |
| | | return 1; |
| | | } |
| | | |
| | | if (indexList.getValues().isEmpty() |
| | | && !rebuildAll.isPresent() |
| | | && !rebuildDegraded.isPresent()) |
| | | { |
| | | printWrappedText(err, ERR_REBUILDINDEX_REQUIRES_AT_LEAST_ONE_INDEX.get()); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_REBUILDINDEX_REQUIRES_AT_LEAST_ONE_INDEX.get()); |
| | | return 1; |
| | | } |
| | | |
| | | if (rebuildAll.isPresent() && indexList.isPresent()) |
| | | { |
| | | printWrappedText(err, ERR_REBUILDINDEX_REBUILD_ALL_ERROR.get()); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_REBUILDINDEX_REBUILD_ALL_ERROR.get()); |
| | | return 1; |
| | | } |
| | | |
| | | if (rebuildDegraded.isPresent() && indexList.isPresent()) |
| | | { |
| | | printWrappedText(err, ERR_REBUILDINDEX_REBUILD_DEGRADED_ERROR.get("index")); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_REBUILDINDEX_REBUILD_DEGRADED_ERROR.get("index")); |
| | | return 1; |
| | | } |
| | | |
| | | if (rebuildDegraded.isPresent() && clearDegradedState.isPresent()) |
| | | { |
| | | printWrappedText(err, ERR_REBUILDINDEX_REBUILD_DEGRADED_ERROR.get("clearDegradedState")); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_REBUILDINDEX_REBUILD_DEGRADED_ERROR.get("clearDegradedState")); |
| | | return 1; |
| | | } |
| | | |
| | | if (rebuildAll.isPresent() && rebuildDegraded.isPresent()) |
| | | { |
| | | printWrappedText(err, ERR_REBUILDINDEX_REBUILD_ALL_DEGRADED_ERROR.get("rebuildDegraded")); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, |
| | | ERR_REBUILDINDEX_REBUILD_ALL_DEGRADED_ERROR.get("rebuildDegraded")); |
| | | return 1; |
| | | } |
| | | |
| | | if (rebuildAll.isPresent() && clearDegradedState.isPresent()) |
| | | { |
| | | printWrappedText(err, ERR_REBUILDINDEX_REBUILD_ALL_DEGRADED_ERROR.get("clearDegradedState")); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, |
| | | ERR_REBUILDINDEX_REBUILD_ALL_DEGRADED_ERROR.get("clearDegradedState")); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | printWrappedText(out, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | argParser.displayMessageAndUsageReference(out, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | printWrappedText(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return 1; |
| | | } |
| | | catch (ClientException ce) |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | printWrappedText(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | printWrappedText(err, ERR_STOPDS_CANNOT_DETERMINE_PORT.get(port.getLongIdentifier(), ae.getMessage())); |
| | | argParser.displayMessageAndUsageReference( |
| | | err, ERR_STOPDS_CANNOT_DETERMINE_PORT.get(port.getLongIdentifier(), ae.getMessage())); |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | catch (LDAPConnectionException lce) |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | printWrappedText(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | return 0; |
| | | } |
| | | |
| | | // If no arguments were provided, then display usage information and exit. |
| | | int numArgs = args.length; |
| | | if (numArgs == 0) |
| | | { |
| | | out.println(argParser.getUsage()); |
| | | return 1; |
| | | } |
| | | |
| | | if (cleanMode.isPresent() && indexList.getValues().size() != 1) |
| | | { |
| | | printWrappedText(err, ERR_VERIFYINDEX_VERIFY_CLEAN_REQUIRES_SINGLE_INDEX.get()); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_VERIFYINDEX_VERIFY_CLEAN_REQUIRES_SINGLE_INDEX.get()); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage()); |
| | | |
| | | println(message); |
| | | println(LocalizableMessage.raw(argParser.getUsage())); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return EXIT_CODE_INTERNAL_ERROR; |
| | | } |
| | | |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | errPrintln(ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | errPrintln(); |
| | | errPrintln(LocalizableMessage.raw(argParser.getUsage())); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | logger.error(LocalizableMessage.raw("Complete error stack:"), ae); |
| | | return ERROR_USER_DATA; |
| | | } |
| | |
| | | catch (ArgumentException ae) |
| | | { |
| | | logger.warn(LocalizableMessage.raw("Argument exception " + ae)); |
| | | errPrintln(); |
| | | errPrintln(ae.getMessageObject()); |
| | | errPrintln(); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ae.getMessageObject()); |
| | | return null; |
| | | } |
| | | firstTry = false; |
| | |
| | | catch (ArgumentException ae) |
| | | { |
| | | logger.warn(LocalizableMessage.raw("Argument exception "+ae)); |
| | | errPrintln(); |
| | | errPrintln(ae.getMessageObject()); |
| | | errPrintln(); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ae.getMessageObject()); |
| | | cancelled = true; |
| | | } |
| | | } |
| | |
| | | catch (ArgumentException ae) |
| | | { |
| | | logger.warn(LocalizableMessage.raw("Argument exception "+ae)); |
| | | errPrintln(); |
| | | errPrintln(ae.getMessageObject()); |
| | | errPrintln(); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ae.getMessageObject()); |
| | | cancelled = true; |
| | | } |
| | | finally |
| | |
| | | catch (ArgumentException ae) |
| | | { |
| | | logger.warn(LocalizableMessage.raw("Argument exception "+ae)); |
| | | errPrintln(); |
| | | errPrintln(ae.getMessageObject()); |
| | | errPrintln(); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ae.getMessageObject()); |
| | | cancelled = true; |
| | | } |
| | | } |
| | |
| | | catch (ArgumentException ae) |
| | | { |
| | | logger.warn(LocalizableMessage.raw("Argument exception " + ae)); |
| | | errPrintln(); |
| | | errPrintln(ae.getMessageObject()); |
| | | errPrintln(); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ae.getMessageObject()); |
| | | return null; |
| | | } |
| | | } |
| | |
| | | catch (ArgumentException ae) |
| | | { |
| | | logger.warn(LocalizableMessage.raw("Argument exception "+ae)); |
| | | errPrintln(); |
| | | errPrintln(ae.getMessageObject()); |
| | | errPrintln(); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ae.getMessageObject()); |
| | | cancelled = true; |
| | | } |
| | | } |
| | |
| | | catch (ArgumentException ae) |
| | | { |
| | | logger.warn(LocalizableMessage.raw("Argument exception "+ae)); |
| | | println(); |
| | | println(ae.getMessageObject()); |
| | | println(); |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ae.getMessageObject()); |
| | | cancelled = true; |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Provides the command-line arguments to the main application for |
| | | * processing and returns the exit code as an integer. |
| | | * |
| | | * @param args |
| | | * The set of command-line arguments provided to this |
| | | * program. |
| | | * @param outStream |
| | | * The output stream for standard output. |
| | | * @param errStream |
| | | * The output stream for standard error. |
| | | * @return Zero to indicate that the program completed successfully, |
| | | * or non-zero to indicate that an error occurred. |
| | | */ |
| | | public static int main(final String[] args, final OutputStream outStream, final OutputStream errStream) |
| | | { |
| | | return new MakeLDIF().makeLDIFMain(args, false, false, outStream, errStream); |
| | | } |
| | | |
| | | /** |
| | | * Creates a new instance of this utility. It should just be used for |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | printWrappedText(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | err.println(argParser.getUsage()); |
| | | argParser.displayMessageAndUsageReference(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | * This class basically is in charge of parsing the data provided by the |
| | | * user in the command line. |
| | | */ |
| | | class StatusCli extends ConsoleApplication |
| | | public class StatusCli extends ConsoleApplication |
| | | { |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | |
| | | try { |
| | | argParser.parseArguments(args); |
| | | } catch (ArgumentException ae) { |
| | | println(ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | println(); |
| | | println(LocalizableMessage.raw(argParser.getUsage())); |
| | | |
| | | argParser.displayMessageAndUsageReference(getErrStream(), ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return ReturnCode.CLIENT_SIDE_PARAM_ERROR.get(); |
| | | } |
| | | |
| | |
| | | secureArgsList.portArg.setPresent(true); |
| | | secureArgsList.hostNameArg.addValue(secureArgsList.hostNameArg.getDefaultValue()); |
| | | secureArgsList.portArg.addValue(Integer.toString(port)); |
| | | // We already know if SSL or StartTLS can be used. If we cannot |
| | | // use them we will not propose them in the connection parameters |
| | | // and if none of them can be used we will just not ask for the |
| | | // protocol to be used. |
| | | final LDAPConnectionConsoleInteraction ci = |
| | | new LDAPConnectionConsoleInteraction(this, argParser.getSecureArgsList()); |
| | | try |
| | | { |
| | | // We already know if SSL or StartTLS can be used. If we cannot |
| | | // use them we will not propose them in the connection parameters |
| | | // and if none of them can be used we will just not ask for the |
| | | // protocol to be used. |
| | | final LDAPConnectionConsoleInteraction ci = |
| | | new LDAPConnectionConsoleInteraction(this, argParser.getSecureArgsList()); |
| | | |
| | | ci.run(false); |
| | | } |
| | | catch (ArgumentException e) |
| | | { |
| | | argParser.displayMessageAndUsageReference(getErrStream(), e.getMessageObject()); |
| | | return ReturnCode.CLIENT_SIDE_PARAM_ERROR.get(); |
| | | } |
| | | try |
| | | { |
| | | if (argParser.isInteractive()) |
| | | { |
| | | bindDn = ci.getBindDN(); |
| | |
| | | controlInfo.setTrustManager(interactiveTrustManager); |
| | | useInteractiveTrustManager = true; |
| | | } |
| | | } catch (ArgumentException | ClientException e) { |
| | | } catch (ClientException e) { |
| | | println(e.getMessageObject()); |
| | | return ReturnCode.CLIENT_SIDE_PARAM_ERROR.get(); |
| | | } finally { |
| | |
| | | } catch (LDAPException le) { |
| | | printWrappedText(err, ERR_TASK_TOOL_LDAP_ERROR.get(le.getMessage())); |
| | | ret = 1; |
| | | } catch (ArgumentException | OpenDsException e) { |
| | | } catch (OpenDsException e) { |
| | | printWrappedText(err, e.getMessageObject()); |
| | | ret = 1; |
| | | } finally |
| | | } catch (ArgumentException e) { |
| | | argParser.displayMessageAndUsageReference(err, e.getMessageObject()); |
| | | ret = 1; |
| | | } |
| | | finally |
| | | { |
| | | if (conn != null) |
| | | { |
| | |
| | | return acceptLicense.isPresent(); |
| | | } |
| | | |
| | | /** Displays the provided message followed by a help usage reference. */ |
| | | private void displayMessageAndUsageReference(final LocalizableMessage message) |
| | | { |
| | | println(message); |
| | | println(); |
| | | println(parser.getHelpUsageReference()); |
| | | } |
| | | |
| | | /** Initialize arguments provided by the command line. */ |
| | | private void initializeGlobalArguments() throws ArgumentException |
| | | { |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | final LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage()); |
| | | displayMessageAndUsageReference(message); |
| | | parser.displayMessageAndUsageReference(getErrStream(), ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | return EXIT_CODE_ERROR; |
| | | } |
| | | |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | System.err.println(ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | argParser.displayMessageAndUsageReference(System.err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | System.exit(1); |
| | | } |
| | | |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | System.err.println(ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | argParser.displayMessageAndUsageReference(System.err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | System.exit(1); |
| | | } |
| | | |
| | |
| | | * stream to write error messages |
| | | * @return LDAPConnection created by this class from parsed arguments |
| | | * @throws LDAPConnectionException |
| | | * if there was a problem connecting to the server indicated by the |
| | | * input arguments |
| | | * if there was a problem connecting to the server |
| | | * @throws ArgumentException |
| | | * if there was a problem indicated by the input arguments |
| | | */ |
| | | public LDAPConnection connect(LDAPConnectionConsoleInteraction ui, PrintStream out, PrintStream err) |
| | | throws LDAPConnectionException |
| | | throws LDAPConnectionException, ArgumentException |
| | | { |
| | | try |
| | | { |
| | |
| | | return connect(ui.getHostName(), ui.getPortNumber(), ui.getBindDN(), |
| | | ui.getBindPassword(), ui.populateLDAPOptions(options), ui.getConnectTimeout(), out, err); |
| | | } |
| | | catch (ArgumentException | OpenDsException e) |
| | | catch (OpenDsException e) |
| | | { |
| | | if (e.getCause() != null && e.getCause().getCause() != null && e.getCause().getCause() instanceof SSLException) |
| | | { |
| | | err.println(ERR_TASKINFO_LDAP_EXCEPTION_SSL.get(ui.getHostName(), ui.getPortNumber())); |
| | | } |
| | | else |
| | | { |
| | | err.println(e.getMessageObject()); |
| | | } |
| | | err.println(isSSLException(e) ? |
| | | ERR_TASKINFO_LDAP_EXCEPTION_SSL.get(ui.getHostName(), ui.getPortNumber()) : e.getMessageObject()); |
| | | return null; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private boolean isSSLException(Exception e) |
| | | { |
| | | return e.getCause() != null |
| | | && e.getCause().getCause() != null |
| | | && e.getCause().getCause() instanceof SSLException; |
| | | } |
| | | |
| | | /** |
| New file |
| | |
| | | /* |
| | | * 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 2015 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.tools; |
| | | |
| | | import static org.assertj.core.api.Assertions.*; |
| | | import static org.forgerock.util.Utils.*; |
| | | |
| | | import static com.forgerock.opendj.cli.CliMessages.*; |
| | | |
| | | import java.io.PrintStream; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | | import org.opends.server.backends.jeb.DBTest; |
| | | import org.opends.server.tools.dsreplication.ReplicationCliMain; |
| | | import org.opends.server.tools.makeldif.MakeLDIF; |
| | | import org.opends.server.tools.status.StatusCli; |
| | | import org.testng.annotations.AfterMethod; |
| | | import org.testng.annotations.BeforeMethod; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | /** |
| | | * This class tests that help reference message is prompted for all tools when |
| | | * no arguments are provided or if they failed to be parsed. |
| | | */ |
| | | public class ArgumentParserToolsTestCase extends ToolsTestCase |
| | | { |
| | | private static final boolean ERRORS_ON_STDOUT = false; |
| | | |
| | | private ByteStringBuilder out; |
| | | private ByteStringBuilder err; |
| | | private PrintStream outStream; |
| | | private PrintStream errStream; |
| | | |
| | | @BeforeMethod |
| | | private void refreshStreams() |
| | | { |
| | | out = new ByteStringBuilder(); |
| | | err = new ByteStringBuilder(); |
| | | outStream = new PrintStream(out.asOutputStream()); |
| | | errStream = new PrintStream(err.asOutputStream()); |
| | | } |
| | | |
| | | @AfterMethod |
| | | private void validateAndCloseStreams() |
| | | { |
| | | closeSilently(outStream, errStream); |
| | | } |
| | | |
| | | private void assertToolFailsWithUsage(final int returnCode) |
| | | { |
| | | assertToolFailsWithUsage(returnCode, true); |
| | | } |
| | | |
| | | private void assertToolFailsWithUsage(final int returnCode, boolean errorsOnStdErr) |
| | | { |
| | | assertThat(returnCode).isNotEqualTo(0); |
| | | assertThat((errorsOnStdErr ? out : err).toString()).isEmpty(); |
| | | final String streamToCheck = (errorsOnStdErr ? err : out).toString() |
| | | .replace(System.getProperty("line.separator"), " "); |
| | | assertThat(streamToCheck).matches(".*" + INFO_GLOBAL_HELP_REFERENCE.get("(.*)") + ".*"); |
| | | assertThat(streamToCheck).contains(ERR_ERROR_PARSING_ARGS.get("")); |
| | | } |
| | | |
| | | @DataProvider |
| | | public Object[][] invalidArg() throws Exception |
| | | { |
| | | return new Object[][] { { new String[] { "-42" } } }; |
| | | } |
| | | |
| | | @DataProvider |
| | | public Object[][] invalidArgs() throws Exception |
| | | { |
| | | return new Object[][] { { new String[] { } }, { new String[] { "-42" } } }; |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArgs") |
| | | public void testBackup(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(BackUpDB.mainBackUpDB(args, false, outStream, errStream)); |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArgs") |
| | | public void testCreateRCScript(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(CreateRCScript.main(args, outStream, errStream)); |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArgs") |
| | | public void testDBTest(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(DBTest.main(args, false, outStream, errStream)); |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArgs") |
| | | public void testDSJavaProperties(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(JavaPropertiesTool.mainCLI(args, outStream, errStream, null)); |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArgs") |
| | | public void testDSReplication(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(ReplicationCliMain.mainCLI(args, false, outStream, errStream), ERRORS_ON_STDOUT); |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArgs") |
| | | public void testEncodePassword(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(EncodePassword.encodePassword(args, false, outStream, errStream)); |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArgs") |
| | | public void testExportLDIF(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(ExportLDIF.mainExportLDIF(args, false, outStream, errStream)); |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArgs") |
| | | public void testImportLDIF(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(ImportLDIF.mainImportLDIF(args, false, outStream, errStream)); |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArgs") |
| | | public void testLDAPCompare(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(LDAPCompare.mainCompare(args, false, outStream, errStream)); |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArg") |
| | | public void testLDAPDelete(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(LDAPDelete.mainDelete(args, false, outStream, errStream)); |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArg") |
| | | public void testLDAPModify(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(LDAPModify.mainModify(args, false, outStream, errStream)); |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArg") |
| | | public void testLDAPPasswordModify(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(LDAPPasswordModify.mainPasswordModify(args, false, outStream, errStream)); |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArgs") |
| | | public void testLDAPSearch(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(LDAPSearch.mainSearch(args, false, outStream, errStream)); |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArgs") |
| | | public void testLDIFDiff(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(LDIFDiff.mainDiff(args, false, outStream, errStream)); |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArgs") |
| | | public void testLDIFModify(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(LDIFModify.ldifModifyMain(args, false, outStream, errStream)); |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArg") |
| | | public void testLDIFSearch(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(LDIFSearch.mainSearch(args, false, outStream, errStream)); |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArgs") |
| | | public void testListBackends(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(ListBackends.listBackends(args, false, outStream, errStream)); |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArgs") |
| | | public void testMakeLDIF(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(MakeLDIF.main(args, outStream, errStream)); |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArgs") |
| | | public void testManageAccount(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(ManageAccount.main(args, false, outStream, errStream)); |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArg") |
| | | public void testManageTasks(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(ManageTasks.mainTaskInfo(args, null, outStream, errStream, false), ERRORS_ON_STDOUT); |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArgs") |
| | | public void testRebuildIndex(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(RebuildIndex.mainRebuildIndex(args, false, outStream, errStream)); |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArg") |
| | | public void testStopDS(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(StopDS.stopDS(args, outStream, errStream)); |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArg") |
| | | public void testStatus(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(StatusCli.mainCLI(args, false, outStream, errStream, null), ERRORS_ON_STDOUT); |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArgs") |
| | | public void testVerifyIndex(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(VerifyIndex.mainVerifyIndex(args, false, outStream, errStream)); |
| | | } |
| | | |
| | | } |