Kaydet (Commit) 3d27b2fa authored tarafından Stephan Bergmann's avatar Stephan Bergmann

tdf#124503: Support JRE installations with unknown java.vendor property

After recent additions of 61c4f96d "Support
AdoptOpenJDK" and 41507db5 "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: 's avatarStephan Bergmann <sbergman@redhat.com>
üst d38f9934
......@@ -16,10 +16,15 @@
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_JVMFWK_SOURCE_FWKBASE_HXX
#define INCLUDED_JVMFWK_SOURCE_FWKBASE_HXX
#ifndef INCLUDED_JVMFWK_INC_FWKBASE_HXX
#define INCLUDED_JVMFWK_INC_FWKBASE_HXX
#include <sal/config.h>
#include <boost/optional.hpp>
#include <rtl/ustring.hxx>
#include "elements.hxx"
#include "libxmlutil.hxx"
namespace jfw
......@@ -34,7 +39,7 @@ class VendorSettings
public:
VendorSettings();
VersionInfo getVersionInformation(const OUString & sVendor) const;
boost::optional<VersionInfo> getVersionInformation(const OUString & sVendor) const;
::std::vector< OUString> getSupportedVendors() const;
};
......
......@@ -16,8 +16,8 @@
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_JVMFWK_SOURCE_LIBXMLUTIL_HXX
#define INCLUDED_JVMFWK_SOURCE_LIBXMLUTIL_HXX
#ifndef INCLUDED_JVMFWK_INC_LIBXMLUTIL_HXX
#define INCLUDED_JVMFWK_INC_LIBXMLUTIL_HXX
#include <libxml/parser.h>
#include <libxml/xpath.h>
......
......@@ -28,10 +28,10 @@
#include <memory>
#include <vector>
#include <utility>
#include "elements.hxx"
#include "vendorbase.hxx"
namespace jfw { class VendorSettings; }
/**
@file
<p>
......@@ -56,7 +56,6 @@ enum class javaPluginError
WrongVersionFormat,
FailedVersion,
NoJre,
WrongVendor,
WrongArch,
VmCreationFailed
};
......@@ -64,26 +63,14 @@ enum class javaPluginError
/** obtains information about installations of Java Runtime Environments (JREs).
<p>The function gathers information about available JREs which have the same
vendor as determined by the <code>sVendor</code> parameter. Only information
<p>The function gathers information about available JREs. Only information
about those JREs which match the version requirements are returned. These
requirements are specified by the parameters <code>sMinVersion</code>,
<code>sMaxVersion</code> and <code>arExcludeList</code>.
requirements are specified by the parameter <code>vendorSettings</code>.
</p>
<p>
The JavaInfo structures returned in <code>parJavaInfo</code> should be ordered
according to their version. The one, representing a JRE with the highest
version should be the first in the array. </p>
@param sVendor
[in] only JREs from this vendor are examined. This parameter always contains
a vendor string. That is, the string it is not empty.
@param sMinVersion
[in] represents the minimum version of a JRE. The string can be empty.
@param sMaxVersion
[in] represents the maximum version of a JRE. The string can be empty.
@param arExcludeList
[in] contains a list of &quot;bad&quot; versions. JREs which have one of these
versions must not be returned by this function.
@param parJavaInfo
[out] if the function runs successfully then <code>parJavaInfo</code> contains
on return a vector of pointers to <code>JavaInfo</code> objects.
......@@ -91,40 +78,25 @@ enum class javaPluginError
@return
javaPluginError::NONE the function ran successfully.</br>
javaPluginError::Error an error occurred during execution.</br>
javaPluginError::InvalidArg an argument was not valid.</br>
javaPluginError::WrongVersionFormat the version strings in
<code>sMinVersion,sMaxVersion,arExcludeList</code> are not recognized as valid
<code>vendorSettings</code> are not recognized as valid
version strings.
*/
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);
/** obtains information for a JRE at a given location.
<p>If the given location belongs to a JRE whoose vendor matches the
sVendor argument and the JRE has a version which meets the requirements as
specified by <code>sMinVersion, sMaxVersion, arExcludeList</code> then
this function shall return a JavaInfo object for this JRE if this implementation
supports this vendor.</p>
<p>If the given location belongs to a JRE
and the JRE has a version which meets the requirements as
specified by <code>vendorSettings</code> then
this function shall return a JavaInfo object for this JRE.</p>
@param sLocation
[in] a file URL to the directory of the JRE.
@param sVendor
[in] a name of a vendor. This parameter always contains
a vendor string. That is, the string it is not empty.
@param sMinVersion
[in] represents the minimum version of a JRE.
@param sMaxVersion
[in] represents the maximum version of a JRE.
@param arExcludeList
[in] contains a list of &quot;bad&quot; versions. JREs which have one of these
versions must not be returned by this function.
@param ppInfo
[out] if the function runs successfully then <code>ppInfo</code> contains
on return a pointer to a <code>JavaInfo</code> object.
......@@ -134,37 +106,23 @@ javaPluginError jfw_plugin_getAllJavaInfos(
javaPluginError::Error an error occurred during execution.</br>
javaPluginError::InvalidArg an argument was not valid. For example, sLocation
is an empty string.</br>
javaPluginError::WrongVersionFormat the version strings in
<code>sMinVersion,sMaxVersion,arExcludeList</code> are not recognized as valid
version strings.
javaPluginError::FailedVersion there is a JRE at the given location but it does not
meet the version requirements.
javaPluginError::NoJre no JRE could be detected at the given location. However, that
does not mean necessarily that there is no JRE. There could be a JRE but it has
a vendor which is not supported by this API implementation.
javaPluginError::NoJre no JRE could be detected at the given location.
*/
javaPluginError jfw_plugin_getJavaInfoByPath(
OUString const& sLocation,
OUString const& sVendor,
OUString const& sMinVersion,
OUString const& sMaxVersion,
std::vector<OUString> const &arExcludeList,
jfw::VendorSettings const & vendorSettings,
std::unique_ptr<JavaInfo> * ppInfo);
/** obtains information for a JRE referenced by the JAVA_HOME environment variable.
<p>If the JAVA_HOME environment variable is set and points to a JRE whoose vendor
matches the requirements given by vecVendorInfos (i.e. it has a vendor that is
given in vecVendorInfos and the version requirements for the vendor are met),
<p>If the JAVA_HOME environment variable is set and points to a JRE that
matches the requirements given by vendorSettings (i.e.
the version requirements, if any, for the vendor are met),
then this function shall return a JavaInfo object for this JRE.</p>
@param vecVendorInfos
[in] vector specifying the vendor and version requirements that the JRE must fulfill.
The vector contains pairs of vendors and the respective version requirements
for those vendors. The JRE must support the requirements of one given pair in the
vector (i.e. it must be of one of the vendors and meet the version requirements
- minVersion, maxVersion, excludeVersions - for that specific vendor).
@param ppInfo
[out] if the JAVA_HOME environment variable is set and points to a suitable
JRE, then <code>ppInfo</code> contains
......@@ -173,12 +131,12 @@ javaPluginError jfw_plugin_getJavaInfoByPath(
@return
javaPluginError::NONE the function ran successfully.</br>
javaPluginError::NoJre no suitable JRE could be detected at the given location. However, that
does not mean necessarily that there is no JRE. There could be a JRE but it has
a vendor which is not supported by this API implementation or it does not
does not mean necessarily that there is no JRE. There could be a JRE but
it does not
meet the version requirements.
*/
javaPluginError jfw_plugin_getJavaInfoFromJavaHome(
std::vector<std::pair<OUString, jfw::VersionInfo>> const& vecVendorInfos,
jfw::VendorSettings const & vendorSettings,
std::unique_ptr<JavaInfo> * ppInfo,
std::vector<rtl::Reference<jfw_plugin::VendorBase>> & infos);
......@@ -187,20 +145,14 @@ javaPluginError jfw_plugin_getJavaInfoFromJavaHome(
whose executable is in the PATH.
<p>The function gathers information about available JREs which are on the PATH
(PATH environment variable) and meet the vendor and version requirements given by
<code>vecVendorInfos</code> (i.e. they have a vendor that is given in
<code>vecVendorInfos</code> and the version requirements for the vendor are met).
(PATH environment variable) and meet the version requirements given by
<code>vendorSettings</code> (i.e.
the version requirements, if any, for the vendor are met).
</p>
<p>
The JavaInfo structures returned in <code>vecJavaInfosFromPath</code> should be ordered
according to their occurrence in the PATH. The one that is the first one on the PATH
is also the first element in the vector.</p>
@param vecVendorInfos
[in] vector specifying the vendor and version requirements that the JRE must fulfill.
The vector contains pairs of vendors and the respective version requirements
for those vendors. The JRE must support the requirements of one given pair in the
vector (i.e. it must be of one of the vendors and meet the version requirements
- minVersion, maxVersion, excludeVersions - for that specific vendor).
@param vecJavaInfosFromPath
[out] if the function runs successfully then <code>vecJavaInfosFromPath</code>
contains on return a vector of pointers to <code>JavaInfo</code> objects.
......@@ -216,7 +168,7 @@ javaPluginError jfw_plugin_getJavaInfoFromJavaHome(
*/
javaPluginError jfw_plugin_getJavaInfosFromPath(
std::vector<std::pair<OUString, jfw::VersionInfo>> const& vecVendorInfos,
jfw::VendorSettings const & vendorSettings,
std::vector<std::unique_ptr<JavaInfo>> & vecJavaInfosFromPath,
std::vector<rtl::Reference<jfw_plugin::VendorBase>> & infos);
......@@ -256,8 +208,6 @@ javaPluginError jfw_plugin_getJavaInfosFromPath(
@return
javaPluginError::NONE the function ran successfully.</br>
javaPluginError::Error an error occurred during execution.</br>
javaPluginError::WrongVendor the <code>JavaInfo</code> object was not created
in by this library and the VM cannot be started.</br>
JFW_PLUGIN_E_VM_CREATION_FAILED a VM could not be created. The error was caused
by the JRE.
*/
......
......@@ -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 )
......
......@@ -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);
......
......@@ -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: */
......@@ -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
......
......@@ -27,9 +27,9 @@
#include <osl/mutex.hxx>
#include <osl/file.hxx>
#include <fwkutil.hxx>
#include "fwkbase.hxx"
#include <fwkbase.hxx>
#include "framework.hxx"
#include "libxmlutil.hxx"
#include <libxmlutil.hxx>
#include <osl/thread.hxx>
#include <algorithm>
#include <libxml/parser.h>
......
This diff is collapsed.
......@@ -29,7 +29,7 @@
#include "framework.hxx"
#include <fwkutil.hxx>
#include <elements.hxx>
#include "fwkbase.hxx"
#include <fwkbase.hxx>
using namespace osl;
......@@ -116,11 +116,23 @@ VendorSettings::VendorSettings():
}
}
VersionInfo VendorSettings::getVersionInformation(const OUString & sVendor) const
boost::optional<VersionInfo> VendorSettings::getVersionInformation(const OUString & sVendor) const
{
OSL_ASSERT(!sVendor.isEmpty());
VersionInfo aVersionInfo;
OString osVendor = OUStringToOString(sVendor, RTL_TEXTENCODING_UTF8);
CXPathObjectPtr pathObject;
pathObject = xmlXPathEvalExpression(
reinterpret_cast<xmlChar const *>(
OString(
"/jf:javaSelection/jf:vendorInfos/jf:vendor[@name=\"" + osVendor
+ "\"]/jf:minVersion").getStr()),
m_xmlPathContextVendorSettings);
if (xmlXPathNodeSetIsEmpty(pathObject->nodesetval))
{
return {};
}
VersionInfo aVersionInfo;
//Get minVersion
OString sExpression = OString(
"/jf:javaSelection/jf:vendorInfos/jf:vendor[@name=\"") +
......
......@@ -17,7 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "libxmlutil.hxx"
#include <libxmlutil.hxx>
namespace jfw
{
......
......@@ -8139,7 +8139,9 @@ jvmaccess/workbench/exceptiontest1.cxx
jvmaccess/workbench/exceptiontest2.cxx
jvmaccess/workbench/javainfo/javainfotest.cxx
jvmfwk/inc/elements.hxx
jvmfwk/inc/fwkbase.hxx
jvmfwk/inc/fwkutil.hxx
jvmfwk/inc/libxmlutil.hxx
jvmfwk/inc/vendorbase.hxx
jvmfwk/inc/vendorplugin.hxx
jvmfwk/plugins/sunmajor/javaenvsetup/javaldx.cxx
......@@ -8163,10 +8165,8 @@ jvmfwk/source/elements.cxx
jvmfwk/source/framework.cxx
jvmfwk/source/framework.hxx
jvmfwk/source/fwkbase.cxx
jvmfwk/source/fwkbase.hxx
jvmfwk/source/fwkutil.cxx
jvmfwk/source/libxmlutil.cxx
jvmfwk/source/libxmlutil.hxx
l10ntools/inc/cfglex.hxx
l10ntools/inc/cfgmerge.hxx
l10ntools/inc/common.hxx
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment