From 4a48f1cf6caab40fa3741d93f8c825078e4820f2 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Fri, 04 May 2007 21:15:31 +0000
Subject: [PATCH] Fix a number of issues with David's approval:

---
 opends/src/statuspanel/org/opends/statuspanel/StatusPanelLauncher.java |   84 +++++++++++++++++++++++++++++++++++++++---
 1 files changed, 78 insertions(+), 6 deletions(-)

diff --git a/opends/src/statuspanel/org/opends/statuspanel/StatusPanelLauncher.java b/opends/src/statuspanel/org/opends/statuspanel/StatusPanelLauncher.java
index 5da9c76..3c19010 100644
--- a/opends/src/statuspanel/org/opends/statuspanel/StatusPanelLauncher.java
+++ b/opends/src/statuspanel/org/opends/statuspanel/StatusPanelLauncher.java
@@ -27,7 +27,10 @@
 package org.opends.statuspanel;
 
 import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.PrintStream;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import org.opends.quicksetup.util.Utils;
 import org.opends.quicksetup.Installation;
@@ -40,12 +43,28 @@
  */
 public class StatusPanelLauncher
 {
+  /** Prefix for log files. */
+  static public final String LOG_FILE_PREFIX = "opends-status-";
+
+  /** Suffix for log files. */
+  static public final String LOG_FILE_SUFFIX = ".log";
+
+  static private final Logger LOG =
+          Logger.getLogger(StatusPanelLauncher.class.getName());
+
   /**
    * The main method which is called by the control panel command lines.
    * @param args the arguments passed by the command lines.
    */
   public static void main(String[] args)
   {
+    try {
+      StatusLog.initLogFileHandler(
+              File.createTempFile(LOG_FILE_PREFIX, LOG_FILE_SUFFIX));
+    } catch (Throwable t) {
+      System.err.println("Unable to initialize log");
+      t.printStackTrace();
+    }
     boolean printUsage = false;
     if ((args != null) && (args.length > 4))
     {
@@ -70,7 +89,20 @@
       int exitCode = launchGuiStatusPanel(args);
       if (exitCode != 0)
       {
-        System.err.println(getMsg("status-panel-launcher-gui-launch-failed"));
+        String logFileName = null;
+        if (StatusLog.getLogFile() != null)
+        {
+          logFileName = StatusLog.getLogFile().toString();
+        }
+        if (logFileName != null)
+        {
+          System.err.println(getMsg(
+              "status-panel-launcher-gui-launch-failed-details", logFileName));
+        }
+        else
+        {
+          System.err.println(getMsg("status-panel-launcher-gui-launch-failed"));
+        }
         System.exit(exitCode);
       }
     }
@@ -99,10 +131,36 @@
     {
       public void run()
       {
-        // Setup MacOSX native menu bar before AWT is loaded.
-        Utils.setMacOSXMenuBar(getMsg("statuspanel-dialog-title"));
-        SplashScreen.main(args);
-        returnValue[0] = 0;
+        try
+        {
+          // Setup MacOSX native menu bar before AWT is loaded.
+          Utils.setMacOSXMenuBar(getMsg("statuspanel-dialog-title"));
+          SplashScreen.main(args);
+          returnValue[0] = 0;
+        }
+        catch (Throwable t)
+        {
+          if (StatusLog.isInitialized())
+          {
+            LOG.log(Level.WARNING, "Error launching GUI: "+t);
+            StringBuilder buf = new StringBuilder();
+            while (t != null)
+            {
+              StackTraceElement[] stack = t.getStackTrace();
+              for (int i = 0; i < stack.length; i++)
+              {
+                buf.append(stack[i].toString()+"\n");
+              }
+
+              t = t.getCause();
+              if (t != null)
+              {
+                buf.append("Root cause:\n");
+              }
+            }
+            LOG.log(Level.WARNING, buf.toString());
+          }
+        }
       }
     });
     /*
@@ -110,7 +168,7 @@
      * problems with the display environment.
      */
     PrintStream printStream = System.err;
-    //System.setErr(new EmptyPrintStream());
+    System.setErr(new EmptyPrintStream());
     t.start();
     try
     {
@@ -154,6 +212,20 @@
         Utils.getCommandLineMaxLineWidth());
   }
 
+  /**
+   * Creates an internationaized message based on the input key and
+   * properly formatted for the terminal.
+   * @param key for the message in the bundle
+   * @param args String... arguments for the message
+   * @return String message properly formatted for the terminal
+   */
+  private static String getMsg(String key, String... args)
+  {
+    return org.opends.server.util.StaticUtils.wrapText(
+        getI18n().getMsg(key, args),
+        Utils.getCommandLineMaxLineWidth());
+  }
+
   private static ResourceProvider getI18n()
   {
     return ResourceProvider.getInstance();

--
Gitblit v1.10.0