From 6df0f6e8fbf553f53e3e558cc108c8ff42dfa48f Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Thu, 09 Aug 2007 08:09:41 +0000
Subject: [PATCH] Fix for issue 1857 (Uninstall silent option works as interactive option).

---
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgradeLauncher.java   |   11 ++++-
 opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/UninstallLauncher.java  |   13 ++++++
 opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/Uninstaller.java        |    8 ++--
 opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java |   68 +++++++++++++++++++++------------
 4 files changed, 68 insertions(+), 32 deletions(-)

diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java
index 4afdca8..b34331b 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java
+++ b/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java
@@ -27,11 +27,14 @@
 
 package org.opends.guitools.uninstaller;
 
+import org.opends.admin.ads.util.ApplicationTrustManager;
 import org.opends.guitools.i18n.ResourceProvider;
 import org.opends.quicksetup.*;
 import org.opends.quicksetup.util.Utils;
+import org.opends.server.util.args.Argument;
+import org.opends.server.util.args.ArgumentException;
+import org.opends.server.util.args.ArgumentParser;
 
-import java.util.HashSet;
 import java.util.Set;
 import java.util.Collections;
 import java.util.logging.Level;
@@ -59,36 +62,48 @@
    * Creates a UserData based in the arguments provided.  It asks
    * user for additional information if what is provided in the arguments is not
    * enough.
-   * @param args the arguments provided in the command line.
+   * @param args the ArgumentParser with the allowed arguments of the command
+   * line.
+   * @param rawArguments the arguments provided in the command line.
+   * @param trustManager the Application Trust Manager to be used to connect
+   * to the remote servers.
    * @return the UserData object with what the user wants to uninstall
    * and null if the user cancels the uninstallation.
    * @throws UserDataException if there is an error parsing the data
    * in the arguments.
    */
-  public UninstallUserData createUserData(String[] args
-  ) throws UserDataException
+  public UninstallUserData createUserData(ArgumentParser args,
+      String[] rawArguments, ApplicationTrustManager trustManager)
+  throws UserDataException
   {
     UninstallUserData userData = new UninstallUserData();
 
-    boolean silentUninstall;
+    boolean isInteractive;
+    boolean isSilent;
     boolean isCancelled = false;
 
-    /* Step 1: validate the arguments
+    /* Step 1: analyze the arguments.  We assume that the arguments have
+     * already been parsed.
      */
-    Set<String> validArgs = new HashSet<String>();
-    validArgs.add("--cli");
-    validArgs.add("-c");
-    validArgs.add("-H");
-    validArgs.add("--help");
-    validArgs.add("--silentUninstall");
-    validArgs.add("-s");
-    validateArguments(userData, args, validArgs);
+    try
+    {
+      args.parseArguments(rawArguments);
+    }
+    catch (ArgumentException ae)
+    {
+      throw new UserDataException(null, ae.getLocalizedMessage());
+    }
 
-    silentUninstall = isSilent(args);
+    Argument interactive = args.getArgumentForLongID(INTERACTIVE_OPTION_LONG);
+    isInteractive = interactive != null && interactive.isPresent();
 
+    Argument silent = args.getArgumentForLongID(SILENT_OPTION_LONG);
+    isSilent = silent != null && silent.isPresent();
 
-    /* Step 2: If this is not a silent install ask for confirmation to delete
-     * the different parts of the installation
+    userData.setSilent(isSilent);
+
+    /* Step 2: If this is an interactive uninstall ask for confirmation to
+     * delete the different parts of the installation.
      */
     Set<String> outsideDbs;
     Set<String> outsideLogs;
@@ -108,7 +123,7 @@
       LOG.log(Level.INFO, "error determining outside logs", ioe);
     }
 
