From f5ef017da469ddbc44d8cd4edce836a564f46ef2 Mon Sep 17 00:00:00 2001
From: lutoff <lutoff@localhost>
Date: Thu, 20 Sep 2007 14:35:30 +0000
Subject: [PATCH] Fix for issue #582 (Need Client-Side Configuration File)

---
 opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java                            |   50 ++++++
 opends/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java                             |    2 
 opends/src/server/org/opends/server/tools/ToolConstants.java                                                   |   36 ++++
 opends/src/messages/messages/tools.properties                                                                  |    4 
 opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliArgumentParser.java                       |    3 
 opends/tests/unit-tests-testng/src/server/org/opends/server/tools/dsconfig/DsconfigLdapConnectionTestCase.java |   15 +
 opends/src/guitools/org/opends/guitools/statuspanel/StatusCliArgumentParser.java                               |    2 
 opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java                                 |    5 
 opends/tests/unit-tests-testng/src/server/org/opends/server/admin/client/cli/DsframeworkTestCase.java          |   17 +
 opends/src/server/org/opends/server/util/args/ArgumentParser.java                                              |  220 +++++++++++++++++++++++++--
 opends/src/server/org/opends/server/util/args/SubCommandArgumentParser.java                                    |   77 ++++++---
 opends/src/server/org/opends/server/tools/dsconfig/DSConfig.java                                               |   29 +++
 opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java                              |   16 ++
 13 files changed, 427 insertions(+), 49 deletions(-)

diff --git a/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliArgumentParser.java b/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliArgumentParser.java
index 4c72ac0..acfe338 100644
--- a/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliArgumentParser.java
+++ b/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliArgumentParser.java
@@ -371,6 +371,9 @@
     {
       defaultArgs.remove(argsToRemove[i]);
     }
+    defaultArgs.remove(noPropertiesFileArg);
+    defaultArgs.remove(propertiesFileArg);
+
     int index = 0;
 
     baseDNsArg = new StringArgument("baseDNs", OPTION_SHORT_BASEDN,
diff --git a/opends/src/guitools/org/opends/guitools/statuspanel/StatusCliArgumentParser.java b/opends/src/guitools/org/opends/guitools/statuspanel/StatusCliArgumentParser.java
index 3a91a25..6b13f96 100644
--- a/opends/src/guitools/org/opends/guitools/statuspanel/StatusCliArgumentParser.java
+++ b/opends/src/guitools/org/opends/guitools/statuspanel/StatusCliArgumentParser.java
@@ -78,6 +78,8 @@
     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,
diff --git a/opends/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java b/opends/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java
index 56dec25..d1e4eeb 100644
--- a/opends/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java
+++ b/opends/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java
@@ -198,6 +198,8 @@
     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,
diff --git a/opends/src/messages/messages/tools.properties b/opends/src/messages/messages/tools.properties
index 6f7aa54..73df212 100644
--- a/opends/src/messages/messages/tools.properties
+++ b/opends/src/messages/messages/tools.properties
@@ -2156,3 +2156,7 @@
   '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
diff --git a/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java b/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java
index 0d59287..5d28633 100644
--- a/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java
+++ b/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java
@@ -387,37 +387,44 @@
 
     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(
@@ -426,34 +433,40 @@
             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",
@@ -461,18 +474,21 @@
         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;
diff --git a/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java b/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java
index 52bed17..2f7d51d 100644
--- a/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java
+++ b/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java
@@ -27,9 +27,11 @@
 
 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.*;
@@ -81,6 +83,17 @@
   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();
@@ -305,6 +318,20 @@
         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;
   }
 
@@ -321,6 +348,9 @@
     {
       addGlobalArgument(arg);
     }
+
+    // Set the propertiesFile argument
+    setFilePropertiesArgument(propertiesFileArg);
   }
 
   /**
@@ -353,7 +383,25 @@
    */
   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.
