26#include <rtl/bootstrap.hxx>
28#include <rtl/ustring.hxx>
29#include <osl/diagnose.h>
30#include <osl/file.hxx>
32#include <osl/process.h>
34#include <osl/thread.hxx>
42#include <elements.hxx>
47bool g_bEnabledSwitchedOn =
false;
49JavaVM * g_pJavaVM =
nullptr;
61 assert(pparInfo !=
nullptr);
67 std::vector<std::unique_ptr<JavaInfo>> vecInfo;
70 std::vector<std::unique_ptr<JavaInfo>> arInfos;
71 std::vector<rtl::Reference<jfw_plugin::VendorBase>> infos;
81 for (
auto & j: arInfos)
82 vecInfo.push_back(std::move(j));
91 const std::vector<OUString> vecJRELocations =
96 for (
auto const & ii: vecJRELocations)
98 std::unique_ptr<JavaInfo> aInfo;
114 vecInfo.begin(), vecInfo.end(),
115 [&aInfo](std::unique_ptr<JavaInfo>
const & info) {
116 return areEqualJavaInfo(
117 info.get(), aInfo.get());
120 vecInfo.push_back(std::move(aInfo));
125 *pparInfo = std::move(vecInfo);
138 std::vector<OUString>
result;
143 OUString sToken(sUserPath.subView(nIdx, nextColon > 0 ? nextColon - nIdx
144 : sUserPath.getLength() - nIdx));
148 if (sToken.startsWith(
"$"))
151 sal_Int32 nBootstrapVarStart = sToken.indexOf(
"${");
152 if (nBootstrapVarStart >= 0)
154 sal_Int32 nBootstrapVarEnd = sToken.indexOf(
"}", nBootstrapVarStart);
155 if (nBootstrapVarEnd == -1)
159 sToken = sUserPath.subView(nIdx, nextColon > 0 ? nextColon - nIdx
160 : sUserPath.getLength() - nIdx);
164 result.emplace_back(sToken);
165 nIdx = nextColon + 1;
171 JavaInfo const * pInfo, std::vector<OUString>
const & arOptions,
172 JavaVM ** ppVM, JNIEnv ** ppEnv)
174 assert(ppVM !=
nullptr);
183 if (g_pJavaVM !=
nullptr)
186 std::vector<OString> vmParams;
187 OString sUserClassPath;
188 std::unique_ptr<JavaInfo> aInfo;
189 if (pInfo ==
nullptr)
212 if (g_bEnabledSwitchedOn &&
226 OUString sUserPathExpanded;
227 for (
auto& path : paths)
229 if (!sUserPathExpanded.isEmpty())
231 if (path.startsWith(
"$"))
233 OUString sURL = path;
234 rtl::Bootstrap::expandMacros(sURL);
235 osl::FileBase::getSystemPathFromFileURL(sURL, path);
237 sUserPathExpanded += path;
253 "-Djava.class.path=" + cp;
260 assert(pInfo !=
nullptr);
268 osl_getEnvironment(OUString(
"PATH").
pData, &sPATH.pData);
269 OUString sJRELocation;
270 osl::FileBase::getSystemPathFromFileURL(pInfo->
sLocation +
"/bin", sJRELocation);
272 sPATH = sJRELocation;
275 osl_setEnvironment(OUString(
"PATH").
pData, sPATH.pData);
281 std::unique_ptr<JavaVMOption[]> sarJOptions(
283 arOptions.size() + (sUserClassPath.isEmpty() ? 2 : 3) + vmParams.size()]);
284 JavaVMOption * arOpt = sarJOptions.get();
290 if (!sUserClassPath.isEmpty()) {
291 arOpt[
index].optionString=
const_cast<char*
>(sUserClassPath.getStr());
292 arOpt[
index].extraInfo =
nullptr;
298 arOpt[
index].optionString =
const_cast<char *
>(
"-Dorg.openoffice.native=");
299 arOpt[
index].extraInfo =
nullptr;
303 arOpt[
index].optionString =
const_cast<char *
>(
"-Xrs");
304 arOpt[
index].extraInfo =
nullptr;
308 for (
auto const & vmParam : vmParams)
310 arOpt[
index].optionString =
const_cast<char*
>(vmParam.getStr());
311 arOpt[
index].extraInfo =
nullptr;
315 std::vector<OString> convertedOptions;
316 for (
auto const & ii: arOptions)
319 convertedOptions.push_back(conv);
322 arOpt[
index].optionString =
const_cast<char *
>(conv.getStr());
323 arOpt[
index].extraInfo =
nullptr;
328 JavaVM *pVm =
nullptr;
368 std::unique_ptr<JavaInfo> aCurrentInfo;
372 bool bInfoFound =
false;
377 std::vector<rtl::Reference<jfw_plugin::VendorBase>> infos;
382 aVendorSettings, &aCurrentInfo, infos)
392 std::vector<std::unique_ptr<JavaInfo>> vecJavaInfosFromPath;
394 aVendorSettings, vecJavaInfosFromPath, infos)
397 assert(!vecJavaInfosFromPath.empty());
398 aCurrentInfo = std::move(vecJavaInfosFromPath[0]);
410 std::vector<std::unique_ptr<JavaInfo>> arInfos;
419 aCurrentInfo = std::move(arInfos[0]);
428 const std::vector<OUString> & vecJRELocations =
431 for (
auto const & JRELocation : vecJRELocations)
433 std::unique_ptr<JavaInfo> aInfo;
447 aCurrentInfo = std::move(aInfo);
463 *pInfo = std::move(aCurrentInfo);
482 if (pInfoA == pInfoB)
484 if (pInfoA ==
nullptr || pInfoB ==
nullptr)
499 assert(ppInfo !=
nullptr);
512 "[Java framework] The JRE specified by the bootstrap "
513 "variable UNO_JAVA_JFW_JREHOME or UNO_JAVA_JFW_ENV_JREHOME "
514 " could not be recognized. Check the values and make sure that you "
515 "use a plug-in library that can recognize that JRE.");
548 return g_pJavaVM !=
nullptr;
553 assert(ppInfo !=
nullptr);
597 std::unique_ptr<JavaInfo> currentInfo;
627 if (!g_bEnabledSwitchedOn && bEnabled)
637 g_bEnabledSwitchedOn =
true;
653 assert(pbEnabled !=
nullptr);
735 assert(ppCP !=
nullptr);
javaFrameworkError errorCode
merges the settings for shared, user and installation during construction.
const ::std::vector< OUString > & getJRELocations() const
bool getEnabled() const
the default is true.
::std::vector< OString > getVmParametersUtf8() const
const OUString & getUserClassPath() const
std::unique_ptr< JavaInfo > createJavaInfo() const
returns a JavaInfo structure representing the node /java/javaInfo.
OString const & getJavaInfoAttrVendorUpdate() const
returns the value of the attribute /java/javaInfo[@vendorUpdate].
void getVmParametersArray(std::vector< OUString > *parParameters) const
this class represents the java settings based on a particular settings file.
void setUserClassPath(const OUString &sClassPath)
sets m_sUserClassPath.
void load()
load the values of the settings file.
void addJRELocation(OUString const &sLocation)
adds a location to the already existing locations.
void setEnabled(bool bEnabled)
sets m_enabled.
void write() const
writes the data to user settings.
void setJavaInfo(const JavaInfo *pInfo, bool bAutoSelect)
sets m_aInfo.
void setVmParameters(std::vector< OUString > const &arParameters)
sets the /java/vmParameters/param elements.
#define SAL_PATHSEPARATOR
javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr< JavaInfo > *pInfo)
We do not use here jfw_findAllJREs and then check if a JavaInfo meets the requirements,...
javaFrameworkError jfw_setSelectedJRE(JavaInfo const *pInfo)
determines the JRE that is to be used.
javaFrameworkError jfw_getJavaInfoByPath(OUString const &pPath, std::unique_ptr< JavaInfo > *ppInfo)
determines if a path points to a Java installation.
void jfw_lock()
locks this API so that it cannot be used by other threads.
javaFrameworkError jfw_setVMParameters(std::vector< OUString > const &arOptions)
determines parameters which are passed to VM during its creation.
javaFrameworkError jfw_addJRELocation(OUString const &sLocation)
saves the location of a JRE.
javaFrameworkError jfw_setUserClassPath(OUString const &pCp)
sets the user class path.
javaFrameworkError jfw_getSelectedJRE(std::unique_ptr< JavaInfo > *ppInfo)
provides information about the JRE that is to be used.
javaFrameworkError jfw_getVMParameters(std::vector< OUString > *parOptions)
obtains the currently used start parameters.
void jfw_unlock()
unlocks this API.
bool jfw_areEqualJavaInfo(JavaInfo const *pInfoA, JavaInfo const *pInfoB)
compares two JavaInfo objects for equality.
javaFrameworkError jfw_getUserClassPath(OUString *ppCP)
provides the value of the current user class path.
javaFrameworkError jfw_startVM(JavaInfo const *pInfo, std::vector< OUString > const &arOptions, JavaVM **ppVM, JNIEnv **ppEnv)
starts a Java Virtual Machine (JVM).
bool jfw_isVMRunning()
determines if a Java Virtual Machine is already running.
javaFrameworkError jfw_setEnabled(bool bEnabled)
determines if Java can be used.
javaFrameworkError jfw_findAllJREs(std::vector< std::unique_ptr< JavaInfo > > *pparInfo)
provides information about all available JRE installations.
javaFrameworkError jfw_getEnabled(bool *pbEnabled)
provides the information if Java can be used.
javaFrameworkError jfw_existJRE(const JavaInfo *pInfo, bool *exist)
checks if the installation of the jre still exists.
std::vector< OUString > jfw_convertUserPathList(OUString const &sUserPath)
Convert colon-separated userClassPath which might contain bootstrap variables (which also might conta...
#define JFW_REQUIRE_NEEDRESTART
indicates that there must be an environment set up before the Java process runs.
javaFrameworkError
error codes which are returned by functions of this API.
@ JFW_E_VM_CREATION_FAILED
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
std::unique_ptr< sal_Int32[]> pData
::std::vector< OString > getVMParameters()
OString getElementUpdated()
gets the value of the updated element from the javavendors.xml.
void setJavaSelected()
Called from writeJavaInfoData.
bool wasJavaSelectedInSameProcess()
Determines if the currently selected Java was set in this process.
OString makeClassPathOption(std::u16string_view sUserClassPath)
creates the -Djava.class.path option with the complete classpath, including the paths which are set b...
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
an instance of this struct represents an installation of a Java Runtime Environment (JRE).
OUString sVersion
contains the version of this Java distribution.
sal_uInt64 nRequirements
indicates requirements for running the java runtime.
OUString sLocation
contains the file URL to the installation directory.
OUString sVendor
contains the vendor.
rtl::ByteSequence arVendorData
contains data needed for the creation of the java runtime.
javaPluginError jfw_plugin_getJavaInfoFromJavaHome(jfw::VendorSettings const &vendorSettings, std::unique_ptr< JavaInfo > *ppInfo, std::vector< rtl::Reference< jfw_plugin::VendorBase > > &infos)
obtains information for a JRE referenced by the JAVA_HOME environment variable.
javaPluginError jfw_plugin_getJavaInfoByPath(OUString const &sLocation, jfw::VendorSettings const &vendorSettings, std::unique_ptr< JavaInfo > *ppInfo)
obtains information for a JRE at a given location.
javaPluginError jfw_plugin_getAllJavaInfos(bool checkJavaHomeAndPath, jfw::VendorSettings const &vendorSettings, std::vector< std::unique_ptr< JavaInfo > > *parJavaInfo, std::vector< rtl::Reference< jfw_plugin::VendorBase > > &infos)
obtains information about installations of Java Runtime Environments (JREs).
javaPluginError jfw_plugin_startJavaVirtualMachine(const JavaInfo *pInfo, const JavaVMOption *arOptions, sal_Int32 nSizeOptions, JavaVM **ppVM, JNIEnv **ppEnv)
starts a Java Virtual Machine.
javaPluginError jfw_plugin_existJRE(const JavaInfo *pInfo, bool *exist)
checks if the installation of the jre still exists.
javaPluginError jfw_plugin_getJavaInfosFromPath(jfw::VendorSettings const &vendorSettings, std::vector< std::unique_ptr< JavaInfo > > &vecJavaInfosFromPath, std::vector< rtl::Reference< jfw_plugin::VendorBase > > &infos)
obtains information about installations of Java Runtime Environments (JREs) whose executable is in th...