From 0b79c912396b6bfd0a3508c3fbe27454de908253 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Wed, 23 Dec 2009 10:50:38 +0000
Subject: [PATCH] Follow up to fix issue 4414 (It would be nice to have the equivalent command-line displayed in setup) Include the stop-ds command-line when the user chooses to configure replication and not to run the server when setup is complete. Make the displayed command-line to be dynamically updated when the user clicks on the check boxes (start server and configure windows service) in the review panel.

---
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java |  113 ++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 84 insertions(+), 29 deletions(-)

diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
index df040c2..a043530 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
@@ -2221,7 +2221,7 @@
     for (int i=initialIndex ; i<cmd.size(); i++)
     {
       String s = cmd.get(i);
-      if (s.startsWith("-") && i > initialIndex)
+      if (s.startsWith("-"))
       {
         builder.append(lineSeparator);
         builder.append(formatter.getFormattedProgress(Message.raw(s)));
@@ -2296,7 +2296,7 @@
     {
       setupFile = Installation.UNIX_SETUP_FILE_NAME;
     }
-    cmdLine.add(setupFile);
+    cmdLine.add(getInstallDir() + setupFile);
     cmdLine.add("--cli");
 
     for (String baseDN : getBaseDNs(userData))
@@ -2350,6 +2350,10 @@
     cmdLine.add("--rootUserPassword");
     cmdLine.add(OBFUSCATED_VALUE);
 
+    if (Utils.isWindows() && userData.getEnableWindowsService())
+    {
+      cmdLine.add("--enableWindowsService");
+    }
     if (userData.getReplicationOptions().getType() ==
       DataReplicationOptions.Type.STANDALONE &&
       !userData.getStartServer())
@@ -2483,15 +2487,7 @@
       UserData userData, Set<String> baseDNs, ServerDescriptor server)
   {
     ArrayList<String> cmdLine = new ArrayList<String>();
-    String cmdName;
-    if (Utils.isWindows())
-    {
-      cmdName = "dsreplication.bat";
-    }
-    else
-    {
-      cmdName = "dsreplication";
-    }
+    String cmdName = getCommandLinePath("dsreplication");
     cmdLine.add(cmdName);
     cmdLine.add("enable");
 
@@ -2564,20 +2560,87 @@
     return cmdLine;
   }
 
+  /**
+   * Returns the full path of the command-line for a given script name.
+   * @param scriptBasicName the script basic name (with no extension).
+   * @return the full path of the command-line for a given script name.
+   */
+  private static String getCommandLinePath(String scriptBasicName)
+  {
+    String cmdLineName;
+    if (isWindows())
+    {
+      cmdLineName = getBinaryDir()+scriptBasicName+".bat";
+    }
+    else
+    {
+      cmdLineName = getBinaryDir()+scriptBasicName;
+    }
+    return cmdLineName;
+  }
+
+  private static String binDir;
+  /**
+   * Returns the binary/script directory.
+   * @return the binary/script directory.
+   */
+  private static String getBinaryDir()
+  {
+    if (binDir == null)
+    {
+      File f = Installation.getLocal().getBinariesDirectory();
+      try
+      {
+        binDir = f.getCanonicalPath();
+      }
+      catch (Throwable t)
+      {
+        binDir = f.getAbsolutePath();
+      }
+      if (binDir.lastIndexOf(File.separatorChar) != (binDir.length() - 1))
+      {
+        binDir += File.separatorChar;
+      }
+    }
+
+    return binDir;
+  }
+
+  private static String installDir;
+  /**
+   * Returns the installation directory.
+   * @return the installation directory.
+   */
+  private static String getInstallDir()
+  {
+    if (installDir == null)
+    {
+      File f =
+        org.opends.quicksetup.Installation.getLocal().getRootDirectory();
+      try
+      {
+        installDir = f.getCanonicalPath();
+      }
+      catch (Throwable t)
+      {
+        installDir = f.getAbsolutePath();
+      }
+      if (installDir.lastIndexOf(File.separatorChar) !=
+        (installDir.length() - 1))
+      {
+        installDir += File.separatorChar;
+      }
+    }
+
+    return installDir;
+  }
+
   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";
-    }
+    String cmdName = getCommandLinePath("dsreplication");
     cmdLine.add(cmdName);
     cmdLine.add("initialize");
 
@@ -2706,15 +2769,7 @@
   {
     ArrayList<ArrayList<String>> cmdLines = new ArrayList<ArrayList<String>>();
 
-    String cmdName;
-    if (Utils.isWindows())
-    {
-      cmdName = "dsconfig.bat";
-    }
-    else
-    {
-      cmdName = "dsconfig";
-    }
+    String cmdName = getCommandLinePath("dsconfig");
 
     ArrayList<String> connectionArgs = new ArrayList<String>();
     connectionArgs.add("--hostName");

--
Gitblit v1.10.0