diff --git a/opends/src/server/org/opends/server/tools/ToolConstants.java b/opends/src/server/org/opends/server/tools/ToolConstants.java
index b33e259..4b3aa7e 100644
--- a/opends/src/server/org/opends/server/tools/ToolConstants.java
+++ b/opends/src/server/org/opends/server/tools/ToolConstants.java
@@ -90,6 +90,25 @@
 
 
   /**
+   * 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';
@@ -727,5 +746,22 @@
    */
   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";
+
 }
 
diff --git a/opends/src/server/org/opends/server/tools/dsconfig/DSConfig.java b/opends/src/server/org/opends/server/tools/dsconfig/DSConfig.java
index 4d17710..a83a43a 100644
--- a/opends/src/server/org/opends/server/tools/dsconfig/DSConfig.java
+++ b/opends/src/server/org/opends/server/tools/dsconfig/DSConfig.java
@@ -63,6 +63,7 @@
 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;
@@ -364,7 +365,12 @@
   // 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.
@@ -515,6 +521,15 @@
           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());
@@ -523,6 +538,10 @@
       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.
@@ -659,6 +678,16 @@
       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();
diff --git a/opends/src/server/org/opends/server/util/args/ArgumentParser.java b/opends/src/server/org/opends/server/util/args/ArgumentParser.java
index 63ea8ab..4b2b5e9 100644
--- a/opends/src/server/org/opends/server/util/args/ArgumentParser.java
+++ b/opends/src/server/org/opends/server/util/args/ArgumentParser.java
@@ -29,10 +29,12 @@
 
 
 
+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;
@@ -60,6 +62,17 @@
  */
 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;
 
@@ -148,6 +161,8 @@
     trailingArguments       = new ArrayList<String>();
     rawArguments            = null;
     usageArgument           = null;
+    filePropertiesPathArgument = null;
+    NoPropertiesFileArgument = null;
     usageOutputStream       = System.out;
   }
 
@@ -402,7 +417,6 @@
   }
 
 
-
   /**
    * Adds the provided argument to the set of arguments handled by this parser.
    *
@@ -501,6 +515,31 @@
   }
 
 
+  /**
+   * 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
@@ -943,37 +982,55 @@
       }
     }
 
+    // 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());
@@ -986,11 +1043,142 @@
 
 
   /**
-   * 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)
   {
diff --git a/opends/src/server/org/opends/server/util/args/SubCommandArgumentParser.java b/opends/src/server/org/opends/server/util/args/SubCommandArgumentParser.java
index 8242a20..9adc76d 100644
--- a/opends/src/server/org/opends/server/util/args/SubCommandArgumentParser.java
+++ b/opends/src/server/org/opends/server/util/args/SubCommandArgumentParser.java
@@ -613,7 +613,6 @@
   }
 
 
-
   /**
    * Parses the provided set of arguments and updates the information associated
    * with this parser accordingly.
@@ -1012,7 +1011,7 @@
               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))
                 {
@@ -1223,35 +1222,53 @@
       }
     }
 
+    // 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());
@@ -1267,31 +1284,43 @@
     {
       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());
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
index 6179bea..91b9f58 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
@@ -1489,7 +1489,7 @@
    */
   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";
