From 7b11fcf138a9310aa14d26fea3249d6073c38828 Mon Sep 17 00:00:00 2001
From: Gaetan Boismal <gaetan.boismal@forgerock.com>
Date: Mon, 11 Apr 2016 17:22:17 +0000
Subject: [PATCH] Code cleanup
---
/dev/null | 122 -----------------
opendj-server-legacy/src/main/java/org/opends/quicksetup/SplashScreen.java | 17 +
opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/UninstallLauncher.java | 33 +---
opendj-server-legacy/src/main/java/org/opends/quicksetup/Application.java | 41 ++---
opendj-server-legacy/src/main/java/org/opends/server/tools/InstallDS.java | 35 ++--
opendj-server-legacy/src/main/java/org/opends/quicksetup/ui/QuickSetup.java | 7
opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java | 12 -
opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/SetupLauncher.java | 45 +----
opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/offline/OfflineInstaller.java | 20 ++
opendj-server-legacy/src/main/java/org/opends/quicksetup/Launcher.java | 47 ++----
opendj-server-legacy/src/main/java/org/opends/quicksetup/Constants.java | 8 -
11 files changed, 99 insertions(+), 288 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/UninstallLauncher.java b/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/UninstallLauncher.java
index 3375210..e450acf 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/UninstallLauncher.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/UninstallLauncher.java
@@ -12,7 +12,7 @@
* information: "Portions Copyright [year] [name of copyright owner]".
*
* Copyright 2006-2010 Sun Microsystems, Inc.
- * Portions Copyright 2011-2015 ForgeRock AS.
+ * Portions Copyright 2011-2016 ForgeRock AS.
*/
package org.opends.guitools.uninstaller;
@@ -25,11 +25,9 @@
import org.forgerock.i18n.LocalizableMessage;
import org.opends.messages.ToolMessages;
-import java.io.File;
import org.opends.quicksetup.CliApplication;
import org.opends.quicksetup.Launcher;
import org.opends.quicksetup.Installation;
-import org.opends.quicksetup.QuickSetupLog;
import org.opends.quicksetup.ReturnCode;
import org.opends.quicksetup.util.Utils;
import org.opends.server.util.DynamicConstants;
@@ -48,9 +46,6 @@
/** Prefix for log files. */
public static final String LOG_FILE_PREFIX = "opendj-uninstall-";
- /** Suffix for log files. */
- public static final String LOG_FILE_SUFFIX = ".log";
-
/**
* The main method which is called by the uninstall command lines.
*
@@ -59,14 +54,6 @@
* will pass to the org.opends.server.tools.InstallDS class.
*/
public static void main(String[] args) {
- try {
- QuickSetupLog.initLogFileHandler(
- File.createTempFile(LOG_FILE_PREFIX, LOG_FILE_SUFFIX));
-
- } catch (Throwable t) {
- System.err.println("Unable to initialize log");
- t.printStackTrace();
- }
new UninstallLauncher(args).launch();
}
@@ -78,7 +65,7 @@
* @param args the arguments passed by the command lines.
*/
public UninstallLauncher(String[] args) {
- super(args);
+ super(args, LOG_FILE_PREFIX);
String scriptName;
if (isWindows()) {
@@ -142,17 +129,11 @@
}
}
- /** {@inheritDoc} */
- protected void guiLaunchFailed(String logFilePath) {
- if (logFilePath != null)
- {
- System.err.println(ERR_UNINSTALL_LAUNCHER_GUI_LAUNCHED_FAILED_DETAILS
- .get(logFilePath));
- }
- else
- {
- System.err.println(ERR_UNINSTALL_LAUNCHER_GUI_LAUNCHED_FAILED.get());
- }
+ @Override
+ protected void guiLaunchFailed() {
+ System.err.println(
+ tempLogFile.isEnabled() ? ERR_UNINSTALL_LAUNCHER_GUI_LAUNCHED_FAILED_DETAILS.get(tempLogFile.getPath())
+ : ERR_UNINSTALL_LAUNCHER_GUI_LAUNCHED_FAILED.get());
}
/** {@inheritDoc} */
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/Application.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/Application.java
index d3d281e..49634ab 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/Application.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/Application.java
@@ -21,7 +21,6 @@
import static com.forgerock.opendj.cli.Utils.*;
import java.io.ByteArrayOutputStream;
-import java.io.File;
import java.io.PrintStream;
import java.util.Map;
import java.util.Set;
@@ -73,6 +72,9 @@
private ErrorPrintStream err = new ErrorPrintStream();
private OutputPrintStream out = new OutputPrintStream();
+ /** Temporary log file where messages will be logged. */
+ protected TempLogFile tempLogFile;
+
/**
* Creates an application by instantiating the Application class
* denoted by the System property
@@ -574,32 +576,6 @@
}
/**
- * Conditionally notifies listeners of the log file if it
- * has been initialized.
- */
- protected void notifyListenersOfLog() {
- File logFile = QuickSetupLog.getLogFile();
- if (logFile != null) {
- notifyListeners(getFormattedProgress(
- INFO_GENERAL_SEE_FOR_DETAILS.get(logFile.getPath())));
- notifyListeners(getLineBreak());
- }
- }
-
- /**
- * Conditionally notifies listeners of the log file if it
- * has been initialized.
- */
- protected void notifyListenersOfLogAfterError() {
- File logFile = QuickSetupLog.getLogFile();
- if (logFile != null) {
- notifyListeners(getFormattedProgress(
- INFO_GENERAL_PROVIDE_LOG_IN_ERROR.get(logFile.getPath())));
- notifyListeners(getLineBreak());
- }
- }
-
- /**
* Returns a localized representation of a TopologyCacheException object.
* @param e the exception we want to obtain the representation from.
* @return a localized representation of a TopologyCacheException object.
@@ -719,6 +695,17 @@
}
/**
+ * Sets the temporary log file where messages will be logged.
+ *
+ * @param tempLogFile
+ * temporary log file where messages will be logged.
+ */
+ public void setTempLogFile(final TempLogFile tempLogFile)
+ {
+ this.tempLogFile = tempLogFile;
+ }
+
+ /**
* This class is used to notify the ProgressUpdateListeners of events
* that are written to the standard error. It is used in OfflineInstaller.
* These classes just create a ErrorPrintStream and
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/Constants.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/Constants.java
index ded50d7..3af5c33 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/Constants.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/Constants.java
@@ -12,7 +12,7 @@
* information: "Portions Copyright [year] [name of copyright owner]".
*
* Copyright 2008 Sun Microsystems, Inc.
- * Portions Copyright 2011-2015 ForgeRock AS.
+ * Portions Copyright 2011-2016 ForgeRock AS.
*/
package org.opends.quicksetup;
@@ -66,10 +66,4 @@
/** The maximum chars we show in a line of a dialog. */
public static final int MAX_CHARS_PER_LINE_IN_DIALOG = 100;
-
- /** Prefix for log files. */
- public static final String LOG_FILE_PREFIX = "opendj-setup-";
-
- /** Suffix for log files. */
- public static final String LOG_FILE_SUFFIX = ".log";
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/Launcher.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/Launcher.java
index b807c3f..6920e0f 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/Launcher.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/Launcher.java
@@ -12,7 +12,7 @@
* information: "Portions Copyright [year] [name of copyright owner]".
*
* Copyright 2008-2009 Sun Microsystems, Inc.
- * Portions Copyright 2013-2015 ForgeRock AS.
+ * Portions Copyright 2013-2016 ForgeRock AS.
*/
package org.opends.quicksetup;
@@ -26,7 +26,6 @@
import org.opends.quicksetup.util.Utils;
import java.io.PrintStream;
-import java.io.File;
import org.forgerock.i18n.slf4j.LocalizedLogger;
@@ -41,16 +40,23 @@
/** Arguments with which this launcher was invoked. */
protected String[] args;
+ /** The temporary log file which will be kept if an error occurs. */
+ protected final TempLogFile tempLogFile;
+
/**
* Creates a Launcher.
- * @param args String[] of argument passes from the command line
+ *
+ * @param args
+ * String[] of argument passes from the command line
+ * @param tempLogFilePrefix
+ * temporary log file path where messages will be logged
*/
- public Launcher(String[] args) {
+ public Launcher(final String[] args, final String tempLogFilePrefix) {
if (args == null) {
throw new IllegalArgumentException("args cannot be null");
}
this.args = args;
-
+ this.tempLogFile = TempLogFile.newTempLogFile(tempLogFilePrefix);
}
/**
@@ -189,12 +195,12 @@
{
try
{
- SplashScreen.main(args);
+ SplashScreen.main(tempLogFile, args);
returnValue[0] = 0;
}
catch (Throwable t)
{
- if (QuickSetupLog.isInitialized())
+ if (tempLogFile.isEnabled())
{
logger.warn(LocalizableMessage.raw("Error launching GUI: "+t));
StringBuilder buf = new StringBuilder();
@@ -315,14 +321,8 @@
*/
protected abstract void willLaunchGui();
- /**
- * Called if launching of the GUI failed. Here
- * subclasses can so application specific things
- * like print a message.
- * @param logFileName the log file containing more information about why
- * the launch failed.
- */
- protected abstract void guiLaunchFailed(String logFileName);
+ /** Called if launching of the GUI failed. */
+ protected abstract void guiLaunchFailed();
/**
* The main method which is called by the command lines.
@@ -350,15 +350,7 @@
willLaunchGui();
int exitCode = launchGui(args);
if (exitCode != 0) {
- File logFile = QuickSetupLog.getLogFile();
- if (logFile != null)
- {
- guiLaunchFailed(logFile.toString());
- }
- else
- {
- guiLaunchFailed(null);
- }
+ guiLaunchFailed();
CliApplication cliApp = createCliApplication();
exitCode = launchCli(cliApp);
preExit(cliApp);
@@ -374,11 +366,8 @@
// Add an extra space systematically
System.out.println();
-
- File logFile = QuickSetupLog.getLogFile();
- if (logFile != null) {
- System.out.println(INFO_GENERAL_SEE_FOR_DETAILS.get(
- QuickSetupLog.getLogFile().getPath()));
+ if (tempLogFile.isEnabled()) {
+ System.out.println(INFO_GENERAL_SEE_FOR_DETAILS.get(tempLogFile.getPath()));
}
}
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/QuickSetupLog.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/QuickSetupLog.java
deleted file mode 100644
index 7c138e4..0000000
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/QuickSetupLog.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * The contents of this file are subject to the terms of the Common Development and
- * Distribution License (the License). You may not use this file except in compliance with the
- * License.
- *
- * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
- * specific language governing permission and limitations under the License.
- *
- * When distributing Covered Software, include this CDDL Header Notice in each file and include
- * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
- * Header, with the fields enclosed by brackets [] replaced by your own identifying
- * information: "Portions Copyright [year] [name of copyright owner]".
- *
- * Copyright 2008-2010 Sun Microsystems, Inc.
- * Portions Copyright 2011-2015 ForgeRock AS.
- */
-package org.opends.quicksetup;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.logging.FileHandler;
-import java.util.logging.Logger;
-import java.util.Date;
-import java.text.DateFormat;
-
-import org.opends.server.loggers.JDKLogging;
-
-/** Utilities for setting up QuickSetup application log. */
-public class QuickSetupLog
-{
- private static final String OPENDS_LOGGER_NAME = "org.opends";
-
- private static File LOG_FILE;
- private static FileHandler FILE_HANDLER;
-
- /**
- * Creates a new file handler for writing log messages to the file indicated by <code>file</code>.
- *
- * @param file
- * log file to which log messages will be written
- * @throws IOException
- * if something goes wrong
- */
- public static void initLogFileHandler(File file) throws IOException
- {
- if (!isInitialized())
- {
- LOG_FILE = file;
- FILE_HANDLER = new FileHandler(LOG_FILE.getCanonicalPath());
- FILE_HANDLER.setFormatter(JDKLogging.getFormatter());
- Logger logger = Logger.getLogger(OPENDS_LOGGER_NAME);
- logger.addHandler(FILE_HANDLER);
- disableConsoleLogging(logger);
- logger = Logger.getLogger(OPENDS_LOGGER_NAME + ".quicksetup");
- logger.info(getInitialLogRecord());
- }
- }
-
- /**
- * Creates a new file handler for writing log messages of a given package to the file indicated by <code>file</code>.
- *
- * @param file
- * log file to which log messages will be written.
- * @param packageName
- * the name of the package of the classes that generate log messages.
- * @throws IOException
- * if something goes wrong
- */
- public static void initLogFileHandler(File file, String packageName) throws IOException
- {
- initLogFileHandler(file);
- final Logger logger = Logger.getLogger(packageName);
- logger.addHandler(FILE_HANDLER);
- disableConsoleLogging(logger);
- }
-
- /** Prevents messages written to loggers from appearing in the console output. */
- private static void disableConsoleLogging(final Logger logger)
- {
- if (!"true".equals(System.getenv("OPENDJ_LOG_TO_STDOUT")))
- {
- logger.setUseParentHandlers(false);
- }
- }
-
- /**
- * Gets the name of the log file.
- *
- * @return File representing the log file
- */
- public static File getLogFile()
- {
- return LOG_FILE;
- }
-
- /**
- * Indicates whether or not the log file has been initialized.
- *
- * @return true when the log file has been initialized
- */
- public static boolean isInitialized()
- {
- return LOG_FILE != null;
- }
-
- /** Closes the log file and deletes it. */
- public static void closeAndDeleteLogFile()
- {
- if (LOG_FILE != null)
- {
- FILE_HANDLER.close();
- LOG_FILE.delete();
- }
- }
-
- private static String getInitialLogRecord()
- {
- // Note; currently the logs are not internationalized.
- return "QuickSetup application launched "
- + DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(new Date());
- }
-}
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/SplashScreen.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/SplashScreen.java
index 4066cfe..5fe7b17 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/SplashScreen.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/SplashScreen.java
@@ -12,7 +12,7 @@
* information: "Portions Copyright [year] [name of copyright owner]".
*
* Copyright 2006-2008 Sun Microsystems, Inc.
- * Portions Copyright 2015 ForgeRock AS.
+ * Portions Copyright 2015-2016 ForgeRock AS.
*/
package org.opends.quicksetup;
@@ -50,6 +50,7 @@
private Object quickSetup;
private Class<?> quickSetupClass;
+ private TempLogFile tempLogFile;
/** Constant for the display of the splash screen. */
private static final int MIN_SPLASH_DISPLAY = 3000;
@@ -57,11 +58,16 @@
/**
* The main method for this class.
* It can be called from the event thread and outside the event thread.
- * @param args arguments to be passed to the method QuickSetup.initialize
+ *
+ * @param tempLogFile
+ * temporary log file where messages will be logged
+ * @param args
+ * arguments to be passed to the method QuickSetup.initialize
*/
- public static void main(String[] args)
+ public static void main(final TempLogFile tempLogFile, String[] args)
{
SplashScreen screen = new SplashScreen();
+ screen.tempLogFile = tempLogFile;
screen.display(args);
}
@@ -187,9 +193,8 @@
{
quickSetupClass = Class.forName("org.opends.quicksetup.ui.QuickSetup");
quickSetup = quickSetupClass.newInstance();
- quickSetupClass.getMethod("initialize", new Class[]
- { String[].class }).invoke(quickSetup, new Object[]
- { args });
+ quickSetupClass.getMethod("initialize", new Class[] { TempLogFile.class, String[].class })
+ .invoke(quickSetup, tempLogFile, args);
} catch (Exception e)
{
InternalError error =
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java
index fa11e05..048c34a 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java
@@ -86,7 +86,6 @@
import org.opends.quicksetup.JavaArguments;
import org.opends.quicksetup.LicenseFile;
import org.opends.quicksetup.ProgressStep;
-import org.opends.quicksetup.QuickSetupLog;
import org.opends.quicksetup.ReturnCode;
import org.opends.quicksetup.SecurityOptions;
import org.opends.quicksetup.Step;
@@ -227,17 +226,6 @@
public Installer()
{
addStepsInOrder(lstSteps, LicenseFile.exists());
- try
- {
- if (!QuickSetupLog.isInitialized())
- {
- QuickSetupLog.initLogFileHandler(File.createTempFile(Constants.LOG_FILE_PREFIX, Constants.LOG_FILE_SUFFIX));
- }
- }
- catch (IOException e)
- {
- System.err.println("Failed to initialize log");
- }
}
@Override
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/SetupLauncher.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/SetupLauncher.java
index 08f7e43..c023961 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/SetupLauncher.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/SetupLauncher.java
@@ -20,14 +20,10 @@
import static org.opends.messages.ToolMessages.*;
import static org.opends.server.util.ServerConstants.*;
-import java.io.File;
-
import org.forgerock.i18n.LocalizableMessage;
import org.opends.quicksetup.CliApplication;
-import org.opends.quicksetup.Constants;
import org.opends.quicksetup.Installation;
import org.opends.quicksetup.Launcher;
-import org.opends.quicksetup.QuickSetupLog;
import org.opends.quicksetup.ReturnCode;
import org.opends.quicksetup.installer.offline.OfflineInstaller;
import org.opends.quicksetup.util.IncompatibleVersionException;
@@ -46,6 +42,9 @@
* based setup much be launched.
*/
public class SetupLauncher extends Launcher {
+
+ private static final String LOG_FILE_PREFIX = "opendj-setup-";
+
/**
* The main method which is called by the setup command lines.
*
@@ -54,14 +53,6 @@
* will pass to the org.opends.server.tools.InstallDS class.
*/
public static void main(String[] args) {
- try {
- QuickSetupLog.initLogFileHandler(
- File.createTempFile(Constants.LOG_FILE_PREFIX,
- Constants.LOG_FILE_SUFFIX));
- } catch (Throwable t) {
- System.err.println("Unable to initialize log");
- t.printStackTrace();
- }
new SetupLauncher(args).launch();
}
@@ -73,7 +64,7 @@
* @param args the arguments passed by the command lines.
*/
public SetupLauncher(String[] args) {
- super(args);
+ super(args, LOG_FILE_PREFIX);
if (System.getProperty(PROPERTY_SCRIPT_NAME) == null)
{
System.setProperty(PROPERTY_SCRIPT_NAME, Installation.getSetupFileName());
@@ -115,7 +106,7 @@
else if (isCli())
{
Utils.checkJavaVersion();
- System.exit(InstallDS.mainCLI(args));
+ System.exit(InstallDS.mainCLI(args, tempLogFile));
}
else
{
@@ -125,17 +116,9 @@
// (if possible) is displayed graphically.
int exitCode = launchGui(args);
if (exitCode != 0) {
- File logFile = QuickSetupLog.getLogFile();
- if (logFile != null)
- {
- guiLaunchFailed(logFile.toString());
- }
- else
- {
- guiLaunchFailed(null);
- }
+ guiLaunchFailed();
Utils.checkJavaVersion();
- System.exit(InstallDS.mainCLI(args));
+ System.exit(InstallDS.mainCLI(args, tempLogFile));
}
}
}
@@ -157,16 +140,10 @@
}
@Override
- protected void guiLaunchFailed(String logFileName) {
- if (logFileName != null)
- {
- System.err.println(INFO_SETUP_LAUNCHER_GUI_LAUNCHED_FAILED_DETAILS.get(
- logFileName));
- }
- else
- {
- System.err.println(INFO_SETUP_LAUNCHER_GUI_LAUNCHED_FAILED.get());
- }
+ protected void guiLaunchFailed() {
+ System.err.println(
+ tempLogFile.isEnabled() ? INFO_SETUP_LAUNCHER_GUI_LAUNCHED_FAILED_DETAILS.get(tempLogFile.getPath())
+ : INFO_SETUP_LAUNCHER_GUI_LAUNCHED_FAILED.get());
}
@Override
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/offline/OfflineInstaller.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/offline/OfflineInstaller.java
index b935d5f..6d3338d 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/offline/OfflineInstaller.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/offline/OfflineInstaller.java
@@ -12,7 +12,7 @@
* information: "Portions Copyright [year] [name of copyright owner]".
*
* Copyright 2006-2010 Sun Microsystems, Inc.
- * Portions Copyright 2011-2015 ForgeRock AS.
+ * Portions Copyright 2011-2016 ForgeRock AS.
*/
package org.opends.quicksetup.installer.offline;
@@ -37,8 +37,8 @@
import org.opends.quicksetup.ProgressStep;
import org.opends.quicksetup.Installation;
import org.opends.quicksetup.SecurityOptions;
-import org.opends.quicksetup.installer.Installer;
import org.opends.quicksetup.installer.InstallProgressStep;
+import org.opends.quicksetup.installer.Installer;
import org.opends.quicksetup.util.Utils;
import org.opends.quicksetup.util.ServerController;
import org.opends.quicksetup.util.FileManager;
@@ -89,7 +89,7 @@
setCurrentProgressStep(InstallProgressStep.CONFIGURING_SERVER);
- notifyListenersOfLog();
+ notifyListenersOfLog(false);
notifyListeners(getLineBreak());
configureServer();
@@ -244,7 +244,7 @@
notifyListeners(html);
logger.error(LocalizableMessage.raw("Error installing.", ex));
notifyListeners(getLineBreak());
- notifyListenersOfLogAfterError();
+ notifyListenersOfLog(true);
}
runError = ex;
}
@@ -278,7 +278,7 @@
notifyListeners(msg);
logger.error(LocalizableMessage.raw("Error installing.", t));
notifyListeners(getLineBreak());
- notifyListenersOfLogAfterError();
+ notifyListenersOfLog(true);
runError = ex;
}
finally
@@ -545,4 +545,14 @@
return Utils.getInstancePathFromInstallPath(installPath);
}
+ private void notifyListenersOfLog(final boolean isError)
+ {
+ if (tempLogFile.isEnabled())
+ {
+ final String tempLogFilePath = tempLogFile.getPath();
+ notifyListeners(getFormattedProgress(isError ? INFO_GENERAL_PROVIDE_LOG_IN_ERROR.get(tempLogFilePath)
+ : INFO_GENERAL_SEE_FOR_DETAILS.get(tempLogFilePath)));
+ notifyListeners(getLineBreak());
+ }
+ }
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/ui/QuickSetup.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/ui/QuickSetup.java
index 7a6cd59..410510e 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/ui/QuickSetup.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/ui/QuickSetup.java
@@ -12,7 +12,7 @@
* information: "Portions Copyright [year] [name of copyright owner]".
*
* Copyright 2006-2010 Sun Microsystems, Inc.
- * Portions Copyright 2011-2015 ForgeRock AS.
+ * Portions Copyright 2011-2016 ForgeRock AS.
*/
package org.opends.quicksetup.ui;
@@ -87,11 +87,13 @@
* it can perform long operations which can make the user think that the UI is
* blocked.
*
+ * @param tempLogFile
+ * temporary log file where messages will be logged.
* @param args
* for the moment this parameter is not used but we keep it in order
* to (in case of need) pass parameters through the command line.
*/
- public void initialize(String[] args)
+ public void initialize(final TempLogFile tempLogFile, String[] args)
{
ProgressMessageFormatter formatter = new HtmlProgressMessageFormatter();
@@ -100,6 +102,7 @@
application = Application.create();
application.setProgressMessageFormatter(formatter);
application.setCurrentInstallStatus(installStatus);
+ application.setTempLogFile(tempLogFile);
if (args != null)
{
application.setUserArguments(args);
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/InstallDS.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/InstallDS.java
index d974731..315751c 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/InstallDS.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/InstallDS.java
@@ -57,7 +57,7 @@
import org.opends.quicksetup.CurrentInstallStatus;
import org.opends.quicksetup.Installation;
import org.opends.quicksetup.LicenseFile;
-import org.opends.quicksetup.QuickSetupLog;
+import org.opends.quicksetup.TempLogFile;
import org.opends.quicksetup.SecurityOptions;
import org.opends.quicksetup.UserData;
import org.opends.quicksetup.UserDataException;
@@ -65,7 +65,6 @@
import org.opends.quicksetup.event.ProgressUpdateListener;
import org.opends.quicksetup.installer.NewSuffixOptions;
import org.opends.quicksetup.installer.offline.OfflineInstaller;
-import org.opends.quicksetup.util.IncompatibleVersionException;
import org.opends.quicksetup.util.PlainTextProgressMessageFormatter;
import org.opends.quicksetup.util.Utils;
import org.opends.server.types.InitializationException;
@@ -220,6 +219,7 @@
private Integer lastResetAdminConnectorPort;
private Integer lastResetJmxPort;
+ private final TempLogFile tempLogFile;
private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
@@ -233,10 +233,13 @@
* the print stream to use for standard error.
* @param in
* the input stream to use for standard input.
+ * @param tempLogFile
+ * the temporary log file where messages will be logged.
*/
- public InstallDS(PrintStream out, PrintStream err, InputStream in)
+ public InstallDS(PrintStream out, PrintStream err, InputStream in, TempLogFile tempLogFile)
{
super(out, err);
+ this.tempLogFile = tempLogFile;
}
/**
@@ -245,11 +248,13 @@
*
* @param args
* the command-line arguments provided to this program.
+ * @param tempLogFile
+ * the temporary log file where messages will be logged.
* @return The error code.
*/
- public static int mainCLI(String[] args)
+ public static int mainCLI(String[] args, final TempLogFile tempLogFile)
{
- return mainCLI(args, System.out, System.err, System.in);
+ return mainCLI(args, System.out, System.err, System.in, tempLogFile);
}
/**
@@ -266,31 +271,24 @@
* if standard error is not needed.
* @param inStream
* The input stream to use for standard input.
+ * @param tempLogFile
+ * the temporary log file where messages will be logged.
* @return The error code.
*/
- public static int mainCLI(String[] args, OutputStream outStream, OutputStream errStream, InputStream inStream)
+ public static int mainCLI(
+ String[] args, OutputStream outStream, OutputStream errStream, InputStream inStream, TempLogFile tempLogFile)
{
final PrintStream out = NullOutputStream.wrapOrNullStream(outStream);
System.setProperty(Constants.CLI_JAVA_PROPERTY, "true");
final PrintStream err = NullOutputStream.wrapOrNullStream(errStream);
-
- try {
- QuickSetupLog.initLogFileHandler(
- QuickSetupLog.isInitialized() ? null :
- File.createTempFile(TMP_FILE_PREFIX, LOG_FILE_SUFFIX));
- } catch (final Throwable t) {
- System.err.println("Unable to initialize log");
- t.printStackTrace();
- }
-
- final InstallDS install = new InstallDS(out, err, inStream);
+ final InstallDS install = new InstallDS(out, err, inStream, tempLogFile);
int retCode = install.execute(args);
if (retCode == 0)
{
- QuickSetupLog.closeAndDeleteLogFile();
+ tempLogFile.deleteLogFileAfterSuccess();
}
return retCode;
}
@@ -371,6 +369,7 @@
System.setProperty(Constants.CLI_JAVA_PROPERTY, "true");
final OfflineInstaller installer = new OfflineInstaller();
+ installer.setTempLogFile(tempLogFile);
installer.setUserData(uData);
installer.setProgressMessageFormatter(formatter);
installer.addProgressUpdateListener(
--
Gitblit v1.10.0