From cddb76e70b7127f5e0d0088bd59de99ebd1359e1 Mon Sep 17 00:00:00 2001
From: Violette Roche-Montane <violette.roche-montane@forgerock.com>
Date: Mon, 27 May 2013 13:07:05 +0000
Subject: [PATCH] OPENDJ-928 Update tool: add option to automatically accept the license
---
opends/src/server/org/opends/server/tools/upgrade/UpgradeCli.java | 56 +++++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 43 insertions(+), 13 deletions(-)
diff --git a/opends/src/server/org/opends/server/tools/upgrade/UpgradeCli.java b/opends/src/server/org/opends/server/tools/upgrade/UpgradeCli.java
index 9834d20..eb78921 100644
--- a/opends/src/server/org/opends/server/tools/upgrade/UpgradeCli.java
+++ b/opends/src/server/org/opends/server/tools/upgrade/UpgradeCli.java
@@ -95,6 +95,7 @@
private BooleanArgument force;
private BooleanArgument quietMode;
private BooleanArgument verbose;
+ private BooleanArgument acceptLicense;
// The argument which should be used to request usage information.
@@ -197,7 +198,7 @@
}
/**
- * Force the upgrade. All answers will be forced to 'yes'.
+ * Force the upgrade. All critical questions will be forced to 'yes'.
*
* @return {@code true} if the upgrade process is forced.
*/
@@ -208,6 +209,7 @@
/**
* Force to ignore the errors during the upgrade process.
+ * Continues rather than fails.
*
* @return {@code true} if the errors are forced to be ignored.
*/
@@ -216,6 +218,16 @@
return ignoreErrors.isPresent();
}
+ /**
+ * Automatically accepts the license if it's present.
+ *
+ * @return {@code true} if license is accepted by default.
+ */
+ public boolean isAcceptLicense()
+ {
+ return acceptLicense.isPresent();
+ }
+
// Displays the provided message followed by a help usage reference.
private void displayMessageAndUsageReference(final Message message)
{
@@ -263,10 +275,14 @@
OPTION_LONG_FORCE_UPGRADE,
INFO_UPGRADE_OPTION_FORCE.get(OPTION_LONG_NO_PROMPT));
+ acceptLicense = new BooleanArgument(OPTION_LONG_ACCEPT_LICENSE, null,
+ OPTION_LONG_ACCEPT_LICENSE, INFO_OPTION_ACCEPT_LICENSE.get());
+
showUsageArgument =
new BooleanArgument("help", OPTION_SHORT_HELP, OPTION_LONG_HELP,
INFO_DESCRIPTION_USAGE.get());
+
// Register the global arguments.
parser.addGlobalArgument(showUsageArgument);
parser.setUsageArgument(showUsageArgument, this.getOutputStream());
@@ -277,6 +293,7 @@
parser.addGlobalArgument(quietMode);
parser.addGlobalArgument(force);
parser.addGlobalArgument(ignoreErrors);
+ parser.addGlobalArgument(acceptLicense);
globalArgumentsInitialized = true;
}
@@ -352,14 +369,15 @@
catch (ClientException ex)
{
LOG.log(SEVERE, ex.getMessage());
- println(ERROR, ex.getMessageObject(), 0);
+ println(Style.ERROR, ex.getMessageObject(), 0);
return ex.getExitCode();
}
catch (Exception ex)
{
LOG.log(SEVERE, ex.getMessage());
- println(ERROR, ERR_UPGRADE_MAIN_UPGRADE_PROCESS.get(ex.getMessage()), 0);
+ println(Style.ERROR, ERR_UPGRADE_MAIN_UPGRADE_PROCESS.get(ex
+ .getMessage()), 0);
return EXIT_CODE_ERROR;
}
@@ -391,13 +409,14 @@
switch (fnc.getMessageSubType())
{
case TITLE_CALLBACK:
- println(TITLE, Message.raw(fnc.getMessage()), 0);
+ println(Style.TITLE, Message.raw(fnc.getMessage()), 0);
break;
case SUBTITLE_CALLBACK:
- println(SUBTITLE, Message.raw(fnc.getMessage()), 4);
+ println(Style.SUBTITLE, Message.raw(fnc.getMessage()),
+ 4);
break;
case NOTICE_CALLBACK:
- println(NOTICE, Message.raw(fnc.getMessage()), 0);
+ println(Style.NOTICE, Message.raw(fnc.getMessage()), 0);
break;
default:
LOG.log(SEVERE, "Unsupported message type: "
@@ -439,8 +458,8 @@
{
if (!isInteractive() && !isForceUpgrade())
{
- println(ERROR, ERR_UPGRADE_USER_INTERACTION_REQUIRED.get(
- OPTION_LONG_NO_PROMPT, OPTION_LONG_FORCE_UPGRADE), 0);
+ println(Style.ERROR, ERR_UPGRADE_USER_INTERACTION_REQUIRED
+ .get(OPTION_LONG_NO_PROMPT, OPTION_LONG_FORCE_UPGRADE), 0);
cc.setSelectedIndex(ConfirmationCallback.NO);
return;
}
@@ -455,15 +474,15 @@
{
if (!isInteractive() && !isForceUpgrade())
{
- println(ERROR, ERR_UPGRADE_USER_INTERACTION_REQUIRED.get(
- OPTION_LONG_NO_PROMPT, OPTION_LONG_FORCE_UPGRADE), 0);
+ println(Style.ERROR, ERR_UPGRADE_USER_INTERACTION_REQUIRED
+ .get(OPTION_LONG_NO_PROMPT, OPTION_LONG_FORCE_UPGRADE), 0);
cc.setSelectedIndex(ConfirmationCallback.NO);
return;
}
}
// Does the user specify the ignore errors mode ?
- if(opt == IGNORE_ERRORS_MODE) {
+ if (opt == IGNORE_ERRORS_MODE) {
if (!isIgnoreErrors())
{
cc.setSelectedIndex(ConfirmationCallback.NO);
@@ -471,6 +490,15 @@
}
cc.setSelectedIndex(ConfirmationCallback.YES);
}
+
+ if (opt == ACCEPT_LICENSE_MODE) {
+ if (!isAcceptLicense())
+ {
+ cc.setSelectedIndex(ConfirmationCallback.NO);
+ return;
+ }
+ cc.setSelectedIndex(ConfirmationCallback.YES);
+ }
}
return;
}
@@ -531,7 +559,9 @@
String value = null;
try
{
- value = readInput(Message.raw(prompt), defaultOption, SUBTITLE);
+ value =
+ readInput(Message.raw(prompt), defaultOption,
+ Style.SUBTITLE);
}
catch (CLIException e)
{
@@ -581,7 +611,7 @@
// Displays the prompt
prompt.append(" ").append(
UpgradeContext.getDefaultOption(cc.getSelectedIndex()));
- println(SUBTITLE, Message.raw(prompt), 0);
+ println(Style.SUBTITLE, Message.raw(prompt), 0);
LOG.log(INFO, UpgradeContext.getDefaultOption(cc.getSelectedIndex()));
}
}
--
Gitblit v1.10.0