From fd04ff2b08cbc214c8c97cd3c4b2995221089424 Mon Sep 17 00:00:00 2001 From: phit <2097483+phit@users.noreply.github.com> Date: Tue, 8 Jun 2021 19:48:12 +0200 Subject: [PATCH 1/3] NOISSUE Add AdoptOpenJDK Java detection --- api/logic/java/JavaUtils.cpp | 109 ++++++++++++++++++++++++++++++----- api/logic/java/JavaUtils.h | 3 +- 2 files changed, 98 insertions(+), 14 deletions(-) diff --git a/api/logic/java/JavaUtils.cpp b/api/logic/java/JavaUtils.cpp index 18a731ca..ec87e7bf 100644 --- a/api/logic/java/JavaUtils.cpp +++ b/api/logic/java/JavaUtils.cpp @@ -150,7 +150,7 @@ JavaInstallPtr JavaUtils::GetDefaultJava() } #if defined(Q_OS_WIN32) -QList JavaUtils::FindJavaFromRegistryKey(DWORD keyType, QString keyName) +QList JavaUtils::FindOracleJavaFromRegistryKey(DWORD keyType, QString keyName) { QList javas; @@ -175,8 +175,6 @@ QList JavaUtils::FindJavaFromRegistryKey(DWORD keyType, QString RegQueryValueExA(jreKey, "CurrentVersion", NULL, NULL, (BYTE *)value, &valueSz); } - QString recommended = value; - TCHAR subKeyName[255]; DWORD subKeyNameSize, numSubKeys, retCode; @@ -233,41 +231,126 @@ QList JavaUtils::FindJavaFromRegistryKey(DWORD keyType, QString return javas; } +QList JavaUtils::FindAdoptJavaFromRegistryKey(DWORD keyType, QString keyName) +{ + QList javas; + + QString archType = "unknown"; + if (keyType == KEY_WOW64_64KEY) + archType = "64"; + else if (keyType == KEY_WOW64_32KEY) + archType = "32"; + + HKEY jreKey; + if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, keyName.toStdString().c_str(), 0, KEY_READ | keyType | KEY_ENUMERATE_SUB_KEYS, &jreKey) == ERROR_SUCCESS) + { + char *value = new char[0]; + DWORD valueSz = 0; + TCHAR subKeyName[255]; + DWORD subKeyNameSize, numSubKeys, retCode; + + // Get the number of subkeys + RegQueryInfoKey(jreKey, NULL, NULL, NULL, &numSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + + // Iterate until RegEnumKeyEx fails + if (numSubKeys > 0) + { + for (DWORD i = 0; i < numSubKeys; i++) + { + subKeyNameSize = 255; + retCode = RegEnumKeyEx(jreKey, i, subKeyName, &subKeyNameSize, NULL, NULL, NULL, NULL); + if (retCode == ERROR_SUCCESS) + { + // Now open the registry key for the version that we just got. + QString newKeyName = keyName + "\\" + subKeyName + "\\hotspot\\MSI"; + + HKEY newKey; + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, newKeyName.toStdString().c_str(), 0, KEY_READ | KEY_WOW64_64KEY, &newKey) == ERROR_SUCCESS) + { + // Read the Path value to find where Java is installed. + value = new char[0]; + valueSz = 0; + if (RegQueryValueEx(newKey, "Path", NULL, NULL, (BYTE *)value, &valueSz) == ERROR_MORE_DATA) + { + value = new char[valueSz]; + RegQueryValueEx(newKey, "Path", NULL, NULL, (BYTE *)value, &valueSz); + + // Now, we construct the version object and add it to the list. + JavaInstallPtr javaVersion(new JavaInstall()); + + javaVersion->id = subKeyName; + javaVersion->arch = archType; + javaVersion->path = QDir(FS::PathCombine(value, "bin")).absoluteFilePath("javaw.exe"); + javas.append(javaVersion); + } + + RegCloseKey(newKey); + } + } + } + } + + RegCloseKey(jreKey); + } + + return javas; +} + QList JavaUtils::FindJavaPaths() { QList java_candidates; - QList JRE64s = this->FindJavaFromRegistryKey( + // Oracle + QList JRE64s = this->FindOracleJavaFromRegistryKey( KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment"); - QList JDK64s = this->FindJavaFromRegistryKey( + QList JDK64s = this->FindOracleJavaFromRegistryKey( KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Development Kit"); - QList NEWJRE64s = this->FindJavaFromRegistryKey( - KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\JRE"); - QList NEWJDK64s = this->FindJavaFromRegistryKey( - KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\JDK"); - QList JRE32s = this->FindJavaFromRegistryKey( + QList JRE32s = this->FindOracleJavaFromRegistryKey( KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment"); - QList JDK32s = this->FindJavaFromRegistryKey( + QList JDK32s = this->FindOracleJavaFromRegistryKey( KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Development Kit"); - QList NEWJRE32s = this->FindJavaFromRegistryKey( + + // Oracle for Java 9 and newer + QList NEWJRE64s = this->FindOracleJavaFromRegistryKey( + KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\JRE"); + QList NEWJDK64s = this->FindOracleJavaFromRegistryKey( + KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\JDK"); + QList NEWJRE32s = this->FindOracleJavaFromRegistryKey( KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\JRE"); - QList NEWJDK32s = this->FindJavaFromRegistryKey( + QList NEWJDK32s = this->FindOracleJavaFromRegistryKey( KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\JDK"); + // AdoptOpenJDK + QList ADOPTOPENJRE32s = this->FindAdoptJavaFromRegistryKey( + KEY_WOW64_32KEY, "SOFTWARE\\AdoptOpenJDK\\JRE"); + QList ADOPTOPENJRE64s = this->FindAdoptJavaFromRegistryKey( + KEY_WOW64_64KEY, "SOFTWARE\\AdoptOpenJDK\\JRE"); + QList ADOPTOPENJDK32s = this->FindAdoptJavaFromRegistryKey( + KEY_WOW64_32KEY, "SOFTWARE\\AdoptOpenJDK\\JDK"); + QList ADOPTOPENJDK64s = this->FindAdoptJavaFromRegistryKey( + KEY_WOW64_64KEY, "SOFTWARE\\AdoptOpenJDK\\JDK"); + + // List x64 before x86 java_candidates.append(JRE64s); java_candidates.append(NEWJRE64s); + java_candidates.append(ADOPTOPENJRE64s); java_candidates.append(MakeJavaPtr("C:/Program Files/Java/jre8/bin/javaw.exe")); java_candidates.append(MakeJavaPtr("C:/Program Files/Java/jre7/bin/javaw.exe")); java_candidates.append(MakeJavaPtr("C:/Program Files/Java/jre6/bin/javaw.exe")); java_candidates.append(JDK64s); java_candidates.append(NEWJDK64s); + java_candidates.append(ADOPTOPENJDK64s); + java_candidates.append(JRE32s); java_candidates.append(NEWJRE32s); + java_candidates.append(ADOPTOPENJRE32s); java_candidates.append(MakeJavaPtr("C:/Program Files (x86)/Java/jre8/bin/javaw.exe")); java_candidates.append(MakeJavaPtr("C:/Program Files (x86)/Java/jre7/bin/javaw.exe")); java_candidates.append(MakeJavaPtr("C:/Program Files (x86)/Java/jre6/bin/javaw.exe")); java_candidates.append(JDK32s); java_candidates.append(NEWJDK32s); + java_candidates.append(ADOPTOPENJDK32s); + java_candidates.append(MakeJavaPtr(this->GetDefaultJava()->path)); QList candidates; diff --git a/api/logic/java/JavaUtils.h b/api/logic/java/JavaUtils.h index 7474c494..9becd9e4 100644 --- a/api/logic/java/JavaUtils.h +++ b/api/logic/java/JavaUtils.h @@ -39,6 +39,7 @@ public: JavaInstallPtr GetDefaultJava(); #ifdef Q_OS_WIN - QList FindJavaFromRegistryKey(DWORD keyType, QString keyName); + QList FindOracleJavaFromRegistryKey(DWORD keyType, QString keyName); + QList FindAdoptJavaFromRegistryKey(DWORD keyType, QString keyName); #endif }; From 7ac6c4f3d9f55d4be86c96d0e52001e7ecc5448b Mon Sep 17 00:00:00 2001 From: phit <2097483+phit@users.noreply.github.com> Date: Fri, 18 Jun 2021 17:02:41 +0200 Subject: [PATCH 2/3] NOISSUE Cleanup duplication and Microsoft JDK --- api/logic/java/JavaUtils.cpp | 126 +++++++++-------------------------- api/logic/java/JavaUtils.h | 3 +- 2 files changed, 34 insertions(+), 95 deletions(-) diff --git a/api/logic/java/JavaUtils.cpp b/api/logic/java/JavaUtils.cpp index ec87e7bf..10ffa018 100644 --- a/api/logic/java/JavaUtils.cpp +++ b/api/logic/java/JavaUtils.cpp @@ -150,7 +150,7 @@ JavaInstallPtr JavaUtils::GetDefaultJava() } #if defined(Q_OS_WIN32) -QList JavaUtils::FindOracleJavaFromRegistryKey(DWORD keyType, QString keyName) +QList JavaUtils::FindJavaFromRegistryKey(DWORD keyType, QString keyName, QString keyJavaDir, QString subkeySuffix) { QList javas; @@ -193,7 +193,7 @@ QList JavaUtils::FindOracleJavaFromRegistryKey(DWORD keyType, QS if (retCode == ERROR_SUCCESS) { // Now open the registry key for the version that we just got. - QString newKeyName = keyName + "\\" + subKeyName; + QString newKeyName = keyName + "\\" + subKeyName + subkeySuffix; HKEY newKey; if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, newKeyName.toStdString().c_str(), 0, @@ -202,11 +202,11 @@ QList JavaUtils::FindOracleJavaFromRegistryKey(DWORD keyType, QS // Read the JavaHome value to find where Java is installed. value = new char[0]; valueSz = 0; - if (RegQueryValueEx(newKey, "JavaHome", NULL, NULL, (BYTE *)value, + if (RegQueryValueEx(newKey, keyJavaDir.toStdString().c_str(), NULL, NULL, (BYTE *)value, &valueSz) == ERROR_MORE_DATA) { value = new char[valueSz]; - RegQueryValueEx(newKey, "JavaHome", NULL, NULL, (BYTE *)value, + RegQueryValueEx(newKey, keyJavaDir.toStdString().c_str(), NULL, NULL, (BYTE *)value, &valueSz); // Now, we construct the version object and add it to the list. @@ -231,104 +231,43 @@ QList JavaUtils::FindOracleJavaFromRegistryKey(DWORD keyType, QS return javas; } -QList JavaUtils::FindAdoptJavaFromRegistryKey(DWORD keyType, QString keyName) -{ - QList javas; - - QString archType = "unknown"; - if (keyType == KEY_WOW64_64KEY) - archType = "64"; - else if (keyType == KEY_WOW64_32KEY) - archType = "32"; - - HKEY jreKey; - if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, keyName.toStdString().c_str(), 0, KEY_READ | keyType | KEY_ENUMERATE_SUB_KEYS, &jreKey) == ERROR_SUCCESS) - { - char *value = new char[0]; - DWORD valueSz = 0; - TCHAR subKeyName[255]; - DWORD subKeyNameSize, numSubKeys, retCode; - - // Get the number of subkeys - RegQueryInfoKey(jreKey, NULL, NULL, NULL, &numSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL); - - // Iterate until RegEnumKeyEx fails - if (numSubKeys > 0) - { - for (DWORD i = 0; i < numSubKeys; i++) - { - subKeyNameSize = 255; - retCode = RegEnumKeyEx(jreKey, i, subKeyName, &subKeyNameSize, NULL, NULL, NULL, NULL); - if (retCode == ERROR_SUCCESS) - { - // Now open the registry key for the version that we just got. - QString newKeyName = keyName + "\\" + subKeyName + "\\hotspot\\MSI"; - - HKEY newKey; - if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, newKeyName.toStdString().c_str(), 0, KEY_READ | KEY_WOW64_64KEY, &newKey) == ERROR_SUCCESS) - { - // Read the Path value to find where Java is installed. - value = new char[0]; - valueSz = 0; - if (RegQueryValueEx(newKey, "Path", NULL, NULL, (BYTE *)value, &valueSz) == ERROR_MORE_DATA) - { - value = new char[valueSz]; - RegQueryValueEx(newKey, "Path", NULL, NULL, (BYTE *)value, &valueSz); - - // Now, we construct the version object and add it to the list. - JavaInstallPtr javaVersion(new JavaInstall()); - - javaVersion->id = subKeyName; - javaVersion->arch = archType; - javaVersion->path = QDir(FS::PathCombine(value, "bin")).absoluteFilePath("javaw.exe"); - javas.append(javaVersion); - } - - RegCloseKey(newKey); - } - } - } - } - - RegCloseKey(jreKey); - } - - return javas; -} - QList JavaUtils::FindJavaPaths() { QList java_candidates; // Oracle - QList JRE64s = this->FindOracleJavaFromRegistryKey( - KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment"); - QList JDK64s = this->FindOracleJavaFromRegistryKey( - KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Development Kit"); - QList JRE32s = this->FindOracleJavaFromRegistryKey( - KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment"); - QList JDK32s = this->FindOracleJavaFromRegistryKey( - KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Development Kit"); + QList JRE64s = this->FindJavaFromRegistryKey( + KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment", "JavaHome"); + QList JDK64s = this->FindJavaFromRegistryKey( + KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Development Kit", "JavaHome"); + QList JRE32s = this->FindJavaFromRegistryKey( + KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment", "JavaHome"); + QList JDK32s = this->FindJavaFromRegistryKey( + KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Development Kit", "JavaHome"); // Oracle for Java 9 and newer - QList NEWJRE64s = this->FindOracleJavaFromRegistryKey( - KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\JRE"); - QList NEWJDK64s = this->FindOracleJavaFromRegistryKey( - KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\JDK"); - QList NEWJRE32s = this->FindOracleJavaFromRegistryKey( - KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\JRE"); - QList NEWJDK32s = this->FindOracleJavaFromRegistryKey( - KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\JDK"); + QList NEWJRE64s = this->FindJavaFromRegistryKey( + KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\JRE", "JavaHome"); + QList NEWJDK64s = this->FindJavaFromRegistryKey( + KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\JDK", "JavaHome"); + QList NEWJRE32s = this->FindJavaFromRegistryKey( + KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\JRE", "JavaHome"); + QList NEWJDK32s = this->FindJavaFromRegistryKey( + KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\JDK", "JavaHome"); // AdoptOpenJDK - QList ADOPTOPENJRE32s = this->FindAdoptJavaFromRegistryKey( - KEY_WOW64_32KEY, "SOFTWARE\\AdoptOpenJDK\\JRE"); - QList ADOPTOPENJRE64s = this->FindAdoptJavaFromRegistryKey( - KEY_WOW64_64KEY, "SOFTWARE\\AdoptOpenJDK\\JRE"); - QList ADOPTOPENJDK32s = this->FindAdoptJavaFromRegistryKey( - KEY_WOW64_32KEY, "SOFTWARE\\AdoptOpenJDK\\JDK"); - QList ADOPTOPENJDK64s = this->FindAdoptJavaFromRegistryKey( - KEY_WOW64_64KEY, "SOFTWARE\\AdoptOpenJDK\\JDK"); + QList ADOPTOPENJRE32s = this->FindJavaFromRegistryKey( + KEY_WOW64_32KEY, "SOFTWARE\\AdoptOpenJDK\\JRE", "Path", "\\hotspot\\MSI"); + QList ADOPTOPENJRE64s = this->FindJavaFromRegistryKey( + KEY_WOW64_64KEY, "SOFTWARE\\AdoptOpenJDK\\JRE", "Path", "\\hotspot\\MSI"); + QList ADOPTOPENJDK32s = this->FindJavaFromRegistryKey( + KEY_WOW64_32KEY, "SOFTWARE\\AdoptOpenJDK\\JDK", "Path", "\\hotspot\\MSI"); + QList ADOPTOPENJDK64s = this->FindJavaFromRegistryKey( + KEY_WOW64_64KEY, "SOFTWARE\\AdoptOpenJDK\\JDK", "Path", "\\hotspot\\MSI"); + + // Microsoft + QList MICROSOFTJDK64s = this->FindJavaFromRegistryKey( + KEY_WOW64_64KEY, "SOFTWARE\\Microsoft\\JDK", "Path", "\\hotspot\\MSI"); // List x64 before x86 java_candidates.append(JRE64s); @@ -340,6 +279,7 @@ QList JavaUtils::FindJavaPaths() java_candidates.append(JDK64s); java_candidates.append(NEWJDK64s); java_candidates.append(ADOPTOPENJDK64s); + java_candidates.append(MICROSOFTJDK64s); java_candidates.append(JRE32s); java_candidates.append(NEWJRE32s); diff --git a/api/logic/java/JavaUtils.h b/api/logic/java/JavaUtils.h index 9becd9e4..206acf89 100644 --- a/api/logic/java/JavaUtils.h +++ b/api/logic/java/JavaUtils.h @@ -39,7 +39,6 @@ public: JavaInstallPtr GetDefaultJava(); #ifdef Q_OS_WIN - QList FindOracleJavaFromRegistryKey(DWORD keyType, QString keyName); - QList FindAdoptJavaFromRegistryKey(DWORD keyType, QString keyName); + QList FindJavaFromRegistryKey(DWORD keyType, QString keyName, QString keyJavaDir, QString subkeySuffix = ""); #endif }; From c2c288a95657b8aa4e0fb56167e9cc4e6551916f Mon Sep 17 00:00:00 2001 From: phit <2097483+phit@users.noreply.github.com> Date: Fri, 18 Jun 2021 17:12:44 +0200 Subject: [PATCH 3/3] NOISSUE Add BellSoft and Azul Java --- api/logic/java/JavaUtils.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/api/logic/java/JavaUtils.cpp b/api/logic/java/JavaUtils.cpp index 10ffa018..5f004a10 100644 --- a/api/logic/java/JavaUtils.cpp +++ b/api/logic/java/JavaUtils.cpp @@ -269,6 +269,18 @@ QList JavaUtils::FindJavaPaths() QList MICROSOFTJDK64s = this->FindJavaFromRegistryKey( KEY_WOW64_64KEY, "SOFTWARE\\Microsoft\\JDK", "Path", "\\hotspot\\MSI"); + // Azul Zulu + QList ZULU64s = this->FindJavaFromRegistryKey( + KEY_WOW64_64KEY, "SOFTWARE\\Azul Systems\\Zulu", "InstallationPath"); + QList ZULU32s = this->FindJavaFromRegistryKey( + KEY_WOW64_64KEY, "SOFTWARE\\Azul Systems\\Zulu", "InstallationPath"); + + // BellSoft Liberica + QList LIBERICA64s = this->FindJavaFromRegistryKey( + KEY_WOW64_64KEY, "SOFTWARE\\BellSoft\\Liberica", "InstallationPath"); + QList LIBERICA32s = this->FindJavaFromRegistryKey( + KEY_WOW64_64KEY, "SOFTWARE\\BellSoft\\Liberica", "InstallationPath"); + // List x64 before x86 java_candidates.append(JRE64s); java_candidates.append(NEWJRE64s); @@ -280,6 +292,8 @@ QList JavaUtils::FindJavaPaths() java_candidates.append(NEWJDK64s); java_candidates.append(ADOPTOPENJDK64s); java_candidates.append(MICROSOFTJDK64s); + java_candidates.append(ZULU64s); + java_candidates.append(LIBERICA64s); java_candidates.append(JRE32s); java_candidates.append(NEWJRE32s); @@ -290,6 +304,8 @@ QList JavaUtils::FindJavaPaths() java_candidates.append(JDK32s); java_candidates.append(NEWJDK32s); java_candidates.append(ADOPTOPENJDK32s); + java_candidates.append(ZULU32s); + java_candidates.append(LIBERICA32s); java_candidates.append(MakeJavaPtr(this->GetDefaultJava()->path));