From 251930b6f131025423207a8a3ea02c21b50bf400 Mon Sep 17 00:00:00 2001
From: Violette Roche-Montane <violette.roche-montane@forgerock.com>
Date: Thu, 30 May 2013 12:17:22 +0000
Subject: [PATCH] OPENDJ-930 setup in non-interactive mode should not accept automatically the license - added --acceptLicense to the setup command line options. - modified code for checking the license during the setup : 	- using the no-prompt option no longer bypass the license if presents. 	- displays now the license text, question and answer(yes) when used with the --acceptLicense.

---
 opends/src/server/org/opends/server/tools/InstallDS.java               |   71 +++++++++++++++++++++--------------
 opends/src/server/org/opends/server/tools/InstallDSArgumentParser.java |    5 ++
 2 files changed, 47 insertions(+), 29 deletions(-)

diff --git a/opends/src/server/org/opends/server/tools/InstallDS.java b/opends/src/server/org/opends/server/tools/InstallDS.java
index 89a6d65..9e7d8a7 100644
--- a/opends/src/server/org/opends/server/tools/InstallDS.java
+++ b/opends/src/server/org/opends/server/tools/InstallDS.java
@@ -428,11 +428,10 @@
       PrintStream printStreamOut = getOutputStream();
       String licenseString = LicenseFile.getText();
       printStreamOut.println(licenseString);
-      if (! argParser.noPromptArg.isPresent())
+      // If the user asks for acceptLicense, license is displayed
+      // and automatically accepted.
+      if (! argParser.acceptLicense.isPresent())
       {
-        // 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.
         String yes = INFO_LICENSE_CLI_ACCEPT_YES.get().toString();
         String no = INFO_LICENSE_CLI_ACCEPT_NO.get().toString();
         String yesShort = INFO_PROMPT_YES_FIRST_LETTER_ANSWER.get().toString();
@@ -441,39 +440,53 @@
             INFO_LICENSE_DETAILS_CLI_LABEL.get());
 
         BufferedReader in = getInputStream();
-        while (true)
+        // No-prompt arg automatically rejects the license.
+        if (!argParser.noPromptArg.isPresent())
         {
-          print(INFO_LICENSE_CLI_ACCEPT_QUESTION.get(yes,no,no));
-          try
+          while (true)
           {
-            String response = in.readLine();
-            if ((response == null)
-                || (response.equalsIgnoreCase(no))
-                || (response.equalsIgnoreCase(noShort))
-                || (response.length() == 0))
+            print(INFO_LICENSE_CLI_ACCEPT_QUESTION.get(yes, no, no));
+            try
             {
-              return ErrorReturnCode.ERROR_LICENSE_NOT_ACCEPTED
-                  .getReturnCode();
+              String response = in.readLine();
+              if ((response == null) || (response.equalsIgnoreCase(no))
+                  || (response.equalsIgnoreCase(noShort))
+                  || (response.length() == 0))
+              {
+                return ErrorReturnCode.ERROR_LICENSE_NOT_ACCEPTED
+                    .getReturnCode();
+              }
+              else if (response.equalsIgnoreCase(yes)
+                  || response.equalsIgnoreCase(yesShort))
+              {
+                LicenseFile.setApproval(true);
+                break;
+              }
+              else
+              {
+                println(
+                    QuickSetupMessages.INFO_LICENSE_CLI_ACCEPT_INVALID_RESPONSE
+                    .get());
+              }
             }
-            else
-            if (response.equalsIgnoreCase(yes)
-                || response.equalsIgnoreCase(yesShort))
+            catch (IOException e)
             {
-              LicenseFile.setApproval(true);
-              break ;
+              println(
+                  QuickSetupMessages.INFO_LICENSE_CLI_ACCEPT_INVALID_RESPONSE
+                  .get());
             }
-            else
-            {
-              println(QuickSetupMessages
-                  .INFO_LICENSE_CLI_ACCEPT_INVALID_RESPONSE.get());
-            }
-          }
-          catch (IOException e)
-          {
-            println(QuickSetupMessages.
-                INFO_LICENSE_CLI_ACCEPT_INVALID_RESPONSE.get());
           }
         }
+        else
+        {
+          return ErrorReturnCode.ERROR_LICENSE_NOT_ACCEPTED.getReturnCode();
+        }
+      }
+      else
+      {
+        print(INFO_LICENSE_ACCEPT.get());
+        print(INFO_PROMPT_YES_COMPLETE_ANSWER.get());
+        LicenseFile.setApproval(true);
       }
     }
 
diff --git a/opends/src/server/org/opends/server/tools/InstallDSArgumentParser.java b/opends/src/server/org/opends/server/tools/InstallDSArgumentParser.java
index aaec993..cdd3871 100644
--- a/opends/src/server/org/opends/server/tools/InstallDSArgumentParser.java
+++ b/opends/src/server/org/opends/server/tools/InstallDSArgumentParser.java
@@ -99,6 +99,7 @@
   StringArgument    certNicknameArg;
   StringArgument    progNameArg;
   IntegerArgument   connectTimeoutArg = null;
+  BooleanArgument   acceptLicense;
 
   private static final Logger LOG = Logger.getLogger(
       InstallDSArgumentParser.class.getName());
@@ -404,6 +405,10 @@
     connectTimeoutArg.setHidden(true);
     addArgument(connectTimeoutArg);
 
+    acceptLicense = new BooleanArgument(OPTION_LONG_ACCEPT_LICENSE, null,
+        OPTION_LONG_ACCEPT_LICENSE, INFO_OPTION_ACCEPT_LICENSE.get());
+    addArgument(acceptLicense);
+
     showUsageArg = new BooleanArgument(
         OPTION_LONG_HELP.toLowerCase(), OPTION_SHORT_HELP,
         OPTION_LONG_HELP,

--
Gitblit v1.10.0