@@ -1499,8 +1499,9 @@
     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);
   }
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/admin/client/cli/DsframeworkTestCase.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/admin/client/cli/DsframeworkTestCase.java
index 8386894..923a6a6 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/admin/client/cli/DsframeworkTestCase.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/admin/client/cli/DsframeworkTestCase.java
@@ -86,6 +86,7 @@
     String[] args =
     {
       "create-ads",
+      "--noPropertiesFile",
       "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
       "-w", "password",
       "--backendName", "admin"
@@ -106,6 +107,7 @@
     String[] args =
     {
       "delete-ads",
+      "--noPropertiesFile",
       "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
       "-w", "password",
       "--backendName", "admin"
@@ -124,6 +126,7 @@
     String[] args =
     {
       "list-groups",
+      "--noPropertiesFile",
       "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
       "-D", "malformed",
       "-w", "password"
@@ -142,6 +145,7 @@
     String[] args =
     {
       "list-groups",
+      "--noPropertiesFile",
       "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
       "-D", "cn=Does Not Exist",
       "-w", "password"
@@ -160,6 +164,7 @@
     String[] args =
     {
       "list-groups",
+      "--noPropertiesFile",
       "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
       "-D", "cn=Directory Manager",
       "-w", "wrongPassword"
@@ -184,6 +189,7 @@
     String[] args =
     {
       "list-groups",
+      "--noPropertiesFile",
       "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
       "-D", "cn=Directory Manager",
       "-j", validPasswordFile,
@@ -205,6 +211,7 @@
     String[] args =
     {
       "list-groups",
+      "--noPropertiesFile",
       "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
       "-D", "cn=Directory Manager",
       "-j",invalidPasswordFile
@@ -223,6 +230,7 @@
     String[] args =
     {
       "list-groups",
+      "--noPropertiesFile",
       "-p", String.valueOf(TestCaseUtils.getServerLdapsPort()),
       "-w", "password",
       "-Z",
@@ -247,6 +255,7 @@
     String[] args =
     {
       "list-groups",
+      "--noPropertiesFile",
       "-p", String.valueOf(TestCaseUtils.getServerLdapsPort()),
       "-w", "password",
       "-Z",
@@ -268,6 +277,7 @@
     String[] args =
     {
       "list-groups",
+      "--noPropertiesFile",
       "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
       "-w", "password",
       "-q",
@@ -292,6 +302,7 @@
     String[] args =
     {
       "list-groups",
+      "--noPropertiesFile",
       "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
       "-w", "password",
       "-q",
@@ -308,15 +319,15 @@
   @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());
   }
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/tools/dsconfig/DsconfigLdapConnectionTestCase.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/tools/dsconfig/DsconfigLdapConnectionTestCase.java
index 0c00ffb..33bdc52 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/tools/dsconfig/DsconfigLdapConnectionTestCase.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/tools/dsconfig/DsconfigLdapConnectionTestCase.java
@@ -103,6 +103,7 @@
     String[] args =
     {
       "-n",
+      "--noPropertiesFile",
       "-Q",
       "list-connection-handlers",
       "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
@@ -123,6 +124,7 @@
     String[] args =
     {
       "-n",
+      "--noPropertiesFile",
       "-Q",
       "list-connection-handlers",
       "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
@@ -143,6 +145,7 @@
     String[] args =
     {
       "-n",
+      "--noPropertiesFile",
       "-Q",
       "list-connection-handlers",
       "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
@@ -169,6 +172,7 @@
     String[] args =
     {
       "-n",
+      "--noPropertiesFile",
       "-Q",
       "list-connection-handlers",
       "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
@@ -192,6 +196,7 @@
     String[] args =
     {
       "-n",
+      "--noPropertiesFile",
       "-Q",
       "list-connection-handlers",
       "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
@@ -212,6 +217,7 @@
     String[] args =
     {
       "-n",
+      "--noPropertiesFile",
       "-Q",
       "list-connection-handlers",
       "-p", String.valueOf(TestCaseUtils.getServerLdapsPort()),
@@ -238,6 +244,7 @@
     String[] args =
     {
       "-n",
+      "--noPropertiesFile",
       "-Q",
       "list-connection-handlers",
       "-p", String.valueOf(TestCaseUtils.getServerLdapsPort()),
@@ -261,6 +268,7 @@
     String[] args =
     {
       "-n",
+      "--noPropertiesFile",
       "-Q",
       "list-connection-handlers",
       "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
@@ -287,6 +295,7 @@
     String[] args =
     {
       "-n",
+      "--noPropertiesFile",
       "-Q",
       "list-connection-handlers",
       "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
@@ -305,15 +314,15 @@
   @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());
   }

--
Gitblit v1.10.0