Bump version to 24.04.3.4
[LibreOffice.git] / jvmfwk / source / framework.cxx
blob0e74420e398fbfa000cc190f62575f28cd2b4680
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
21 #include <sal/log.hxx>
23 #include <cassert>
24 #include <memory>
26 #include <rtl/bootstrap.hxx>
27 #include <rtl/ref.hxx>
28 #include <rtl/ustring.hxx>
29 #include <osl/diagnose.h>
30 #include <osl/file.hxx>
31 #ifdef _WIN32
32 #include <osl/process.h>
33 #endif
34 #include <osl/thread.hxx>
35 #include <jvmfwk/framework.hxx>
36 #include <vendorbase.hxx>
37 #include <vendorplugin.hxx>
38 #include <vector>
39 #include <algorithm>
40 #include "framework.hxx"
41 #include <fwkutil.hxx>
42 #include <elements.hxx>
43 #include <fwkbase.hxx>
45 namespace {
47 bool g_bEnabledSwitchedOn = false;
49 JavaVM * g_pJavaVM = nullptr;
51 bool areEqualJavaInfo(
52 JavaInfo const * pInfoA,JavaInfo const * pInfoB)
54 return jfw_areEqualJavaInfo(pInfoA, pInfoB);
59 javaFrameworkError jfw_findAllJREs(std::vector<std::unique_ptr<JavaInfo>> *pparInfo)
61 assert(pparInfo != nullptr);
62 try
64 osl::MutexGuard guard(jfw::FwkMutex());
66 jfw::VendorSettings aVendorSettings;
67 std::vector<std::unique_ptr<JavaInfo>> vecInfo;
69 //Use all plug-in libraries to get Java installations.
70 std::vector<std::unique_ptr<JavaInfo>> arInfos;
71 std::vector<rtl::Reference<jfw_plugin::VendorBase>> infos;
72 javaPluginError plerr = jfw_plugin_getAllJavaInfos(
73 true,
74 aVendorSettings,
75 & arInfos,
76 infos);
78 if (plerr != javaPluginError::NONE)
79 return JFW_E_ERROR;
81 for (auto & j: arInfos)
82 vecInfo.push_back(std::move(j));
84 // direct mode disregards Java settings, so only retrieve
85 // JREs from settings when application mode is used
86 if (jfw::getMode() == jfw::JFW_MODE_APPLICATION)
88 //get the list of paths to jre locations which have been
89 //added manually
90 const jfw::MergedSettings settings;
91 const std::vector<OUString> vecJRELocations =
92 settings.getJRELocations();
93 //Check if any plugin can detect JREs at the location
94 // of the paths added by jfw_addJRELocation
95 //Check every manually added location
96 for (auto const & ii: vecJRELocations)
98 std::unique_ptr<JavaInfo> aInfo;
99 plerr = jfw_plugin_getJavaInfoByPath(
101 aVendorSettings,
102 &aInfo);
103 if (plerr == javaPluginError::NoJre)
104 continue;
105 if (plerr == javaPluginError::FailedVersion)
106 continue;
107 if (plerr == javaPluginError::WrongArch)
108 continue;
109 else if (plerr != javaPluginError::NONE)
110 return JFW_E_ERROR;
112 // Was this JRE already added?
113 if (std::none_of(
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);
127 return JFW_E_NONE;
129 catch (const jfw::FrameworkException& e)
131 SAL_WARN( "jfw", e.message);
132 return e.errorCode;
136 std::vector<OUString> jfw_convertUserPathList(OUString const& sUserPath)
138 std::vector<OUString> result;
139 sal_Int32 nIdx = 0;
142 sal_Int32 nextColon = sUserPath.indexOf(SAL_PATHSEPARATOR, nIdx);
143 OUString sToken(sUserPath.subView(nIdx, nextColon > 0 ? nextColon - nIdx
144 : sUserPath.getLength() - nIdx));
146 // Check if we are in bootstrap variable mode (class path starts with '$').
147 // Then the class path must be in URL format.
148 if (sToken.startsWith("$"))
150 // Detect open bootstrap variables - they might contain colons - we need to skip those.
151 sal_Int32 nBootstrapVarStart = sToken.indexOf("${");
152 if (nBootstrapVarStart >= 0)
154 sal_Int32 nBootstrapVarEnd = sToken.indexOf("}", nBootstrapVarStart);
155 if (nBootstrapVarEnd == -1)
157 // Current colon is part of bootstrap variable - skip it!
158 nextColon = sUserPath.indexOf(SAL_PATHSEPARATOR, nextColon + 1);
159 sToken = sUserPath.subView(nIdx, nextColon > 0 ? nextColon - nIdx
160 : sUserPath.getLength() - nIdx);
164 result.emplace_back(sToken);
165 nIdx = nextColon + 1;
166 } while (nIdx > 0);
167 return result;
170 javaFrameworkError jfw_startVM(
171 JavaInfo const * pInfo, std::vector<OUString> const & arOptions,
172 JavaVM ** ppVM, JNIEnv ** ppEnv)
174 assert(ppVM != nullptr);
175 javaFrameworkError errcode = JFW_E_NONE;
179 osl::MutexGuard guard(jfw::FwkMutex());
181 //We keep this pointer so we can determine if a VM has already
182 //been created.
183 if (g_pJavaVM != nullptr)
184 return JFW_E_RUNNING_JVM;
186 std::vector<OString> vmParams;
187 OString sUserClassPath;
188 std::unique_ptr<JavaInfo> aInfo;
189 if (pInfo == nullptr)
191 jfw::JFW_MODE mode = jfw::getMode();
192 if (mode == jfw::JFW_MODE_APPLICATION)
194 const jfw::MergedSettings settings;
195 if (!settings.getEnabled())
196 return JFW_E_JAVA_DISABLED;
197 aInfo = settings.createJavaInfo();
198 //check if a Java has ever been selected
199 if (!aInfo)
200 return JFW_E_NO_SELECT;
202 //check if the javavendors.xml has changed after a Java was selected
203 OString sVendorUpdate = jfw::getElementUpdated();
205 if (sVendorUpdate != settings.getJavaInfoAttrVendorUpdate())
206 return JFW_E_INVALID_SETTINGS;
208 //check if JAVA is disabled
209 //If Java is enabled, but it was disabled when this process was started
210 // then no preparational work, such as setting the LD_LIBRARY_PATH, was
211 //done. Therefore if a JRE needs it, it must not be started.
212 if (g_bEnabledSwitchedOn &&
213 (aInfo->nRequirements & JFW_REQUIRE_NEEDRESTART))
214 return JFW_E_NEED_RESTART;
216 //Check if the selected Java was set in this process. If so it
217 //must not have the requirements flag JFW_REQUIRE_NEEDRESTART
218 if ((aInfo->nRequirements & JFW_REQUIRE_NEEDRESTART)
219 && jfw::wasJavaSelectedInSameProcess())
220 return JFW_E_NEED_RESTART;
222 vmParams = settings.getVmParametersUtf8();
223 // Expand user classpath (might contain bootstrap vars)
224 OUString sUserPath(settings.getUserClassPath());
225 std::vector paths = jfw_convertUserPathList(sUserPath);
226 OUString sUserPathExpanded;
227 for (auto& path : paths)
229 if (!sUserPathExpanded.isEmpty())
230 sUserPathExpanded += OUStringChar(SAL_PATHSEPARATOR);
231 if (path.startsWith("$"))
233 OUString sURL = path;
234 rtl::Bootstrap::expandMacros(sURL);
235 osl::FileBase::getSystemPathFromFileURL(sURL, path);
237 sUserPathExpanded += path;
239 sUserClassPath = jfw::makeClassPathOption(sUserPathExpanded);
240 } // end mode FWK_MODE_OFFICE
241 else if (mode == jfw::JFW_MODE_DIRECT)
243 errcode = jfw_getSelectedJRE(&aInfo);
244 if (errcode != JFW_E_NONE)
245 return errcode;
246 //In direct mode the options are specified by bootstrap variables
247 //of the form UNO_JAVA_JFW_PARAMETER_1 .. UNO_JAVA_JFW_PARAMETER_n
248 vmParams = jfw::BootParams::getVMParameters();
249 auto const cp = jfw::BootParams::getClasspath();
250 if (!cp.isEmpty())
252 sUserClassPath =
253 "-Djava.class.path=" + cp;
256 else
257 OSL_ASSERT(false);
258 pInfo = aInfo.get();
260 assert(pInfo != nullptr);
262 #ifdef _WIN32
263 // Alternative JREs (AdoptOpenJDK, Azul Zulu) are missing the bin/ folder in
264 // java.library.path. Somehow setting java.library.path accordingly doesn't work,
265 // but the PATH gets picked up, so add it there.
266 // Without this hack, some features don't work in alternative JREs.
267 OUString sPATH;
268 osl_getEnvironment(OUString("PATH").pData, &sPATH.pData);
269 OUString sJRELocation;
270 osl::FileBase::getSystemPathFromFileURL(pInfo->sLocation + "/bin", sJRELocation);
271 if (sPATH.isEmpty())
272 sPATH = sJRELocation;
273 else
274 sPATH = sJRELocation + OUStringChar(SAL_PATHSEPARATOR) + sPATH;
275 osl_setEnvironment(OUString("PATH").pData, sPATH.pData);
276 #endif // _WIN32
278 // create JavaVMOptions array that is passed to the plugin
279 // it contains the classpath and all options set in the
280 //options dialog
281 std::unique_ptr<JavaVMOption[]> sarJOptions(
282 new JavaVMOption[
283 arOptions.size() + (sUserClassPath.isEmpty() ? 2 : 3) + vmParams.size()]);
284 JavaVMOption * arOpt = sarJOptions.get();
285 if (! arOpt)
286 return JFW_E_ERROR;
288 //The first argument is the classpath
289 int index = 0;
290 if (!sUserClassPath.isEmpty()) {
291 arOpt[index].optionString= const_cast<char*>(sUserClassPath.getStr());
292 arOpt[index].extraInfo = nullptr;
293 ++index;
295 // Set a flag that this JVM has been created via the JNI Invocation API
296 // (used, for example, by UNO remote bridges to share a common thread pool
297 // factory among Java and native bridge implementations):
298 arOpt[index].optionString = const_cast<char *>("-Dorg.openoffice.native=");
299 arOpt[index].extraInfo = nullptr;
300 ++index;
302 // Don't intercept SIGTERM
303 arOpt[index].optionString = const_cast<char *>("-Xrs");
304 arOpt[index].extraInfo = nullptr;
305 ++index;
307 //add the options set by options dialog
308 for (auto const & vmParam : vmParams)
310 arOpt[index].optionString = const_cast<char*>(vmParam.getStr());
311 arOpt[index].extraInfo = nullptr;
312 index ++;
314 //add all options of the arOptions argument
315 std::vector<OString> convertedOptions;
316 for (auto const & ii: arOptions)
318 OString conv = OUStringToOString(ii, osl_getThreadTextEncoding());
319 convertedOptions.push_back(conv);
320 // keep conv.getStr() alive until after the call to
321 // jfw_plugin_startJavaVirtualMachine below
322 arOpt[index].optionString = const_cast<char *>(conv.getStr());
323 arOpt[index].extraInfo = nullptr;
324 index++;
327 //start Java
328 JavaVM *pVm = nullptr;
329 SAL_INFO("jfw", "Starting Java");
330 javaPluginError plerr = jfw_plugin_startJavaVirtualMachine(pInfo, arOpt, index, & pVm, ppEnv);
331 if (plerr == javaPluginError::VmCreationFailed)
333 errcode = JFW_E_VM_CREATION_FAILED;
335 else if (plerr != javaPluginError::NONE )
337 errcode = JFW_E_ERROR;
339 else
341 g_pJavaVM = pVm;
342 *ppVM = pVm;
345 catch (const jfw::FrameworkException& e)
347 errcode = e.errorCode;
348 SAL_WARN( "jfw", e.message);
351 return errcode;
354 /** We do not use here jfw_findAllJREs and then check if a JavaInfo
355 meets the requirements, because that means using all plug-ins, which
356 may take quite a while. The implementation first inspects JAVA_HOME and
357 PATH environment variables. If no suitable JavaInfo is found there, it
358 inspects all JavaInfos found by the jfw_plugin_get* functions.
360 javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo)
362 javaFrameworkError errcode = JFW_E_NONE;
365 osl::MutexGuard guard(jfw::FwkMutex());
366 if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
367 return JFW_E_DIRECT_MODE;
368 std::unique_ptr<JavaInfo> aCurrentInfo;
371 // 'bInfoFound' indicates whether a Java installation has been found
372 bool bInfoFound = false;
374 // get list of vendors for Java installations
375 jfw::VendorSettings aVendorSettings;
377 std::vector<rtl::Reference<jfw_plugin::VendorBase>> infos;
379 // first inspect Java installation that the JAVA_HOME
380 // environment variable points to (if it is set)
381 if (jfw_plugin_getJavaInfoFromJavaHome(
382 aVendorSettings, &aCurrentInfo, infos)
383 == javaPluginError::NONE)
385 bInfoFound = true;
388 // if no Java installation was detected by using JAVA_HOME,
389 // query PATH for Java installations
390 if (!bInfoFound)
392 std::vector<std::unique_ptr<JavaInfo>> vecJavaInfosFromPath;
393 if (jfw_plugin_getJavaInfosFromPath(
394 aVendorSettings, vecJavaInfosFromPath, infos)
395 == javaPluginError::NONE)
397 assert(!vecJavaInfosFromPath.empty());
398 aCurrentInfo = std::move(vecJavaInfosFromPath[0]);
399 bInfoFound = true;
404 // if no suitable Java installation has been found yet:
405 // first use jfw_plugin_getAllJavaInfos to find a suitable Java installation,
406 // then try paths that have been added manually
407 if (!bInfoFound)
409 //get all installations
410 std::vector<std::unique_ptr<JavaInfo>> arInfos;
411 javaPluginError plerr = jfw_plugin_getAllJavaInfos(
412 false,
413 aVendorSettings,
414 & arInfos,
415 infos);
417 if (plerr == javaPluginError::NONE && !arInfos.empty())
419 aCurrentInfo = std::move(arInfos[0]);
422 if (!aCurrentInfo)
423 {//The plug-ins did not find a suitable Java. Now try the paths which have been
424 //added manually.
425 //get the list of paths to jre locations which have been added manually
426 const jfw::MergedSettings settings;
427 //node.loadFromSettings();
428 const std::vector<OUString> & vecJRELocations =
429 settings.getJRELocations();
430 //use all plug-ins to determine the JavaInfo objects
431 for (auto const & JRELocation : vecJRELocations)
433 std::unique_ptr<JavaInfo> aInfo;
434 javaPluginError err = jfw_plugin_getJavaInfoByPath(
435 JRELocation,
436 aVendorSettings,
437 &aInfo);
438 if (err == javaPluginError::NoJre)
439 continue;
440 if (err == javaPluginError::FailedVersion)
441 continue;
442 else if (err !=javaPluginError::NONE)
443 return JFW_E_ERROR;
445 if (aInfo)
447 aCurrentInfo = std::move(aInfo);
448 break;
450 }//end iterate over paths
453 if (aCurrentInfo)
455 jfw::NodeJava javaNode(jfw::NodeJava::USER);
456 javaNode.setJavaInfo(aCurrentInfo.get(),true);
457 javaNode.write();
458 //remember that this JRE was selected in this process
459 jfw::setJavaSelected();
461 if (pInfo !=nullptr)
463 *pInfo = std::move(aCurrentInfo);
466 else
468 errcode = JFW_E_NO_JAVA_FOUND;
471 catch (const jfw::FrameworkException& e)
473 errcode = e.errorCode;
474 SAL_WARN( "jfw", e.message );
477 return errcode;
480 bool jfw_areEqualJavaInfo(JavaInfo const * pInfoA,JavaInfo const * pInfoB)
482 if (pInfoA == pInfoB)
483 return true;
484 if (pInfoA == nullptr || pInfoB == nullptr)
485 return false;
486 if (pInfoA->sVendor == pInfoB->sVendor
487 && pInfoA->sLocation == pInfoB->sLocation
488 && pInfoA->sVersion == pInfoB->sVersion
489 && pInfoA->nRequirements == pInfoB->nRequirements
490 && pInfoA->arVendorData == pInfoB->arVendorData)
492 return true;
494 return false;
497 javaFrameworkError jfw_getSelectedJRE(std::unique_ptr<JavaInfo> *ppInfo)
499 assert(ppInfo != nullptr);
500 javaFrameworkError errcode = JFW_E_NONE;
503 osl::MutexGuard guard(jfw::FwkMutex());
505 if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
507 if ((errcode = jfw_getJavaInfoByPath(
508 jfw::BootParams::getJREHome(), ppInfo))
509 != JFW_E_NONE)
510 throw jfw::FrameworkException(
511 JFW_E_CONFIGURATION,
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."_ostr);
517 return JFW_E_NONE;
520 const jfw::MergedSettings settings;
521 *ppInfo = settings.createJavaInfo();
522 if (!*ppInfo)
524 return JFW_E_NONE;
526 //If the javavendors.xml has changed, then the current selected
527 //Java is not valid anymore
528 // /java/javaInfo/@vendorUpdate != javaSelection/updated (javavendors.xml)
529 OString sUpdated = jfw::getElementUpdated();
531 if (sUpdated != settings.getJavaInfoAttrVendorUpdate())
533 ppInfo->reset();
534 return JFW_E_INVALID_SETTINGS;
537 catch (const jfw::FrameworkException& e)
539 errcode = e.errorCode;
540 SAL_WARN( "jfw", e.message );
542 return errcode;
545 bool jfw_isVMRunning()
547 osl::MutexGuard guard(jfw::FwkMutex());
548 return g_pJavaVM != nullptr;
551 javaFrameworkError jfw_getJavaInfoByPath(OUString const & pPath, std::unique_ptr<JavaInfo> *ppInfo)
553 assert(ppInfo != nullptr);
554 javaFrameworkError errcode = JFW_E_NONE;
557 osl::MutexGuard guard(jfw::FwkMutex());
559 jfw::VendorSettings aVendorSettings;
561 //ask all plugins if this is a JRE.
562 //If so check if it meets the version requirements.
563 //Only if it does return a JavaInfo
564 javaPluginError plerr = jfw_plugin_getJavaInfoByPath(
565 pPath,
566 aVendorSettings,
567 ppInfo);
569 if(plerr == javaPluginError::FailedVersion)
570 {//found JRE but it has the wrong version
571 ppInfo->reset();
572 errcode = JFW_E_FAILED_VERSION;
574 OSL_ASSERT(plerr == javaPluginError::NONE || plerr == javaPluginError::NoJre);
575 if (!*ppInfo && errcode != JFW_E_FAILED_VERSION)
576 errcode = JFW_E_NOT_RECOGNIZED;
578 catch (const jfw::FrameworkException& e)
580 errcode = e.errorCode;
581 SAL_WARN( "jfw", e.message );
584 return errcode;
588 javaFrameworkError jfw_setSelectedJRE(JavaInfo const *pInfo)
590 javaFrameworkError errcode = JFW_E_NONE;
593 osl::MutexGuard guard(jfw::FwkMutex());
594 if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
595 return JFW_E_DIRECT_MODE;
596 //check if pInfo is the selected JRE
597 std::unique_ptr<JavaInfo> currentInfo;
598 errcode = jfw_getSelectedJRE( & currentInfo);
599 if (errcode != JFW_E_NONE && errcode != JFW_E_INVALID_SETTINGS)
600 return errcode;
602 if (!jfw_areEqualJavaInfo(currentInfo.get(), pInfo))
604 jfw::NodeJava node(jfw::NodeJava::USER);
605 node.setJavaInfo(pInfo, false);
606 node.write();
607 //remember that the JRE was selected in this process
608 jfw::setJavaSelected();
611 catch (const jfw::FrameworkException& e)
613 errcode = e.errorCode;
614 SAL_WARN( "jfw", e.message );
616 return errcode;
618 javaFrameworkError jfw_setEnabled(bool bEnabled)
620 javaFrameworkError errcode = JFW_E_NONE;
623 osl::MutexGuard guard(jfw::FwkMutex());
624 if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
625 return JFW_E_DIRECT_MODE;
627 if (!g_bEnabledSwitchedOn && bEnabled)
629 //When the process started then Enabled was false.
630 //This is first time enabled is set to true.
631 //That means, no preparational work has been done, such as setting the
632 //LD_LIBRARY_PATH, etc.
634 //check if Enabled is false;
635 const jfw::MergedSettings settings;
636 if (!settings.getEnabled())
637 g_bEnabledSwitchedOn = true;
639 jfw::NodeJava node(jfw::NodeJava::USER);
640 node.setEnabled(bEnabled);
641 node.write();
643 catch (const jfw::FrameworkException& e)
645 errcode = e.errorCode;
646 SAL_WARN( "jfw", e.message );
648 return errcode;
651 javaFrameworkError jfw_getEnabled(bool *pbEnabled)
653 assert(pbEnabled != nullptr);
654 javaFrameworkError errcode = JFW_E_NONE;
657 if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
658 return JFW_E_DIRECT_MODE;
659 osl::MutexGuard guard(jfw::FwkMutex());
660 jfw::MergedSettings settings;
661 *pbEnabled = settings.getEnabled();
663 catch (const jfw::FrameworkException& e)
665 errcode = e.errorCode;
666 SAL_WARN( "jfw", e.message );
668 return errcode;
672 javaFrameworkError jfw_setVMParameters(std::vector<OUString> const & arOptions)
674 javaFrameworkError errcode = JFW_E_NONE;
677 osl::MutexGuard guard(jfw::FwkMutex());
678 if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
679 return JFW_E_DIRECT_MODE;
680 jfw::NodeJava node(jfw::NodeJava::USER);
681 node.setVmParameters(arOptions);
682 node.write();
684 catch (const jfw::FrameworkException& e)
686 errcode = e.errorCode;
687 SAL_WARN( "jfw", e.message );
690 return errcode;
693 javaFrameworkError jfw_getVMParameters(std::vector<OUString> * parOptions)
695 javaFrameworkError errcode = JFW_E_NONE;
698 osl::MutexGuard guard(jfw::FwkMutex());
699 if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
700 return JFW_E_DIRECT_MODE;
702 const jfw::MergedSettings settings;
703 settings.getVmParametersArray(parOptions);
705 catch (const jfw::FrameworkException& e)
707 errcode = e.errorCode;
708 SAL_WARN( "jfw", e.message );
710 return errcode;
713 javaFrameworkError jfw_setUserClassPath(OUString const & pCp)
715 javaFrameworkError errcode = JFW_E_NONE;
718 osl::MutexGuard guard(jfw::FwkMutex());
719 if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
720 return JFW_E_DIRECT_MODE;
721 jfw::NodeJava node(jfw::NodeJava::USER);
722 node.setUserClassPath(pCp);
723 node.write();
725 catch (const jfw::FrameworkException& e)
727 errcode = e.errorCode;
728 SAL_WARN( "jfw", e.message );
730 return errcode;
733 javaFrameworkError jfw_getUserClassPath(OUString * ppCP)
735 assert(ppCP != nullptr);
736 javaFrameworkError errcode = JFW_E_NONE;
739 osl::MutexGuard guard(jfw::FwkMutex());
740 if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
741 return JFW_E_DIRECT_MODE;
742 const jfw::MergedSettings settings;
743 *ppCP = settings.getUserClassPath();
745 catch (const jfw::FrameworkException& e)
747 errcode = e.errorCode;
748 SAL_WARN( "jfw", e.message );
750 return errcode;
753 javaFrameworkError jfw_addJRELocation(OUString const & sLocation)
755 javaFrameworkError errcode = JFW_E_NONE;
758 osl::MutexGuard guard(jfw::FwkMutex());
759 if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
760 return JFW_E_DIRECT_MODE;
761 jfw::NodeJava node(jfw::NodeJava::USER);
762 node.load();
763 node.addJRELocation(sLocation);
764 node.write();
766 catch (const jfw::FrameworkException& e)
768 errcode = e.errorCode;
769 SAL_WARN( "jfw", e.message );
772 return errcode;
776 javaFrameworkError jfw_existJRE(const JavaInfo *pInfo, bool *exist)
778 javaPluginError plerr = jfw_plugin_existJRE(pInfo, exist);
780 javaFrameworkError ret = JFW_E_NONE;
781 switch (plerr)
783 case javaPluginError::NONE:
784 ret = JFW_E_NONE;
785 break;
786 case javaPluginError::Error:
787 ret = JFW_E_ERROR;
788 break;
789 default:
790 ret = JFW_E_ERROR;
792 return ret;
795 void jfw_lock()
797 jfw::FwkMutex().acquire();
800 void jfw_unlock()
802 jfw::FwkMutex().release();
805 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */