From 43d448ea9173f0ffc89920a14d874356f51351fc Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Tue, 22 Dec 2009 16:54:18 +0000
Subject: [PATCH] Fix for issue 4414 (It would be nice to have the equivalent command-line displayed in setup) Implement the feature as it is described in the issue.

---
 opends/src/quicksetup/org/opends/quicksetup/ui/ReviewPanel.java                  |    4 
 opends/src/server/org/opends/server/tools/InstallDS.java                         |   56 +++
 opends/src/messages/messages/quicksetup.properties                               |   12 
 opends/src/messages/messages/tools.properties                                    |    3 
 opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetupStepPanel.java          |    2 
 opends/src/quicksetup/org/opends/quicksetup/util/Utils.java                      |  586 +++++++++++++++++++++++++++++++++++++++
 opends/src/quicksetup/org/opends/quicksetup/installer/ui/InstallReviewPanel.java |  228 +++++++++++++++
 7 files changed, 877 insertions(+), 14 deletions(-)

diff --git a/opends/src/messages/messages/quicksetup.properties b/opends/src/messages/messages/quicksetup.properties
index e002c66..51037fe 100644
--- a/opends/src/messages/messages/quicksetup.properties
+++ b/opends/src/messages/messages/quicksetup.properties
@@ -883,6 +883,18 @@
 INFO_REVIEW_PANEL_TITLE=Review
 INFO_REVIEW_REPLICATE_SUFFIX=Replicate contents with base DNs:%n%s
 INFO_REVIEW_STEP=Review
+INFO_REVIEW_DISPLAY_TEXT=Show Summary
+INFO_REVIEW_DISPLAY_EQUIVALENT_COMMAND=Show Equivalent Command-Line
+INFO_INSTALL_SETUP_EQUIVALENT_COMMAND_LINE=Equivalent non-interactive \
+ command-line to setup server:
+INFO_INSTALL_ENABLE_REPLICATION_EQUIVALENT_COMMAND_LINE=Equivalent \
+ non-interactive command-line to enable replication:
+INFO_INSTALL_INITIALIZE_REPLICATION_EQUIVALENT_COMMAND_LINE=Equivalent \
+ non-interactive command-line to initialize replication:
+INFO_INSTALL_ENABLE_REPLICATION_EQUIVALENT_COMMAND_LINES=Equivalent \
+ non-interactive command-lines to enable replication:
+INFO_INSTALL_INITIALIZE_REPLICATION_EQUIVALENT_COMMAND_LINES=Equivalent \
+ non-interactive command-lines to initialize replication:
 INFO_SECURITY_OPTIONS_CANCEL_BUTTON_TOOLTIP=Close this dialog and discard \
  configuration.
 INFO_SECURITY_OPTIONS_DIALOG_TITLE=Security Options
diff --git a/opends/src/messages/messages/tools.properties b/opends/src/messages/messages/tools.properties
index 9bcacf1..0fe5f9f 100644
--- a/opends/src/messages/messages/tools.properties
+++ b/opends/src/messages/messages/tools.properties
@@ -2550,4 +2550,5 @@
 INFO_DESCRIPTION_REFRESH_PERIOD_1706=When this argument is specified, the \
  status command will display its contents periodically.  Used to specify \
  the period (in seconds) between two displays of the status
-
+INFO_INSTALLDS_PRINT_EQUIVALENT_COMMAND_LINE_1708=Print equivalent \
+ non-interactive command-line
diff --git a/opends/src/quicksetup/org/opends/quicksetup/installer/ui/InstallReviewPanel.java b/opends/src/quicksetup/org/opends/quicksetup/installer/ui/InstallReviewPanel.java
index 0e246b4..5b14a5f 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/installer/ui/InstallReviewPanel.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/installer/ui/InstallReviewPanel.java
@@ -37,13 +37,17 @@
 import org.opends.quicksetup.installer.DataReplicationOptions;
 import org.opends.quicksetup.installer.SuffixesToReplicateOptions;
 import org.opends.quicksetup.ui.*;
+import org.opends.quicksetup.util.HtmlProgressMessageFormatter;
 import org.opends.quicksetup.util.Utils;
 
 import javax.swing.*;
+import javax.swing.border.EmptyBorder;
+import javax.swing.text.BadLocationException;
 import javax.swing.text.JTextComponent;
 import java.awt.*;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.TreeSet;
@@ -68,6 +72,15 @@
   private JCheckBox enableWindowsServiceCheckBox;
   private JLabel warningLabel;
 
