2010-10-14 08:30:07 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-07-11 19:49:09 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2006-09-16 16:48:06 +00:00
|
|
|
|
2017-10-23 22:38:59 +02:00
|
|
|
#include <rtl/ustring.hxx>
|
|
|
|
#include <rtl/ustrbuf.hxx>
|
2018-08-05 00:50:24 +02:00
|
|
|
#include <sal/log.hxx>
|
2017-10-23 22:38:59 +02:00
|
|
|
#include <libxml/xpathInternals.h>
|
|
|
|
#include <osl/file.hxx>
|
2019-03-09 17:28:06 +01:00
|
|
|
#include <osl/thread.hxx>
|
2004-11-09 13:00:36 +00:00
|
|
|
#include "framework.hxx"
|
2017-10-23 22:38:59 +02:00
|
|
|
#include <fwkutil.hxx>
|
|
|
|
#include <elements.hxx>
|
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>
2019-04-09 14:51:54 +02:00
|
|
|
#include <fwkbase.hxx>
|
2004-11-09 13:00:36 +00:00
|
|
|
|
|
|
|
using namespace osl;
|
2011-03-02 21:53:12 +01:00
|
|
|
|
2004-11-09 13:00:36 +00:00
|
|
|
|
|
|
|
#define UNO_JAVA_JFW_PARAMETER "UNO_JAVA_JFW_PARAMETER_"
|
|
|
|
#define UNO_JAVA_JFW_JREHOME "UNO_JAVA_JFW_JREHOME"
|
|
|
|
#define UNO_JAVA_JFW_ENV_JREHOME "UNO_JAVA_JFW_ENV_JREHOME"
|
|
|
|
#define UNO_JAVA_JFW_CLASSPATH "UNO_JAVA_JFW_CLASSPATH"
|
|
|
|
#define UNO_JAVA_JFW_ENV_CLASSPATH "UNO_JAVA_JFW_ENV_CLASSPATH"
|
|
|
|
#define UNO_JAVA_JFW_CLASSPATH_URLS "UNO_JAVA_JFW_CLASSPATH_URLS"
|
|
|
|
#define UNO_JAVA_JFW_VENDOR_SETTINGS "UNO_JAVA_JFW_VENDOR_SETTINGS"
|
|
|
|
|
|
|
|
namespace jfw
|
|
|
|
{
|
2017-01-09 15:42:37 +01:00
|
|
|
static bool g_bJavaSet = false;
|
2004-11-09 13:00:36 +00:00
|
|
|
|
2007-06-13 06:57:54 +00:00
|
|
|
namespace {
|
|
|
|
|
2020-12-28 19:27:38 +03:00
|
|
|
#if defined _WIN32
|
|
|
|
// The paths are used in libxml. On Windows, it takes UTF-8 paths.
|
|
|
|
constexpr rtl_TextEncoding PathEncoding() { return RTL_TEXTENCODING_UTF8; }
|
|
|
|
#else
|
|
|
|
rtl_TextEncoding PathEncoding() { return osl_getThreadTextEncoding(); }
|
|
|
|
#endif
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OString getVendorSettingsPath(OUString const & sURL)
|
2007-06-13 06:57:54 +00:00
|
|
|
{
|
2012-01-04 11:38:41 -02:00
|
|
|
if (sURL.isEmpty())
|
2013-04-07 12:06:47 +02:00
|
|
|
return OString();
|
|
|
|
OUString sSystemPathSettings;
|
2007-06-13 06:57:54 +00:00
|
|
|
if (osl_getSystemPathFromFileURL(sURL.pData,
|
|
|
|
& sSystemPathSettings.pData) != osl_File_E_None)
|
|
|
|
throw FrameworkException(
|
|
|
|
JFW_E_ERROR,
|
2017-05-29 09:48:54 +02:00
|
|
|
"[Java framework] Error in function getVendorSettingsPath (fwkbase.cxx) ");
|
2020-12-28 19:27:38 +03:00
|
|
|
OString osSystemPathSettings = OUStringToOString(sSystemPathSettings, PathEncoding());
|
2007-06-13 06:57:54 +00:00
|
|
|
return osSystemPathSettings;
|
|
|
|
}
|
|
|
|
|
2013-10-28 16:06:43 +01:00
|
|
|
OUString getParam(OUString const & name)
|
2007-06-13 06:57:54 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString retVal;
|
2021-11-15 21:44:42 +02:00
|
|
|
bool b = Bootstrap()->getFrom(name, retVal);
|
2013-10-28 16:06:43 +01:00
|
|
|
SAL_INFO(
|
|
|
|
"jfw",
|
|
|
|
"Using bootstrap parameter " << name << " = \"" << retVal << "\""
|
|
|
|
<< (b ? "" : " (undefined)"));
|
2007-06-13 06:57:54 +00:00
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
2013-10-28 16:06:43 +01:00
|
|
|
OUString getParamFirstUrl(OUString const & name)
|
2008-03-18 11:22:17 +00:00
|
|
|
{
|
|
|
|
// Some parameters can consist of multiple URLs (separated by space
|
|
|
|
// characters, although trim() harmlessly also removes other white-space),
|
|
|
|
// of which only the first is used:
|
2019-02-23 20:04:41 +01:00
|
|
|
return getParam(name).trim().getToken(0, ' ');
|
2008-03-18 11:22:17 +00:00
|
|
|
}
|
|
|
|
|
2007-06-13 06:57:54 +00:00
|
|
|
}//blind namespace
|
|
|
|
|
2005-06-17 09:12:18 +00:00
|
|
|
|
2020-03-06 14:40:40 +02:00
|
|
|
VendorSettings::VendorSettings()
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
2020-03-06 14:40:40 +02:00
|
|
|
OUString xmlDocVendorSettingsFileUrl(BootParams::getVendorSettings());
|
2004-12-16 10:47:49 +00:00
|
|
|
//Prepare the xml document and context
|
2020-03-06 14:40:40 +02:00
|
|
|
OString sSettingsPath = getVendorSettingsPath(xmlDocVendorSettingsFileUrl);
|
2012-01-04 11:38:41 -02:00
|
|
|
if (sSettingsPath.isEmpty())
|
2004-12-16 10:47:49 +00:00
|
|
|
{
|
|
|
|
OString sMsg("[Java framework] A vendor settings file was not specified."
|
|
|
|
"Check the bootstrap parameter " UNO_JAVA_JFW_VENDOR_SETTINGS ".");
|
2017-05-29 09:48:54 +02:00
|
|
|
SAL_WARN( "jfw", sMsg );
|
2004-12-16 10:47:49 +00:00
|
|
|
throw FrameworkException(JFW_E_CONFIGURATION, sMsg);
|
|
|
|
}
|
2020-04-07 14:16:40 +02:00
|
|
|
if (sSettingsPath.isEmpty())
|
|
|
|
return;
|
2004-11-09 13:00:36 +00:00
|
|
|
|
2020-04-07 14:16:40 +02:00
|
|
|
m_xmlDocVendorSettings = xmlParseFile(sSettingsPath.getStr());
|
|
|
|
if (m_xmlDocVendorSettings == nullptr)
|
|
|
|
throw FrameworkException(
|
|
|
|
JFW_E_ERROR,
|
2021-04-20 21:07:42 +02:00
|
|
|
OString::Concat("[Java framework] Error while parsing file: ")
|
2020-04-07 14:16:40 +02:00
|
|
|
+ sSettingsPath + ".");
|
|
|
|
|
|
|
|
m_xmlPathContextVendorSettings = xmlXPathNewContext(m_xmlDocVendorSettings);
|
|
|
|
int res = xmlXPathRegisterNs(
|
|
|
|
m_xmlPathContextVendorSettings, reinterpret_cast<xmlChar const *>("jf"),
|
|
|
|
reinterpret_cast<xmlChar const *>(NS_JAVA_FRAMEWORK));
|
|
|
|
if (res == -1)
|
|
|
|
throw FrameworkException(JFW_E_ERROR,
|
|
|
|
"[Java framework] Error in constructor VendorSettings::VendorSettings() (fwkbase.cxx)");
|
2004-11-09 13:00:36 +00:00
|
|
|
}
|
|
|
|
|
Make getVersionInformation always return a VersionInfo
...even for JREs not listed in javavendors.xml, making it default to a
VersionInfo with sMinVersion = "1.8.0".
3d27b2fa9c5a03f78e5145377402f8a88e3da1be "tdf#124503: Support JRE installations
with unknown java.vendor property", which had changed getVersionInformation to
return an optional<VersionInfo>, said in the commit message: "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." Our baseline is Java 8 by now, and there are still unlikely any older
JREs out there, but for macOS ARM64 we may want to restrict to at least Java 17
implementing <http://openjdk.java.net/jeps/391> "JEP 391: macOS/AArch64 Port",
and this commit is a prerequisite for such a change (where we would then e.g.
change the hardcoded "1.8.0" to "17" for just that one platform).
(OtherInfo::compareVersions in jvmfwk/plugins/sunmajor/pluginlib/otherjre.cxx
unconditionally returns 0, meaning "versions compare equal", so introducing a
default version of "1.8.0" should have no negative effect on any JREs that use
OtherInfo.)
Change-Id: I34dc5f2b755c2254a91d42c262786ceec70c746e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123958
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2021-10-21 10:14:38 +02:00
|
|
|
VersionInfo VendorSettings::getVersionInformation(std::u16string_view sVendor) const
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
2020-12-11 17:44:34 +01:00
|
|
|
OSL_ASSERT(!sVendor.empty());
|
2004-11-09 13:00:36 +00:00
|
|
|
OString osVendor = OUStringToOString(sVendor, RTL_TEXTENCODING_UTF8);
|
2019-07-28 12:03:35 +02:00
|
|
|
CXPathObjectPtr pathObject = xmlXPathEvalExpression(
|
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>
2019-04-09 14:51:54 +02:00
|
|
|
reinterpret_cast<xmlChar const *>(
|
|
|
|
OString(
|
|
|
|
"/jf:javaSelection/jf:vendorInfos/jf:vendor[@name=\"" + osVendor
|
|
|
|
+ "\"]/jf:minVersion").getStr()),
|
|
|
|
m_xmlPathContextVendorSettings);
|
|
|
|
if (xmlXPathNodeSetIsEmpty(pathObject->nodesetval))
|
|
|
|
{
|
2021-10-21 13:06:25 +02:00
|
|
|
return {
|
|
|
|
{},
|
|
|
|
#if defined MACOSX && defined __aarch64__
|
|
|
|
"17",
|
|
|
|
#else
|
|
|
|
"1.8.0",
|
|
|
|
#endif
|
|
|
|
""};
|
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>
2019-04-09 14:51:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VersionInfo aVersionInfo;
|
2004-11-09 13:00:36 +00:00
|
|
|
//Get minVersion
|
2019-10-13 08:47:47 +02:00
|
|
|
OString sExpression =
|
|
|
|
"/jf:javaSelection/jf:vendorInfos/jf:vendor[@name=\"" +
|
|
|
|
osVendor + "\"]/jf:minVersion";
|
2004-11-09 13:00:36 +00:00
|
|
|
|
2019-04-13 14:54:59 +02:00
|
|
|
CXPathObjectPtr xPathObjectMin =
|
2017-03-19 17:35:07 +01:00
|
|
|
xmlXPathEvalExpression(reinterpret_cast<xmlChar const *>(sExpression.getStr()),
|
2004-11-09 13:00:36 +00:00
|
|
|
m_xmlPathContextVendorSettings);
|
|
|
|
if (xmlXPathNodeSetIsEmpty(xPathObjectMin->nodesetval))
|
|
|
|
{
|
2014-11-12 14:24:10 +05:30
|
|
|
aVersionInfo.sMinVersion.clear();
|
2004-11-09 13:00:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-13 14:54:59 +02:00
|
|
|
CXmlCharPtr sVersion = xmlNodeListGetString(
|
2004-11-09 13:00:36 +00:00
|
|
|
m_xmlDocVendorSettings,
|
|
|
|
xPathObjectMin->nodesetval->nodeTab[0]->xmlChildrenNode, 1);
|
2015-01-17 18:48:45 +01:00
|
|
|
OString osVersion(sVersion);
|
2014-11-06 17:24:13 +01:00
|
|
|
aVersionInfo.sMinVersion = OStringToOUString(
|
|
|
|
osVersion, RTL_TEXTENCODING_UTF8);
|
2004-11-09 13:00:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Get maxVersion
|
2019-10-13 08:47:47 +02:00
|
|
|
sExpression = "/jf:javaSelection/jf:vendorInfos/jf:vendor[@name=\"" +
|
|
|
|
osVendor + "\"]/jf:maxVersion";
|
2019-04-13 14:54:59 +02:00
|
|
|
CXPathObjectPtr xPathObjectMax = xmlXPathEvalExpression(
|
2017-03-19 17:35:07 +01:00
|
|
|
reinterpret_cast<xmlChar const *>(sExpression.getStr()),
|
2004-11-09 13:00:36 +00:00
|
|
|
m_xmlPathContextVendorSettings);
|
|
|
|
if (xmlXPathNodeSetIsEmpty(xPathObjectMax->nodesetval))
|
|
|
|
{
|
2014-11-12 14:24:10 +05:30
|
|
|
aVersionInfo.sMaxVersion.clear();
|
2004-11-09 13:00:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-13 14:54:59 +02:00
|
|
|
CXmlCharPtr sVersion = xmlNodeListGetString(
|
2004-11-09 13:00:36 +00:00
|
|
|
m_xmlDocVendorSettings,
|
|
|
|
xPathObjectMax->nodesetval->nodeTab[0]->xmlChildrenNode, 1);
|
2015-01-17 18:48:45 +01:00
|
|
|
OString osVersion(sVersion);
|
2014-11-06 17:24:13 +01:00
|
|
|
aVersionInfo.sMaxVersion = OStringToOUString(
|
|
|
|
osVersion, RTL_TEXTENCODING_UTF8);
|
2004-11-09 13:00:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Get excludeVersions
|
2019-10-13 08:47:47 +02:00
|
|
|
sExpression = "/jf:javaSelection/jf:vendorInfos/jf:vendor[@name=\"" +
|
|
|
|
osVendor + "\"]/jf:excludeVersions/jf:version";
|
2019-04-13 14:54:59 +02:00
|
|
|
CXPathObjectPtr xPathObjectVersions =
|
2017-03-19 17:35:07 +01:00
|
|
|
xmlXPathEvalExpression(reinterpret_cast<xmlChar const *>(sExpression.getStr()),
|
2004-11-09 13:00:36 +00:00
|
|
|
m_xmlPathContextVendorSettings);
|
|
|
|
if (!xmlXPathNodeSetIsEmpty(xPathObjectVersions->nodesetval))
|
|
|
|
{
|
|
|
|
xmlNode* cur = xPathObjectVersions->nodesetval->nodeTab[0];
|
2015-11-10 10:18:19 +01:00
|
|
|
while (cur != nullptr)
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
|
|
|
if (cur->type == XML_ELEMENT_NODE )
|
|
|
|
{
|
2015-01-17 18:48:45 +01:00
|
|
|
if (xmlStrcmp(cur->name, reinterpret_cast<xmlChar const *>("version")) == 0)
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
2019-04-13 14:54:59 +02:00
|
|
|
CXmlCharPtr sVersion = xmlNodeListGetString(
|
2004-11-09 13:00:36 +00:00
|
|
|
m_xmlDocVendorSettings, cur->xmlChildrenNode, 1);
|
2015-01-17 18:48:45 +01:00
|
|
|
OString osVersion(sVersion);
|
2014-11-06 17:24:13 +01:00
|
|
|
OUString usVersion = OStringToOUString(
|
|
|
|
osVersion, RTL_TEXTENCODING_UTF8);
|
2017-04-11 21:52:36 +02:00
|
|
|
aVersionInfo.vecExcludeVersions.push_back(usVersion);
|
2004-11-09 13:00:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return aVersionInfo;
|
|
|
|
}
|
|
|
|
|
2007-06-13 06:57:54 +00:00
|
|
|
::std::vector<OString> BootParams::getVMParameters()
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
2007-06-13 06:57:54 +00:00
|
|
|
::std::vector<OString> vecParams;
|
2004-11-09 13:00:36 +00:00
|
|
|
|
|
|
|
for (sal_Int32 i = 1; ; i++)
|
|
|
|
{
|
2014-12-16 17:29:29 +01:00
|
|
|
OUString sName = UNO_JAVA_JFW_PARAMETER + OUString::number(i);
|
2004-11-09 13:00:36 +00:00
|
|
|
OUString sValue;
|
2021-11-15 21:44:42 +02:00
|
|
|
if (Bootstrap()->getFrom(sName, sValue))
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
|
|
|
OString sParam =
|
|
|
|
OUStringToOString(sValue, osl_getThreadTextEncoding());
|
|
|
|
vecParams.push_back(sParam);
|
2015-05-27 17:24:02 +02:00
|
|
|
SAL_INFO(
|
|
|
|
"jfw.level2",
|
|
|
|
"Using bootstrap parameter " << sName << " = " << sParam);
|
2004-11-09 13:00:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return vecParams;
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString BootParams::getUserData()
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
2013-10-28 16:06:43 +01:00
|
|
|
return getParamFirstUrl("UNO_JAVA_JFW_USER_DATA");
|
2004-11-09 13:00:36 +00:00
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString BootParams::getSharedData()
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
2013-10-28 16:06:43 +01:00
|
|
|
return getParamFirstUrl("UNO_JAVA_JFW_SHARED_DATA");
|
2004-11-09 13:00:36 +00:00
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OString BootParams::getClasspath()
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OString sClassPath;
|
|
|
|
OUString sCP;
|
2021-11-15 21:44:42 +02:00
|
|
|
if (Bootstrap()->getFrom( UNO_JAVA_JFW_CLASSPATH, sCP ))
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
2020-12-28 19:27:38 +03:00
|
|
|
sClassPath = OUStringToOString(sCP, PathEncoding());
|
2015-05-27 17:24:02 +02:00
|
|
|
SAL_INFO(
|
|
|
|
"jfw.level2",
|
|
|
|
"Using bootstrap parameter " UNO_JAVA_JFW_CLASSPATH " = "
|
|
|
|
<< sClassPath);
|
2004-11-09 13:00:36 +00:00
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sEnvCP;
|
2021-11-15 21:44:42 +02:00
|
|
|
if (Bootstrap()->getFrom( UNO_JAVA_JFW_ENV_CLASSPATH, sEnvCP ))
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
|
|
|
char * pCp = getenv("CLASSPATH");
|
|
|
|
if (pCp)
|
|
|
|
{
|
2020-08-31 17:02:49 +02:00
|
|
|
sClassPath += OStringChar(SAL_PATHSEPARATOR) + pCp;
|
2004-11-09 13:00:36 +00:00
|
|
|
}
|
2015-05-27 17:24:02 +02:00
|
|
|
SAL_INFO(
|
|
|
|
"jfw.level2",
|
|
|
|
"Using bootstrap parameter " UNO_JAVA_JFW_ENV_CLASSPATH
|
|
|
|
" and class path is: " << (pCp ? pCp : ""));
|
2004-11-09 13:00:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return sClassPath;
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString BootParams::getVendorSettings()
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sVendor;
|
2021-11-15 21:44:42 +02:00
|
|
|
if (Bootstrap()->getFrom(UNO_JAVA_JFW_VENDOR_SETTINGS, sVendor))
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
|
|
|
//check the value of the bootstrap variable
|
|
|
|
jfw::FileStatus s = checkFileURL(sVendor);
|
|
|
|
if (s != FILE_OK)
|
|
|
|
{
|
|
|
|
//This bootstrap parameter can contain a relative URL
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sAbsoluteUrl;
|
|
|
|
OUString sBaseDir = getLibraryLocation();
|
2004-11-09 13:00:36 +00:00
|
|
|
if (File::getAbsoluteFileURL(sBaseDir, sVendor, sAbsoluteUrl)
|
|
|
|
!= File::E_None)
|
|
|
|
throw FrameworkException(
|
|
|
|
JFW_E_CONFIGURATION,
|
2017-05-29 09:48:54 +02:00
|
|
|
"[Java framework] Invalid value for bootstrap variable: "
|
|
|
|
UNO_JAVA_JFW_VENDOR_SETTINGS);
|
2004-11-09 13:00:36 +00:00
|
|
|
sVendor = sAbsoluteUrl;
|
|
|
|
s = checkFileURL(sVendor);
|
|
|
|
if (s == jfw::FILE_INVALID || s == jfw::FILE_DOES_NOT_EXIST)
|
|
|
|
{
|
|
|
|
throw FrameworkException(
|
|
|
|
JFW_E_CONFIGURATION,
|
2017-05-29 09:48:54 +02:00
|
|
|
"[Java framework] Invalid value for bootstrap variable: "
|
|
|
|
UNO_JAVA_JFW_VENDOR_SETTINGS);
|
2004-11-09 13:00:36 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-08 13:18:51 +02:00
|
|
|
SAL_INFO(
|
2015-05-27 17:24:02 +02:00
|
|
|
"jfw.level2",
|
|
|
|
"Using bootstrap parameter " UNO_JAVA_JFW_VENDOR_SETTINGS " = "
|
|
|
|
<< sVendor);
|
2004-11-09 13:00:36 +00:00
|
|
|
}
|
|
|
|
return sVendor;
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString BootParams::getJREHome()
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sJRE;
|
|
|
|
OUString sEnvJRE;
|
2021-11-15 21:44:42 +02:00
|
|
|
bool bJRE = Bootstrap()->getFrom(UNO_JAVA_JFW_JREHOME, sJRE);
|
|
|
|
bool bEnvJRE = Bootstrap()->getFrom(UNO_JAVA_JFW_ENV_JREHOME, sEnvJRE);
|
2004-11-09 13:00:36 +00:00
|
|
|
|
2014-02-18 12:01:43 +01:00
|
|
|
if (bJRE && bEnvJRE)
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
|
|
|
throw FrameworkException(
|
|
|
|
JFW_E_CONFIGURATION,
|
2017-05-29 09:48:54 +02:00
|
|
|
"[Java framework] Both bootstrap parameter "
|
|
|
|
UNO_JAVA_JFW_JREHOME" and "
|
|
|
|
UNO_JAVA_JFW_ENV_JREHOME" are set. However only one of them can be set."
|
|
|
|
"Check bootstrap parameters: environment variables, command line "
|
|
|
|
"arguments, rc/ini files for executable and java framework library.");
|
2004-11-09 13:00:36 +00:00
|
|
|
}
|
2014-02-18 12:01:43 +01:00
|
|
|
else if (bEnvJRE)
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
|
|
|
const char * pJRE = getenv("JAVA_HOME");
|
2015-11-10 10:18:19 +01:00
|
|
|
if (pJRE == nullptr)
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
|
|
|
throw FrameworkException(
|
2017-05-29 09:48:54 +02:00
|
|
|
JFW_E_CONFIGURATION,
|
|
|
|
"[Java framework] Both bootstrap parameter "
|
|
|
|
UNO_JAVA_JFW_ENV_JREHOME" is set, but the environment variable "
|
|
|
|
"JAVA_HOME is not set.");
|
2004-11-09 13:00:36 +00:00
|
|
|
}
|
2013-04-07 12:06:47 +02:00
|
|
|
OString osJRE(pJRE);
|
|
|
|
OUString usJRE = OStringToOUString(osJRE, osl_getThreadTextEncoding());
|
2004-11-09 13:00:36 +00:00
|
|
|
if (File::getFileURLFromSystemPath(usJRE, sJRE) != File::E_None)
|
|
|
|
throw FrameworkException(
|
|
|
|
JFW_E_ERROR,
|
2017-05-29 09:48:54 +02:00
|
|
|
"[Java framework] Error in function BootParams::getJREHome() "
|
|
|
|
"(fwkbase.cxx).");
|
2015-05-27 17:24:02 +02:00
|
|
|
SAL_INFO(
|
|
|
|
"jfw.level2",
|
|
|
|
"Using bootstrap parameter " UNO_JAVA_JFW_ENV_JREHOME
|
|
|
|
" with JAVA_HOME = " << pJRE);
|
2004-11-09 13:00:36 +00:00
|
|
|
}
|
2018-11-24 21:55:10 +03:00
|
|
|
else if (getMode() == JFW_MODE_DIRECT && !bJRE)
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
|
|
|
throw FrameworkException(
|
|
|
|
JFW_E_CONFIGURATION,
|
2017-05-29 09:48:54 +02:00
|
|
|
"[Java framework] The bootstrap parameter "
|
|
|
|
UNO_JAVA_JFW_ENV_JREHOME" or " UNO_JAVA_JFW_JREHOME
|
|
|
|
" must be set in direct mode.");
|
2004-11-09 13:00:36 +00:00
|
|
|
}
|
|
|
|
|
2015-05-27 17:24:02 +02:00
|
|
|
SAL_INFO_IF(
|
|
|
|
bJRE, "jfw.level2",
|
|
|
|
"Using bootstrap parameter " UNO_JAVA_JFW_JREHOME " = " << sJRE);
|
2004-11-09 13:00:36 +00:00
|
|
|
return sJRE;
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString BootParams::getClasspathUrls()
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sParams;
|
2021-11-15 21:44:42 +02:00
|
|
|
Bootstrap()->getFrom( UNO_JAVA_JFW_CLASSPATH_URLS, sParams);
|
2015-05-27 17:24:02 +02:00
|
|
|
SAL_INFO(
|
|
|
|
"jfw.level2",
|
|
|
|
"Using bootstrap parameter " UNO_JAVA_JFW_CLASSPATH_URLS " = "
|
|
|
|
<< sParams);
|
2004-11-09 13:00:36 +00:00
|
|
|
return sParams;
|
|
|
|
}
|
|
|
|
|
|
|
|
JFW_MODE getMode()
|
|
|
|
{
|
|
|
|
static bool g_bMode = false;
|
|
|
|
static JFW_MODE g_mode = JFW_MODE_APPLICATION;
|
|
|
|
|
2015-04-27 15:28:09 +02:00
|
|
|
if (!g_bMode)
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
|
|
|
//check if either of the "direct mode" bootstrap variables is set
|
|
|
|
bool bDirectMode = true;
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sValue;
|
2021-11-15 21:44:42 +02:00
|
|
|
const rtl::Bootstrap * aBoot = Bootstrap();
|
2015-11-06 09:23:33 +02:00
|
|
|
if (!aBoot->getFrom(UNO_JAVA_JFW_JREHOME, sValue))
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
2015-11-06 09:23:33 +02:00
|
|
|
if (!aBoot->getFrom(UNO_JAVA_JFW_ENV_JREHOME, sValue))
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
2015-11-06 09:23:33 +02:00
|
|
|
if (!aBoot->getFrom(UNO_JAVA_JFW_CLASSPATH, sValue))
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
2015-11-06 09:23:33 +02:00
|
|
|
if (!aBoot->getFrom(UNO_JAVA_JFW_ENV_CLASSPATH, sValue))
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
2014-12-16 17:29:29 +01:00
|
|
|
OUString sParams = UNO_JAVA_JFW_PARAMETER +
|
2013-08-21 15:07:31 +02:00
|
|
|
OUString::number(1);
|
2014-01-27 10:44:30 +01:00
|
|
|
if (!aBoot->getFrom(sParams, sValue))
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
2004-12-16 10:47:49 +00:00
|
|
|
bDirectMode = false;
|
2004-11-09 13:00:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bDirectMode)
|
|
|
|
g_mode = JFW_MODE_DIRECT;
|
|
|
|
else
|
|
|
|
g_mode = JFW_MODE_APPLICATION;
|
|
|
|
g_bMode = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_mode;
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString getApplicationClassPath()
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
2017-05-07 17:03:35 +10:00
|
|
|
OSL_ASSERT(getMode() == JFW_MODE_APPLICATION);
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sParams = BootParams::getClasspathUrls();
|
2012-01-04 11:38:41 -02:00
|
|
|
if (sParams.isEmpty())
|
2017-07-13 11:45:53 +02:00
|
|
|
return OUString();
|
2004-11-09 13:00:36 +00:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUStringBuffer buf;
|
2004-11-09 13:00:36 +00:00
|
|
|
sal_Int32 index = 0;
|
|
|
|
do
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString token( sParams.getToken( 0, ' ', index ).trim() );
|
2012-01-04 11:38:41 -02:00
|
|
|
if (!token.isEmpty())
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString systemPathElement;
|
2004-11-09 13:00:36 +00:00
|
|
|
oslFileError rc = osl_getSystemPathFromFileURL(
|
|
|
|
token.pData, &systemPathElement.pData );
|
2017-05-07 17:03:35 +10:00
|
|
|
OSL_ASSERT( rc == osl_File_E_None );
|
2012-01-04 11:38:41 -02:00
|
|
|
if (rc == osl_File_E_None && !systemPathElement.isEmpty())
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
|
|
|
if (buf.getLength() > 0)
|
2020-08-31 17:02:49 +02:00
|
|
|
buf.append( SAL_PATHSEPARATOR );
|
2004-11-09 13:00:36 +00:00
|
|
|
buf.append( systemPathElement );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (index >= 0);
|
|
|
|
return buf.makeStringAndClear();
|
|
|
|
}
|
|
|
|
|
2021-01-28 20:29:16 +02:00
|
|
|
OString makeClassPathOption(std::u16string_view sUserClassPath)
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
|
|
|
//Compose the class path
|
2013-04-07 12:06:47 +02:00
|
|
|
OString sPaths;
|
|
|
|
OUStringBuffer sBufCP(4096);
|
2004-11-09 13:00:36 +00:00
|
|
|
|
2007-06-13 06:57:54 +00:00
|
|
|
// append all user selected jars to the class path
|
2021-01-28 20:29:16 +02:00
|
|
|
if (!sUserClassPath.empty())
|
2007-06-13 06:57:54 +00:00
|
|
|
sBufCP.append(sUserClassPath);
|
|
|
|
|
|
|
|
//append all jar libraries and components to the class path
|
|
|
|
OUString sAppCP = getApplicationClassPath();
|
2012-01-04 11:38:41 -02:00
|
|
|
if (!sAppCP.isEmpty())
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
2021-01-28 20:29:16 +02:00
|
|
|
if (!sUserClassPath.empty())
|
2013-02-12 21:24:03 +01:00
|
|
|
{
|
2017-07-30 12:16:31 +02:00
|
|
|
sBufCP.append(SAL_PATHSEPARATOR);
|
2013-02-12 21:24:03 +01:00
|
|
|
}
|
2007-06-13 06:57:54 +00:00
|
|
|
sBufCP.append(sAppCP);
|
2004-11-09 13:00:36 +00:00
|
|
|
}
|
|
|
|
|
2020-12-28 19:27:38 +03:00
|
|
|
sPaths = OUStringToOString(sBufCP.makeStringAndClear(), PathEncoding());
|
2022-02-21 11:55:21 +01:00
|
|
|
if (sPaths.isEmpty()) {
|
|
|
|
return "";
|
|
|
|
}
|
2007-06-13 06:57:54 +00:00
|
|
|
|
2019-09-30 15:10:42 +02:00
|
|
|
OString sOptionClassPath = "-Djava.class.path=" + sPaths;
|
2004-11-09 13:00:36 +00:00
|
|
|
return sOptionClassPath;
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OString getUserSettingsPath()
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
2007-06-13 06:57:54 +00:00
|
|
|
return getSettingsPath(BootParams::getUserData());
|
2004-11-09 13:00:36 +00:00
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OString getSharedSettingsPath()
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
2007-06-13 06:57:54 +00:00
|
|
|
return getSettingsPath(BootParams::getSharedData());
|
|
|
|
}
|
2004-11-09 13:00:36 +00:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OString getSettingsPath( const OUString & sURL)
|
2004-11-09 13:00:36 +00:00
|
|
|
{
|
2012-01-04 11:38:41 -02:00
|
|
|
if (sURL.isEmpty())
|
2013-04-07 12:06:47 +02:00
|
|
|
return OString();
|
|
|
|
OUString sPath;
|
2004-11-09 13:00:36 +00:00
|
|
|
if (osl_getSystemPathFromFileURL(sURL.pData,
|
2007-06-13 06:57:54 +00:00
|
|
|
& sPath.pData) != osl_File_E_None)
|
2004-11-09 13:00:36 +00:00
|
|
|
throw FrameworkException(
|
2017-05-29 09:48:54 +02:00
|
|
|
JFW_E_ERROR,
|
|
|
|
"[Java framework] Error in function ::getSettingsPath (fwkbase.cxx).");
|
2020-12-28 19:27:38 +03:00
|
|
|
return OUStringToOString(sPath, PathEncoding());
|
2004-11-09 13:00:36 +00:00
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OString getVendorSettingsPath()
|
2005-06-17 09:12:18 +00:00
|
|
|
{
|
|
|
|
return getVendorSettingsPath(BootParams::getVendorSettings());
|
|
|
|
}
|
2004-11-09 13:00:36 +00:00
|
|
|
|
|
|
|
void setJavaSelected()
|
|
|
|
{
|
|
|
|
g_bJavaSet = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wasJavaSelectedInSameProcess()
|
|
|
|
{
|
|
|
|
//g_setJavaProcId not set means no Java selected
|
2017-04-24 09:23:15 +02:00
|
|
|
return g_bJavaSet;
|
2004-11-09 13:00:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2010-10-14 08:30:07 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|