From 0138b5924ff14ef709398bf878dbb9bf2a0b7c33 Mon Sep 17 00:00:00 2001
From: Valery Kharseko <vharseko@3a-systems.ru>
Date: Wed, 23 Sep 2026 13:05:17 +0000
Subject: [PATCH] [#1030] Keep the setup log out of the way of start-ds, and say when it is gone (#1032)

---
 opendj-server-legacy/src/main/java/org/opends/server/tools/InstallDS.java |   41 +++++++++++++++++++++++++++++++++++++----
 1 files changed, 37 insertions(+), 4 deletions(-)

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 b652428..49931c0 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
@@ -40,6 +40,7 @@
 import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.function.Supplier;
 
 import com.forgerock.opendj.util.FipsStaticUtils;
 import org.forgerock.i18n.LocalizableMessage;
@@ -202,7 +203,11 @@
   private Integer lastResetAdminConnectorPort;
   private Integer lastResetJmxPort;
 
-  private final TempLogFile tempLogFile;
+  /**
+   * The temporary log file where messages will be logged, asked for only once an install is
+   * about to run: the roads which return before that one leave no log behind (issue #1030).
+   */
+  private final Supplier<TempLogFile> tempLogFile;
 
   private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
 
@@ -216,7 +221,7 @@
    * @param tempLogFile
    *          the temporary log file where messages will be logged.
    */
-  private InstallDS(PrintStream out, PrintStream err, TempLogFile tempLogFile)
+  private InstallDS(PrintStream out, PrintStream err, Supplier<TempLogFile> tempLogFile)
   {
     super(out, err);
     this.tempLogFile = tempLogFile;
@@ -229,10 +234,12 @@
    * @param args
    *          the command-line arguments provided to this program.
    * @param tempLogFile
-   *          the temporary log file where messages will be logged.
+   *          supplies the temporary log file where messages will be logged. It is called on
+   *          the road that runs the install and not on the roads which return before it, so
+   *          that a run which installs nothing creates no log.
    * @return The error code.
    */
-  public static int mainCLI(String[] args, final TempLogFile tempLogFile)
+  public static int mainCLI(String[] args, final Supplier<TempLogFile> tempLogFile)
   {
     return mainCLI(args, System.out, System.err, tempLogFile);
   }
@@ -259,7 +266,29 @@
     //
     // *NOTE* this method has been kept public because it is used by OpenAM.
     //
+    return mainCLI(args, outStream, errStream, () -> tempLogFile);
+  }
 
+  /**
+   * Parses the provided command-line arguments and uses that information to run
+   * the setup tool.
+   *
+   * @param args
+   *          The command-line arguments provided to this program.
+   * @param outStream
+   *          The output stream to use for standard output, or <CODE>null</CODE>
+   *          if standard output is not needed.
+   * @param errStream
+   *          The output stream to use for standard error, or <CODE>null</CODE>
+   *          if standard error is not needed.
+   * @param tempLogFile
+   *          supplies the temporary log file where messages will be logged, see
+   *          {@link #mainCLI(String[], Supplier)}.
+   * @return The error code.
+   */
+  public static int mainCLI(
+      String[] args, OutputStream outStream, OutputStream errStream, Supplier<TempLogFile> tempLogFile)
+  {
     final PrintStream out = NullOutputStream.wrapOrNullStream(outStream);
 
     System.setProperty(Constants.CLI_JAVA_PROPERTY, "true");
@@ -349,6 +378,10 @@
 
     System.setProperty(Constants.CLI_JAVA_PROPERTY, "true");
     final Installer installer = new Installer();
+    // The supplier is handed over, not the file: the installer creates it when it starts to
+    // run, which is the first point where something can fail. The roads above - a usage
+    // error, "already installed", a refused licence, a cancel at the prompt - return without
+    // asking for it and leave no log behind (issue #1030).
     installer.setTempLogFile(tempLogFile);
     installer.setUserData(uData);
     installer.setProgressMessageFormatter(formatter);

--
Gitblit v1.10.0