Author: markt
Date: Tue Oct 31 17:25:30 2017
New Revision: 1813916

URL: http://svn.apache.org/viewvc?rev=1813916&view=rev
Log:
Fix DAEMON-376 and DAEMON-311. When checking the registry for JVM locations, 
add checks for the Java 9 locations and the IBM locations.

Modified:
    commons/proper/daemon/trunk/src/changes/changes.xml
    commons/proper/daemon/trunk/src/native/windows/src/registry.c

Modified: commons/proper/daemon/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/changes/changes.xml?rev=1813916&r1=1813915&r2=1813916&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/changes/changes.xml (original)
+++ commons/proper/daemon/trunk/src/changes/changes.xml Tue Oct 31 17:25:30 2017
@@ -115,6 +115,18 @@
         Ensure that the //MQ command closes the prunmgr process even if the 
         configuration dialog is open when the //MQ command is used.
       </action>
+      <action issue="DAEMON-311" type="fix" dev="markt">
+        When looking in the Windows registry for JRE and JDK installation
+        locations, additionally check the registry keys used by IBM provided
+        JREs and JDKs. Do this after checking the keys used by Oracle provided
+        JREs and JDKs.
+      </action>
+      <action issue="DAEMON-376" type="fix" dev="markt">
+        When looking in the Windows registry for JRE and JDK installation
+        locations, additionally check the registry keys used by Oracle provided
+        Java 9 and later JREs and JDKs. Do this after checking the keys used by
+        Oracle provided Java 8 and earlier JREs and JDKs.
+      </action>
     </release>
   </body>
 </document>

Modified: commons/proper/daemon/trunk/src/native/windows/src/registry.c
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/src/registry.c?rev=1813916&r1=1813915&r2=1813916&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/windows/src/registry.c (original)
+++ commons/proper/daemon/trunk/src/native/windows/src/registry.c Tue Oct 31 
17:25:30 2017
@@ -25,9 +25,21 @@ static LPCWSTR REGPARAMS        = L"Para
 static LPCWSTR REGDESCRIPTION   = L"Description";
 static LPCWSTR REGSEPARATOR     = L"\\";
 static LPCWSTR REGAPACHE_ROOT   = L"Apache Software Foundation";
-/* predefined Java keys */
-static LPCWSTR JRE_REGKEY       = L"SOFTWARE\\JavaSoft\\Java Runtime 
Environment\\";
-static LPCWSTR JDK_REGKEY       = L"SOFTWARE\\JavaSoft\\Java Development 
Kit\\";
+/* Predefined Java keys
+ * The code below assumes the JRE and JDK arrays are the same length
+ */
+static LPCWSTR JRE_REGKEYS[] = {
+    L"SOFTWARE\\JavaSoft\\JRE\\",                       /* Oracle Java 8 and 
earlier */
+    L"SOFTWARE\\JavaSoft\\Java Runtime Environment\\",  /* Oracle Java 9 (and 
hopefully later) */
+    L"SOFTWARE\\IBM\\Java2 Runtime Environment\\",      /* IBM */
+    NULL
+};
+static LPCWSTR JDK_REGKEYS[] = {
+    L"SOFTWARE\\JavaSoft\\JDK\\",                       /* Oracle Java 8 and 
ealier */
+    L"SOFTWARE\\JavaSoft\\Java Development Kit\\",      /* Oracle Java 9 (and 
hopefully later) */
+    L"SOFTWARE\\IBM\\Java2 Development Kit\\",          /* IBM */
+    NULL
+};
 static LPCWSTR JAVA_CURRENT     = L"CurrentVersion";
 static LPCWSTR JAVA_RUNTIME     = L"RuntimeLib";
 static LPCWSTR JAVA_HOME        = L"JAVA_HOME";