+  private JComboBox viewCombo;
+  private final Message DISPLAY_TEXT = INFO_REVIEW_DISPLAY_TEXT.get();
+  private final Message DISPLAY_EQUIVALENT_COMMAND =
+    INFO_REVIEW_DISPLAY_EQUIVALENT_COMMAND.get();
+
+  private JComponent cardLayoutPanel;
+
+  private JEditorPane equivalentCommandPane;
+
   /**
    * Constructor of the panel.
    * @param application Application represented by this panel
@@ -127,6 +140,88 @@
       getLabel(FieldName.REPLICATION_PORT).setVisible(true);
     }
     checkStartWarningLabel();
+    updateEquivalentCommand(userData);
+  }
+
+  /**
+   * Creates and returns the instructions panel.
+   * @return the instructions panel.
+   */
+  protected Component createInstructionsPanel()
+  {
+    JPanel instructionsPanel = new JPanel(new GridBagLayout());
+    instructionsPanel.setOpaque(false);
+    Message instructions = getInstructions();
+    JLabel l = new JLabel(instructions.toString());
+    l.setFont(UIFactory.INSTRUCTIONS_FONT);
+
+    Message[] values = {
+      DISPLAY_TEXT,
+      DISPLAY_EQUIVALENT_COMMAND
+    };
+    DefaultComboBoxModel model = new DefaultComboBoxModel(values);
+    viewCombo = new JComboBox();
+    viewCombo.setModel(model);
+    viewCombo.setSelectedIndex(0);
+
+    viewCombo.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent ev)
+      {
+        updateInputPanel();
+      }
+    });
+
+    GridBagConstraints gbc = new GridBagConstraints();
+    gbc.gridx = 0;
+    gbc.gridy = 0;
+    gbc.anchor = GridBagConstraints.WEST;
+    instructionsPanel.add(l, gbc);
+    gbc.gridx = 1;
+    gbc.weightx = 1.0;
+    instructionsPanel.add(Box.createHorizontalGlue(), gbc);
+    gbc.gridx = 2;
+    gbc.weightx = 0.0;
+    gbc.insets.left = UIFactory.LEFT_INSET_BROWSE;
+    instructionsPanel.add(viewCombo);
+
+    return instructionsPanel;
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  protected boolean requiresScroll()
+  {
+    return false;
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  protected Component createInputPanel()
+  {
+    JPanel panel = UIFactory.makeJPanel();
+    panel.setLayout(new GridBagLayout());
+
+    GridBagConstraints gbc = new GridBagConstraints();
+
+    gbc.insets = UIFactory.getEmptyInsets();
+    gbc.gridwidth = GridBagConstraints.REMAINDER;
+    gbc.weightx = 1.0;
+    gbc.weighty = 1.0;
+    gbc.fill = GridBagConstraints.BOTH;
+    panel.add(createFieldsPanel(), gbc);
+
+    JComponent chk = getBottomComponent();
+    if (chk != null) {
+      gbc.insets.top = UIFactory.TOP_INSET_PRIMARY_FIELD;
+      gbc.weighty = 0.0;
+      gbc.fill = GridBagConstraints.HORIZONTAL;
+      panel.add(chk, gbc);
+    }
+
+    return panel;
   }
 
   /**
@@ -162,6 +257,12 @@
     return INFO_REVIEW_PANEL_TITLE.get();
   }
 
+  private void updateInputPanel()
+  {
+    CardLayout cl = (CardLayout)cardLayoutPanel.getLayout();
+    cl.show(cardLayoutPanel, viewCombo.getSelectedItem().toString());
+  }
+
   /**
    * Create the components and populate the Maps.
    */
@@ -361,6 +462,35 @@
    */
   protected JPanel createFieldsPanel()
   {
+    JPanel fieldsPanel = new JPanel(new GridBagLayout());
+    fieldsPanel.setOpaque(false);
+
+    GridBagConstraints gbc = new GridBagConstraints();
+
+    cardLayoutPanel = new JPanel(new CardLayout());
+
+    JComponent p = createReadOnlyPanel();
+    p.setBorder(new EmptyBorder(UIFactory.LEFT_INSET_SECONDARY_FIELD,
+        UIFactory.LEFT_INSET_SECONDARY_FIELD,
+        UIFactory.LEFT_INSET_SECONDARY_FIELD,
+        UIFactory.LEFT_INSET_SECONDARY_FIELD));
+
+    cardLayoutPanel.add(new JScrollPane(p), DISPLAY_TEXT.toString());
+    cardLayoutPanel.add(new JScrollPane(createEquivalentCommandPanel()),
+        DISPLAY_EQUIVALENT_COMMAND.toString());
+
+    gbc.gridx = 0;
+    gbc.gridy = 0;
+    gbc.weightx = 1.0;
+    gbc.weighty = 1.0;
+    gbc.gridwidth = 3;
+    gbc.fill = GridBagConstraints.BOTH;
+    fieldsPanel.add(cardLayoutPanel, gbc);
+    return fieldsPanel;
+  }
+
+  private JComponent createReadOnlyPanel()
+  {
     JPanel panel = new JPanel(new GridBagLayout());
     panel.setOpaque(false);
     GridBagConstraints gbc = new GridBagConstraints();
@@ -421,9 +551,21 @@
       panel.add(getField(fieldNames[i]), gbc);
     }
 
+    gbc.weighty = 1.0;
+    gbc.insets = UIFactory.getEmptyInsets();
+    gbc.fill = GridBagConstraints.VERTICAL;
+    panel.add(Box.createVerticalGlue(), gbc);
+
     return panel;
   }
 
+  private Component createEquivalentCommandPanel()
+  {
+    equivalentCommandPane = UIFactory.makeHtmlPane(Message.EMPTY,
+        UIFactory.INSTRUCTIONS_FONT);
+    return equivalentCommandPane;
+  }
+
   /**
    * {@inheritDoc}
    */
@@ -516,4 +658,90 @@
     }
     getWarningLabel().setVisible(visible);
   }
