From 6df6635f1250c399a2f39d87d0534301ce4c22d7 Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Fri, 31 Aug 2007 15:43:58 +0000
Subject: [PATCH] Exposes the reversion functionality of the upgrader (issue 2169).  Originally it was intended to be exposed as a new script but in order to avoid the negativity of having a command devoted to undoing the upgrade and to avoid more scripts in the top-level directory, I've exposed the functionality as 2 new options in the existing upgrade script.  I will update the Wiki with documentation for these new options soon.

---
 opends/src/quicksetup/org/opends/quicksetup/upgrader/BuildExtractorCliHelper.java |   72 ++++++++++++++++++++++--------------
 1 files changed, 44 insertions(+), 28 deletions(-)

diff --git a/opends/src/quicksetup/org/opends/quicksetup/upgrader/BuildExtractorCliHelper.java b/opends/src/quicksetup/org/opends/quicksetup/upgrader/BuildExtractorCliHelper.java
index 5b03db0..ec58cdd 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/upgrader/BuildExtractorCliHelper.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/upgrader/BuildExtractorCliHelper.java
@@ -28,6 +28,7 @@
 package org.opends.quicksetup.upgrader;
 
 import static org.opends.messages.QuickSetupMessages.*;
+import org.opends.messages.Message;
 
 import org.opends.quicksetup.UserDataException;
 
@@ -44,6 +45,14 @@
           Logger.getLogger(BuildExtractorCliHelper.class.getName());
 
   /**
+   * Create a parameterized instance.
+   * @param launcher for this CLI
+   */
+  public BuildExtractorCliHelper(UpgradeLauncher launcher) {
+    super(launcher);
+  }
+
+  /**
    * Creates a set of user data from command line arguments and installation
    * status.
    * @param args String[] of arguments passed in from the command line
@@ -53,37 +62,44 @@
   public UpgradeUserData createUserData(String[] args)
     throws UserDataException {
     UpgradeUserData uud = super.createUserData(args);
-
-    // Build extractor is always quiet whether user
-    // has specified this or not.
-    uud.setQuiet(true);
-
-    if (localInstallPackFileNameArg.isPresent()) {
-      String localInstallPackFileName =
-              localInstallPackFileNameArg.getValue();
-      LOG.log(Level.INFO, "file specified on command line: " +
-              localInstallPackFileName);
-      uud.setInstallPackage(
-              validateInstallPackFile(localInstallPackFileName));
-    } else if (isInteractive()) {
-      LOG.log(Level.INFO, "obtaining file information interactively");
-      while(true) {
-        String fileName = promptForString(
-                INFO_UPGRADE_FILE_PROMPT.get(), null);
-        try {
-          uud.setInstallPackage(validateInstallPackFile(fileName));
-          LOG.log(Level.INFO, "file specified interactively: " +
-                  fileName);
-          break;
-        } catch (UserDataException ude) {
-          System.out.println(ude.getMessage());
+    if (launcher.isInteractive()) {
+      if (!launcher.isNoPrompt()) {
+        LOG.log(Level.INFO, "obtaining file information interactively");
+        Message[] options = new Message[] {
+                INFO_UPGRADE_OPERATION_UPGRADE.get(),
+                INFO_UPGRADE_OPERATION_REVERSION.get()
+        };
+        int response = promptOptions(
+                INFO_UPGRADE_OPERATION_PROMPT.get(),
+                options[0],
+                options);
+        if (response == 0) {
+          uud.setOperation(UpgradeUserData.Operation.UPGRADE);
+          while(true) {
+            String fileName = promptForString(
+                    INFO_UPGRADE_FILE_PROMPT.get(), null);
+            try {
+              uud.setInstallPackage(validateInstallPackFile(fileName));
+              LOG.log(Level.INFO, "file specified interactively: " +
+                      fileName);
+              break;
+            } catch (UserDataException ude) {
+              System.out.println(ude.getMessage());
+            }
+          }
+        } else {
+          uud.setOperation(UpgradeUserData.Operation.REVERSION);
         }
+      } else {
+        throw new UserDataException(null,
+                INFO_ERROR_OPTIONS_REQUIRED_OR_INTERACTIVE.get());
       }
     } else {
-      throw new UserDataException(null,
-              INFO_ERROR_OPTION_REQUIRED_OR_INTERACTIVE.get("-" +
-                      UpgradeLauncher.FILE_OPTION_SHORT + "/--" +
-                              UpgradeLauncher.FILE_OPTION_LONG));
+      String upgradeFile = launcher.getUpgradeFileName();
+      if (upgradeFile != null) {
+        uud.setInstallPackage(
+                validateInstallPackFile(upgradeFile));
+      }
     }
     return uud;
   }

--
Gitblit v1.10.0