From 7d4d2d228f709268250855b1609c8501c43c874e Mon Sep 17 00:00:00 2001
From: Violette Roche-Montane <violette.roche-montane@forgerock.com>
Date: Tue, 25 Jun 2013 15:06:39 +0000
Subject: [PATCH] OPENDJ-1010 "upgrade --force" should not automatically accept the license

---
 opendj-sdk/opends/src/server/org/opends/server/tools/upgrade/Upgrade.java                       |   29 +++++++++++++++++++----------
 opendj-sdk/opends/src/server/org/opends/server/tools/upgrade/UpgradeCli.java                    |   13 +++++++------
 opendj-sdk/opends/src/server/org/opends/server/tools/upgrade/UpgradeTasks.java                  |    2 ++
 opendj-sdk/opends/src/server/org/opends/server/tools/upgrade/FormattedNotificationCallback.java |    4 ++++
 4 files changed, 32 insertions(+), 16 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/upgrade/FormattedNotificationCallback.java b/opendj-sdk/opends/src/server/org/opends/server/tools/upgrade/FormattedNotificationCallback.java
index ad864ba..9fd962b 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/upgrade/FormattedNotificationCallback.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/upgrade/FormattedNotificationCallback.java
@@ -46,6 +46,10 @@
 
   static final int NOTICE_CALLBACK = 7;
 
+  static final int ERROR_CALLBACK = 8;
+
+  static final int BREAKLINE = 9;
+
   /**
    * An integer representing the message's sub-type.
    */
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/upgrade/Upgrade.java b/opendj-sdk/opends/src/server/org/opends/server/tools/upgrade/Upgrade.java
index 86eca24..830f4a5 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/upgrade/Upgrade.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/upgrade/Upgrade.java
@@ -631,18 +631,26 @@
       if (LicenseFile.exists())
       {
         context.notify(Message.raw("\n" + LicenseFile.getText()));
-
-        // If the user asks for no-prompt. We just display the license text.
-        // User doesn't asks for no-prompt. We just display the license text
-        // and force to accept it.
         context.notify(INFO_LICENSE_DETAILS_CLI_LABEL.get());
-
         if (!context.isAcceptLicenseMode())
         {
+          final int answer;
 
-          final int answer =
-              context.confirmYN(INFO_LICENSE_ACCEPT.get(),
-                  ConfirmationCallback.NO);
+          // The force cannot answer yes to the license's question,
+          // which is not a task even if it requires a user interaction OR
+          // -an accept license mode to continue the process.
+          if (context.isForceUpgradeMode())
+          {
+            answer = ConfirmationCallback.NO;
+            context.notify(Message.raw(INFO_LICENSE_ACCEPT.get() + " "
+                + INFO_PROMPT_NO_COMPLETE_ANSWER.get()));
+          }
+          else
+          {
+            answer =
+                context.confirmYN(INFO_LICENSE_ACCEPT.get(),
+                    ConfirmationCallback.NO);
+          }
 
           if (answer == ConfirmationCallback.NO)
           {
@@ -655,8 +663,9 @@
         }
         else
         {
-          context.notify(INFO_LICENSE_ACCEPT.get());
-          context.notify(INFO_PROMPT_YES_COMPLETE_ANSWER.get());
+          // We automatically accept the license with this option.
+          context.notify(Message.raw(INFO_LICENSE_ACCEPT.get() + " "
+              + INFO_PROMPT_YES_COMPLETE_ANSWER.get()));
           LicenseFile.setApproval(true);
         }
       }
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/upgrade/UpgradeCli.java b/opendj-sdk/opends/src/server/org/opends/server/tools/upgrade/UpgradeCli.java
index bf0cbb3..8b1d334 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/upgrade/UpgradeCli.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/upgrade/UpgradeCli.java
@@ -32,12 +32,7 @@
 import static org.opends.server.util.StaticUtils.filterExitCode;
 import static java.util.logging.Level.INFO;
 import static java.util.logging.Level.SEVERE;
-import static org.opends.server.tools.upgrade.
-FormattedNotificationCallback.NOTICE_CALLBACK;
-import static org.opends.server.tools.upgrade.
-FormattedNotificationCallback.SUBTITLE_CALLBACK;
-import static org.opends.server.tools.upgrade.
-FormattedNotificationCallback.TITLE_CALLBACK;
+import static org.opends.server.tools.upgrade.FormattedNotificationCallback.*;
 import static org.opends.server.tools.upgrade.Upgrade.EXIT_CODE_ERROR;
 import static org.opends.server.tools.upgrade.Upgrade.EXIT_CODE_SUCCESS;
 
@@ -427,6 +422,12 @@
         case NOTICE_CALLBACK:
           println(Style.NOTICE, Message.raw(fnc.getMessage()), 1);
           break;
+        case ERROR_CALLBACK:
+          println(Style.ERROR, Message.raw(fnc.getMessage()), 1);
+          break;
+        case BREAKLINE:
+          println(Style.BREAKLINE, Message.raw(fnc.getMessage()), 1);
+          break;
         default:
           LOG.log(SEVERE, "Unsupported message type: "
             + fnc.getMessage());
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/upgrade/UpgradeTasks.java b/opendj-sdk/opends/src/server/org/opends/server/tools/upgrade/UpgradeTasks.java
index 334f8e1..e371846 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/upgrade/UpgradeTasks.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/upgrade/UpgradeTasks.java
@@ -797,6 +797,8 @@
       // The option is not present ? Stops the process.
       if (!context.isInteractiveMode() && !context.isForceUpgradeMode())
       {
+        context
+            .notify(Message.raw(" "), FormattedNotificationCallback.BREAKLINE);
         context.notify(ERR_UPGRADE_USER_INTERACTION_REQUIRED.get(
             OPTION_LONG_NO_PROMPT, OPTION_LONG_FORCE_UPGRADE),
             FormattedNotificationCallback.NOTICE_CALLBACK);

--
Gitblit v1.10.0