+
+  private void updateEquivalentCommand(UserData userData)
+  {
+    HtmlProgressMessageFormatter formatter =
+      new HtmlProgressMessageFormatter();
+    StringBuilder sb = new StringBuilder();
+    try
+    {
+      equivalentCommandPane.getDocument().remove(0,
+          equivalentCommandPane.getDocument().getLength());
+    }
+    catch (BadLocationException ble)
+    {
+      throw new RuntimeException("Unexpected error: "+ble, ble);
+    }
+    sb.append(formatter.getFormattedProgress(
+        INFO_INSTALL_SETUP_EQUIVALENT_COMMAND_LINE.get()));
+    sb.append(formatter.getLineBreak());
+    sb.append("<b>"+Utils.getFormattedEquivalentCommandLine(
+        Utils.getSetupEquivalentCommandLine(userData), formatter)+
+        "</b>");
+    if (userData.getReplicationOptions().getType() ==
+      DataReplicationOptions.Type.IN_EXISTING_TOPOLOGY)
+    {
+      sb.append(formatter.getTaskSeparator());
+      ArrayList<ArrayList<String>> cmdLines =
+        Utils.getDsReplicationEnableEquivalentCommandLines(userData);
+      if (cmdLines.size() == 1)
+      {
+        sb.append(formatter.getFormattedProgress(
+          INFO_INSTALL_ENABLE_REPLICATION_EQUIVALENT_COMMAND_LINE.get()));
+      }
+      else if (cmdLines.size() > 1)
+      {
+        sb.append(formatter.getFormattedProgress(
+            INFO_INSTALL_ENABLE_REPLICATION_EQUIVALENT_COMMAND_LINES.get()));
+      }
+      for (ArrayList<String> cmdLine : cmdLines)
+      {
+        sb.append(formatter.getLineBreak());
+        sb.append("<b>"+
+                Utils.getFormattedEquivalentCommandLine(cmdLine, formatter)+
+            "</b>");
+      }
+
+      sb.append(formatter.getLineBreak());
+      sb.append(formatter.getLineBreak());
+      cmdLines =
+        Utils.getDsReplicationInitializeEquivalentCommandLines(userData);
+      if (cmdLines.size() == 1)
+      {
+        sb.append(formatter.getFormattedProgress(
+            INFO_INSTALL_INITIALIZE_REPLICATION_EQUIVALENT_COMMAND_LINE.get()));
+      }
+      else if (cmdLines.size() > 1)
+      {
+        sb.append(formatter.getFormattedProgress(
+           INFO_INSTALL_INITIALIZE_REPLICATION_EQUIVALENT_COMMAND_LINES.get()));
+      }
+
+      for (ArrayList<String> cmdLine : cmdLines)
+      {
+        sb.append(formatter.getLineBreak());
+        sb.append("<b>"+
+                Utils.getFormattedEquivalentCommandLine(cmdLine, formatter)+
+            "</b>");
+      }
+    }
+    else if (userData.getReplicationOptions().getType() ==
+      DataReplicationOptions.Type.FIRST_IN_TOPOLOGY)
+    {
+      sb.append(formatter.getTaskSeparator());
+      sb.append(formatter.getFormattedProgress(
+          INFO_INSTALL_ENABLE_REPLICATION_EQUIVALENT_COMMAND_LINES.get()));
+      ArrayList<ArrayList<String>> cmdLines =
+        Utils.getDsConfigReplicationEnableEquivalentCommandLines(userData);
+      for (ArrayList<String> cmdLine : cmdLines)
+      {
+        sb.append(formatter.getLineBreak());
+        sb.append("<b>"+
+                Utils.getFormattedEquivalentCommandLine(cmdLine, formatter)+
+            "</b>");
+      }
+    }
+    equivalentCommandPane.setText(sb.toString());
+  }
 }
diff --git a/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetupStepPanel.java b/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetupStepPanel.java
index be83e33..c673a40 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetupStepPanel.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetupStepPanel.java
@@ -509,7 +509,7 @@
    * Creates and returns the instructions panel.
    * @return the instructions panel.
    */
-  private Component createInstructionsPanel()
+  protected Component createInstructionsPanel()
   {
     Component instructionsPanel = null;
     Message instructions = getInstructions();
diff --git a/opends/src/quicksetup/org/opends/quicksetup/ui/ReviewPanel.java b/opends/src/quicksetup/org/opends/quicksetup/ui/ReviewPanel.java
index 8a3179e..d63b863 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/ui/ReviewPanel.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/ui/ReviewPanel.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2006-2008 Sun Microsystems, Inc.
+ *      Copyright 2006-2009 Sun Microsystems, Inc.
  */
 
 package org.opends.quicksetup.ui;
@@ -53,7 +53,7 @@
   /**
    * {@inheritDoc}
    */
-  final protected Component createInputPanel()
+  protected Component createInputPanel()
   {
     JPanel panel = UIFactory.makeJPanel();
     panel.setLayout(new GridBagLayout());
diff --git a/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java b/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
index 21e22f8..df040c2 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
@@ -61,10 +61,14 @@
 import javax.net.ssl.HostnameVerifier;
 import javax.net.ssl.TrustManager;
 
+import org.opends.admin.ads.ADSContext;
+import org.opends.admin.ads.ReplicaDescriptor;
+import org.opends.admin.ads.ServerDescriptor;
 import org.opends.admin.ads.SuffixDescriptor;
 import org.opends.admin.ads.TopologyCacheException;
 import org.opends.admin.ads.util.ConnectionUtils;
 import org.opends.quicksetup.*;
+import org.opends.quicksetup.installer.AuthenticationData;
 import org.opends.quicksetup.installer.DataReplicationOptions;
 import org.opends.quicksetup.installer.NewSuffixOptions;
 import org.opends.quicksetup.installer.SuffixesToReplicateOptions;
@@ -2183,6 +2187,588 @@
       return buf.toString();
     }
   }