@@ -925,76 +937,89 @@ apxDeleteRegistryA(LPCSTR szRoot,
 LPWSTR apxGetJavaSoftHome(APXHANDLE hPool, BOOL bPreferJre)
 {
     LPWSTR  wsJhome, off;
-    DWORD   err, dwLen;
+    DWORD   err, dwLen, dwRegKey = 0;
     HKEY    hKey;
     WCHAR   wsBuf[SIZ_BUFLEN];
     WCHAR   wsKey[SIZ_RESLEN];
+
 #if 1 /* XXX: Add that customizable using function call arg */
     if (!bPreferJre && (wsJhome = __apxGetEnvironmentVariableW(hPool, 
JAVA_HOME)))
         return wsJhome;
 #endif
-    lstrcpyW(wsKey, JAVA_CURRENT);
-    if (bPreferJre)
-        lstrcpyW(wsBuf, JRE_REGKEY);
-    else
-        lstrcpyW(wsBuf, JDK_REGKEY);
-    dwLen = lstrlenW(wsBuf);
-    off = &wsBuf[dwLen];
-    dwLen = SIZ_RESMAX;
-    if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
-                             0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
-        return NULL;
-    }
-    if ((err = RegQueryValueExW(hKey, JAVA_CURRENT, NULL, NULL,
-                                (LPBYTE)off,
-                                &dwLen)) != ERROR_SUCCESS) {
+
+    while (JRE_REGKEYS[dwRegKey]) {
+        lstrcpyW(wsKey, JAVA_CURRENT);
+        if (bPreferJre)
+            lstrcpyW(wsBuf, JRE_REGKEYS[dwRegKey]);
+        else
+            lstrcpyW(wsBuf, JDK_REGKEYS[dwRegKey]);
+        dwRegKey = dwRegKey++;
+        dwLen = lstrlenW(wsBuf);
+        off = &wsBuf[dwLen];
+        dwLen = SIZ_RESMAX;
+        if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
+                                 0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
+            continue;
+        }
+        if ((err = RegQueryValueExW(hKey, JAVA_CURRENT, NULL, NULL,
+                                    (LPBYTE)off,
+                                    &dwLen)) != ERROR_SUCCESS) {
+            RegCloseKey(hKey);
+            continue;
+        }
         RegCloseKey(hKey);
-        return NULL;
-    }
-    RegCloseKey(hKey);
-    if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
-                             0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
-        return NULL;
+        if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
+                                 0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
+            continue;
+        }
+        wsJhome = __apxGetRegistrySzW(hPool, hKey, JAVAHOME);
+        if (wsJhome)
+            SetEnvironmentVariableW(JAVA_HOME, wsJhome);
+        RegCloseKey(hKey);
+
+        return wsJhome;
     }
-    wsJhome = __apxGetRegistrySzW(hPool, hKey, JAVAHOME);
-    if (wsJhome)
-        SetEnvironmentVariableW(JAVA_HOME, wsJhome);
-    RegCloseKey(hKey);
 
-    return wsJhome;
+    return NULL;
 }
 
 LPWSTR apxGetJavaSoftRuntimeLib(APXHANDLE hPool)
 {
     LPWSTR  wsRtlib, off;
-    DWORD   err, dwLen = SIZ_RESLEN;
+    DWORD   err, dwLen = SIZ_RESLEN, dwRegKey = 0;
     HKEY    hKey;
     WCHAR   wsBuf[SIZ_BUFLEN];
 
-    lstrcpyW(wsBuf, JRE_REGKEY);
 
-    dwLen = lstrlenW(wsBuf);
-    off = &wsBuf[dwLen];
-    dwLen = SIZ_RESLEN;
-    if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
-                             0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
-        return NULL;
-    }
-    if ((err = RegQueryValueExW(hKey, JAVA_CURRENT, NULL, NULL,
-                                (LPBYTE)off,
-                                &dwLen)) != ERROR_SUCCESS) {
+    while(JRE_REGKEYS[dwRegKey]) {
+        lstrcpyW(wsBuf, JRE_REGKEYS[dwRegKey]);
+        dwRegKey = dwRegKey++;
+
+        dwLen = lstrlenW(wsBuf);
+        off = &wsBuf[dwLen];
+        dwLen = SIZ_RESLEN;
+        if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
+                                 0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
+            continue;
+        }
+        if ((err = RegQueryValueExW(hKey, JAVA_CURRENT, NULL, NULL,
+                                    (LPBYTE)off,
+                                    &dwLen)) != ERROR_SUCCESS) {
+            RegCloseKey(hKey);
+            continue;
+        }
         RegCloseKey(hKey);
-        return NULL;
-    }
-    RegCloseKey(hKey);
-    if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
-                             0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
-        return NULL;
+        if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
+                                 0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
+            continue;
+        }
+        wsRtlib = __apxGetRegistrySzW(hPool, hKey, JAVA_RUNTIME);
+        RegCloseKey(hKey);
+
+        return wsRtlib;
     }
-    wsRtlib = __apxGetRegistrySzW(hPool, hKey, JAVA_RUNTIME);
-    RegCloseKey(hKey);
 
-    return wsRtlib;
+    return NULL;
 }
 
 /* Service Registry helper functions */


Reply via email to