mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Gaetan Boismal
14.40.2016 7b11fcf138a9310aa14d26fea3249d6073c38828
Code cleanup

* Rename QuickSetupLog to TempLogFile
* Make TempLogFile non static
1 files deleted
10 files modified
387 ■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/UninstallLauncher.java 33 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/quicksetup/Application.java 41 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/quicksetup/Constants.java 8 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/quicksetup/Launcher.java 47 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/quicksetup/QuickSetupLog.java 122 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/quicksetup/SplashScreen.java 17 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java 12 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/SetupLauncher.java 45 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/offline/OfflineInstaller.java 20 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/quicksetup/ui/QuickSetup.java 7 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/tools/InstallDS.java 35 ●●●● patch | view | raw | blame | history
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} */
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
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";
}
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()));
        }
      }
    }
opendj-server-legacy/src/main/java/org/opends/quicksetup/QuickSetupLog.java
File was deleted
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 =
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
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
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());
    }
  }
}
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);
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(