-    if (silentUninstall)
+    if (!isInteractive)
     {
       userData.setRemoveBackups(true);
       userData.setRemoveConfigurationAndSchema(true);
@@ -131,7 +146,7 @@
      */
     if (!isCancelled)
     {
-      isCancelled = askConfirmationToStop(userData, silentUninstall);
+      isCancelled = askConfirmationToStop(userData, isInteractive);
     }
 
     if (isCancelled)
@@ -300,8 +315,11 @@
             !userData.getRemoveLogs())
         {
           somethingSelected = false;
-          System.out.println(Constants.LINE_SEPARATOR+
-              getMsg("cli-uninstall-nothing-to-be-uninstalled"));
+          if (!userData.isSilent())
+          {
+            System.out.println(Constants.LINE_SEPARATOR+
+                getMsg("cli-uninstall-nothing-to-be-uninstalled"));
+          }
         }
         else
         {
@@ -319,7 +337,7 @@
    * be able to shut down the server in Windows.
    * @param userData the UserData object to be updated with the
    * authentication of the user.
-   * @param silentUninstall boolean telling whether this is a silent uninstall
+   * @param interactive boolean telling whether this is an interactive uninstall
    * or not.
    * @return <CODE>true</CODE> if the user wants to continue with uninstall and
    * <CODE>false</CODE> otherwise.
@@ -328,14 +346,14 @@
    * uninstall and some data is missing or not valid).
    */
   private boolean askConfirmationToStop(UserData userData,
-                                        boolean silentUninstall)
+                                        boolean interactive)
   throws UserDataException
   {
     boolean cancelled = false;
     Status status = Installation.getLocal().getStatus();
     if (status.isServerRunning())
     {
-        if (!silentUninstall)
+        if (interactive)
         {
             /* Ask for confirmation to stop server */
             cancelled = !confirmToStopServer();
@@ -350,7 +368,7 @@
     else
     {
       userData.setStopServer(false);
-      if (!silentUninstall)
+      if (interactive)
       {
         /* Ask for confirmation to delete files */
         cancelled = !confirmDeleteFiles();
diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/UninstallLauncher.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/UninstallLauncher.java
index 3ad72c0..04318a3 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/UninstallLauncher.java
+++ b/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/UninstallLauncher.java
@@ -35,6 +35,7 @@
 
 import org.opends.guitools.i18n.ResourceProvider;
 import org.opends.quicksetup.CliApplication;
+import org.opends.quicksetup.CliApplicationHelper;
 import org.opends.quicksetup.Launcher;
 import org.opends.quicksetup.Installation;
 import org.opends.quicksetup.QuickSetupLog;
@@ -102,13 +103,23 @@
         getI18n().getMsg("uninstall-launcher-usage-description"), false);
     BooleanArgument cli;
     BooleanArgument silent;
+    BooleanArgument interactive;
     BooleanArgument showUsage;
     try
     {
       cli = new BooleanArgument("cli", 'c', "cli",
           MSGID_UNINSTALLDS_DESCRIPTION_CLI);
       argParser.addArgument(cli);
-      silent = new BooleanArgument("silent", 's', "silent",
+      interactive = new BooleanArgument(
+          CliApplicationHelper.INTERACTIVE_OPTION_LONG,
+          CliApplicationHelper.INTERACTIVE_OPTION_SHORT,
+          CliApplicationHelper.INTERACTIVE_OPTION_LONG,
+          MSGID_DESCRIPTION_INTERACTIVE);
+      argParser.addArgument(interactive);
+      silent = new BooleanArgument(
+          CliApplicationHelper.SILENT_OPTION_LONG,
+          CliApplicationHelper.SILENT_OPTION_SHORT,
+          CliApplicationHelper.SILENT_OPTION_LONG,
           MSGID_UNINSTALLDS_DESCRIPTION_SILENT);
       argParser.addArgument(silent);
       showUsage = new BooleanArgument("showusage", OPTION_SHORT_HELP,
diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/Uninstaller.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/Uninstaller.java
index 5b82226..e293176 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/Uninstaller.java
+++ b/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/Uninstaller.java
@@ -107,8 +107,6 @@
   private UninstallData conf;
   private String replicationServerHostPort;
   private TopologyCache lastLoadedCache;
-  private ApplicationTrustManager trustManager =
-    new ApplicationTrustManager(null);
 
   /**
    * Default constructor.
@@ -567,7 +565,8 @@
    */
   public UserData createUserData(Launcher launcher)
           throws UserDataException {
-    return cliHelper.createUserData(launcher.getArguments());
+    return cliHelper.createUserData(launcher.getArgumentParser(),
+        launcher.getArguments(), getTrustManager());
   }
 
   /**
@@ -1328,7 +1327,8 @@
   {
     if (loginDialog == null)
     {
-      loginDialog = new LoginDialog(qs.getDialog().getFrame(), trustManager);
+      loginDialog = new LoginDialog(qs.getDialog().getFrame(),
+          getTrustManager());
       loginDialog.pack();
     }
     Utilities.centerOnComponent(loginDialog, qs.getDialog().getFrame());
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgradeLauncher.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgradeLauncher.java
index 11084c6..ee3a6f4 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgradeLauncher.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgradeLauncher.java
@@ -30,6 +30,7 @@
 import static org.opends.server.messages.ToolMessages.*;
 import static org.opends.server.tools.ToolConstants.*;
 
+import org.opends.quicksetup.CliApplicationHelper;
 import org.opends.quicksetup.Launcher;
 import org.opends.quicksetup.CliApplication;
 import org.opends.quicksetup.Installation;
@@ -186,10 +187,16 @@
               "{file}",
               null, null, MSGID_UPGRADE_DESCRIPTION_FILE);
       argParser.addArgument(file);
-      interactive = new BooleanArgument("interactive", 'i', "interactive",
+      interactive = new BooleanArgument(
+          CliApplicationHelper.INTERACTIVE_OPTION_LONG,
+          CliApplicationHelper.INTERACTIVE_OPTION_SHORT,
+          CliApplicationHelper.INTERACTIVE_OPTION_LONG,
           MSGID_UPGRADE_DESCRIPTION_INTERACTIVE);
       argParser.addArgument(interactive);
-      silent = new BooleanArgument("silent", 's', "silent",
+      silent = new BooleanArgument(
+          CliApplicationHelper.SILENT_OPTION_LONG,
+          CliApplicationHelper.SILENT_OPTION_SHORT,
+          CliApplicationHelper.SILENT_OPTION_LONG,
           MSGID_UPGRADE_DESCRIPTION_SILENT);
       argParser.addArgument(silent);
       showUsage = new BooleanArgument("showusage", OPTION_SHORT_HELP,

--
Gitblit v1.10.0