diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2019-04-09 14:51:54 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2019-04-09 22:31:17 +0200 |
commit | 3d27b2fa9c5a03f78e5145377402f8a88e3da1be (patch) | |
tree | be09d47208ad2f3f4564987a25d5d6d875744792 /jvmfwk/plugins | |
parent | d38f9934f08939032cca64a32de58fa3901a88d5 (diff) |
tdf#124503: Support JRE installations with unknown java.vendor property
After recent additions of 61c4f96d6ae6a80370774e53287edb27cbce8067 "Support
AdoptOpenJDK" and 41507db590b24e1b9b45d95cad55c71ba2e4091d "Support Amazon
Corretto" to our hard-coded list, there is now reports that at least Debian and
Ubuntu tried to distribute versions of OpenJDK with the java.vendor propety set
to string like "Debian" or "Ubuntu". Instead of trying to catch up with an
ever-growing hard-coded list, it is probably better to stop relying exclusively
on such a hard-coded list, and for unknown vendor values, try out whether the
SunInfo backend (which supports the "generic" OpenJDK) would be able to handle
the given JRE. (For simplicity, assume that any versions of such JREs are
supported. Our baseline is Java 6, and there are unlikely any older versions of
JREs from unknown vendors out there. If this turns out to be problematic, we
could include information about problematic vendors after all, or add a general
check that JREs from unknown vendors are at least Java 6.)
Many functions in jvmfwk/inc/vendorplugin.hxx that used to take a set of
sVendor/sMinVersion/sMaxVerison/arExcludeList paramters had to be revised to
take a vendorSettings parameter instead, and
VendorSettings::getVersionInformation has been changed to return a
boost::optional, so that unknown vendors can be handled gracefully.
Change-Id: Ibf915f2ddd59e09b77e2c03be688cac0547b9ac9
Reviewed-on: https://gerrit.libreoffice.org/70460
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'jvmfwk/plugins')
-rw-r--r-- | jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx | 109 | ||||
-rw-r--r-- | jvmfwk/plugins/sunmajor/pluginlib/util.cxx | 7 | ||||
-rw-r--r-- | jvmfwk/plugins/sunmajor/pluginlib/vendorlist.cxx | 18 | ||||
-rw-r--r-- | jvmfwk/plugins/sunmajor/pluginlib/vendorlist.hxx | 5 |
4 files changed, 46 insertions, 93 deletions
diff --git a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx index b2cc8ed40803..395ef332e0e8 100644 --- a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx +++ b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx @@ -57,6 +57,7 @@ #include <jni.h> #include <rtl/byteseq.hxx> +#include <fwkbase.hxx> #include <vendorplugin.hxx> #include "util.hxx" #include "sunversion.hxx" @@ -296,19 +297,12 @@ javaPluginError checkJavaVersionRequirements( javaPluginError jfw_plugin_getAllJavaInfos( bool checkJavaHomeAndPath, - OUString const& sVendor, - OUString const& sMinVersion, - OUString const& sMaxVersion, - std::vector<OUString> const &arExcludeList, + jfw::VendorSettings const & vendorSettings, std::vector<std::unique_ptr<JavaInfo>>* parJavaInfo, std::vector<rtl::Reference<jfw_plugin::VendorBase>> & infos) { assert(parJavaInfo); - OSL_ASSERT(!sVendor.isEmpty()); - if (sVendor.isEmpty()) - return javaPluginError::InvalidArg; - //Find all JREs vector<rtl::Reference<VendorBase> > vecInfos = addAllJREInfos(checkJavaHomeAndPath, infos); @@ -316,17 +310,16 @@ javaPluginError jfw_plugin_getAllJavaInfos( for (auto const& vecInfo : vecInfos) { + if (auto const versionInfo = vendorSettings.getVersionInformation(vecInfo->getVendor())) + { + javaPluginError err = checkJavaVersionRequirements( + vecInfo, versionInfo->sMinVersion, versionInfo->sMaxVersion, versionInfo->vecExcludeVersions); - if (sVendor != vecInfo->getVendor()) - continue; - - javaPluginError err = checkJavaVersionRequirements( - vecInfo, sMinVersion, sMaxVersion, arExcludeList); - - if (err == javaPluginError::FailedVersion || err == javaPluginError::WrongArch) - continue; - else if (err == javaPluginError::WrongVersionFormat) - return err; + if (err == javaPluginError::FailedVersion || err == javaPluginError::WrongArch) + continue; + else if (err == javaPluginError::WrongVersionFormat) + return err; + } vecVerifiedInfos.push_back(vecInfo); } @@ -343,10 +336,7 @@ javaPluginError jfw_plugin_getAllJavaInfos( javaPluginError jfw_plugin_getJavaInfoByPath( OUString const& sPath, - OUString const& sVendor, - OUString const& sMinVersion, - OUString const& sMaxVersion, - std::vector<OUString> const &arExcludeList, + jfw::VendorSettings const & vendorSettings, std::unique_ptr<JavaInfo> * ppInfo) { assert(ppInfo != nullptr); @@ -354,19 +344,17 @@ javaPluginError jfw_plugin_getJavaInfoByPath( if (sPath.isEmpty()) return javaPluginError::InvalidArg; - OSL_ASSERT(!sVendor.isEmpty()); - if (sVendor.isEmpty()) - return javaPluginError::InvalidArg; - rtl::Reference<VendorBase> aVendorInfo = getJREInfoByPath(sPath); if (!aVendorInfo.is()) return javaPluginError::NoJre; //Check if the detected JRE matches the version requirements - if (sVendor != aVendorInfo->getVendor()) - return javaPluginError::NoJre; - javaPluginError errorcode = checkJavaVersionRequirements( - aVendorInfo, sMinVersion, sMaxVersion, arExcludeList); + javaPluginError errorcode = javaPluginError::NONE; + if (auto const versionInfo = vendorSettings.getVersionInformation(aVendorInfo->getVendor())) + { + errorcode = checkJavaVersionRequirements( + aVendorInfo, versionInfo->sMinVersion, versionInfo->sMaxVersion, versionInfo->vecExcludeVersions); + } if (errorcode == javaPluginError::NONE) *ppInfo = createJavaInfo(aVendorInfo); @@ -375,7 +363,7 @@ javaPluginError jfw_plugin_getJavaInfoByPath( } javaPluginError jfw_plugin_getJavaInfoFromJavaHome( - std::vector<pair<OUString, jfw::VersionInfo>> const& vecVendorInfos, + jfw::VendorSettings const & vendorSettings, std::unique_ptr<JavaInfo> * ppInfo, std::vector<rtl::Reference<VendorBase>> & infos) { @@ -389,32 +377,24 @@ javaPluginError jfw_plugin_getJavaInfoFromJavaHome( assert(infoJavaHome.size() == 1); //Check if the detected JRE matches the version requirements - for (auto const& vendorInfo : vecVendorInfos) - { - const OUString& vendor = vendorInfo.first; - jfw::VersionInfo versionInfo = vendorInfo.second; - - if (vendor == infoJavaHome[0]->getVendor()) - { - javaPluginError errorcode = checkJavaVersionRequirements( + auto const versionInfo = vendorSettings.getVersionInformation(infoJavaHome[0]->getVendor()); + if (!versionInfo + || (checkJavaVersionRequirements( infoJavaHome[0], - versionInfo.sMinVersion, - versionInfo.sMaxVersion, - versionInfo.vecExcludeVersions); - - if (errorcode == javaPluginError::NONE) - { - *ppInfo = createJavaInfo(infoJavaHome[0]); - return javaPluginError::NONE; - } - } + versionInfo->sMinVersion, + versionInfo->sMaxVersion, + versionInfo->vecExcludeVersions) + == javaPluginError::NONE)) + { + *ppInfo = createJavaInfo(infoJavaHome[0]); + return javaPluginError::NONE; } return javaPluginError::NoJre; } javaPluginError jfw_plugin_getJavaInfosFromPath( - std::vector<std::pair<OUString, jfw::VersionInfo>> const& vecVendorInfos, + jfw::VendorSettings const & vendorSettings, std::vector<std::unique_ptr<JavaInfo>> & javaInfosFromPath, std::vector<rtl::Reference<jfw_plugin::VendorBase>> & infos) { @@ -427,24 +407,16 @@ javaPluginError jfw_plugin_getJavaInfosFromPath( // copy infos of JREs that meet version requirements to vecVerifiedInfos for (auto const& infosFromPath : vecInfosFromPath) { - for (auto const& vendorInfo : vecVendorInfos) - { - const OUString& vendor = vendorInfo.first; - jfw::VersionInfo const & versionInfo = vendorInfo.second; - - if (vendor == infosFromPath->getVendor()) - { - javaPluginError errorcode = checkJavaVersionRequirements( + auto const versionInfo = vendorSettings.getVersionInformation(infosFromPath->getVendor()); + if (!versionInfo + || (checkJavaVersionRequirements( infosFromPath, - versionInfo.sMinVersion, - versionInfo.sMaxVersion, - versionInfo.vecExcludeVersions); - - if (errorcode == javaPluginError::NONE) - { - vecVerifiedInfos.push_back(createJavaInfo(infosFromPath)); - } - } + versionInfo->sMinVersion, + versionInfo->sMaxVersion, + versionInfo->vecExcludeVersions) + == javaPluginError::NONE)) + { + vecVerifiedInfos.push_back(createJavaInfo(infosFromPath)); } } @@ -621,9 +593,6 @@ javaPluginError jfw_plugin_startJavaVirtualMachine( // unless errorcode is volatile the following warning occurs on gcc: // warning: variable 'errorcode' might be clobbered by `longjmp' or `vfork' volatile javaPluginError errorcode = javaPluginError::NONE; - //Check if the Vendor (pInfo->sVendor) is supported by this plugin - if ( ! isVendorSupported(pInfo->sVendor)) - return javaPluginError::WrongVendor; #ifdef MACOSX rtl::Reference<VendorBase> aVendorInfo = getJREInfoByPath( pInfo->sLocation ); if ( !aVendorInfo.is() || aVendorInfo->compareVersions( pInfo->sVersion ) < 0 ) diff --git a/jvmfwk/plugins/sunmajor/pluginlib/util.cxx b/jvmfwk/plugins/sunmajor/pluginlib/util.cxx index 249deeaf304c..a21aa4ff933f 100644 --- a/jvmfwk/plugins/sunmajor/pluginlib/util.cxx +++ b/jvmfwk/plugins/sunmajor/pluginlib/util.cxx @@ -1032,6 +1032,7 @@ rtl::Reference<VendorBase> getJREInfoByPath( } } + auto knownVendor = false; if (!sVendorName.isEmpty()) { //find the creator func for the respective vendor name @@ -1043,10 +1044,16 @@ rtl::Reference<VendorBase> getJREInfoByPath( if (sNameMap == sVendorName) { ret = createInstance(gVendorMap[c].createFunc, props); + knownVendor = true; break; } } } + // For unknown vendors, try SunInfo as fallback: + if (!knownVendor) + { + ret = createInstance(SunInfo::createInstance, props); + } if (!ret.is()) { vecBadPaths.push_back(sFilePath); diff --git a/jvmfwk/plugins/sunmajor/pluginlib/vendorlist.cxx b/jvmfwk/plugins/sunmajor/pluginlib/vendorlist.cxx index 60911f8a63ca..cc3088fbc683 100644 --- a/jvmfwk/plugins/sunmajor/pluginlib/vendorlist.cxx +++ b/jvmfwk/plugins/sunmajor/pluginlib/vendorlist.cxx @@ -22,10 +22,6 @@ #include "gnujre.hxx" #include "sunjre.hxx" #include "otherjre.hxx" -#include <osl/thread.h> -#include <stdio.h> -#include <sal/log.hxx> - namespace jfw_plugin { @@ -54,20 +50,6 @@ VendorSupportMapEntry const gVendorMap[] ={ VENDOR_MAP_ENTRY<OtherInfo>("Azul Systems, Inc."), {nullptr, nullptr, nullptr} }; - -bool isVendorSupported(const OUString& sVendor) -{ - const size_t count = SAL_N_ELEMENTS(gVendorMap) - 1; - for ( size_t pos = 0; pos < count; ++pos ) - { - if (sVendor.equalsAscii(gVendorMap[pos].sVendorName)) - return true; - } - SAL_INFO( - "jfw.level2", "sunjavaplugin does not support vendor: " << sVendor); - return false; -} - } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jvmfwk/plugins/sunmajor/pluginlib/vendorlist.hxx b/jvmfwk/plugins/sunmajor/pluginlib/vendorlist.hxx index 10e3cec10518..a0e682a9e09b 100644 --- a/jvmfwk/plugins/sunmajor/pluginlib/vendorlist.hxx +++ b/jvmfwk/plugins/sunmajor/pluginlib/vendorlist.hxx @@ -41,11 +41,6 @@ template<typename y> constexpr VendorSupportMapEntry VENDOR_MAP_ENTRY(char const return {x, & y::getJavaExePaths, & y::createInstance}; } -/* Examines if the vendor supplied in parameter sVendor is part of the - list of supported vendors. That is the arry of VendorSupportMapEntry - is search for an respective entry. -*/ -bool isVendorSupported(const OUString & sVendor); } #endif |