From 4b6eae2b88b5a5abc3bc7bcee205ecf033675a0f Mon Sep 17 00:00:00 2001
From: Ludovic Poitou <ludovic.poitou@forgerock.com>
Date: Fri, 20 Nov 2015 23:34:13 +0000
Subject: [PATCH] OPENDJ-2436 - Close and Delete temporary log files on success.
---
opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java | 5 ++
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ControlPanelLauncher.java | 2 +
opendj-server-legacy/src/main/java/org/opends/server/tools/status/StatusCli.java | 7 +++
opendj-server-legacy/src/main/java/org/opends/server/tools/InstallDS.java | 7 +++
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/ControlPanelLog.java | 25 ++++++++----
opendj-server-legacy/src/main/java/org/opends/quicksetup/QuickSetupLog.java | 16 ++++++--
6 files changed, 47 insertions(+), 15 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ControlPanelLauncher.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ControlPanelLauncher.java
index 0cc7cba..fd04e94 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ControlPanelLauncher.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ControlPanelLauncher.java
@@ -100,6 +100,7 @@
// then print it and exit.
if (argParser.usageOrVersionDisplayed())
{
+ ControlPanelLog.closeAndDeleteLogFile();
System.exit(ErrorReturnCode.SUCCESSFUL_NOP.getReturnCode());
}
@@ -143,6 +144,7 @@
System.exit(exitCode);
}
}
+ ControlPanelLog.closeAndDeleteLogFile();
}
/**
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/ControlPanelLog.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/ControlPanelLog.java
index 3f74cf2..de4d5da 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/ControlPanelLog.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/ControlPanelLog.java
@@ -47,8 +47,7 @@
private static FileHandler fileHandler;
/**
- * Creates a new file handler for writing log messages to the file indicated
- * by <code>file</code>.
+ * 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
*/
@@ -76,9 +75,8 @@
}
/**
- * Writes messages under a given package in the file handler defined when
- * calling initLogFileHandler. Note that initLogFileHandler should be called
- * before calling this method.
+ * Writes messages under a given package in the file handler defined when calling initLogFileHandler.
+ * Note that initLogFileHandler should be called before calling this method.
* @param packageName the package name.
* @throws IOException if something goes wrong
*/
@@ -108,12 +106,21 @@
return logFile != null;
}
- private static String getInitialLogRecord() {
+ /** Closes the log file and deletes it. */
+ public static void closeAndDeleteLogFile()
+ {
+ if (logFile != null)
+ {
+ fileHandler.close();
+ logFile.delete();
+ }
+ }
+
+ private static String getInitialLogRecord()
+ {
StringBuilder sb = new StringBuilder()
.append("Application launched " +
- DateFormat.getDateTimeInstance(DateFormat.LONG,
- DateFormat.LONG).
- format(new Date()));
+ DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(new Date()));
return sb.toString();
}
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
index a99c35c..baca94f 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/QuickSetupLog.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/QuickSetupLog.java
@@ -44,8 +44,7 @@
private static FileHandler FILE_HANDLER;
/**
- * Creates a new file handler for writing log messages to the file indicated
- * by <code>file</code>.
+ * 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
@@ -68,8 +67,7 @@
}
/**
- * Creates a new file handler for writing log messages of a given package to
- * the file indicated by <code>file</code>.
+ * 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.
@@ -115,6 +113,16 @@
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.
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 29e8f5c..2740a17 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
@@ -309,7 +309,12 @@
final InstallDS install = new InstallDS(out, err, inStream);
- return install.execute(args);
+ int retCode = install.execute(args);
+ if (retCode == 0)
+ {
+ QuickSetupLog.closeAndDeleteLogFile();
+ }
+ return retCode;
}
/**
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java
index c612fad..07ec649 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java
@@ -365,6 +365,11 @@
}
ReplicationCliMain replicationCli = new ReplicationCliMain(out, err);
ReplicationCliReturnCode result = replicationCli.execute(args, initializeServer);
+ if (result.getReturnCode() == 0)
+ {
+ // Delete the temp log file, in case of success.
+ ControlPanelLog.closeAndDeleteLogFile();
+ }
return result.getReturnCode();
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/status/StatusCli.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/status/StatusCli.java
index a92f077..34f661a 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/status/StatusCli.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/status/StatusCli.java
@@ -201,7 +201,12 @@
}
final StatusCli statusCli = new StatusCli(out, err, inStream);
- return statusCli.execute(args);
+ int retCode = statusCli.execute(args);
+ if (retCode == 0)
+ {
+ ControlPanelLog.closeAndDeleteLogFile();
+ }
+ return retCode;
}
/**
--
Gitblit v1.10.0