+
+  /**
+   * Returns a String representation of the provided command-line.
+   * @param cmd the command-line arguments.
+   * @param formatter the formatted to be used to create the String
+   * representation.
+   * @return a String representation of the provided command-line.
+   */
+  public static String getFormattedEquivalentCommandLine(ArrayList<String> cmd,
+      ProgressMessageFormatter formatter)
+  {
+    StringBuilder builder = new StringBuilder();
+    builder.append(formatter.getFormattedProgress(Message.raw(cmd.get(0))));
+    int initialIndex = 1;
+    StringBuilder sbSeparator = new StringBuilder();
+    if (Utils.isWindows())
+    {
+      sbSeparator.append(formatter.getSpace());
+    }
+    else
+    {
+      sbSeparator.append(formatter.getSpace());
+      sbSeparator.append("\\");
+      sbSeparator.append(formatter.getLineBreak());
+      for (int i=0 ; i < 10 ; i++)
+      {
+        sbSeparator.append(formatter.getSpace());
+      }
+    }
+
+    String lineSeparator = sbSeparator.toString();
+    for (int i=initialIndex ; i<cmd.size(); i++)
+    {
+      String s = cmd.get(i);
+      if (s.startsWith("-") && i > initialIndex)
+      {
+        builder.append(lineSeparator);
+        builder.append(formatter.getFormattedProgress(Message.raw(s)));
+      }
+      else
+      {
+        builder.append(formatter.getSpace());
+        builder.append(formatter.getFormattedProgress(Message.raw(
+            escapeValue(s))));
+      }
+    }
+    return builder.toString();
+  }
+
+  //Chars that require special treatment when passing them to command-line.
+  private final static char[] charsToEscape = {' ', '\t', '\n', '|', ';', '<',
+    '>', '(', ')', '$', '`', '\\', '"', '\''};
+  private static final String OBFUSCATED_VALUE = "******";
+
+  /**
+   * This method simply takes a value and tries to transform it (with escape or
+   * '"') characters so that it can be used in a command line.
+   * @param value the String to be treated.
+   * @return the transformed value.
+   */
+  private static String escapeValue(String value)
+  {
+    StringBuilder b = new StringBuilder();
+    if (Utils.isUnix())
+    {
+      for (int i=0 ; i<value.length(); i++)
+      {
+        char c = value.charAt(i);
+        boolean charToEscapeFound = false;
+        for (int j=0; j<charsToEscape.length && !charToEscapeFound; j++)
+        {
+          charToEscapeFound = c == charsToEscape[j];
+        }
+        if (charToEscapeFound)
+        {
+          b.append('\\');
+        }
+        b.append(c);
+      }
+    }
+    else
+    {
+      b.append('"').append(value).append('"');
+    }
+
+    return b.toString();
+  }
+
+  /**
+   * Returns the equivalent setup CLI command-line.  Note that this command-line
+   * does not cover all the replication part of the GUI install.  Note also
+   * that to avoid problems in the WebStart setup, all the Strings are
+   * hard-coded in the implementation of this method.
+   * @param userData the user data.
+   * @return the equivalent setup command-line.
+   */
+  public static ArrayList<String> getSetupEquivalentCommandLine(
+      UserData userData)
+  {
+    ArrayList<String> cmdLine = new ArrayList<String>();
+    String setupFile;
+    if (Utils.isWindows())
+    {
+      setupFile = Installation.WINDOWS_SETUP_FILE_NAME;
+    }
+    else
+    {
+      setupFile = Installation.UNIX_SETUP_FILE_NAME;
+    }
+    cmdLine.add(setupFile);
+    cmdLine.add("--cli");
+
+    for (String baseDN : getBaseDNs(userData))
+    {
+      cmdLine.add("--baseDN");
+      cmdLine.add(baseDN);
+    }
+
+    switch (userData.getNewSuffixOptions().getType())
+    {
+    case CREATE_BASE_ENTRY:
+      cmdLine.add("--addBaseEntry");
+      break;
+    case IMPORT_AUTOMATICALLY_GENERATED_DATA:
+      cmdLine.add("--sampleData");
+      cmdLine.add(String.valueOf(
+          userData.getNewSuffixOptions().getNumberEntries()));
+      break;
+    case IMPORT_FROM_LDIF_FILE:
+      for (String ldifFile : userData.getNewSuffixOptions().getLDIFPaths())
+      {
+        cmdLine.add("--ldifFile");
+        cmdLine.add(ldifFile);
+      }
+      String rejectFile = userData.getNewSuffixOptions().getRejectedFile();
+      if (rejectFile != null)
+      {
+        cmdLine.add("--rejectFile");
+        cmdLine.add(rejectFile);
+      }
+      String skipFile = userData.getNewSuffixOptions().getSkippedFile();
+      if (skipFile != null)
+      {
+        cmdLine.add("--skipFile");
+        cmdLine.add(skipFile);
+      }
+      break;
+    }
+
+    cmdLine.add("--ldapPort");
+    cmdLine.add(String.valueOf(userData.getServerPort()));
+    cmdLine.add("--adminConnectorPort");
+    cmdLine.add(String.valueOf(userData.getAdminConnectorPort()));
+    if (userData.getServerJMXPort() != -1)
+    {
+      cmdLine.add("--jmxPort");
+      cmdLine.add(String.valueOf(userData.getServerJMXPort()));
+    }
+    cmdLine.add("--rootUserDN");
+    cmdLine.add(userData.getDirectoryManagerDn());
+    cmdLine.add("--rootUserPassword");
+    cmdLine.add(OBFUSCATED_VALUE);
+
+    if (userData.getReplicationOptions().getType() ==
+      DataReplicationOptions.Type.STANDALONE &&
+      !userData.getStartServer())
+    {
+      cmdLine.add("--doNotStart");
+    }
+
+    if (userData.getSecurityOptions().getEnableStartTLS())
+    {
+      cmdLine.add("--enableStartTLS");
+    }
+    if (userData.getSecurityOptions().getEnableSSL())
+    {
+      cmdLine.add("--ldapsPort");
+      cmdLine.add(String.valueOf(userData.getSecurityOptions().getSslPort()));
+    }
+    switch (userData.getSecurityOptions().getCertificateType())
+    {
+    case SELF_SIGNED_CERTIFICATE:
+      cmdLine.add("--generateSelfSignedCertificate");
+      cmdLine.add("--hostName");
+      cmdLine.add(userData.getHostName());
+      break;
+    case JKS:
+      cmdLine.add("--useJavaKeystore");
+      cmdLine.add(userData.getSecurityOptions().getKeystorePath());
+      if (userData.getSecurityOptions().getKeystorePassword() != null)
+      {
+        cmdLine.add("--keyStorePassword");
+        cmdLine.add(OBFUSCATED_VALUE);
+      }
+      if (userData.getSecurityOptions().getAliasToUse() != null)
+      {
+        cmdLine.add("--certNickname");
+        cmdLine.add(userData.getSecurityOptions().getAliasToUse());
+      }
+      break;
+    case JCEKS:
+      cmdLine.add("--useJCEKS");
+      cmdLine.add(userData.getSecurityOptions().getKeystorePath());
+      if (userData.getSecurityOptions().getKeystorePassword() != null)
+      {
+        cmdLine.add("--keyStorePassword");
+        cmdLine.add(OBFUSCATED_VALUE);
+      }
+      if (userData.getSecurityOptions().getAliasToUse() != null)
+      {
+        cmdLine.add("--certNickname");
+        cmdLine.add(userData.getSecurityOptions().getAliasToUse());
+      }
+      break;
+    case PKCS12:
+      cmdLine.add("--usePkcs12keyStore");
+      cmdLine.add(userData.getSecurityOptions().getKeystorePath());
+      if (userData.getSecurityOptions().getKeystorePassword() != null)
+      {
+        cmdLine.add("--keyStorePassword");
+        cmdLine.add(OBFUSCATED_VALUE);
+      }
+      if (userData.getSecurityOptions().getAliasToUse() != null)
+      {
+        cmdLine.add("--certNickname");
+        cmdLine.add(userData.getSecurityOptions().getAliasToUse());
+      }
+      break;
+    case PKCS11:
+      cmdLine.add("--usePkcs11Keystore");
+      if (userData.getSecurityOptions().getKeystorePassword() != null)
+      {
+        cmdLine.add("--keyStorePassword");
+        cmdLine.add(OBFUSCATED_VALUE);
+      }
+      if (userData.getSecurityOptions().getAliasToUse() != null)
+      {
+        cmdLine.add("--certNickname");
+        cmdLine.add(userData.getSecurityOptions().getAliasToUse());
+      }
+      break;
+    }
+
+    cmdLine.add("--no-prompt");
+    cmdLine.add("--noPropertiesFile");
+    return cmdLine;
+  }
+
+  /**
+   * Returns the list of equivalent command-lines that must be executed to
+   * enable replication as the setup does.
+   * @param userData the user data.
+   * @return the list of equivalent command-lines that must be executed to
+   * enable replication as the setup does.
+   */
+  public static ArrayList<ArrayList<String>>
+  getDsReplicationEnableEquivalentCommandLines(
+      UserData userData)
+  {
+    ArrayList<ArrayList<String>> cmdLines = new ArrayList<ArrayList<String>>();
+    Map<ServerDescriptor, Set<String>> hmServerBaseDNs =
+      getServerDescriptorBaseDNMap(userData);
+    for (ServerDescriptor server : hmServerBaseDNs.keySet())
+    {
+      cmdLines.add(getDsReplicationEnableEquivalentCommandLine(userData,
+          hmServerBaseDNs.get(server), server));
+    }
+    return cmdLines;
+  }
+
+  /**
+   * Returns the list of equivalent command-lines that must be executed to
+   * initialize replication as the setup does.
+   * @param userData the user data.
+   * @return the list of equivalent command-lines that must be executed to
+   * initialize replication as the setup does.
+   */
+  public static ArrayList<ArrayList<String>>
+  getDsReplicationInitializeEquivalentCommandLines(
+      UserData userData)
+  {
+    ArrayList<ArrayList<String>> cmdLines = new ArrayList<ArrayList<String>>();
+    Map<ServerDescriptor, Set<String>> hmServerBaseDNs =
+      getServerDescriptorBaseDNMap(userData);
+    for (ServerDescriptor server : hmServerBaseDNs.keySet())
+    {
+      cmdLines.add(getDsReplicationInitializeEquivalentCommandLine(userData,
+          hmServerBaseDNs.get(server), server));
+    }
+    return cmdLines;
+  }
+
+  private static ArrayList<String> getDsReplicationEnableEquivalentCommandLine(
+      UserData userData, Set<String> baseDNs, ServerDescriptor server)
+  {
+    ArrayList<String> cmdLine = new ArrayList<String>();
+    String cmdName;
+    if (Utils.isWindows())
+    {
+      cmdName = "dsreplication.bat";
+    }
+    else
+    {
+      cmdName = "dsreplication";
+    }
+    cmdLine.add(cmdName);
+    cmdLine.add("enable");
+
+    DataReplicationOptions replOptions = userData.getReplicationOptions();
+    cmdLine.add("--host1");
+    cmdLine.add(server.getHostName());
+    cmdLine.add("--port1");
+    cmdLine.add(String.valueOf(server.getEnabledAdministrationPorts().get(0)));
+
+    AuthenticationData authData =
+      userData.getReplicationOptions().getAuthenticationData();
+    if (!Utils.areDnsEqual(authData.getDn(),
+        ADSContext.getAdministratorDN(userData.getGlobalAdministratorUID())))
+    {
+      cmdLine.add("--bindDN1");
+      cmdLine.add(authData.getDn());
+      cmdLine.add("--bindPassword1");
+      cmdLine.add(OBFUSCATED_VALUE);
+    }
+    for (ServerDescriptor s :
+      userData.getRemoteWithNoReplicationPort().keySet())
+    {
+      if (s.getAdminConnectorURL().equals(server.getAdminConnectorURL()))
+      {
+        AuthenticationData remoteRepl =
+          userData.getRemoteWithNoReplicationPort().get(server);
+        int remoteReplicationPort = remoteRepl.getPort();
+
+        cmdLine.add("--replicationPort1");
+        cmdLine.add(String.valueOf(remoteReplicationPort));
+        if (remoteRepl.useSecureConnection())
+        {
+          cmdLine.add("--secureReplication1");
+        }
+      }
+    }
+    cmdLine.add("--host2");
+    cmdLine.add(userData.getHostName());
+    cmdLine.add("--port2");
+    cmdLine.add(String.valueOf(userData.getAdminConnectorPort()));
+    cmdLine.add("--bindDN2");
+    cmdLine.add(userData.getDirectoryManagerDn());
+    cmdLine.add("--bindPassword2");
+    cmdLine.add(OBFUSCATED_VALUE);
+    if (replOptions.getReplicationPort() != -1)
+    {
+      cmdLine.add("--replicationPort2");
+      cmdLine.add(
+         String.valueOf(replOptions.getReplicationPort()));
+      if (replOptions.useSecureReplication())
+      {
+        cmdLine.add("--secureReplication2");
+      }
+    }
+
+    for (String baseDN : baseDNs)
+    {
+      cmdLine.add("--baseDN");
+      cmdLine.add(baseDN);
+    }
+
+    cmdLine.add("--adminUID");
+    cmdLine.add(userData.getGlobalAdministratorUID());
+    cmdLine.add("--adminPassword");
+    cmdLine.add(OBFUSCATED_VALUE);
+
+    cmdLine.add("--trustAll");
+    cmdLine.add("--no-prompt");
+    cmdLine.add("--noPropertiesFile");
+    return cmdLine;
+  }
+
+  private static ArrayList<String>
+  getDsReplicationInitializeEquivalentCommandLine(
+      UserData userData, Set<String> baseDNs, ServerDescriptor server)
+  {
+    ArrayList<String> cmdLine = new ArrayList<String>();
+    String cmdName;
+    if (Utils.isWindows())
+    {
+      cmdName = "dsreplication.bat";
+    }
+    else
+    {
+      cmdName = "dsreplication";
+    }
+    cmdLine.add(cmdName);
+    cmdLine.add("initialize");
+
+    cmdLine.add("--hostSource");
+    cmdLine.add(server.getHostName());
+    cmdLine.add("--portSource");
+    cmdLine.add(String.valueOf(server.getEnabledAdministrationPorts().get(0)));
+
+    cmdLine.add("--hostDestination");
+    cmdLine.add(userData.getHostName());
+    cmdLine.add("--portDestination");
+    cmdLine.add(String.valueOf(userData.getAdminConnectorPort()));
+
+    for (String baseDN : baseDNs)
+    {
+      cmdLine.add("--baseDN");
+      cmdLine.add(baseDN);
+    }
+
+    cmdLine.add("--adminUID");
+    cmdLine.add(userData.getGlobalAdministratorUID());
+    cmdLine.add("--adminPassword");
+    cmdLine.add(OBFUSCATED_VALUE);
+
+    cmdLine.add("--trustAll");
+    cmdLine.add("--no-prompt");
+    cmdLine.add("--noPropertiesFile");
+    return cmdLine;
+  }
+
+  private static ArrayList<String> getBaseDNs(UserData userData)
+  {
+    ArrayList<String> baseDNs = new ArrayList<String>();
+
+    DataReplicationOptions repl = userData.getReplicationOptions();
+    SuffixesToReplicateOptions suf = userData.getSuffixesToReplicateOptions();
+
+    boolean createSuffix =
+      repl.getType() == DataReplicationOptions.Type.FIRST_IN_TOPOLOGY ||
+      repl.getType() == DataReplicationOptions.Type.STANDALONE ||
+      suf.getType() == SuffixesToReplicateOptions.Type.NEW_SUFFIX_IN_TOPOLOGY;
+
+    if (createSuffix)
+    {
+      NewSuffixOptions options = userData.getNewSuffixOptions();
+      baseDNs.addAll(options.getBaseDns());
+    }
+    else
+    {
+      Set<SuffixDescriptor> suffixes = suf.getSuffixes();
+      for (SuffixDescriptor suffix : suffixes)
+      {
+        baseDNs.add(suffix.getDN());
+      }
+    }
+    return baseDNs;
+  }
+
+  private static Map<ServerDescriptor, Set<String>>
+  getServerDescriptorBaseDNMap(UserData userData)
+  {
+    Map<ServerDescriptor, Set<String>> hm =
+      new HashMap<ServerDescriptor, Set<String>>();
+
+    Set<SuffixDescriptor> suffixes =
+      userData.getSuffixesToReplicateOptions().getSuffixes();
+    AuthenticationData authData =
+      userData.getReplicationOptions().getAuthenticationData();
+    String ldapURL = ConnectionUtils.getLDAPUrl(authData.getHostName(),
+        authData.getPort(), authData.useSecureConnection());
+    for (SuffixDescriptor suffix : suffixes)
+    {
+      boolean found = false;
+      for (ReplicaDescriptor replica : suffix.getReplicas())
+      {
+        if (ldapURL.equalsIgnoreCase(
+            replica.getServer().getAdminConnectorURL()))
+        {
+          found = true;
+          Set<String> baseDNs = hm.get(replica.getServer());
+          if (baseDNs == null)
+          {
+            baseDNs = new LinkedHashSet<String>();
+            hm.put(replica.getServer(), baseDNs);
+          }
+          baseDNs.add(suffix.getDN());
+          break;
+        }
+      }
+      if (!found)
+      {
+        for (ReplicaDescriptor replica : suffix.getReplicas())
+        {
+          if (hm.keySet().contains(replica.getServer()))
+          {
+            hm.get(replica.getServer()).add(suffix.getDN());
+            found = true;
+            break;
+          }
+        }
+      }
+      if (!found)
+      {
+        for (ReplicaDescriptor replica : suffix.getReplicas())
+        {
+          Set<String> baseDNs = new LinkedHashSet<String>();
+          hm.put(replica.getServer(), baseDNs);
+          baseDNs.add(suffix.getDN());
+          break;
+        }
+      }
+    }
+    return hm;
+  }
+
+  /**
+   * Returns the equivalent dsconfig command-line required to configure
+   * the first replicated server in the topology.
+   * @param userData the user data.
+   * @return the equivalent dsconfig command-line required to configure
+   * the first replicated server in the topology.
+   */
+  public static ArrayList<ArrayList<String>>
+  getDsConfigReplicationEnableEquivalentCommandLines(
+      UserData userData)
+  {
+    ArrayList<ArrayList<String>> cmdLines = new ArrayList<ArrayList<String>>();
+
+    String cmdName;
+    if (Utils.isWindows())
+    {
+      cmdName = "dsconfig.bat";
+    }
+    else
+    {
+      cmdName = "dsconfig";
+    }
+
+    ArrayList<String> connectionArgs = new ArrayList<String>();
+    connectionArgs.add("--hostName");
+    connectionArgs.add(userData.getHostName());
+    connectionArgs.add("--port");
+    connectionArgs.add(String.valueOf(userData.getAdminConnectorPort()));
+    connectionArgs.add("--bindDN");
+    connectionArgs.add(userData.getDirectoryManagerDn());
+    connectionArgs.add("--bindPassword");
+    connectionArgs.add(OBFUSCATED_VALUE);
+    connectionArgs.add("--trustAll");
+    connectionArgs.add("--no-prompt");
+    connectionArgs.add("--noPropertiesFile");
+
+    ArrayList<String> cmdReplicationServer = new ArrayList<String>();
+    cmdReplicationServer.add(cmdName);
+    cmdReplicationServer.add("create-replication-server");
+    cmdReplicationServer.add("--provider-name");
+    cmdReplicationServer.add("Multimaster Synchronization");
+    cmdReplicationServer.add("--set");
+    cmdReplicationServer.add("replication-port:"+
+        userData.getReplicationOptions().getReplicationPort());
+    cmdReplicationServer.add("--set");
+    cmdReplicationServer.add("replication-server-id:1");
+    cmdReplicationServer.add("--type");
+    cmdReplicationServer.add("generic");
+    cmdReplicationServer.addAll(connectionArgs);
+
+    cmdLines.add(cmdReplicationServer);
+
+    for (String baseDN : getBaseDNs(userData))
+    {
+      ArrayList<String> cmdDomain = new ArrayList<String>();
+      cmdDomain.add(cmdName);
+      cmdDomain.add("create-replication-domain");
+      cmdDomain.add("--provider-name");
+      cmdDomain.add("Multimaster Synchronization");
+      cmdDomain.add("--set");
+      cmdDomain.add("base-dn:"+baseDN);
+      cmdDomain.add("--set");
+      cmdDomain.add("replication-server:"+userData.getHostName()+":"+
+          userData.getReplicationOptions().getReplicationPort());
+      cmdDomain.add("--set");
+      cmdDomain.add("server-id:1");
+      cmdDomain.add("--type");
+      cmdDomain.add("generic");
+      cmdDomain.add("--domain-name");
+      cmdDomain.add(baseDN);
+      cmdDomain.addAll(connectionArgs);
+      cmdLines.add(cmdDomain);
+    }
+
+    return cmdLines;
+  }
 }
 
 /**
diff --git a/opends/src/server/org/opends/server/tools/InstallDS.java b/opends/src/server/org/opends/server/tools/InstallDS.java
index 364f010..e7ae5bd 100644
--- a/opends/src/server/org/opends/server/tools/InstallDS.java
+++ b/opends/src/server/org/opends/server/tools/InstallDS.java
@@ -39,6 +39,7 @@
 import java.io.OutputStream;
 import java.io.PrintStream;
 import java.security.KeyStoreException;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.LinkedList;
 import java.util.logging.Level;
@@ -180,6 +181,8 @@
     CONTINUE(1),
     // Provide information again
     PROVIDE_INFORMATION_AGAIN(2),
+    // Display equivalent command-line
+    PRINT_EQUIVALENT_COMMAND_LINE(3),
     // Cancel the install
     CANCEL(3);
 
@@ -510,8 +513,18 @@
           return ErrorReturnCode.ERROR_USER_DATA.getReturnCode();
         }
       }
-      if (isInteractive())
+      boolean promptAgain = true;
+      if (!isInteractive())
       {
+        userApproved = true;
+      }
+      else
+      {
+        printSummary(uData);
+      }
+      while (isInteractive() && promptAgain)
+      {
+        promptAgain = false;
         ConfirmCode confirm = askForConfirmation(uData);
         switch (confirm)
         {
@@ -521,6 +534,10 @@
         case CANCEL:
           LOG.log(Level.INFO, "User cancelled setup.");
           return ErrorReturnCode.ERROR_USER_CANCELLED.getReturnCode();
+        case PRINT_EQUIVALENT_COMMAND_LINE:
+          printEquivalentCommandLine(uData);
+          promptAgain = true;
+          break;
         default:
           // Reset the arguments
           try
@@ -534,7 +551,7 @@
           userApproved = false;
         }
       }
-      else
+      if (!isInteractive())
       {
         userApproved = true;
       }
@@ -2509,17 +2526,11 @@
   }
 
   /**
-   * This method asks the user to confirm to continue the setup.  It basically
-   * displays the information provided by the user and at the end proposes a
-   * menu with the different options to choose from.
+   * It displays the information provided by the user.
    * @param uData the UserData that the user provided.
-   * @return the answer provided by the user: cancel setup, continue setup or
-   * provide information again.
    */
