From ffd927de702a353b8e57ad3abdfa9cc75309f232 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Wed, 11 Feb 2009 03:29:00 +0000
Subject: [PATCH] Add options displayCommand and commandFilePath to the dsreplication command-line.  These options display the equivalent non-interactive command-line when dsreplication is run in interactive mode (they are the same options already provided by dsconfig).  The WIKI content has already been updated to reflect these changes.

---
 opendj-sdk/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java         |    7 
 opendj-sdk/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java           |  887 +++++++++++++++++++++++++++++++++++++++++++++
 opendj-sdk/opends/src/messages/messages/dsconfig.properties                                          |    4 
 opendj-sdk/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliArgumentParser.java |  127 +++++-
 opendj-sdk/opends/src/server/org/opends/server/util/cli/CommandBuilder.java                          |    4 
 opendj-sdk/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java        |   35 +
 opendj-sdk/opends/src/messages/messages/admin_tool.properties                                        |   41 +
 7 files changed, 1,034 insertions(+), 71 deletions(-)

diff --git a/opendj-sdk/opends/src/messages/messages/admin_tool.properties b/opendj-sdk/opends/src/messages/messages/admin_tool.properties
index 8e515a9..021cba3 100644
--- a/opendj-sdk/opends/src/messages/messages/admin_tool.properties
+++ b/opendj-sdk/opends/src/messages/messages/admin_tool.properties
@@ -435,11 +435,11 @@
 INFO_DESCRIPTION_ENABLE_REPLICATION_PORT2=Port that will be used \
  by the replication mechanism in the second server to communicate with the \
  other servers.  You have to specify this option only if replication was not \
- previously configured in the second server.
+ previously configured in the second server
 INFO_DESCRIPTION_ENABLE_SECURE_REPLICATION2=Specifies whether or not the \
  communication through the replication port of the second server is encrypted \
  or not.  This option will only be taken into account the first time \
- replication is configured on the second server.
+ replication is configured on the second server
 INFO_DESCRIPTION_ENABLE_REPLICATION_STARTTLS2=Use StartTLS to secure \
  communication with the second server
 INFO_DESCRIPTION_REPLICATION_BASEDNS=Base DN of \
@@ -472,7 +472,7 @@
  replication between servers so that the data of the servers is synchronized.\
  For replication to work you must first to enable replication using the \
  '%s' subcommand and then initialize the contents of one of \
- the servers with the contents of the other using the '%s' subcommand.
+ the servers with the contents of the other using the '%s' subcommand
 INFO_REPLICATION_DESCRIPTION_QUIET=Perform a quiet operation (no \
  progress information is written to the standard output)
 INFO_DESCRIPTION_DISABLE_REPLICATION_BINDDN=DN to use to \
@@ -480,42 +480,42 @@
  be used when no Global Administrator has been defined on the server or if the \
  user does not want to remove references in the other replicated servers.  The \
  password provided for the Global Administrator will be used when specifying \
- this option.
+ this option
 INFO_DESCRIPTION_SUBCMD_INITIALIZE_REPLICATION=Initialize the contents of the \
  data under the specified Base DN on the destination server with the contents \
  on the source server.  This operation is required after enabling replication \
- in order replication to work ('%s' can also be used for this purpose).
+ in order replication to work ('%s' can also be used for this purpose)
 INFO_DESCRIPTION_SUBCMD_INITIALIZE_ALL_REPLICATION=Initialize the contents of \
  the data under the specified Base DN on all the servers whose contents are \
  being replicated with the contents on the specified server.  This operation \
  is required after enabling replication in order replication to work ('%s' \
- applied to each server can also be used for this purpose).
+ applied to each server can also be used for this purpose)
 INFO_DESCRIPTION_SUBCMD_PRE_EXTERNAL_INITIALIZATION=This subcommand must be \
  called before initializing the contents of all the replicated servers using \
  the tool import-ldif or the binary copy method.  You must specify the list of \
  Base DN's that will be initialized and you must \
  provide the credentials of any of the servers that are being replicated.  \
  After calling this subcommand, initialize the contents of all the servers in \
- the topology, then call the subcommand '%s'.
+ the topology, then call the subcommand '%s'
 INFO_DESCRIPTION_SUBCMD_POST_EXTERNAL_INITIALIZATION=This subcommand must be \
  called after initializing the contents of all the replicated servers using \
  the tool import-ldif or the binary copy method.  You \
  must specify the list of Base DN's that have been initialized and you must \
  provide the credentials of any of the servers that are being replicated.  See \
- the usage of the subcommand '%s' for more information.
+ the usage of the subcommand '%s' for more information
 INFO_DESCRIPTION_SUBCMD_ENABLE_REPLICATION=Updates the configuration of the \
  servers to replicate the data under the specified Base DN.  If one of the \
  specified servers is already replicating the data under the Base DN with \
  other servers, executing this subcommand will update the configuration of all \
  the servers (so it is sufficient to execute the command line once for each \
- server we add to the replication topology).
+ server we add to the replication topology)
 INFO_DESCRIPTION_SUBCMD_DISABLE_REPLICATION=Disables replication on the \
  specified server for the provided Base DN and removes references in the other \
- servers with which it is replicating data.
+ servers with which it is replicating data
 INFO_DESCRIPTION_SUBCMD_STATUS_REPLICATION=Displays a list with the basic \
  replication configuration of the base DN's of the servers defined in the \
  registration information.  If no base DN's are specified as parameter the \
- information for all base DN's is displayed.
+ information for all base DN's is displayed
 SEVERE_ERR_REPLICATION_NO_BASE_DN_PROVIDED=You must provide at least one base \
  DN in no interactive mode.
 SEVERE_ERR_REPLICATION_NO_ADMINISTRATOR_PASSWORD_PROVIDED=You must provide the \
@@ -796,6 +796,25 @@
 INFO_REPLICATION_POST_ENABLE_INFO=Replication has been successfully enabled.  \
  Note that for replication to work you must initialize the contents of the \
  base DN's that are being replicated (use %s %s to do so).
+SEVERE_ERR_REPLICATION_ERROR_MISSING_NON_INTERACTIVE_ARG=The argument \
+ "--%s" must be specified when this application is used non-interactively
+INFO_REPLICATION_NON_INTERACTIVE=The equivalent non-interactive command-line \
+ is:%n%s
+INFO_REPLICATION_DESCRIPTION_DISPLAY_EQUIVALENT=Display the equivalent \
+ non-interactive argument in the standard output when this command is run in \
+ interactive mode
+INFO_REPLICATION_DESCRIPTION_EQUIVALENT_COMMAND_FILE_PATH=The full path to \
+ the file where the equivalent non-interactive commands will be written when \
+ this command is run in interactive mode
+MILD_ERR_REPLICATION_ERROR_WRITING_EQUIVALENT_COMMAND_LINE=An error \
+ occurred while attempting to write equivalent non-interactive command line to \
+ file %s.  Error details:  %s
+SEVERE_ERR_REPLICATION_CANNOT_WRITE_EQUIVALENT_COMMAND_LINE_FILE=Cannot \
+ write to file %s.  Verify that you have access rights to that file and that \
+ you provided the full path of the file
+SEVERE_ERR_REPLICATION_EQUIVALENT_COMMAND_LINE_FILE_DIRECTORY=The \
+ specified path %s to write the equivalent command is a directory.  You must \
+ specify a path to a file
 INFO_CONTROL_PANEL_TITLE=OpenDS Control Panel
 INFO_PERSON_ICON_DESCRIPTION=Person object
 INFO_ORGANIZATION_ICON_DESCRIPTION=Organization
diff --git a/opendj-sdk/opends/src/messages/messages/dsconfig.properties b/opendj-sdk/opends/src/messages/messages/dsconfig.properties
index 0d5e492..e139610 100644
--- a/opendj-sdk/opends/src/messages/messages/dsconfig.properties
+++ b/opendj-sdk/opends/src/messages/messages/dsconfig.properties
@@ -20,7 +20,7 @@
 #
 # CDDL HEADER END
 #
-#      Copyright 2006-2008 Sun Microsystems, Inc.
+#      Copyright 2006-2009 Sun Microsystems, Inc.
 
 
 
@@ -465,7 +465,7 @@
  provided the full path of the file
 SEVERE_ERR_DSCFG_EQUIVALENT_COMMAND_LINE_FILE_DIRECTORY_156=The specified \
  path %s to write the equivalent command is a directory.  You must specify a \
