From d3fb1bc29594027e6e13f56327d61fd78fdb5555 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Wed, 09 Apr 2008 15:49:56 +0000
Subject: [PATCH] Fix for issue 3131 (Windows: upgrade using the webinstaller should not hang)

---
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/BuildInformation.java |   67 +++++++++++++++++++++++++++++++++
 opendj-sdk/opends/src/messages/messages/quicksetup.properties                |    2 +
 2 files changed, 68 insertions(+), 1 deletions(-)

diff --git a/opendj-sdk/opends/src/messages/messages/quicksetup.properties b/opendj-sdk/opends/src/messages/messages/quicksetup.properties
index d09d0ee..7dfe4c0 100644
--- a/opendj-sdk/opends/src/messages/messages/quicksetup.properties
+++ b/opendj-sdk/opends/src/messages/messages/quicksetup.properties
@@ -320,6 +320,8 @@
  Check that you have file system access rights.
 INFO_ERROR_CREATING_BASE_ENTRY=Error Creating Base Entry.
 INFO_ERROR_CREATING_BUILD_INFO=Error determining OpenDS build information.
+INFO_ERROR_CREATING_BUILD_INFO_MSG=Error determining OpenDS build information.  \
+ Details: %s
 INFO_ERROR_CREATING_TEMP_FILE=An error occurred creating the temporary file.
 INFO_ERROR_DELETING_DIRECTORY=Error deleting directory %s.  Check that you \
  have the rights to delete this directory and that there is no other \
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/BuildInformation.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/BuildInformation.java
index 382289b..6b9b3af 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/BuildInformation.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/BuildInformation.java
@@ -48,6 +48,7 @@
 import java.io.BufferedReader;
 import java.io.InputStreamReader;
 import java.io.IOException;
+import java.io.OutputStream;
 
 /**
  * Represents information about the current build that is
@@ -75,15 +76,50 @@
     args.add("-F"); // full verbose
     ProcessBuilder pb = new ProcessBuilder(args);
     InputStream is = null;
+    OutputStream out = null;
+    final boolean[] done = {false};
     try {
       Map<String, String> env = pb.environment();
       env.put(SetupUtils.OPENDS_JAVA_HOME, System.getProperty("java.home"));
-      Process process = pb.start();
+      final Process process = pb.start();
       is = process.getInputStream();
+      out = process.getOutputStream();
+      final OutputStream fOut = out;
+      if (Utils.isWindows())
+      {
+        // In windows if there is an error we wait the user to click on
+        // return to continue.
+        Thread t = new Thread(new Runnable()
+        {
+          public void run()
+          {
+            while (!done[0])
+            {
+              try
+              {
+                Thread.sleep(5000);
+                fOut.write(Constants.LINE_SEPARATOR.getBytes());
+                fOut.flush();
+              }
+              catch (Throwable t)
+              {
+                LOG.log(Level.WARNING, "Error writing to process: "+t, t);
+              }
+            }
+          }
+        });
+        t.start();
+      }
       BufferedReader reader = new BufferedReader(new InputStreamReader(is));
       String line = reader.readLine();
       bi.values.put(NAME, line);
+      StringBuilder sb = new StringBuilder();
       while (null != (line = reader.readLine())) {
+        if (sb.length() > 0)
+        {
+          sb.append('\n');
+        }
+        sb.append(line);
         int colonIndex = line.indexOf(':');
         if (-1 != colonIndex) {
           String name = line.substring(0, colonIndex).trim();
@@ -91,11 +127,33 @@
           bi.values.put(name, value);
         }
       }
+      int resultCode = process.waitFor();
+      if (resultCode != 0)
+      {
+        if (sb.length() == 0)
+        {
+          throw new ApplicationException(
+            ReturnCode.START_ERROR,
+            INFO_ERROR_CREATING_BUILD_INFO.get(), null);
+        }
+        else
+        {
+          throw new ApplicationException(
+              ReturnCode.START_ERROR,
+              INFO_ERROR_CREATING_BUILD_INFO_MSG.get(sb.toString()), null);
+        }
+      }
     } catch (IOException e) {
       throw new ApplicationException(
           ReturnCode.START_ERROR,
           INFO_ERROR_CREATING_BUILD_INFO.get(), e);
+
+    } catch (InterruptedException ie) {
+      throw new ApplicationException(
+          ReturnCode.START_ERROR,
+          INFO_ERROR_CREATING_BUILD_INFO.get(), ie);
     } finally {
+      done[0] = true;
       if (is != null) {
         try {
           is.close();
@@ -103,6 +161,13 @@
           // ignore;
         }
       }
+      if (out != null) {
+        try {
+          out.close();
+        } catch (IOException e) {
+          // ignore;
+        }
+      }
     }
 
     // Make sure we got values for important properties that are used

--
Gitblit v1.10.0