-  private ConfirmCode askForConfirmation(UserData uData)
+  private void printSummary(UserData uData)
   {
-    ConfirmCode returnValue;
-
     println();
     println();
     println(INFO_INSTALLDS_SUMMARY.get());
@@ -2605,6 +2616,30 @@
         println(INFO_INSTALLDS_DO_NOT_ENABLE_WINDOWS_SERVICE.get());
       }
     }
+  }
+
+  private void printEquivalentCommandLine(UserData uData)
+  {
+    println();
+
+    println(INFO_INSTALL_SETUP_EQUIVALENT_COMMAND_LINE.get());
+    println();
+    ArrayList<String> cmd = Utils.getSetupEquivalentCommandLine(uData);
+    println(Message.raw(
+        Utils.getFormattedEquivalentCommandLine(cmd, formatter)));
+  }
+
+  /**
+   * This method asks the user to confirm to continue the setup.  It basically
+   * displays the information provided by the user and at the end proposes a
+   * menu with the different options to choose from.
+   * @param uData the UserData that the user provided.
+   * @return the answer provided by the user: cancel setup, continue setup or
+   * provide information again.
+   */
+  private ConfirmCode askForConfirmation(UserData uData)
+  {
+    ConfirmCode returnValue;
 
     println();
     println();
@@ -2612,6 +2647,7 @@
     Message[] msgs = new Message[] {
         INFO_INSTALLDS_CONFIRM_INSTALL.get(),
         INFO_INSTALLDS_PROVIDE_DATA_AGAIN.get(),
+        INFO_INSTALLDS_PRINT_EQUIVALENT_COMMAND_LINE.get(),
         INFO_INSTALLDS_CANCEL.get()
       };
 

--
Gitblit v1.10.0