- path to a file 
+ path to a file
 SEVERE_ERR_DSCFG_ERROR_LDAP_FAILED_TO_CONNECT_WRONG_PORT_157=Unable to connect to the \
  server at %s on port %s. Check this port is an administration port
 SEVERE_ERR_DSCFG_ERROR_LDAP_FAILED_TO_CONNECT_NOT_TRUSTED_158=Unable to connect to the \
diff --git a/opendj-sdk/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java b/opendj-sdk/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java
index ca365d8..77b1566 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2007-2008 Sun Microsystems, Inc.
+ *      Copyright 2007-2009 Sun Microsystems, Inc.
  */
 
 package org.opends.server.admin.client.cli;
@@ -486,10 +486,11 @@
     // It is up to the classes that required admin UID to make this argument
     // visible and add it.
     adminUidArg = new StringArgument("adminUID", 'I',
-        "adminUID", false, false, true, INFO_ADMINUID_PLACEHOLDER.get(),
+        OPTION_LONG_ADMIN_UID, false, false, true,
+        INFO_ADMINUID_PLACEHOLDER.get(),
         Constants.GLOBAL_ADMIN_UID, null,
         INFO_DESCRIPTION_ADMIN_UID.get());
-    adminUidArg.setPropertyName("adminUID");
+    adminUidArg.setPropertyName(OPTION_LONG_ADMIN_UID);
     adminUidArg.setHidden(true);
 
     bindPasswordArg = new StringArgument("bindPassword",
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliArgumentParser.java b/opendj-sdk/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliArgumentParser.java
index c115368..cd7abac 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliArgumentParser.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliArgumentParser.java
@@ -31,6 +31,7 @@
 import static org.opends.messages.ToolMessages.*;
 import static org.opends.server.tools.ToolConstants.*;
 
+import java.io.File;
 import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.LinkedList;
@@ -66,7 +67,10 @@
   private SubCommand preExternalInitializationSubCmd;
   private SubCommand statusReplicationSubCmd;
 
-  private BooleanArgument noPromptArg;
+  /**
+   * No-prompt argument.
+   */
+  BooleanArgument noPromptArg;
 
   private String defaultLocalHostValue;
 
@@ -88,22 +92,22 @@
   /**
    * The 'bindPasswordFile' argument for the first server.
    */
-  private FileBasedArgument bindPasswordFile1Arg = null;
+  FileBasedArgument bindPasswordFile1Arg = null;
 
   /**
    * The 'bindPassword' argument for the first server.
    */
-  private StringArgument bindPassword1Arg = null;
+  StringArgument bindPassword1Arg = null;
 
   /**
    * The 'replicationPort' argument for the first server.
    */
-  private IntegerArgument replicationPort1Arg = null;
+  IntegerArgument replicationPort1Arg = null;
 
   /**
    * The 'secureReplication' argument for the first server.
    */
-  private BooleanArgument secureReplication1Arg = null;
+  BooleanArgument secureReplication1Arg = null;
 
   /**
    * The 'hostName' argument for the second server.
@@ -123,12 +127,12 @@
   /**
    * The 'bindPasswordFile' argument for the second server.
    */
-  private FileBasedArgument bindPasswordFile2Arg = null;
+  FileBasedArgument bindPasswordFile2Arg = null;
 
   /**
    * The 'bindPassword' argument for the second server.
    */
-  private StringArgument bindPassword2Arg = null;
+  StringArgument bindPassword2Arg = null;
 
   /**
    * The 'replicationPort' argument for the second server.
@@ -148,7 +152,7 @@
   /**
    * The 'noSchemaReplication' argument to not replicate schema.
    */
-  private BooleanArgument noSchemaReplicationArg;
+  BooleanArgument noSchemaReplicationArg;
 
   /**
    * The 'useSecondServerAsSchemaSource' argument to not replicate schema.
@@ -189,12 +193,34 @@
   /**
    * The 'quiet' argument.
    */
-  private BooleanArgument quietArg;
+  BooleanArgument quietArg;
 
   /**
    * The 'scriptFriendly' argument.
    */
-  private BooleanArgument scriptFriendlyArg;
+  BooleanArgument scriptFriendlyArg;
+
+  /**
+   * Properties file argument.
+   */
+  StringArgument propertiesFileArgument;
+
+  /**
+   * No-properties file argument.
+   */
+  BooleanArgument noPropertiesFileArgument;
+
+  /**
+   * The argument that the user must set to display the equivalent
+   * non-interactive mode argument.
+   */
+  BooleanArgument displayEquivalentArgument;
+
+  /**
+   * The argument that allows the user to dump the equivalent non-interactive
+   * command to a file.
+   */
+  StringArgument equivalentCommandFileArgument;
 
   /**
    * The text of the enable replication subcommand.
@@ -307,6 +333,28 @@
       errors.add(message);
     }
 
+    // Check that we can write on the provided path where we write the
+    // equivalent non-interactive commands.
+    if (equivalentCommandFileArgument.isPresent())
+    {
+      String file = equivalentCommandFileArgument.getValue();
+      if (!Utils.canWrite(file))
+      {
+        errors.add(
+            ERR_REPLICATION_CANNOT_WRITE_EQUIVALENT_COMMAND_LINE_FILE.get(
+                file));
+      }
+      else
+      {
+        File f = new File(file);
+        if (f.isDirectory())
+        {
+          errors.add(
+              ERR_REPLICATION_EQUIVALENT_COMMAND_LINE_FILE_DIRECTORY.get(file));
+        }
+      }
+    }
+
     if (!isInteractive())
     {
       // Check that we have the required data
@@ -379,8 +427,8 @@
     {
       defaultArgs.remove(argsToRemove[i]);
     }
-    defaultArgs.remove(noPropertiesFileArg);
-    defaultArgs.remove(propertiesFileArg);
+    defaultArgs.remove(super.noPropertiesFileArg);
+    defaultArgs.remove(super.propertiesFileArg);
     // Remove it from the default location and redefine it.
     defaultArgs.remove(secureArgsList.adminUidArg);
 
@@ -394,11 +442,12 @@
     defaultArgs.add(index++, baseDNsArg);
 
     secureArgsList.adminUidArg = new StringArgument("adminUID", 'I',
-        "adminUID", false, false, true, INFO_ADMINUID_PLACEHOLDER.get(),
+        OPTION_LONG_ADMIN_UID, false, false, true,
+        INFO_ADMINUID_PLACEHOLDER.get(),
         Constants.GLOBAL_ADMIN_UID, null,
         INFO_DESCRIPTION_REPLICATION_ADMIN_UID.get(
             ENABLE_REPLICATION_SUBCMD_NAME));
-    secureArgsList.adminUidArg.setPropertyName("adminUID");
+    secureArgsList.adminUidArg.setPropertyName(OPTION_LONG_ADMIN_UID);
     secureArgsList.adminUidArg.setHidden(false);
     defaultArgs.add(index++, secureArgsList.adminUidArg);
 
@@ -416,6 +465,14 @@
     defaultArgs.add(index++, secureArgsList.bindPasswordFileArg);
 
     defaultArgs.remove(verboseArg);
+
+    quietArg = new BooleanArgument(
+        OPTION_LONG_QUIET,
+        OPTION_SHORT_QUIET,
+        OPTION_LONG_QUIET,
+        INFO_REPLICATION_DESCRIPTION_QUIET.get());
+    defaultArgs.add(index++, quietArg);
+
     noPromptArg = new BooleanArgument(
         OPTION_LONG_NO_PROMPT,
         OPTION_SHORT_NO_PROMPT,
@@ -423,32 +480,37 @@
         INFO_DESCRIPTION_NO_PROMPT.get());
     defaultArgs.add(index++, noPromptArg);
 
+    displayEquivalentArgument = new BooleanArgument(
+        OPTION_DSCFG_LONG_DISPLAY_EQUIVALENT,
+        null, OPTION_DSCFG_LONG_DISPLAY_EQUIVALENT,
+        INFO_REPLICATION_DESCRIPTION_DISPLAY_EQUIVALENT.get());
+    defaultArgs.add(index++, displayEquivalentArgument);
+
+    equivalentCommandFileArgument = new StringArgument(
+        OPTION_LONG_EQUIVALENT_COMMAND_FILE_PATH, null,
+        OPTION_LONG_EQUIVALENT_COMMAND_FILE_PATH, false, false, true,
+        INFO_PATH_PLACEHOLDER.get(), null, null,
+        INFO_REPLICATION_DESCRIPTION_EQUIVALENT_COMMAND_FILE_PATH.get());
+    defaultArgs.add(index++, equivalentCommandFileArgument);
+
     for (int i=0; i<index; i++)
     {
       Argument arg = defaultArgs.get(i);
       arg.setPropertyName(arg.getLongIdentifier());
     }
 
-    quietArg = new BooleanArgument(
-        OPTION_LONG_QUIET,
-        OPTION_SHORT_QUIET,
-        OPTION_LONG_QUIET,
-        INFO_REPLICATION_DESCRIPTION_QUIET.get());
-    quietArg.setPropertyName(OPTION_LONG_QUIET);
-    defaultArgs.add(quietArg);
-
-    StringArgument propertiesFileArgument = new StringArgument(
+    this.propertiesFileArgument = new StringArgument(
         "propertiesFilePath", null, OPTION_LONG_PROP_FILE_PATH, false, false,
         true, INFO_PROP_FILE_PATH_PLACEHOLDER.get(), null, null,
         INFO_DESCRIPTION_PROP_FILE_PATH.get());
-    defaultArgs.add(propertiesFileArgument);
-    setFilePropertiesArgument(propertiesFileArgument);
+    defaultArgs.add(this.propertiesFileArgument);
+    setFilePropertiesArgument(this.propertiesFileArgument);
 
-    BooleanArgument noPropertiesFileArgument = new BooleanArgument(
+    this.noPropertiesFileArgument = new BooleanArgument(
         "noPropertiesFileArgument", null, OPTION_LONG_NO_PROP_FILE,
         INFO_DESCRIPTION_NO_PROP_FILE.get());
-    defaultArgs.add(noPropertiesFileArgument);
-    setNoPropertiesFileArgument(noPropertiesFileArgument);
+    defaultArgs.add(this.noPropertiesFileArgument);
+    setNoPropertiesFileArgument(this.noPropertiesFileArgument);
 
     initializeGlobalArguments(defaultArgs);
   }
@@ -467,7 +529,7 @@
         null, INFO_DESCRIPTION_ENABLE_REPLICATION_HOST1.get());
 
     port1Arg = new IntegerArgument("port1", OPTION_SHORT_PORT, "port1",
-        false, false, true, INFO_PORT_PLACEHOLDER.get(), 389, null,
+        false, false, true, INFO_PORT_PLACEHOLDER.get(), 4444, null,
         INFO_DESCRIPTION_ENABLE_REPLICATION_SERVER_PORT1.get());
 
     bindDn1Arg = new StringArgument("bindDN1", OPTION_SHORT_BINDDN,
@@ -500,7 +562,7 @@
         null, INFO_DESCRIPTION_ENABLE_REPLICATION_HOST2.get());
 
     port2Arg = new IntegerArgument("port2", null, "port2",
-        false, false, true, INFO_PORT_PLACEHOLDER.get(), 389, null,
+        false, false, true, INFO_PORT_PLACEHOLDER.get(), 4444, null,
         INFO_DESCRIPTION_ENABLE_REPLICATION_SERVER_PORT2.get());
 
     bindDn2Arg = new StringArgument("bindDN2", null,
@@ -597,7 +659,7 @@
         INFO_DESCRIPTION_INITIALIZE_REPLICATION_HOST_SOURCE.get());
 
     portSourceArg = new IntegerArgument("portSource", OPTION_SHORT_PORT,
-        "portSource", false, false, true, INFO_PORT_PLACEHOLDER.get(), 389,
+        "portSource", false, false, true, INFO_PORT_PLACEHOLDER.get(), 4444,
         null,
         INFO_DESCRIPTION_INITIALIZE_REPLICATION_SERVER_PORT_SOURCE.get());
 
@@ -607,7 +669,8 @@
         INFO_DESCRIPTION_INITIALIZE_REPLICATION_HOST_DESTINATION.get());
 
     portDestinationArg = new IntegerArgument("portDestination", null,
-        "portDestination", false, false, true, INFO_PORT_PLACEHOLDER.get(), 389,
+        "portDestination", false, false, true, INFO_PORT_PLACEHOLDER.get(),
+        4444,
         null,
         INFO_DESCRIPTION_INITIALIZE_REPLICATION_SERVER_PORT_DESTINATION.get());
 
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java b/opendj-sdk/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java
index 97e2d0b..ff0ead3 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java
@@ -32,9 +32,13 @@
 import static org.opends.messages.ToolMessages.*;
 import static org.opends.quicksetup.util.Utils.getFirstValue;
 import static org.opends.quicksetup.util.Utils.getThrowableMsg;
+import static org.opends.server.tools.ToolConstants.*;
 import static org.opends.server.tools.dsreplication.ReplicationCliReturnCode.*;
 
+import java.io.BufferedWriter;
 import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PrintStream;
@@ -44,6 +48,7 @@
 import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.Map;
@@ -113,9 +118,16 @@
 import org.opends.server.types.InitializationException;
 import org.opends.server.types.NullOutputStream;
 import org.opends.server.types.OpenDsException;
+import org.opends.server.util.ServerConstants;
 import org.opends.server.util.SetupUtils;
+import org.opends.server.util.args.Argument;
 import org.opends.server.util.args.ArgumentException;
+import org.opends.server.util.args.BooleanArgument;
+import org.opends.server.util.args.FileBasedArgument;
+import org.opends.server.util.args.IntegerArgument;
+import org.opends.server.util.args.StringArgument;
 import org.opends.server.util.cli.CLIException;
+import org.opends.server.util.cli.CommandBuilder;
 import org.opends.server.util.cli.ConsoleApplication;
 import org.opends.server.util.cli.LDAPConnectionConsoleInteraction;
 import org.opends.server.util.cli.MenuBuilder;
@@ -204,7 +216,9 @@
 
   // The argument parser to be used.
   private ReplicationCliArgumentParser argParser;
+  private FileBasedArgument userProvidedAdminPwdFile;
   private LDAPConnectionConsoleInteraction ci = null;
+  private CommandBuilder firstServerCommandBuilder;
   // The message formatter
   PlainTextProgressMessageFormatter formatter =
       new PlainTextProgressMessageFormatter();
@@ -388,6 +402,25 @@
 
       if (returnValue == SUCCESSFUL_NOP)
       {
+        if (argParser.getSecureArgsList().
+        bindPasswordFileArg.isPresent())
+        {
+          try
+          {
+            userProvidedAdminPwdFile = new FileBasedArgument(
+                "adminPasswordFile",
+                OPTION_SHORT_BINDPWD_FILE, "adminPasswordFile", false, false,
+                INFO_BINDPWD_FILE_PLACEHOLDER.get(), null, null,
+                INFO_DESCRIPTION_REPLICATION_ADMIN_BINDPASSWORDFILE.get());
+            userProvidedAdminPwdFile.getNameToValueMap().putAll(
+                argParser.getSecureArgsList().
+                bindPasswordFileArg.getNameToValueMap());
+          }
+          catch (Throwable t)
+          {
+            throw new IllegalStateException("Unexpected error: "+t, t);
+          }
+        }
         ci = new LDAPConnectionConsoleInteraction(this,
             argParser.getSecureArgsList());
         ci.setDisplayLdapIfSecureParameters(
@@ -775,23 +808,33 @@
     int port1 = argParser.getPort1();
     String bindDn1 = argParser.getBindDn1();
     String pwd1 = argParser.getBindPassword1();
-
     String pwd = null;
-    if (pwd1 != null)
+    LinkedHashMap<String, String> pwdFile = null;
+    if (argParser.bindPassword1Arg.isPresent())
     {
-      pwd = pwd1;
+      pwd = argParser.bindPassword1Arg.getValue();
     }
-    else if (bindDn1 != null)
+    else if (argParser.bindPasswordFile1Arg.isPresent())
     {
-      pwd = null;
+      pwdFile = argParser.bindPasswordFile1Arg.getNameToValueMap();
     }
-    else
+    else if (bindDn1 == null)
     {
       pwd = adminPwd;
+      if (argParser.getSecureArgsList().bindPasswordFileArg.isPresent())
+      {
+        pwdFile = argParser.getSecureArgsList().bindPasswordFileArg.
+          getNameToValueMap();
+      }
     }
 
+    /*
+     * Use a copy of the argument properties since the map might be cleared
+     * in initializeGlobalArguments.
+     */
     initializeGlobalArguments(host1, port1, adminUid,
-        bindDn1, pwd);
+        bindDn1, pwd,
+        pwdFile == null ? null : new LinkedHashMap<String, String>(pwdFile));
     InitialLdapContext ctx1 = null;
 
     while ((ctx1 == null) && !cancelled)
