| | |
| | | { |
| | | defaultArgs.remove(argsToRemove[i]); |
| | | } |
| | | defaultArgs.remove(noPropertiesFileArg); |
| | | defaultArgs.remove(propertiesFileArg); |
| | | |
| | | int index = 0; |
| | | |
| | | baseDNsArg = new StringArgument("baseDNs", OPTION_SHORT_BASEDN, |
| | |
| | | defaultArgs.remove(secureArgsList.portArg); |
| | | defaultArgs.remove(secureArgsList.hostNameArg); |
| | | defaultArgs.remove(verboseArg); |
| | | defaultArgs.remove(noPropertiesFileArg); |
| | | defaultArgs.remove(propertiesFileArg); |
| | | noPromptArg = new BooleanArgument( |
| | | ToolConstants.OPTION_LONG_NO_PROMPT, |
| | | ToolConstants.OPTION_SHORT_NO_PROMPT, |
| | |
| | | defaultArgs.remove(secureArgsList.hostNameArg); |
| | | defaultArgs.remove(secureArgsList.portArg); |
| | | defaultArgs.remove(verboseArg); |
| | | defaultArgs.remove(noPropertiesFileArg); |
| | | defaultArgs.remove(propertiesFileArg); |
| | | UserData uData = new UserData(); |
| | | referencedHostNameArg = new StringArgument("referencedHostName", |
| | | ToolConstants.OPTION_SHORT_HOST, |
| | |
| | | 'YYYYMMDDhhmmss' as the value or '0' to schedule the task for immediate \ |
| | | execution. To run this operation locally and not as a server task omit the \ |
| | | Directory Server connection options |
| | | INFO_DESCRIPTION_PROP_FILE_PATH_1461=Path to the file which contains default \ |
| | | properties value used for command line argument |
| | | INFO_DESCRIPTION_NO_PROP_FILE_1462=Indicates that we will not use properties \ |
| | | file to get default command line argument value |
| | |
| | | |
| | | useSSLArg = new BooleanArgument("useSSL", OPTION_SHORT_USE_SSL, |
| | | OPTION_LONG_USE_SSL, INFO_DESCRIPTION_USE_SSL.get()); |
| | | useSSLArg.setPropertyName(OPTION_LONG_USE_SSL); |
| | | argList.add(useSSLArg); |
| | | |
| | | useStartTLSArg = new BooleanArgument("startTLS", OPTION_SHORT_START_TLS, |
| | | OPTION_LONG_START_TLS, |
| | | INFO_DESCRIPTION_START_TLS.get()); |
| | | useStartTLSArg.setPropertyName(OPTION_LONG_START_TLS); |
| | | argList.add(useStartTLSArg); |
| | | |
| | | hostNameArg = new StringArgument("host", OPTION_SHORT_HOST, |
| | | OPTION_LONG_HOST, false, false, true, OPTION_VALUE_HOST, "localhost", |
| | | null, INFO_DESCRIPTION_HOST.get()); |
| | | hostNameArg.setPropertyName(OPTION_LONG_HOST); |
| | | argList.add(hostNameArg); |
| | | |
| | | portArg = new IntegerArgument("port", OPTION_SHORT_PORT, OPTION_LONG_PORT, |
| | | false, false, true, OPTION_VALUE_PORT, 389, null, |
| | | INFO_DESCRIPTION_PORT.get()); |
| | | portArg.setPropertyName(OPTION_LONG_PORT); |
| | | argList.add(portArg); |
| | | |
| | | bindDnArg = new StringArgument("bindDN", OPTION_SHORT_BINDDN, |
| | | OPTION_LONG_BINDDN, false, false, true, OPTION_VALUE_BINDDN, |
| | | "cn=Directory Manager", null, INFO_DESCRIPTION_BINDDN.get()); |
| | | bindDnArg.setPropertyName(OPTION_LONG_BINDDN); |
| | | argList.add(bindDnArg); |
| | | |
| | | bindPasswordArg = new StringArgument("bindPassword", |
| | | OPTION_SHORT_BINDPWD, OPTION_LONG_BINDPWD, false, false, true, |
| | | OPTION_VALUE_BINDPWD, null, null, INFO_DESCRIPTION_BINDPASSWORD.get()); |
| | | bindPasswordArg.setPropertyName(OPTION_LONG_BINDPWD); |
| | | argList.add(bindPasswordArg); |
| | | |
| | | bindPasswordFileArg = new FileBasedArgument("bindPasswordFile", |
| | | OPTION_SHORT_BINDPWD_FILE, OPTION_LONG_BINDPWD_FILE, false, false, |
| | | OPTION_VALUE_BINDPWD_FILE, null, null, |
| | | INFO_DESCRIPTION_BINDPASSWORDFILE.get()); |
| | | bindPasswordFileArg.setPropertyName(OPTION_LONG_BINDPWD_FILE); |
| | | argList.add(bindPasswordFileArg); |
| | | |
| | | saslOptionArg = new StringArgument( |
| | |
| | | true, true, |
| | | OPTION_VALUE_SASLOPTION, null, null, |
| | | INFO_LDAP_CONN_DESCRIPTION_SASLOPTIONS.get()); |
| | | saslOptionArg.setPropertyName(OPTION_LONG_SASLOPTION); |
| | | argList.add(saslOptionArg); |
| | | |
| | | trustAllArg = new BooleanArgument("trustAll", OPTION_SHORT_TRUSTALL, |
| | | OPTION_LONG_TRUSTALL, INFO_DESCRIPTION_TRUSTALL.get()); |
| | | trustAllArg.setPropertyName(OPTION_LONG_TRUSTALL); |
| | | argList.add(trustAllArg); |
| | | |
| | | trustStorePathArg = new StringArgument("trustStorePath", |
| | | OPTION_SHORT_TRUSTSTOREPATH, OPTION_LONG_TRUSTSTOREPATH, false, |
| | | false, true, OPTION_VALUE_TRUSTSTOREPATH, null, null, |
| | | INFO_DESCRIPTION_TRUSTSTOREPATH.get()); |
| | | trustStorePathArg.setPropertyName(OPTION_LONG_TRUSTSTOREPATH); |
| | | argList.add(trustStorePathArg); |
| | | |
| | | trustStorePasswordArg = new StringArgument("trustStorePassword", |
| | | OPTION_SHORT_TRUSTSTORE_PWD, OPTION_LONG_TRUSTSTORE_PWD, false, false, |
| | | true, OPTION_VALUE_TRUSTSTORE_PWD, null, null, |
| | | INFO_DESCRIPTION_TRUSTSTOREPASSWORD.get()); |
| | | trustStorePasswordArg.setPropertyName(OPTION_LONG_TRUSTSTORE_PWD); |
| | | argList.add(trustStorePasswordArg); |
| | | |
| | | trustStorePasswordFileArg = new FileBasedArgument("trustStorePasswordFile", |
| | | OPTION_SHORT_TRUSTSTORE_PWD_FILE, OPTION_LONG_TRUSTSTORE_PWD_FILE, |
| | | false, false, OPTION_VALUE_TRUSTSTORE_PWD_FILE, null, null, |
| | | INFO_DESCRIPTION_TRUSTSTOREPASSWORD_FILE.get()); |
| | | trustStorePasswordFileArg.setPropertyName(OPTION_LONG_TRUSTSTORE_PWD_FILE); |
| | | argList.add(trustStorePasswordFileArg); |
| | | |
| | | keyStorePathArg = new StringArgument("keyStorePath", |
| | | OPTION_SHORT_KEYSTOREPATH, OPTION_LONG_KEYSTOREPATH, false, false, |
| | | true, OPTION_VALUE_KEYSTOREPATH, null, null, |
| | | INFO_DESCRIPTION_KEYSTOREPATH.get()); |
| | | keyStorePathArg.setPropertyName(OPTION_LONG_KEYSTOREPATH); |
| | | argList.add(keyStorePathArg); |
| | | |
| | | keyStorePasswordArg = new StringArgument("keyStorePassword", |
| | |
| | | OPTION_LONG_KEYSTORE_PWD, false, false, true, |
| | | OPTION_VALUE_KEYSTORE_PWD, null, null, |
| | | INFO_DESCRIPTION_KEYSTOREPASSWORD.get()); |
| | | keyStorePasswordArg.setPropertyName(OPTION_LONG_KEYSTORE_PWD); |
| | | argList.add(keyStorePasswordArg); |
| | | |
| | | keyStorePasswordFileArg = new FileBasedArgument("keystorePasswordFile", |
| | | OPTION_SHORT_KEYSTORE_PWD_FILE, OPTION_LONG_KEYSTORE_PWD_FILE, false, |
| | | false, OPTION_VALUE_KEYSTORE_PWD_FILE, null, null, |
| | | INFO_DESCRIPTION_KEYSTOREPASSWORD_FILE.get()); |
| | | keyStorePasswordFileArg.setPropertyName(OPTION_LONG_KEYSTORE_PWD_FILE); |
| | | argList.add(keyStorePasswordFileArg); |
| | | |
| | | certNicknameArg = new StringArgument("certNickname", |
| | | OPTION_SHORT_CERT_NICKNAME, OPTION_LONG_CERT_NICKNAME, |
| | | false, false, true, OPTION_VALUE_CERT_NICKNAME, null, null, |
| | | INFO_DESCRIPTION_CERT_NICKNAME.get()); |
| | | certNicknameArg.setPropertyName(OPTION_LONG_CERT_NICKNAME); |
| | | argList.add(certNicknameArg); |
| | | |
| | | return argList; |
| | |
| | | |
| | | package org.opends.server.admin.client.cli; |
| | | |
| | | import static org.opends.server.admin.client.cli.DsFrameworkCliReturnCode.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.debugEnabled; |
| | | import static org.opends.server.loggers.debug.DebugLogger.getTracer; |
| | | import static org.opends.messages.ToolMessages.*; |
| | | |
| | | import org.opends.messages.Message; |
| | | import org.opends.messages.MessageBuilder; |
| | | import static org.opends.server.tools.ToolConstants.*; |
| | |
| | | protected SecureConnectionCliArgs secureArgsList ; |
| | | |
| | | /** |
| | | * Argument indicating a properties file argument. |
| | | */ |
| | | protected StringArgument propertiesFileArg = null; |
| | | |
| | | /** |
| | | * The argument which should be used to indicate that we will not |
| | | * look for properties file. |
| | | */ |
| | | protected BooleanArgument noPropertiesFileArg; |
| | | |
| | | /** |
| | | * The tracer object for the debug logger. |
| | | */ |
| | | private static final DebugTracer TRACER = getTracer(); |
| | |
| | | OPTION_LONG_VERBOSE, INFO_DESCRIPTION_VERBOSE.get()); |
| | | set.add(verboseArg); |
| | | |
| | | propertiesFileArg = new StringArgument("propertieFilePath", |
| | | null, OPTION_LONG_PROP_FILE_PATH, |
| | | false, false, true, OPTION_VALUE_PROP_FILE_PATH, null, null, |
| | | INFO_DESCRIPTION_PROP_FILE_PATH.get()); |
| | | setFilePropertiesArgument(propertiesFileArg); |
| | | set.add(propertiesFileArg); |
| | | |
| | | noPropertiesFileArg = new BooleanArgument( |
| | | "noPropertiesFileArgument", null, OPTION_LONG_NO_PROP_FILE, |
| | | INFO_DESCRIPTION_NO_PROP_FILE.get()); |
| | | setNoPropertiesFileArgument(noPropertiesFileArg); |
| | | set.add(noPropertiesFileArg); |
| | | |
| | | |
| | | return set; |
| | | } |
| | | |
| | |
| | | { |
| | | addGlobalArgument(arg); |
| | | } |
| | | |
| | | // Set the propertiesFile argument |
| | | setFilePropertiesArgument(propertiesFileArg); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public int validateGlobalOptions(MessageBuilder buf) |
| | | { |
| | | return secureArgsList.validateGlobalOptions(buf) ; |
| | | int ret = secureArgsList.validateGlobalOptions(buf) ; |
| | | |
| | | // Couldn't have at the same time properties file arg and |
| | | // propertiesFileArg |
| | | if (noPropertiesFileArg.isPresent() |
| | | && propertiesFileArg.isPresent()) |
| | | { |
| | | Message message = ERR_TOOL_CONFLICTING_ARGS.get( |
| | | noPropertiesFileArg.getLongIdentifier(), propertiesFileArg |
| | | .getLongIdentifier()); |
| | | if (buf.length() > 0) |
| | | { |
| | | buf.append(EOL); |
| | | } |
| | | buf.append(message); |
| | | ret = CONFLICTING_ARGS.getReturnCode(); |
| | | } |
| | | |
| | | return ret; |
| | | } |
| | | /** |
| | | * Indication if provided global options are validate. |
| | |
| | | |
| | | |
| | | /** |
| | | * The name of the opends configuration direction in the user |
| | | * home directory. |
| | | */ |
| | | public static final String DEFAULT_OPENDS_CONFIG_DIR = ".opends"; |
| | | |
| | | /** |
| | | * The default properties file name. |
| | | */ |
| | | public static final String DEFAULT_OPENDS_PROPERTIES_FILE_NAME = |
| | | "tools"; |
| | | |
| | | /** |
| | | * The default properties file extension. |
| | | */ |
| | | public static final String DEFAULT_OPENDS_PROPERTIES_FILE_EXTENSION = |
| | | ".properties"; |
| | | |
| | | |
| | | /** |
| | | * The value for the short option configClass. |
| | | */ |
| | | public static final char OPTION_SHORT_CONFIG_CLASS = 'C'; |
| | |
| | | */ |
| | | public static final String OPTION_VALUE_START_DATETIME = "{startTime}"; |
| | | |
| | | /** |
| | | * The value for the long option propertiesFilePAth . |
| | | */ |
| | | public static final String OPTION_LONG_PROP_FILE_PATH = "propertiesFilePath"; |
| | | |
| | | /** |
| | | * The placeholder value of propertiesFilePAth that will be |
| | | * displayed in usage information. |
| | | */ |
| | | public static final String OPTION_VALUE_PROP_FILE_PATH = |
| | | "{propertiesFilePath}"; |
| | | |
| | | /** |
| | | * The value for the long option propertiesFilePAth . |
| | | */ |
| | | public static final String OPTION_LONG_NO_PROP_FILE = "noPropertiesFile"; |
| | | |
| | | } |
| | | |
| | |
| | | import org.opends.server.util.StaticUtils; |
| | | import org.opends.server.util.args.ArgumentException; |
| | | import org.opends.server.util.args.BooleanArgument; |
| | | import org.opends.server.util.args.StringArgument; |
| | | import org.opends.server.util.args.SubCommand; |
| | | import org.opends.server.util.args.SubCommandArgumentParser; |
| | | import org.opends.server.util.cli.CLIException; |
| | |
| | | // The argument which should be used to request verbose output. |
| | | private BooleanArgument verboseArgument; |
| | | |
| | | // The argument which should be used to indicate the properties file. |
| | | private StringArgument propertiesFileArgument; |
| | | |
| | | // The argument which should be used to indicate that we will not look for |
| | | // properties file. |
| | | private BooleanArgument noPropertiesFileArgument; |
| | | |
| | | /** |
| | | * Creates a new dsconfig application instance. |
| | |
| | | OPTION_LONG_HELP, INFO_DSCFG_DESCRIPTION_SHOW_GROUP_USAGE_SUMMARY |
| | | .get()); |
| | | |
| | | propertiesFileArgument = new StringArgument("propertieFilePath", |
| | | null, OPTION_LONG_PROP_FILE_PATH, |
| | | false, false, true, OPTION_VALUE_PROP_FILE_PATH, null, null, |
| | | INFO_DESCRIPTION_PROP_FILE_PATH.get()); |
| | | |
| | | noPropertiesFileArgument = new BooleanArgument( |
| | | "noPropertiesFileArgument", null, OPTION_LONG_NO_PROP_FILE, |
| | | INFO_DESCRIPTION_NO_PROP_FILE.get()); |
| | | |
| | | // Register the global arguments. |
| | | parser.addGlobalArgument(showUsageArgument); |
| | | parser.setUsageArgument(showUsageArgument, getOutputStream()); |
| | |
| | | parser.addGlobalArgument(scriptFriendlyArgument); |
| | | parser.addGlobalArgument(noPromptArgument); |
| | | parser.addGlobalArgument(advancedModeArgument); |
| | | parser.addGlobalArgument(propertiesFileArgument); |
| | | parser.setFilePropertiesArgument(propertiesFileArgument); |
| | | parser.addGlobalArgument(noPropertiesFileArgument); |
| | | parser.setNoPropertiesFileArgument(noPropertiesFileArgument); |
| | | |
| | | // Register any global arguments required by the management |
| | | // context factory. |
| | |
| | | return 1; |
| | | } |
| | | |
| | | if (noPropertiesFileArgument.isPresent() |
| | | && propertiesFileArgument.isPresent()) |
| | | { |
| | | Message message = ERR_TOOL_CONFLICTING_ARGS.get( |
| | | noPropertiesFileArgument.getLongIdentifier(), |
| | | propertiesFileArgument.getLongIdentifier()); |
| | | displayMessageAndUsageReference(message); |
| | | return 1; |
| | | } |
| | | |
| | | // Make sure that management context's arguments are valid. |
| | | try { |
| | | factory.validateGlobalArguments(); |
| | |
| | | |
| | | |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.util.ArrayList; |
| | | import java.util.Enumeration; |
| | | import java.util.HashMap; |
| | | import java.util.LinkedList; |
| | | import java.util.Properties; |
| | |
| | | */ |
| | | public class ArgumentParser |
| | | { |
| | | /** |
| | | * The argument that will be used to indicate the file properties. |
| | | */ |
| | | private StringArgument filePropertiesPathArgument; |
| | | |
| | | /** |
| | | * The argument that will be used to indicate that we'll not look for |
| | | * default properties file. |
| | | */ |
| | | private BooleanArgument NoPropertiesFileArgument; |
| | | |
| | | // The argument that will be used to trigger the display of usage information. |
| | | private Argument usageArgument; |
| | | |
| | |
| | | trailingArguments = new ArrayList<String>(); |
| | | rawArguments = null; |
| | | usageArgument = null; |
| | | filePropertiesPathArgument = null; |
| | | NoPropertiesFileArgument = null; |
| | | usageOutputStream = System.out; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Adds the provided argument to the set of arguments handled by this parser. |
| | | * |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Sets the provided argument which will be used to identify the |
| | | * file properties. |
| | | * |
| | | * @param argument |
| | | * The argument which will be used to identify the file |
| | | * properties. |
| | | */ |
| | | public void setFilePropertiesArgument(StringArgument argument) |
| | | { |
| | | filePropertiesPathArgument= argument; |
| | | } |
| | | |
| | | /** |
| | | * Sets the provided argument which will be used to identify the |
| | | * file properties. |
| | | * |
| | | * @param argument |
| | | * The argument which will be used to indicate if we have to |
| | | * look for properties file. |
| | | */ |
| | | public void setNoPropertiesFileArgument(BooleanArgument argument) |
| | | { |
| | | NoPropertiesFileArgument= argument; |
| | | } |
| | | |
| | | /** |
| | | * Parses the provided set of arguments and updates the information associated |
| | |
| | | } |
| | | } |
| | | |
| | | // If we don't have the argumentProperties, try to load a properties file. |
| | | if (argumentProperties == null) |
| | | { |
| | | argumentProperties = checkExternalProperties(); |
| | | } |
| | | |
| | | // Iterate through all of the arguments. For any that were not provided on |
| | | // the command line, see if there is an alternate default that can be used. |
| | | // For cases where there is not, see that argument is required. |
| | | for (Argument a : argumentList) |
| | | { |
| | | if ((! a.isPresent()) && a.needsValue()) |
| | | if (! a.isPresent()) |
| | | { |
| | | // See if there is a default value in the properties that can be used. |
| | | boolean valueSet = false; |
| | | // See if there is a value in the properties that can be used |
| | | if ((argumentProperties != null) && (a.getPropertyName() != null)) |
| | | { |
| | | String value = argumentProperties.getProperty(a.getPropertyName()); |
| | | String value = argumentProperties.getProperty(a.getPropertyName() |
| | | .toLowerCase()); |
| | | if (value != null) |
| | | { |
| | | a.addValue(value); |
| | | valueSet = true; |
| | | if (a.needsValue()) |
| | | { |
| | | a.addValue(value); |
| | | a.setPresent(true); |
| | | } |
| | | else |
| | | if (value.toLowerCase().equals(CONFIG_VALUE_TRUE)) |
| | | { |
| | | // Boolean value. Set to "present" only if |
| | | // value property value is "true" |
| | | // (insensitive case) |
| | | a.setPresent(true); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // If there is still no value, then see if the argument defines a |
| | | // default. |
| | | if ((! valueSet) && (a.getDefaultValue() != null)) |
| | | |
| | | if ((! a.isPresent()) && a.needsValue()) |
| | | { |
| | | // See if the argument defines a default. |
| | | if (a.getDefaultValue() != null) |
| | | { |
| | | a.addValue(a.getDefaultValue()); |
| | | valueSet = true; |
| | | } |
| | | |
| | | // If there is still no value and the argument is required, then that's |
| | | // a problem. |
| | | if ((! valueSet) && a.isRequired()) |
| | | if ((! a.hasValue()) && a.isRequired()) |
| | | { |
| | | Message message = |
| | | ERR_ARGPARSER_NO_VALUE_FOR_REQUIRED_ARG.get(a.getName()); |
| | |
| | | |
| | | |
| | | /** |
| | | * Appends usage information based on the defined arguments to the provided |
| | | * buffer. |
| | | * Check if we have a properties file. |
| | | * |
| | | * @param buffer The buffer to which the usage information should be |
| | | * appended. |
| | | * @return The properties found in the properties file or null. |
| | | * @throws ArgumentException |
| | | * If a problem was encountered while parsing the provided |
| | | * arguments. |
| | | */ |
| | | protected Properties checkExternalProperties() |
| | | throws ArgumentException |
| | | { |
| | | // We don't look for properties file. |
| | | if ((NoPropertiesFileArgument != null) |
| | | && (NoPropertiesFileArgument.isPresent())) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | // Check if we have a properties file argument |
| | | if (filePropertiesPathArgument == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | // check if the properties file argument has been set. If not |
| | | // look for default location. |
| | | String propertiesFilePath = null; |
| | | if (filePropertiesPathArgument.isPresent()) |
| | | { |
| | | propertiesFilePath = filePropertiesPathArgument.getValue(); |
| | | } |
| | | else |
| | | { |
| | | // Check in "user home"/.opends directory |
| | | String userDir = System.getProperty("user.home"); |
| | | propertiesFilePath = findPropertiesFile(userDir + File.separator |
| | | + DEFAULT_OPENDS_CONFIG_DIR); |
| | | |
| | | if (propertiesFilePath == null) |
| | | { |
| | | // check "Opends instance"/config directory |
| | | String instanceDir = System.getProperty(PROPERTY_SERVER_ROOT); |
| | | propertiesFilePath = findPropertiesFile(instanceDir+ File.separator |
| | | + "config"); |
| | | } |
| | | } |
| | | |
| | | // We don't have a properties file location |
| | | if (propertiesFilePath == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | // We have a location for the properties file. |
| | | Properties argumentProperties = new Properties(); |
| | | String scriptName = System.getProperty(PROPERTY_SCRIPT_NAME); |
| | | try |
| | | { |
| | | Properties p = new Properties(); |
| | | FileInputStream fis = new FileInputStream(propertiesFilePath); |
| | | p.load(fis); |
| | | fis.close(); |
| | | |
| | | for (Enumeration<?> e = p.propertyNames(); e.hasMoreElements();) |
| | | { |
| | | String currentPropertyName = (String) e.nextElement(); |
| | | String propertyName = currentPropertyName; |
| | | |
| | | // Property name form <script name>.<property name> has the |
| | | // precedence to <property name> |
| | | if (scriptName != null) |
| | | { |
| | | if (currentPropertyName.startsWith(scriptName)) |
| | | { |
| | | propertyName = currentPropertyName |
| | | .substring(scriptName.length() + 1); |
| | | } |
| | | else |
| | | { |
| | | if (p.containsKey(scriptName + "." + currentPropertyName )) |
| | | { |
| | | continue; |
| | | } |
| | | } |
| | | } |
| | | argumentProperties.setProperty(propertyName.toLowerCase(), p |
| | | .getProperty(currentPropertyName)); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Message message = ERR_ARGPARSER_CANNOT_READ_PROPERTIES_FILE.get(String |
| | | .valueOf(propertiesFilePath), getExceptionMessage(e)); |
| | | throw new ArgumentException(message, e); |
| | | } |
| | | return argumentProperties; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Get the absolute path of the properties file. |
| | | * |
| | | * @param directory |
| | | * The location in which we should look for properties file |
| | | * @return The absolute path of the properties file or null |
| | | */ |
| | | private String findPropertiesFile(String directory) |
| | | { |
| | | // Check directory |
| | | File dir = new File(directory); |
| | | if (! dir.exists()) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | // Look for the tools properties file |
| | | String path = directory + File.separator |
| | | + DEFAULT_OPENDS_PROPERTIES_FILE_NAME |
| | | + DEFAULT_OPENDS_PROPERTIES_FILE_EXTENSION; |
| | | File f = new File(path); |
| | | if (f.exists() && f.canRead()) |
| | | { |
| | | return f.getAbsolutePath(); |
| | | } |
| | | else |
| | | { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Appends usage information based on the defined arguments to the |
| | | * provided buffer. |
| | | * |
| | | * @param buffer |
| | | * The buffer to which the usage information should be |
| | | * appended. |
| | | */ |
| | | public void getUsage(StringBuilder buffer) |
| | | { |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Parses the provided set of arguments and updates the information associated |
| | | * with this parser accordingly. |
| | |
| | | if (argCharacter == OPTION_SHORT_PRODUCT_VERSION) |
| | | { |
| | | // "-V" will always be interpreted as requesting |
| | | // version information except if it's alreadydefined. |
| | | // version information except if it's already defined. |
| | | boolean dashVAccepted = true; |
| | | if (globalShortIDMap.containsKey(OPTION_SHORT_PRODUCT_VERSION)) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | // If we don't have the argumentProperties, try to load a properties file. |
| | | if (argumentProperties == null) |
| | | { |
| | | argumentProperties = checkExternalProperties(); |
| | | } |
| | | |
| | | // Iterate through all the global arguments and make sure that they have |
| | | // values or a suitable default is available. |
| | | for (Argument a : globalArgumentList) |
| | | { |
| | | if ((! a.isPresent()) && a.needsValue()) |
| | | if (! a.isPresent()) |
| | | { |
| | | // See if there is a default value in the properties that can be used. |
| | | boolean valueSet = false; |
| | | // See if there is a value in the properties that can be used |
| | | if ((argumentProperties != null) && (a.getPropertyName() != null)) |
| | | { |
| | | String value = argumentProperties.getProperty(a.getPropertyName()); |
| | | String value = argumentProperties.getProperty(a.getPropertyName() |
| | | .toLowerCase()); |
| | | if (value != null) |
| | | { |
| | | a.addValue(value); |
| | | valueSet = true; |
| | | if (a.needsValue()) |
| | | { |
| | | a.addValue(value); |
| | | a.setPresent(true); |
| | | } |
| | | else |
| | | if (value.toLowerCase().equals(CONFIG_VALUE_TRUE)) |
| | | { |
| | | // Boolean value. Set to "present" only if |
| | | // value property value is "true" |
| | | // (insensitive case) |
| | | a.setPresent(true); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // If there is still no value, then see if the argument defines a |
| | | // default. |
| | | if ((! valueSet) && (a.getDefaultValue() != null)) |
| | | if ((! a.isPresent()) && a.needsValue()) |
| | | { |
| | | // ISee if the argument defines a default. |
| | | if (a.getDefaultValue() != null) |
| | | { |
| | | a.addValue(a.getDefaultValue()); |
| | | valueSet = true; |
| | | } |
| | | |
| | | // If there is still no value and the argument is required, then that's |
| | | // a problem. |
| | | if ((! valueSet) && a.isRequired()) |
| | | if ((! a.hasValue()) && a.isRequired()) |
| | | { |
| | | Message message = |
| | | ERR_SUBCMDPARSER_NO_VALUE_FOR_REQUIRED_ARG.get(a.getName()); |
| | |
| | | { |
| | | for (Argument a : subCommand.getArguments()) |
| | | { |
| | | if ((! a.isPresent()) && a.needsValue()) |
| | | if (! a.isPresent()) |
| | | { |
| | | // See if there is a default value in the properties that can be used. |
| | | boolean valueSet = false; |
| | | // See if there is a value in the properties that can be used |
| | | if ((argumentProperties != null) && (a.getPropertyName() != null)) |
| | | { |
| | | String value = argumentProperties.getProperty(a.getPropertyName()); |
| | | String value = argumentProperties.getProperty(a.getPropertyName() |
| | | .toLowerCase()); |
| | | if (value != null) |
| | | { |
| | | a.addValue(value); |
| | | valueSet = true; |
| | | if (a.needsValue()) |
| | | { |
| | | a.addValue(value); |
| | | a.setPresent(true); |
| | | } |
| | | else |
| | | if (value.toLowerCase().equals(CONFIG_VALUE_TRUE)) |
| | | { |
| | | // Boolean value. Set to "present" only if |
| | | // value property value is "true" |
| | | // (insensitive case) |
| | | a.setPresent(true); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // If there is still no value, then see if the argument defines a |
| | | // default. |
| | | if ((! valueSet) && (a.getDefaultValue() != null)) |
| | | if ((! a.isPresent()) && a.needsValue()) |
| | | { |
| | | // See if the argument defines a default. |
| | | if (a.getDefaultValue() != null) |
| | | { |
| | | a.addValue(a.getDefaultValue()); |
| | | valueSet = true; |
| | | } |
| | | |
| | | // If there is still no value and the argument is required, then |
| | | // that's a problem. |
| | | if ((! valueSet) && a.isRequired()) |
| | | if ((! a.hasValue()) && a.isRequired()) |
| | | { |
| | | Message message = |
| | | ERR_SUBCMDPARSER_NO_VALUE_FOR_REQUIRED_ARG.get(a.getName()); |
| | |
| | | */ |
| | | public static void dsconfig(String... args) |
| | | { |
| | | String[] fullArgs = new String[args.length + 9]; |
| | | String[] fullArgs = new String[args.length + 10]; |
| | | fullArgs[0] = "-h"; |
| | | fullArgs[1] = "127.0.0.1"; |
| | | fullArgs[2] = "-p"; |
| | |
| | | fullArgs[6] = "-w"; |
| | | fullArgs[7] = "password"; |
| | | fullArgs[8] = "-n"; |
| | | fullArgs[9] = "--noPropertiesFile"; |
| | | |
| | | System.arraycopy(args, 0, fullArgs, 9, args.length); |
| | | System.arraycopy(args, 0, fullArgs, 10, args.length); |
| | | |
| | | assertEquals(DSConfig.main(fullArgs, false, System.out, System.err), 0); |
| | | } |
| | |
| | | String[] args = |
| | | { |
| | | "create-ads", |
| | | "--noPropertiesFile", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-w", "password", |
| | | "--backendName", "admin" |
| | |
| | | String[] args = |
| | | { |
| | | "delete-ads", |
| | | "--noPropertiesFile", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-w", "password", |
| | | "--backendName", "admin" |
| | |
| | | String[] args = |
| | | { |
| | | "list-groups", |
| | | "--noPropertiesFile", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-D", "malformed", |
| | | "-w", "password" |
| | |
| | | String[] args = |
| | | { |
| | | "list-groups", |
| | | "--noPropertiesFile", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-D", "cn=Does Not Exist", |
| | | "-w", "password" |
| | |
| | | String[] args = |
| | | { |
| | | "list-groups", |
| | | "--noPropertiesFile", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-D", "cn=Directory Manager", |
| | | "-w", "wrongPassword" |
| | |
| | | String[] args = |
| | | { |
| | | "list-groups", |
| | | "--noPropertiesFile", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-D", "cn=Directory Manager", |
| | | "-j", validPasswordFile, |
| | |
| | | String[] args = |
| | | { |
| | | "list-groups", |
| | | "--noPropertiesFile", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-D", "cn=Directory Manager", |
| | | "-j",invalidPasswordFile |
| | |
| | | String[] args = |
| | | { |
| | | "list-groups", |
| | | "--noPropertiesFile", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapsPort()), |
| | | "-w", "password", |
| | | "-Z", |
| | |
| | | String[] args = |
| | | { |
| | | "list-groups", |
| | | "--noPropertiesFile", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapsPort()), |
| | | "-w", "password", |
| | | "-Z", |
| | |
| | | String[] args = |
| | | { |
| | | "list-groups", |
| | | "--noPropertiesFile", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-w", "password", |
| | | "-q", |
| | |
| | | String[] args = |
| | | { |
| | | "list-groups", |
| | | "--noPropertiesFile", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-w", "password", |
| | | "-q", |
| | |
| | | @Test() |
| | | public void testHelp() |
| | | { |
| | | String[] args = { "--help" }; |
| | | String[] args = {"--noPropertiesFile", "--help" }; |
| | | assertEquals(DsFrameworkCliMain.mainCLI(args, false, null, null), |
| | | SUCCESSFUL.getReturnCode()); |
| | | |
| | | args = new String[] { "-H" }; |
| | | args = new String[] {"--noPropertiesFile", "-H" }; |
| | | assertEquals(DsFrameworkCliMain.mainCLI(args, false, null, null), |
| | | SUCCESSFUL.getReturnCode()); |
| | | |
| | | args = new String[] { "-?" }; |
| | | args = new String[] {"--noPropertiesFile", "-?" }; |
| | | assertEquals(DsFrameworkCliMain.mainCLI(args, false, null, null), |
| | | SUCCESSFUL.getReturnCode()); |
| | | } |
| | |
| | | String[] args = |
| | | { |
| | | "-n", |
| | | "--noPropertiesFile", |
| | | "-Q", |
| | | "list-connection-handlers", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | |
| | | String[] args = |
| | | { |
| | | "-n", |
| | | "--noPropertiesFile", |
| | | "-Q", |
| | | "list-connection-handlers", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | |
| | | String[] args = |
| | | { |
| | | "-n", |
| | | "--noPropertiesFile", |
| | | "-Q", |
| | | "list-connection-handlers", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | |
| | | String[] args = |
| | | { |
| | | "-n", |
| | | "--noPropertiesFile", |
| | | "-Q", |
| | | "list-connection-handlers", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | |
| | | String[] args = |
| | | { |
| | | "-n", |
| | | "--noPropertiesFile", |
| | | "-Q", |
| | | "list-connection-handlers", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | |
| | | String[] args = |
| | | { |
| | | "-n", |
| | | "--noPropertiesFile", |
| | | "-Q", |
| | | "list-connection-handlers", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapsPort()), |
| | |
| | | String[] args = |
| | | { |
| | | "-n", |
| | | "--noPropertiesFile", |
| | | "-Q", |
| | | "list-connection-handlers", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapsPort()), |
| | |
| | | String[] args = |
| | | { |
| | | "-n", |
| | | "--noPropertiesFile", |
| | | "-Q", |
| | | "list-connection-handlers", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | |
| | | String[] args = |
| | | { |
| | | "-n", |
| | | "--noPropertiesFile", |
| | | "-Q", |
| | | "list-connection-handlers", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | |
| | | @Test() |
| | | public void testHelp() |
| | | { |
| | | String[] args = { "--help" }; |
| | | String[] args = {"--noPropertiesFile","--help" }; |
| | | assertEquals(DSConfig.main(args, false, null, null), |
| | | SUCCESSFUL.getReturnCode()); |
| | | |
| | | args = new String[] { "-H" }; |
| | | args = new String[] { "--noPropertiesFile", "-H" }; |
| | | assertEquals(DSConfig.main(args, false, null, null), |
| | | SUCCESSFUL.getReturnCode()); |
| | | |
| | | args = new String[] { "-?" }; |
| | | args = new String[] { "--noPropertiesFile", "-?" }; |
| | | assertEquals(DSConfig.main(args, false, null, null), |
| | | SUCCESSFUL.getReturnCode()); |
| | | } |