From 84bb0e96722a3e49a3d01d1592bdb57fcfc99582 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Wed, 02 Apr 2008 15:16:09 +0000
Subject: [PATCH] Fix for issue 2444 (Commands setup/start/etc... should check Java release and reject unsupported ones)

---
 opendj-sdk/opends/resource/bin/_script-util.bat                     |   11 ++++++++++-
 opendj-sdk/opends/resource/bin/_script-util.sh                      |   18 ++++++++++++++++--
 opendj-sdk/opends/src/server/org/opends/server/tools/InstallDS.java |   12 ++++++++++++
 3 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/opendj-sdk/opends/resource/bin/_script-util.bat b/opendj-sdk/opends/resource/bin/_script-util.bat
index 1a0ac23..97d66d2 100644
--- a/opendj-sdk/opends/resource/bin/_script-util.bat
+++ b/opendj-sdk/opends/resource/bin/_script-util.bat
@@ -124,7 +124,9 @@
 
 :testJava
 "%OPENDS_JAVA_BIN%" %OPENDS_JAVA_ARGS% org.opends.server.tools.InstallDS -t > NUL 2>&1
-if not %errorlevel% == 0 goto noValidJavaHome
+set RESULT_CODE=%errorlevel%
+if %RESULT_CODE% == 13 goto notSupportedJavaHome
+if not %RESULT_CODE% == 0 goto noValidJavaHome
 goto end
 
 :noValidJavaHome
@@ -146,6 +148,13 @@
 pause
 exit /B 1
 
+:notSupportedJavaHome
+rem We get here when the java version is 5 (or up) but not supported.  We run
+rem InstallDS again to see a localized message.
+"%OPENDS_JAVA_BIN%" %OPENDS_JAVA_ARGS% org.opends.server.tools.InstallDS -t
+pause
+exit /B 1
+
 :noValidHomeWithArgs
 echo ERROR:  The detected Java version could not be used with the set of java
 echo arguments %OPENDS_JAVA_ARGS%.
diff --git a/opendj-sdk/opends/resource/bin/_script-util.sh b/opendj-sdk/opends/resource/bin/_script-util.sh
index 459bfdf..d053a21 100644
--- a/opendj-sdk/opends/resource/bin/_script-util.sh
+++ b/opendj-sdk/opends/resource/bin/_script-util.sh
@@ -71,7 +71,14 @@
   if test -z "${OPENDS_JAVA_ARGS}"
   then
     "${OPENDS_JAVA_BIN}" org.opends.server.tools.InstallDS -t 2> /dev/null
-    if test ${?} -ne 0
+    RESULT_CODE=${?}
+    if test ${RESULT_CODE} -eq 13
+    then
+      # This is a particular error code that means that the Java version is 5
+      # but not supported.  Let InstallDS to display the localized error message
+      "${OPENDS_JAVA_BIN}" org.opends.server.tools.InstallDS -t
+      exit 1
+    elif test ${RESULT_CODE} -ne 0
     then
       echo "ERROR:  The detected Java version could not be used.  The detected"
       echo "java binary is:"
@@ -91,7 +98,14 @@
     fi
   else
     "${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} org.opends.server.tools.InstallDS -t 2> /dev/null
-    if test ${?} -ne 0
+    RESULT_CODE=${?}
+    if test ${RESULT_CODE} -eq 13
+    then
+      # This is a particular error code that means that the Java version is 5
+      # but not supported.  Let InstallDS to display the localized error message
+      "${OPENDS_JAVA_BIN}" org.opends.server.tools.InstallDS -t
+      exit 1
+    elif test ${RESULT_CODE} -ne 0
     then
       echo "ERROR:  The detected Java version could not be used with the set of java"
       echo "arguments ${OPENDS_JAVA_ARGS}."
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/InstallDS.java b/opendj-sdk/opends/src/server/org/opends/server/tools/InstallDS.java
index 230d855..c8975f6 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/InstallDS.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/InstallDS.java
@@ -49,6 +49,7 @@
 import org.opends.quicksetup.CurrentInstallStatus;
 import org.opends.quicksetup.Installation;
 import org.opends.quicksetup.QuickSetupLog;
+import org.opends.quicksetup.ReturnCode;
 import org.opends.quicksetup.SecurityOptions;
 import org.opends.quicksetup.UserData;
 import org.opends.quicksetup.UserDataException;
@@ -58,6 +59,7 @@
 import org.opends.quicksetup.installer.offline.OfflineInstaller;
 import org.opends.quicksetup.installer.ui.InstallReviewPanel;
 import org.opends.quicksetup.ui.QuickSetupStepPanel;
+import org.opends.quicksetup.util.IncompatibleVersionException;
 import org.opends.quicksetup.util.PlainTextProgressMessageFormatter;
 import org.opends.quicksetup.util.Utils;
 import org.opends.server.core.DirectoryServer;
@@ -373,6 +375,16 @@
         LOG.log(Level.WARNING, "Error while trying to update the contents of "+
             "the set-java-home file in test only mode: "+t, t);
       }
+      // Test that we are running a compatible java 1.5 version.
+      try
+      {
+        Utils.checkJavaVersion();
+      }
+      catch (IncompatibleVersionException ive)
+      {
+        println(ive.getMessageObject());
+        return ReturnCode.JAVA_VERSION_INCOMPATIBLE.getReturnCode();
+      }
     }
 
     // If either the showUsage or testOnly or version arguments were provided,

--
Gitblit v1.10.0