@@ -931,6 +974,11 @@
     }
     uData.setReplicationPort1(replicationPort1);
     uData.setSecureReplication1(secureReplication1);
+    firstServerCommandBuilder = new CommandBuilder(null);
+    if (mustPrintCommandBuilder())
+    {
+      firstServerCommandBuilder.append(ci.getCommandBuilder());
+    }
 
     /*
      * Prompt for information on the second server.
@@ -946,21 +994,34 @@
       port2 = argParser.getPort2();
       bindDn2 = argParser.getBindDn2();
       pwd2 = argParser.getBindPassword2();
-      if (pwd2 != null)
+
+      pwdFile = null;
+      pwd = null;
+      if (argParser.bindPassword2Arg.isPresent())
       {
-        pwd = pwd2;
+        pwd = argParser.bindPassword2Arg.getValue();
       }
-      else if (bindDn2 != null)
+      else if (argParser.bindPasswordFile2Arg.isPresent())
       {
-        pwd = null;
+        pwdFile = argParser.bindPasswordFile2Arg.getNameToValueMap();
       }
-      else
+      else if (bindDn2 == null)
       {
         pwd = adminPwd;
+        if (argParser.getSecureArgsList().bindPasswordFileArg.isPresent())
+        {
+          pwdFile = argParser.getSecureArgsList().bindPasswordFileArg.
+            getNameToValueMap();
+        }
       }
 
+      /*
+       * Use a copy of the argument properties since the map might be cleared
+       * in initializeGlobalArguments.
+       */
       initializeGlobalArguments(host2, port2, adminUid,
-          bindDn2, pwd);
+          bindDn2, pwd,
+          pwdFile == null ? null : new LinkedHashMap<String, String>(pwdFile));
     }
     InitialLdapContext ctx2 = null;
 
@@ -1863,7 +1924,22 @@
     String hostSource = argParser.getHostNameSource();
     int portSource = argParser.getPortSource();
 
-    initializeGlobalArguments(hostSource, portSource, adminUid, null, adminPwd);
+    LinkedHashMap<String, String> pwdFile = null;
+
+    if (argParser.getSecureArgsList().bindPasswordFileArg.isPresent())
+    {
+      pwdFile =
+        argParser.getSecureArgsList().bindPasswordFileArg.
+        getNameToValueMap();
+    }
+
+
+    /*
+     * Use a copy of the argument properties since the map might be cleared
+     * in initializeGlobalArguments.
+     */
+    initializeGlobalArguments(hostSource, portSource, adminUid, null, adminPwd,
+        pwdFile == null ? null : new LinkedHashMap<String, String>(pwdFile));
     /*
      * Try to connect to the source server.
      */
@@ -1913,12 +1989,23 @@
       uData.setAdminPwd(adminPwd);
     }
 
+    firstServerCommandBuilder = new CommandBuilder(null);
+    if (mustPrintCommandBuilder())
+    {
+      firstServerCommandBuilder.append(ci.getCommandBuilder());
+    }
+
     /* Prompt for destination server credentials */
     String hostDestination = argParser.getHostNameDestination();
     int portDestination = argParser.getPortDestination();
 
+    /*
+     * Use a copy of the argument properties since the map might be cleared
+     * in initializeGlobalArguments.
+     */
     initializeGlobalArguments(hostDestination, portDestination,
-        adminUid, null, adminPwd);
+        adminUid, null, adminPwd,
+        pwdFile == null ? null : new LinkedHashMap<String, String>(pwdFile));
     /*
      * Try to connect to the destination server.
      */
@@ -2899,6 +2986,7 @@
       EnableReplicationUserData uData)
   {
     ReplicationCliReturnCode returnValue = SUCCESSFUL_NOP;
+
     InitialLdapContext ctx1 = null;
     InitialLdapContext ctx2 = null;
 
@@ -3016,6 +3104,22 @@
       if (!suffixes.isEmpty())
       {
         uData.setBaseDNs(suffixes);
+
+        if (mustPrintCommandBuilder())
+        {
+          try
+          {
+            CommandBuilder commandBuilder = createCommandBuilder(
+                ReplicationCliArgumentParser.ENABLE_REPLICATION_SUBCMD_NAME,
+                uData);
+            printCommandBuilder(commandBuilder);
+          }
+          catch (Throwable t)
+          {
+            LOG.log(Level.SEVERE, "Error printing equivalente command-line: "+t,
+                t);
+          }
+        }
         try
         {
           updateConfiguration(ctx1, ctx2, uData);
@@ -3130,6 +3234,21 @@
       if (!suffixes.isEmpty())
       {
         uData.setBaseDNs(suffixes);
+        if (mustPrintCommandBuilder())
+        {
+          try
+          {
+            CommandBuilder commandBuilder = createCommandBuilder(
+                ReplicationCliArgumentParser.DISABLE_REPLICATION_SUBCMD_NAME,
+                uData);
+            printCommandBuilder(commandBuilder);
+          }
+          catch (Throwable t)
+          {
+            LOG.log(Level.SEVERE, "Error printing equivalente command-line: "+t,
+                t);
+          }
+        }
         try
         {
           updateConfiguration(ctx, uData);
@@ -3282,6 +3401,23 @@
           false);
       if (!baseDNs.isEmpty())
       {
+        if (mustPrintCommandBuilder())
+        {
+          try
+          {
+            uData.setBaseDNs(baseDNs);
+            CommandBuilder commandBuilder = createCommandBuilder(
+                ReplicationCliArgumentParser.INITIALIZE_REPLICATION_SUBCMD_NAME,
+                uData);
+            printCommandBuilder(commandBuilder);
+          }
+          catch (Throwable t)
+          {
+            LOG.log(Level.SEVERE, "Error printing equivalente command-line: "+t,
+                t);
+          }
+        }
+
         for (String baseDN : baseDNs)
         {
           try
@@ -3371,6 +3507,22 @@
       checkSuffixesForInitializeReplication(baseDNs, ctx, false);
       if (!baseDNs.isEmpty())
       {
+        if (mustPrintCommandBuilder())
+        {
+          uData.setBaseDNs(baseDNs);
+          try
+          {
+            CommandBuilder commandBuilder = createCommandBuilder(
+            ReplicationCliArgumentParser.INITIALIZE_ALL_REPLICATION_SUBCMD_NAME,
+            uData);
+            printCommandBuilder(commandBuilder);
+          }
+          catch (Throwable t)
+          {
+            LOG.log(Level.SEVERE, "Error printing equivalente command-line: "+t,
+                t);
+          }
+        }
         for (String baseDN : baseDNs)
         {
           try
@@ -3451,6 +3603,22 @@
       checkSuffixesForInitializeReplication(baseDNs, ctx, false);
       if (!baseDNs.isEmpty())
       {
+        if (mustPrintCommandBuilder())
+        {
+          uData.setBaseDNs(baseDNs);
+          try
+          {
+            CommandBuilder commandBuilder = createCommandBuilder(
+           ReplicationCliArgumentParser.PRE_EXTERNAL_INITIALIZATION_SUBCMD_NAME,
+            uData);
+            printCommandBuilder(commandBuilder);
+          }
+          catch (Throwable t)
+          {
+            LOG.log(Level.SEVERE, "Error printing equivalente command-line: "+t,
+                t);
+          }
+        }
         for (String baseDN : baseDNs)
         {
           try
@@ -3550,6 +3718,22 @@
       checkSuffixesForInitializeReplication(baseDNs, ctx, false);
       if (!baseDNs.isEmpty())
       {
+        if (mustPrintCommandBuilder())
+        {
+          uData.setBaseDNs(baseDNs);
+          try
+          {
+            CommandBuilder commandBuilder = createCommandBuilder(
+          ReplicationCliArgumentParser.POST_EXTERNAL_INITIALIZATION_SUBCMD_NAME,
+            uData);
+            printCommandBuilder(commandBuilder);
+          }
+          catch (Throwable t)
+          {
+            LOG.log(Level.SEVERE, "Error printing equivalente command-line: "+t,
+                t);
+          }
+        }
         for (String baseDN : baseDNs)
         {
           try
@@ -5097,6 +5281,21 @@
           ERR_REPLICATION_READING_ADS.get(tce.getMessage()),
           ERROR_READING_TOPOLOGY_CACHE, tce);
     }
+    if (mustPrintCommandBuilder())
+    {
+      try
+      {
+        CommandBuilder commandBuilder = createCommandBuilder(
+            ReplicationCliArgumentParser.STATUS_REPLICATION_SUBCMD_NAME,
+            uData);
+        printCommandBuilder(commandBuilder);
+      }
+      catch (Throwable t)
+      {
+        LOG.log(Level.SEVERE, "Error printing equivalente command-line: "+t,
+            t);
+      }
+    }
     if (!argParser.isInteractive())
     {
       // Inform the user of the potential errors that we found.
@@ -7326,6 +7525,8 @@
     argParser.getSecureArgsList().bindPasswordArg.clearValues();
     argParser.getSecureArgsList().bindPasswordArg.setPresent(false);
     argParser.getSecureArgsList().bindPasswordFileArg.clearValues();
+    argParser.getSecureArgsList().bindPasswordFileArg.getNameToValueMap().
+    clear();
     argParser.getSecureArgsList().bindPasswordFileArg.setPresent(false);
     argParser.getSecureArgsList().adminUidArg.clearValues();
     argParser.getSecureArgsList().adminUidArg.setPresent(false);
@@ -7336,7 +7537,7 @@
    */
   private void initializeGlobalArguments(String hostName, int port,
       String adminUid, String bindDn,
-      String bindPwd)
+      String bindPwd, LinkedHashMap<String, String> pwdFile)
   {
     resetConnectionArguments();
     if (hostName != null)
@@ -7369,7 +7570,17 @@
       argParser.getSecureArgsList().bindDnArg.addValue(bindDn);
       argParser.getSecureArgsList().bindDnArg.setPresent(true);
     }
-    if (bindPwd != null)
+    if (pwdFile != null)
+    {
+      argParser.getSecureArgsList().bindPasswordFileArg.getNameToValueMap().
+      putAll(pwdFile);
+      for (String value : pwdFile.keySet())
+      {
+        argParser.getSecureArgsList().bindPasswordFileArg.addValue(value);
+      }
+      argParser.getSecureArgsList().bindPasswordFileArg.setPresent(true);
+    }
+    else if (bindPwd != null)
     {
       argParser.getSecureArgsList().bindPasswordArg.addValue(bindPwd);
       argParser.getSecureArgsList().bindPasswordArg.setPresent(true);
@@ -7617,4 +7828,646 @@
     }
     return returnValue;
   }
+
+  private boolean mustPrintCommandBuilder()
+  {
+    return argParser.isInteractive() &&
+        (argParser.displayEquivalentArgument.isPresent() ||
+        argParser.equivalentCommandFileArgument.isPresent());
+  }
+
+  /**
+   * Prints the contents of a command builder.  This method has been created
+   * since SetPropSubCommandHandler calls it.  All the logic of DSConfig is on
+   * this method.  Currently it simply writes the content of the CommandBuilder
+   * to the standard output, but if we provide an option to write the content
+   * to a file only the implementation of this method must be changed.
+   * @param commandBuilder the command builder to be printed.
+   */
+  private void printCommandBuilder(CommandBuilder commandBuilder)
+  {
+    if (argParser.displayEquivalentArgument.isPresent())
+    {
+      println();
+      // We assume that the app we are running is this one.
+      println(
+          INFO_REPLICATION_NON_INTERACTIVE.get(commandBuilder.toString()));
+    }
+    if (argParser.equivalentCommandFileArgument.isPresent())
+    {
+      // Write to the file.
+      String file = argParser.equivalentCommandFileArgument.getValue();
+      try
+      {
+        BufferedWriter writer =
+          new BufferedWriter(new FileWriter(file, false));
+        writer.write(commandBuilder.toString());
+        writer.newLine();
+
+        writer.flush();
+        writer.close();
+      }
+      catch (IOException ioe)
+      {
+        println(
+            ERR_REPLICATION_ERROR_WRITING_EQUIVALENT_COMMAND_LINE.get(file,
+                ioe.toString()));
+      }
+    }
+  }
+
+  /**
+   * Creates a command builder with the global options: script friendly,
+   * verbose, etc. for a given subcommand name.  It also adds systematically the
+   * no-prompt option.
+   * @param subcommandName the subcommand name.
+   * @param uData the user data.
+   * @return the command builder that has been created with the specified
+   * subcommandName.
+   */
+  private CommandBuilder createCommandBuilder(String subcommandName,
+      ReplicationUserData uData) throws ArgumentException
+  {
+    String commandName =
+      System.getProperty(ServerConstants.PROPERTY_SCRIPT_NAME);
+    if (commandName == null)
+    {
+      commandName = "dsreplication";
+    }
+
+    CommandBuilder commandBuilder =
+      new CommandBuilder(commandName, subcommandName);
+
+
+    if (subcommandName.equals(
+            ReplicationCliArgumentParser.ENABLE_REPLICATION_SUBCMD_NAME))
+    {
+      // All the arguments for enable replication are update here.
+      updateCommandBuilder(commandBuilder, (EnableReplicationUserData)uData);
+    }
+    else if (subcommandName.equals(
+            ReplicationCliArgumentParser.INITIALIZE_REPLICATION_SUBCMD_NAME))
+    {
+      // All the arguments for initialize replication are update here.
+      updateCommandBuilder(commandBuilder,
+          (InitializeReplicationUserData)uData);
+    }
+    else
+    {
+      // Update the arguments used in the console interaction with the
+      // actual arguments of dsreplication.
+      if ((ci != null) && (ci.getCommandBuilder() != null))
+      {
+        CommandBuilder interactionBuilder = ci.getCommandBuilder();
+        for (Argument arg : interactionBuilder.getArguments())
+        {
+          if (arg.getLongIdentifier().equals(OPTION_LONG_BINDPWD))
+          {
+            StringArgument bindPasswordArg = new StringArgument("adminPassword",
+                OPTION_SHORT_BINDPWD, "adminPassword", false, false, true,
+                INFO_BINDPWD_PLACEHOLDER.get(), null, null,
+                INFO_DESCRIPTION_REPLICATION_ADMIN_BINDPASSWORD.get());
+            bindPasswordArg.addValue(arg.getValue());
+            commandBuilder.addObfuscatedArgument(bindPasswordArg);
+          }
+          else if (arg.getLongIdentifier().equals(OPTION_LONG_BINDPWD_FILE))
+          {
+            FileBasedArgument bindPasswordFileArg = new FileBasedArgument(
+                "adminPasswordFile",
+                OPTION_SHORT_BINDPWD_FILE, "adminPasswordFile", false, false,
+                INFO_BINDPWD_FILE_PLACEHOLDER.get(), null, null,
+                INFO_DESCRIPTION_REPLICATION_ADMIN_BINDPASSWORDFILE.get());
+            bindPasswordFileArg.getNameToValueMap().putAll(
+                ((FileBasedArgument)arg).getNameToValueMap());
+            commandBuilder.addArgument(bindPasswordFileArg);
+          }
+          else
+          {
+            if (interactionBuilder.isObfuscated(arg))
+            {
+              commandBuilder.addObfuscatedArgument(arg);
+            }
+            else
+            {
+              commandBuilder.addArgument(arg);
+            }
+          }
+        }
+      }
+    }
+
+    addGlobalArguments(commandBuilder, uData);
+    return commandBuilder;
+  }
+
+  private void addGlobalArguments(CommandBuilder commandBuilder,
+      ReplicationUserData uData)
+  throws ArgumentException
+  {
+    LinkedList<String> baseDNs = uData.getBaseDNs();
+    StringArgument baseDNsArg = new StringArgument("baseDNs",
+        OPTION_SHORT_BASEDN,
+        OPTION_LONG_BASEDN, false, true, true, INFO_BASEDN_PLACEHOLDER.get(),
+        null,
+        null, INFO_DESCRIPTION_REPLICATION_BASEDNS.get());
+    for (String baseDN : baseDNs)
+    {
+      baseDNsArg.addValue(baseDN);
+    }
+    commandBuilder.addArgument(baseDNsArg);
+
+    // Try to find some arguments and put them at the end.
+    String[] identifiersToMove ={
+        OPTION_LONG_ADMIN_UID,
+        "adminPassword",
+        "adminPasswordFile",
+        OPTION_LONG_SASLOPTION,
+        OPTION_LONG_TRUSTALL,
+        OPTION_LONG_TRUSTSTOREPATH,
+        OPTION_LONG_TRUSTSTORE_PWD,
+        OPTION_LONG_TRUSTSTORE_PWD_FILE,
+        OPTION_LONG_KEYSTOREPATH,
+        OPTION_LONG_KEYSTORE_PWD,
+        OPTION_LONG_KEYSTORE_PWD_FILE,
+        OPTION_LONG_CERT_NICKNAME
+    };
+
+    ArrayList<Argument> toMoveArgs = new ArrayList<Argument>();
+    for (String longID : identifiersToMove)
+    {
+      for (Argument arg : commandBuilder.getArguments())
+      {
+        if (longID.equals(arg.getLongIdentifier()))
+        {
+          toMoveArgs.add(arg);
+          break;
+        }
+      }
+    }
+    for (Argument argToMove : toMoveArgs)
+    {
+      boolean toObfuscate = commandBuilder.isObfuscated(argToMove);
+      commandBuilder.removeArgument(argToMove);
+      if (toObfuscate)
+      {
+        commandBuilder.addObfuscatedArgument(argToMove);
+      }
+      else
+      {
+        commandBuilder.addArgument(argToMove);
+      }
+    }
+
+    if (argParser.isVerbose())
+    {
+      commandBuilder.addArgument(new BooleanArgument("verbose",
+          OPTION_SHORT_VERBOSE,
+          OPTION_LONG_VERBOSE, INFO_DESCRIPTION_VERBOSE.get()));
+    }
+
+    if (argParser.isScriptFriendly())
+    {
+      commandBuilder.addArgument(argParser.scriptFriendlyArg);
+    }
+
+    commandBuilder.addArgument(argParser.noPromptArg);
+
+    if (argParser.propertiesFileArgument.isPresent())
+    {
+      commandBuilder.addArgument(argParser.propertiesFileArgument);
+    }
+
+    if (argParser.noPropertiesFileArgument.isPresent())
+    {
+      commandBuilder.addArgument(argParser.noPropertiesFileArgument);
+    }
+  }
+
+  private void updateCommandBuilder(CommandBuilder commandBuilder,
+      EnableReplicationUserData uData)
+  throws ArgumentException
+  {
+    // Update the arguments used in the console interaction with the
+    // actual arguments of dsreplication.
+    boolean adminInformationAdded = false;
+
+    if (firstServerCommandBuilder != null)
+    {
+      boolean useAdminUID = false;
+      for (Argument arg : firstServerCommandBuilder.getArguments())
+      {
+        if (arg.getLongIdentifier().equals(OPTION_LONG_ADMIN_UID))
+        {
+          useAdminUID = true;
+          break;
+        }
+      }
+      for (Argument arg : firstServerCommandBuilder.getArguments())
+      {
+        if (arg.getLongIdentifier().equals(OPTION_LONG_HOST))
+        {
+          StringArgument host = new StringArgument("host1", OPTION_SHORT_HOST,
+              "host1", false, false, true, INFO_HOST_PLACEHOLDER.get(),
+              null,
+              null, INFO_DESCRIPTION_ENABLE_REPLICATION_HOST1.get());
+          host.addValue(uData.getHostName1());
+          commandBuilder.addArgument(host);
+        }
+        else if (arg.getLongIdentifier().equals(OPTION_LONG_PORT))
+        {
+          IntegerArgument port = new IntegerArgument("port1", OPTION_SHORT_PORT,
+              "port1",
+              false, false, true, INFO_PORT_PLACEHOLDER.get(), 4444, null,
+              INFO_DESCRIPTION_ENABLE_REPLICATION_SERVER_PORT1.get());
+          port.addValue(String.valueOf(uData.getPort1()));
+          commandBuilder.addArgument(port);
+        }
+        else if (arg.getLongIdentifier().equals(OPTION_LONG_BINDDN))
+        {
+          StringArgument bindDN = new StringArgument("bindDN1",
+              OPTION_SHORT_BINDDN,
+              "bindDN1", false, false, true, INFO_BINDDN_PLACEHOLDER.get(),
+              "cn=Directory Manager", null,
+              INFO_DESCRIPTION_ENABLE_REPLICATION_BINDDN1.get());
+          bindDN.addValue(uData.getBindDn1());
+          commandBuilder.addArgument(bindDN);
+        }
+        else if (arg.getLongIdentifier().equals(OPTION_LONG_BINDPWD))
+        {
+          if (useAdminUID)
+          {
+            adminInformationAdded = true;
+            StringArgument bindPasswordArg = new StringArgument("adminPassword",
+                OPTION_SHORT_BINDPWD, "adminPassword", false, false, true,
+                INFO_BINDPWD_PLACEHOLDER.get(), null, null,
+                INFO_DESCRIPTION_REPLICATION_ADMIN_BINDPASSWORD.get());
+            bindPasswordArg.addValue(arg.getValue());
+            commandBuilder.addObfuscatedArgument(bindPasswordArg);
+          }
+          else
+          {
+            StringArgument bindPasswordArg = new StringArgument("bindPassword1",
+                null, "bindPassword1", false, false, true,
+                INFO_BINDPWD_PLACEHOLDER.get(), null, null,
+                INFO_DESCRIPTION_ENABLE_REPLICATION_BINDPASSWORD1.get());
+            bindPasswordArg.addValue(arg.getValue());
+            commandBuilder.addObfuscatedArgument(bindPasswordArg);
+          }
+        }
+        else if (arg.getLongIdentifier().equals(OPTION_LONG_BINDPWD_FILE))
+        {
+          if (useAdminUID)
+          {
+            FileBasedArgument bindPasswordFileArg = new FileBasedArgument(
+                "adminPasswordFile",
+                OPTION_SHORT_BINDPWD_FILE, "adminPasswordFile", false, false,
+                INFO_BINDPWD_FILE_PLACEHOLDER.get(), null, null,
+                INFO_DESCRIPTION_REPLICATION_ADMIN_BINDPASSWORDFILE.get());
+            bindPasswordFileArg.getNameToValueMap().putAll(
+                ((FileBasedArgument)arg).getNameToValueMap());
+            commandBuilder.addArgument(bindPasswordFileArg);
+          }
+          else
+          {
+            FileBasedArgument bindPasswordFileArg = new FileBasedArgument(
+                "bindPasswordFile1",
+                null, "bindPasswordFile1", false, false,
+                INFO_BINDPWD_FILE_PLACEHOLDER.get(), null, null,
+                INFO_DESCRIPTION_ENABLE_REPLICATION_BINDPASSWORDFILE1.get());
+            bindPasswordFileArg.getNameToValueMap().putAll(
+                ((FileBasedArgument)arg).getNameToValueMap());
+            commandBuilder.addArgument(bindPasswordFileArg);
+          }
+        }
+        else
+        {
+          if (arg.getLongIdentifier().equals(OPTION_LONG_ADMIN_UID))
+          {
+            adminInformationAdded = true;
+          }
+          if (firstServerCommandBuilder.isObfuscated(arg))
+          {
+            commandBuilder.addObfuscatedArgument(arg);
+          }
+          else
+          {
+            commandBuilder.addArgument(arg);
+          }
+        }
+      }
+    }
+
+
+    if ((ci != null) && (ci.getCommandBuilder() != null))
+    {
+      CommandBuilder interactionBuilder = ci.getCommandBuilder();
+      boolean useAdminUID = false;
+      boolean hasBindDN = false;
+      for (Argument arg : interactionBuilder.getArguments())
+      {
+        if (arg.getLongIdentifier().equals(OPTION_LONG_ADMIN_UID))
+        {
+          useAdminUID = true;
+        }
+        else if (arg.getLongIdentifier().equals(OPTION_LONG_BINDDN))
+        {
+          hasBindDN = true;
+        }
+        if (useAdminUID && hasBindDN)
+        {
+          break;
+        }
+      }
+      ArrayList<Argument> argsToAnalyze = new ArrayList<Argument>();
+      for (Argument arg : interactionBuilder.getArguments())
+      {
+        if (arg.getLongIdentifier().equals(OPTION_LONG_HOST))
+        {
+          StringArgument host = new StringArgument("host2", 'O',
+              "host2", false, false, true, INFO_HOST_PLACEHOLDER.get(),
+              null,
+              null, INFO_DESCRIPTION_ENABLE_REPLICATION_HOST2.get());
+          host.addValue(uData.getHostName2());
+          commandBuilder.addArgument(host);
+        }
+        else if (arg.getLongIdentifier().equals(OPTION_LONG_PORT))
+        {
+          IntegerArgument port = new IntegerArgument("port2", null, "port2",
+              false, false, true, INFO_PORT_PLACEHOLDER.get(), 4444, null,
+              INFO_DESCRIPTION_ENABLE_REPLICATION_SERVER_PORT2.get());
+          port.addValue(String.valueOf(uData.getPort2()));
+          commandBuilder.addArgument(port);
+        }
+        else if (arg.getLongIdentifier().equals(OPTION_LONG_BINDDN))
+        {
+          StringArgument bindDN = new StringArgument("bindDN2", null,
+              "bindDN2", false, false, true, INFO_BINDDN_PLACEHOLDER.get(),
+              "cn=Directory Manager", null,
+              INFO_DESCRIPTION_ENABLE_REPLICATION_BINDDN2.get());
+          bindDN.addValue(uData.getBindDn2());
+          commandBuilder.addArgument(bindDN);
+        }
+        else if (arg.getLongIdentifier().equals(OPTION_LONG_BINDPWD))
+        {
+          if (useAdminUID && !adminInformationAdded)
+          {
+            adminInformationAdded = true;
+            StringArgument bindPasswordArg = new StringArgument("adminPassword",
+                OPTION_SHORT_BINDPWD, "adminPassword", false, false, true,
+                INFO_BINDPWD_PLACEHOLDER.get(), null, null,
+                INFO_DESCRIPTION_REPLICATION_ADMIN_BINDPASSWORD.get());
+            bindPasswordArg.addValue(arg.getValue());
+            commandBuilder.addObfuscatedArgument(bindPasswordArg);
+          }
+          else if (hasBindDN)
+          {
+            StringArgument bindPasswordArg = new StringArgument("bindPassword2",
+                null, "bindPassword2", false, false, true,
+                INFO_BINDPWD_PLACEHOLDER.get(), null, null,
+                INFO_DESCRIPTION_ENABLE_REPLICATION_BINDPASSWORD2.get());
+            bindPasswordArg.addValue(arg.getValue());
+            commandBuilder.addObfuscatedArgument(bindPasswordArg);
+          }
+        }
+        else if (arg.getLongIdentifier().equals(OPTION_LONG_BINDPWD_FILE))
+        {
+          if (useAdminUID && !adminInformationAdded)
+          {
+            adminInformationAdded = true;
+            FileBasedArgument bindPasswordFileArg = new FileBasedArgument(
+                "adminPasswordFile",
+                OPTION_SHORT_BINDPWD_FILE, "adminPasswordFile", false, false,
+                INFO_BINDPWD_FILE_PLACEHOLDER.get(), null, null,
+                INFO_DESCRIPTION_REPLICATION_ADMIN_BINDPASSWORDFILE.get());
+            bindPasswordFileArg.getNameToValueMap().putAll(
+                ((FileBasedArgument)arg).getNameToValueMap());
+            commandBuilder.addArgument(bindPasswordFileArg);
+          }
+          else if (hasBindDN)
+          {
+            FileBasedArgument bindPasswordFileArg = new FileBasedArgument(
+                "bindPasswordFile2",
+                null, "bindPasswordFile2", false, false,
+                INFO_BINDPWD_FILE_PLACEHOLDER.get(), null, null,
+                INFO_DESCRIPTION_ENABLE_REPLICATION_BINDPASSWORDFILE2.get());
+            bindPasswordFileArg.getNameToValueMap().putAll(
+                ((FileBasedArgument)arg).getNameToValueMap());
+            commandBuilder.addArgument(bindPasswordFileArg);
+          }
+        }
+        else
+        {
+          argsToAnalyze.add(arg);
+        }
+      }
+
+      for (Argument arg : argsToAnalyze)
+      {
+        // Just check that the arguments have not already been added.
+        boolean found = false;
+        for (Argument a : commandBuilder.getArguments())
+        {
+          if (a.getLongIdentifier().equals(arg.getLongIdentifier()))
+          {
+            found = true;
+            break;
+          }
+        }
+
+        if (!found)
+        {
+          if (interactionBuilder.isObfuscated(arg))
+          {
+            commandBuilder.addObfuscatedArgument(arg);
+          }
+          else
+          {
+            commandBuilder.addArgument(arg);
+          }
+        }
+      }
+    }
+
+    // Try to add the new administration information.
+    if (!adminInformationAdded)
+    {
+      StringArgument adminUID = new StringArgument(OPTION_LONG_ADMIN_UID, 'I',
+          OPTION_LONG_ADMIN_UID, false, false, true,
+          INFO_ADMINUID_PLACEHOLDER.get(),
+          Constants.GLOBAL_ADMIN_UID, null,
+          INFO_DESCRIPTION_REPLICATION_ADMIN_UID.get(
+              ReplicationCliArgumentParser.ENABLE_REPLICATION_SUBCMD_NAME));
+      if (uData.getAdminUid() != null)
+      {
+        adminUID.addValue(uData.getAdminUid());
+        commandBuilder.addArgument(adminUID);
+      }
+
+      if (userProvidedAdminPwdFile != null)
+      {
+        commandBuilder.addArgument(userProvidedAdminPwdFile);
+      }
+      else
+      {
+        Argument bindPasswordArg = new StringArgument("adminPassword",
+            OPTION_SHORT_BINDPWD, "adminPassword", false, false, true,
+            INFO_BINDPWD_PLACEHOLDER.get(), null, null,
+            INFO_DESCRIPTION_REPLICATION_ADMIN_BINDPASSWORD.get());
+        if (uData.getAdminPwd() != null)
+        {
+          bindPasswordArg.addValue(uData.getAdminPwd());
+          commandBuilder.addObfuscatedArgument(bindPasswordArg);
+        }
+      }
+    }
+
+    if (uData.getReplicationPort1() > 0)
+    {
+      IntegerArgument replicationPort1 = new IntegerArgument(
+          "replicationPort1", 'r',
+          "replicationPort1", false, false, true, INFO_PORT_PLACEHOLDER.get(),
+          8989, null,
+          INFO_DESCRIPTION_ENABLE_REPLICATION_PORT1.get());
+      replicationPort1.addValue(String.valueOf(uData.getReplicationPort1()));
+      commandBuilder.addArgument(replicationPort1);
+    }
+    if (uData.isSecureReplication1())
+    {
+      commandBuilder.addArgument(new BooleanArgument("secureReplication1", null,
+          "secureReplication1",
+          INFO_DESCRIPTION_ENABLE_SECURE_REPLICATION1.get()));
+    }
+    if (uData.getReplicationPort2() > 0)
+    {
+      IntegerArgument replicationPort2 = new IntegerArgument(
+          "replicationPort2", 'r',
+          "replicationPort2", false, false, true, INFO_PORT_PLACEHOLDER.get(),
+          uData.getReplicationPort2(), null,
+          INFO_DESCRIPTION_ENABLE_REPLICATION_PORT2.get());
+      replicationPort2.addValue(String.valueOf(uData.getReplicationPort2()));
+      commandBuilder.addArgument(replicationPort2);
+    }
+    if (uData.isSecureReplication2())
+    {
+      commandBuilder.addArgument(new BooleanArgument("secureReplication2", null,
+          "secureReplication2",
+          INFO_DESCRIPTION_ENABLE_SECURE_REPLICATION2.get()));
+    }
+    if (!uData.replicateSchema())
+    {
+      commandBuilder.addArgument(new BooleanArgument(
+          "noschemareplication", null, "noSchemaReplication",
+          INFO_DESCRIPTION_ENABLE_REPLICATION_NO_SCHEMA_REPLICATION.get()));
+    }
+    if (argParser.skipReplicationPortCheck())
+    {
+      commandBuilder.addArgument(new BooleanArgument(
+          "skipportcheck", 'S', "skipPortCheck",
+          INFO_DESCRIPTION_ENABLE_REPLICATION_SKIPPORT.get()));
+    }
+    if (argParser.useSecondServerAsSchemaSource())
+    {
+      commandBuilder.addArgument(new BooleanArgument(
+          "usesecondserverasschemasource", null,
+          "useSecondServerAsSchemaSource",
+          INFO_DESCRIPTION_ENABLE_REPLICATION_USE_SECOND_AS_SCHEMA_SOURCE.get(
+              "--"+argParser.noSchemaReplicationArg.getLongIdentifier())));
+    }
+  }
+
+  private void updateCommandBuilder(CommandBuilder commandBuilder,
+      InitializeReplicationUserData uData)
+  throws ArgumentException
+  {
+    // Update the arguments used in the console interaction with the
+    // actual arguments of dsreplication.
+
+    if (firstServerCommandBuilder != null)
+    {
+      for (Argument arg : firstServerCommandBuilder.getArguments())
+      {
+        if (arg.getLongIdentifier().equals(OPTION_LONG_HOST))
+        {
+          StringArgument host = new StringArgument("hostSource", 'O',
+              "hostSource", false, false, true,
+              INFO_HOST_PLACEHOLDER.get(), null, null,
+              INFO_DESCRIPTION_INITIALIZE_REPLICATION_HOST_SOURCE.get());
+          host.addValue(uData.getHostNameSource());
+          commandBuilder.addArgument(host);
+        }
+        else if (arg.getLongIdentifier().equals(OPTION_LONG_PORT))
+        {
+          IntegerArgument port = new IntegerArgument("portSource", null,
+              "portSource", false, false, true,
+              INFO_PORT_PLACEHOLDER.get(),
+              4444,
+              null,
+         INFO_DESCRIPTION_INITIALIZE_REPLICATION_SERVER_PORT_SOURCE.get());
+          port.addValue(String.valueOf(uData.getPortSource()));
+          commandBuilder.addArgument(port);
+        }
+        else if (arg.getLongIdentifier().equals(OPTION_LONG_BINDPWD))
+        {
+          StringArgument bindPasswordArg = new StringArgument("adminPassword",
+              OPTION_SHORT_BINDPWD, "adminPassword", false, false, true,
+              INFO_BINDPWD_PLACEHOLDER.get(), null, null,
+              INFO_DESCRIPTION_REPLICATION_ADMIN_BINDPASSWORD.get());
+          bindPasswordArg.addValue(arg.getValue());
+          commandBuilder.addObfuscatedArgument(bindPasswordArg);
+        }
+        else if (arg.getLongIdentifier().equals(OPTION_LONG_BINDPWD_FILE))
+        {
+          FileBasedArgument bindPasswordFileArg = new FileBasedArgument(
+              "adminPasswordFile",
+              OPTION_SHORT_BINDPWD_FILE, "adminPasswordFile", false, false,
+              INFO_BINDPWD_FILE_PLACEHOLDER.get(), null, null,
+              INFO_DESCRIPTION_REPLICATION_ADMIN_BINDPASSWORDFILE.get());
+          bindPasswordFileArg.getNameToValueMap().putAll(
+              ((FileBasedArgument)arg).getNameToValueMap());
+          commandBuilder.addArgument(bindPasswordFileArg);
+        }
+        else
+        {
+          if (firstServerCommandBuilder.isObfuscated(arg))
+          {
+            commandBuilder.addObfuscatedArgument(arg);
+          }
+          else
+          {
+            commandBuilder.addArgument(arg);
+          }
+        }
+      }
+    }
+
+
+    if ((ci != null) && (ci.getCommandBuilder() != null))
+    {
+      CommandBuilder interactionBuilder = ci.getCommandBuilder();
+      for (Argument arg : interactionBuilder.getArguments())
+      {
+        if (arg.getLongIdentifier().equals(OPTION_LONG_HOST))
+        {
+          StringArgument host = new StringArgument("hostDestination", 'O',
+              "hostDestination", false, false, true,
+              INFO_HOST_PLACEHOLDER.get(),
+              null, null,
+              INFO_DESCRIPTION_INITIALIZE_REPLICATION_HOST_DESTINATION.get());
+          host.addValue(uData.getHostNameDestination());
+          commandBuilder.addArgument(host);
+        }
+        else if (arg.getLongIdentifier().equals(OPTION_LONG_PORT))
+        {
+          IntegerArgument port = new IntegerArgument("portDestination", null,
+              "portDestination", false, false, true,
+              INFO_PORT_PLACEHOLDER.get(),
+              4444,
+              null,
+         INFO_DESCRIPTION_INITIALIZE_REPLICATION_SERVER_PORT_DESTINATION.get());
+          port.addValue(String.valueOf(uData.getPortDestination()));
+          commandBuilder.addArgument(port);
+        }
+      }
+    }
+  }
 }
diff --git a/opendj-sdk/opends/src/server/org/opends/server/util/cli/CommandBuilder.java b/opendj-sdk/opends/src/server/org/opends/server/util/cli/CommandBuilder.java
index 650a22a..680ce4a 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/util/cli/CommandBuilder.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/util/cli/CommandBuilder.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2008 Sun Microsystems, Inc.
+ *      Copyright 2008-2009 Sun Microsystems, Inc.
  */
 
 package org.opends.server.util.cli;
@@ -248,7 +248,7 @@
    * @return <CODE>true</CODE> if the attribute's values must be obfuscated and
    * <CODE>false</CODE> otherwise.
    */
-  private boolean isObfuscated(Argument argument)
+  public boolean isObfuscated(Argument argument)
   {
     return obfuscatedArgs.contains(argument);
   }
diff --git a/opendj-sdk/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java b/opendj-sdk/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java
index ed2d41c..cb376ab 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2008 Sun Microsystems, Inc.
+ *      Copyright 2008-2009 Sun Microsystems, Inc.
  */
 
 package org.opends.server.util.cli;
@@ -677,7 +677,29 @@
               .unableToReadConnectionParameters(e);
         }
       }
-      if (useAdmin)
+      if (useAdminOrBindDn)
+      {
+        boolean addAdmin = providedAdminUID != null;
+        boolean addBindDN = providedBindDN != null;
+        if (!addAdmin && !addBindDN)
+        {
+          addAdmin = getAdministratorUID() != null;
+          addBindDN = getBindDN() != null;
+        }
+        if (addAdmin)
+        {
+          copySecureArgsList.adminUidArg.clearValues();
+          copySecureArgsList.adminUidArg.addValue(getAdministratorUID());
+          commandBuilder.addArgument(copySecureArgsList.adminUidArg);
+        }
+        else if (addBindDN)
+        {
+          copySecureArgsList.bindDnArg.clearValues();
+          copySecureArgsList.bindDnArg.addValue(getBindDN());
+          commandBuilder.addArgument(copySecureArgsList.bindDnArg);
+        }
+      }
+      else if (useAdmin)
       {
         copySecureArgsList.adminUidArg.clearValues();
         copySecureArgsList.adminUidArg.addValue(getAdministratorUID());
@@ -696,6 +718,7 @@
       adminUID = null;
     }
 
+    boolean addedPasswordFileArgument = false;
     bindPassword = secureArgsList.bindPasswordArg.getValue();
     if (keyManager == null)
     {
@@ -718,7 +741,8 @@
         copySecureArgsList.bindPasswordFileArg.clearValues();
         copySecureArgsList.bindPasswordFileArg.getNameToValueMap().putAll(
             secureArgsList.bindPasswordFileArg.getNameToValueMap());
-        commandBuilder.addArgument(secureArgsList.bindPasswordFileArg);
+        commandBuilder.addArgument(copySecureArgsList.bindPasswordFileArg);
+        addedPasswordFileArgument = true;
       }
       else if (bindPassword == null || bindPassword.equals("-"))
       {
@@ -761,8 +785,11 @@
       }
       copySecureArgsList.bindPasswordArg.clearValues();
       copySecureArgsList.bindPasswordArg.addValue(bindPassword);
-      commandBuilder.addObfuscatedArgument(
+      if (!addedPasswordFileArgument)
+      {
+        commandBuilder.addObfuscatedArgument(
           copySecureArgsList.bindPasswordArg);
+      }
     }
   }
 

--
Gitblit v1.10.0