tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / jvmfwk / source / framework.cxx
blob0fe6ed7903c400ea2445b1accd2d8aebbb217349
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 <o3tl/string_view.hxx>
36 #include <jvmfwk/framework.hxx>
37 #include <vendorbase.hxx>
38 #include <vendorplugin.hxx>
39 #include <vector>
40 #include <algorithm>
41 #include "framework.hxx"
42 #include <fwkutil.hxx>
43 #include <elements.hxx>
44 #include <fwkbase.hxx>
46 namespace {
48 bool g_bEnabledSwitchedOn = false;
50 JavaVM * g_pJavaVM = nullptr;
52 bool areEqualJavaInfo(
53 JavaInfo const * pInfoA,JavaInfo const * pInfoB)
55 return jfw_areEqualJavaInfo(pInfoA, pInfoB);
60 javaFrameworkError jfw_findAllJREs(std::vector<std::unique_ptr<JavaInfo>> *pparInfo)
62 assert(pparInfo != nullptr);
63 try
65 osl::MutexGuard guard(jfw::FwkMutex());
67 jfw::VendorSettings aVendorSettings;
68 std::vector<std::unique_ptr<JavaInfo>> vecInfo;
70 //Use all plug-in libraries to get Java installations.
71 std::vector<std::unique_ptr<JavaInfo>> arInfos;
72 std::vector<rtl::Reference<jfw_plugin::VendorBase>> infos;
73 javaPluginError plerr = jfw_plugin_getAllJavaInfos(
74 true,
75 aVendorSettings,
76 & arInfos,
77 infos);
79 if (plerr != javaPluginError::NONE)
80 return JFW_E_ERROR;
82 for (auto & j: arInfos)
83 vecInfo.push_back(std::move(j));
85 // direct mode disregards Java settings, so only retrieve
86 // JREs from settings when application mode is used
87 if (jfw::getMode() == jfw::JFW_MODE_APPLICATION)
89 //get the list of paths to jre locations which have been
90 //added manually
91 const jfw::MergedSettings settings;
92 const std::vector<OUString>& vecJRELocations =
93 settings.getJRELocations();
94 //Check if any plugin can detect JREs at the location
95 // of the paths added by jfw_addJRELocation
96 //Check every manually added location
97 for (auto const & ii: vecJRELocations)
99 std::unique_ptr<JavaInfo> aInfo;
100 plerr = jfw_plugin_getJavaInfoByPath(
102 aVendorSettings,
103 &aInfo);
104 if (plerr == javaPluginError::NoJre)
105 continue;
106 if (plerr == javaPluginError::FailedVersion)
107 continue;
108 if (plerr == javaPluginError::WrongArch)
109 continue;
110 else if (plerr != javaPluginError::NONE)
111 return JFW_E_ERROR;
113 // Was this JRE already added?
114 if (std::none_of(
115 vecInfo.begin(), vecInfo.end(),
116 [&aInfo](std::unique_ptr<JavaInfo> const & info) {
117 return areEqualJavaInfo(
118 info.get(), aInfo.get());
121 vecInfo.push_back(std::move(aInfo));
126 *pparInfo = std::move(vecInfo);
128 return JFW_E_NONE;
130 catch (const jfw::FrameworkException& e)
132 SAL_WARN( "jfw", e.message);
133 return e.errorCode;
137 std::vector<OUString> jfw_convertUserPathList(std::u16string_view sUserPath)
139 std::vector<OUString> result;
140 sal_Int32 nIdx = 0;
143 size_t nextColon = sUserPath.find(SAL_PATHSEPARATOR, nIdx);
144 std::u16string_view sToken;
145 if (nextColon != 0 && nextColon != std::u16string_view::npos)
146 sToken = sUserPath.substr(nIdx, nextColon - nIdx);
147 else
148 sToken = sUserPath.substr(nIdx, sUserPath.size() - nIdx);
150 // Check if we are in bootstrap variable mode (class path starts with '$').
151 // Then the class path must be in URL format.
152 if (o3tl::starts_with(sToken, u"$"))
154 // Detect open bootstrap variables - they might contain colons - we need to skip those.
155 size_t nBootstrapVarStart = sToken.find(u"${");
156 if (nBootstrapVarStart != std::u16string_view::npos)
158 size_t nBootstrapVarEnd = sToken.find(u"}", nBootstrapVarStart);
159 if (nBootstrapVarEnd == std::u16string_view::npos)
161 // Current colon is part of bootstrap variable - skip it!
162 const auto nAfterColon = (nextColon != std::string_view::npos) ? (nextColon + 1) : 0;
163 nextColon = sUserPath.find(SAL_PATHSEPARATOR, nAfterColon);
164 if (nextColon != 0 && nextColon != std::u16string_view::npos)
165 sToken = sUserPath.substr(nIdx, nextColon - nIdx);
166 else
167 sToken = sUserPath.substr(nIdx, sUserPath.size() - nIdx);
171 result.emplace_back(sToken);
172 if (nextColon == std::u16string_view::npos)
173 break;
174 nIdx = nextColon + 1;
175 } while (nIdx > 0);
176 return result;
179 javaFrameworkError jfw_startVM(
180 JavaInfo const * pInfo, std::vector<OUString> const & arOptions,
181 JavaVM ** ppVM, JNIEnv ** ppEnv)
183 assert(ppVM != nullptr);
184 javaFrameworkError errcode = JFW_E_NONE;
188 osl::MutexGuard guard(jfw::FwkMutex());
190 //We keep this pointer so we can determine if a VM has already
191 //been created.
192 if (g_pJavaVM != nullptr)
193 return JFW_E_RUNNING_JVM;
195 std::vector<OString> vmParams;
196 OString sUserClassPath;
197 std::unique_ptr<JavaInfo> aInfo;
198 if (pInfo == nullptr)
200 jfw::JFW_MODE mode = jfw::getMode();
201 if (mode == jfw::JFW_MODE_APPLICATION)
203 const jfw::MergedSettings settings;
204 if (!settings.getEnabled())
205 return JFW_E_JAVA_DISABLED;
206 aInfo = settings.createJavaInfo();
207 //check if a Java has ever been selected
208 if (!aInfo)
209 return JFW_E_NO_SELECT;
211 //check if the javavendors.xml has changed after a Java was selected
212 OString sVendorUpdate = jfw::getElementUpdated();
214 if (sVendorUpdate != settings.getJavaInfoAttrVendorUpdate())
215 return JFW_E_INVALID_SETTINGS;
217 //check if JAVA is disabled
218 //If Java is enabled, but it was disabled when this process was started
219 // then no preparational work, such as setting the LD_LIBRARY_PATH, was
220 //done. Therefore if a JRE needs it, it must not be started.
221 if (g_bEnabledSwitchedOn &&
222 (aInfo->nRequirements & JFW_REQUIRE_NEEDRESTART))
223 return JFW_E_NEED_RESTART;
225 //Check if the selected Java was set in this process. If so it
226 //must not have the requirements flag JFW_REQUIRE_NEEDRESTART
227 if ((aInfo->nRequirements & JFW_REQUIRE_NEEDRESTART)
228 && jfw::wasJavaSelectedInSameProcess())
229 return JFW_E_NEED_RESTART;
231 vmParams = settings.getVmParametersUtf8();
232 // Expand user classpath (might contain bootstrap vars)
233 const OUString& sUserPath(settings.getUserClassPath());
234 std::vector paths = jfw_convertUserPathList(sUserPath);
235 OUString sUserPathExpanded;
236 for (auto& path : paths)
238 if (!sUserPathExpanded.isEmpty())
239 sUserPathExpanded += OUStringChar(SAL_PATHSEPARATOR);
240 if (path.startsWith("$"))
242 OUString sURL = path;
243 rtl::Bootstrap::expandMacros(sURL);
244 osl::FileBase::getSystemPathFromFileURL(sURL, path);
246 sUserPathExpanded += path;
248 sUserClassPath = jfw::makeClassPathOption(sUserPathExpanded);
249 } // end mode FWK_MODE_OFFICE
250 else if (mode == jfw::JFW_MODE_DIRECT)
252 errcode = jfw_getSelectedJRE(&aInfo);
253 if (errcode != JFW_E_NONE)
254 return errcode;
255 //In direct mode the options are specified by bootstrap variables
256 //of the form UNO_JAVA_JFW_PARAMETER_1 .. UNO_JAVA_JFW_PARAMETER_n
257 vmParams = jfw::BootParams::getVMParameters();
258 auto const cp = jfw::BootParams::getClasspath();
259 if (!cp.isEmpty())
261 sUserClassPath =
262 "-Djava.class.path=" + cp;
265 else
266 OSL_ASSERT(false);
267 pInfo = aInfo.get();
269 assert(pInfo != nullptr);
271 #ifdef _WIN32
272 // Alternative JREs (AdoptOpenJDK, Azul Zulu) are missing the bin/ folder in
273 // java.library.path. Somehow setting java.library.path accordingly doesn't work,
274 // but the PATH gets picked up, so add it there.
275 // Without this hack, some features don't work in alternative JREs.
276 OUString sPATH;
277 osl_getEnvironment(OUString("PATH").pData, &sPATH.pData);
278 OUString sJRELocation;
279 osl::FileBase::getSystemPathFromFileURL(pInfo->sLocation + "/bin", sJRELocation);
280 if (sPATH.isEmpty())
281 sPATH = sJRELocation;
282 else
283 sPATH = sJRELocation + OUStringChar(SAL_PATHSEPARATOR) + sPATH;
284 osl_setEnvironment(OUString("PATH").pData, sPATH.pData);
285 #endif // _WIN32
287 // create JavaVMOptions array that is passed to the plugin
288 // it contains the classpath and all options set in the
289 //options dialog
290 std::unique_ptr<JavaVMOption[]> sarJOptions(
291 new JavaVMOption[
292 arOptions.size() + (sUserClassPath.isEmpty() ? 2 : 3) + vmParams.size()]);
293 JavaVMOption * arOpt = sarJOptions.get();
294 if (! arOpt)
295 return JFW_E_ERROR;
297 //The first argument is the classpath
298 int index = 0;
299 if (!sUserClassPath.isEmpty()) {
300 arOpt[index].optionString= const_cast<char*>(sUserClassPath.getStr());
301 arOpt[index].extraInfo = nullptr;
302 ++index;
304 // Set a flag that this JVM has been created via the JNI Invocation API
305 // (used, for example, by UNO remote bridges to share a common thread pool
306 // factory among Java and native bridge implementations):
307 arOpt[index].optionString = const_cast<char *>("-Dorg.openoffice.native=");
308 arOpt[index].extraInfo = nullptr;
309 ++index;
311 // Don't intercept SIGTERM
312 arOpt[index].optionString = const_cast<char *>("-Xrs");
313 arOpt[index].extraInfo = nullptr;
314 ++index;
316 //add the options set by options dialog
317 for (auto const & vmParam : vmParams)
319 arOpt[index].optionString = const_cast<char*>(vmParam.getStr());
320 arOpt[index].extraInfo = nullptr;
321 index ++;
323 //add all options of the arOptions argument
324 std::vector<OString> convertedOptions;
325 for (auto const & ii: arOptions)
327 OString conv = OUStringToOString(ii, osl_getThreadTextEncoding());
328 convertedOptions.push_back(conv);
329 // keep conv.getStr() alive until after the call to
330 // jfw_plugin_startJavaVirtualMachine below
331 arOpt[index].optionString = const_cast<char *>(conv.getStr());
332 arOpt[index].extraInfo = nullptr;
333 index++;
336 //start Java
337 JavaVM *pVm = nullptr;
338 SAL_INFO("jfw", "Starting Java");
339 javaPluginError plerr = jfw_plugin_startJavaVirtualMachine(pInfo, arOpt, index, & pVm, ppEnv);
340 if (plerr == javaPluginError::VmCreationFailed)
342 errcode = JFW_E_VM_CREATION_FAILED;
344 else if (plerr != javaPluginError::NONE )
346 errcode = JFW_E_ERROR;
348 else
350 g_pJavaVM = pVm;
351 *ppVM = pVm;
354 catch (const jfw::FrameworkException& e)
356 errcode = e.errorCode;
357 SAL_WARN( "jfw", e.message);
360 return errcode;
363 /** We do not use here jfw_findAllJREs and then check if a JavaInfo
364 meets the requirements, because that means using all plug-ins, which
365 may take quite a while. The implementation first inspects JAVA_HOME and
366 PATH environment variables. If no suitable JavaInfo is found there, it
367 inspects all JavaInfos found by the jfw_plugin_get* functions.
369 javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo)
371 javaFrameworkError errcode = JFW_E_NONE;
374 osl::MutexGuard guard(jfw::FwkMutex());
375 if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
376 return JFW_E_DIRECT_MODE;
377 std::unique_ptr<JavaInfo> aCurrentInfo;
380 // 'bInfoFound' indicates whether a Java installation has been found
381 bool bInfoFound = false;
383 // get list of vendors for Java installations
384 jfw::VendorSettings aVendorSettings;
386 std::vector<rtl::Reference<jfw_plugin::VendorBase>> infos;
388 // first inspect Java installation that the JAVA_HOME
389 // environment variable points to (if it is set)
390 if (jfw_plugin_getJavaInfoFromJavaHome(
391 aVendorSettings, &aCurrentInfo, infos)
392 == javaPluginError::NONE)
394 bInfoFound = true;
397 // if no Java installation was detected by using JAVA_HOME,
398 // query PATH for Java installations
399 if (!bInfoFound)
401 std::vector<std::unique_ptr<JavaInfo>> vecJavaInfosFromPath;
402 if (jfw_plugin_getJavaInfosFromPath(
403 aVendorSettings, vecJavaInfosFromPath, infos)
404 == javaPluginError::NONE)
406 assert(!vecJavaInfosFromPath.empty());
407 aCurrentInfo = std::move(vecJavaInfosFromPath[0]);
408 bInfoFound = true;
413 // if no suitable Java installation has been found yet:
414 // first use jfw_plugin_getAllJavaInfos to find a suitable Java installation,
415 // then try paths that have been added manually
416 if (!bInfoFound)
418 //get all installations
419 std::vector<std::unique_ptr<JavaInfo>> arInfos;
420 javaPluginError plerr = jfw_plugin_getAllJavaInfos(
421 false,
422 aVendorSettings,
423 & arInfos,
424 infos);
426 if (plerr == javaPluginError::NONE && !arInfos.empty())
428 aCurrentInfo = std::move(arInfos[0]);
431 if (!aCurrentInfo)
432 {//The plug-ins did not find a suitable Java. Now try the paths which have been
433 //added manually.
434 //get the list of paths to jre locations which have been added manually
435 const jfw::MergedSettings settings;
436 //node.loadFromSettings();
437 const std::vector<OUString> & vecJRELocations =
438 settings.getJRELocations();
439 //use all plug-ins to determine the JavaInfo objects
440 for (auto const & JRELocation : vecJRELocations)
442 std::unique_ptr<JavaInfo> aInfo;
443 javaPluginError err = jfw_plugin_getJavaInfoByPath(
444 JRELocation,
445 aVendorSettings,
446 &aInfo);
447 if (err == javaPluginError::NoJre)
448 continue;
449 if (err == javaPluginError::FailedVersion)
450 continue;
451 else if (err !=javaPluginError::NONE)
452 return JFW_E_ERROR;
454 if (aInfo)
456 aCurrentInfo = std::move(aInfo);
457 break;
459 }//end iterate over paths
462 if (aCurrentInfo)
464 jfw::NodeJava javaNode(jfw::NodeJava::USER);
465 javaNode.setJavaInfo(aCurrentInfo.get(),true);
466 javaNode.write();
467 //remember that this JRE was selected in this process
468 jfw::setJavaSelected();
470 if (pInfo !=nullptr)
472 *pInfo = std::move(aCurrentInfo);
475 else
477 errcode = JFW_E_NO_JAVA_FOUND;
480 catch (const jfw::FrameworkException& e)
482 errcode = e.errorCode;
483 SAL_WARN( "jfw", e.message );
486 return errcode;
489 bool jfw_areEqualJavaInfo(JavaInfo const * pInfoA,JavaInfo const * pInfoB)
491 if (pInfoA == pInfoB)
492 return true;
493 if (pInfoA == nullptr || pInfoB == nullptr)
494 return false;
495 if (pInfoA->sVendor == pInfoB->sVendor
496 && pInfoA->sLocation == pInfoB->sLocation
497 && pInfoA->sVersion == pInfoB->sVersion
498 && pInfoA->nRequirements == pInfoB->nRequirements
499 && pInfoA->arVendorData == pInfoB->arVendorData)
501 return true;
503 return false;
506 javaFrameworkError jfw_getSelectedJRE(std::unique_ptr<JavaInfo> *ppInfo)
508 assert(ppInfo != nullptr);
509 javaFrameworkError errcode = JFW_E_NONE;
512 osl::MutexGuard guard(jfw::FwkMutex());
514 if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
516 if ((errcode = jfw_getJavaInfoByPath(
517 jfw::BootParams::getJREHome(), ppInfo))
518 != JFW_E_NONE)
519 throw jfw::FrameworkException(
520 JFW_E_CONFIGURATION,
521 "[Java framework] The JRE specified by the bootstrap "
522 "variable UNO_JAVA_JFW_JREHOME or UNO_JAVA_JFW_ENV_JREHOME "
523 " could not be recognized. Check the values and make sure that you "
524 "use a plug-in library that can recognize that JRE."_ostr);
526 return JFW_E_NONE;
529 const jfw::MergedSettings settings;
530 *ppInfo = settings.createJavaInfo();
531 if (!*ppInfo)
533 return JFW_E_NONE;
535 //If the javavendors.xml has changed, then the current selected
536 //Java is not valid anymore
537 // /java/javaInfo/@vendorUpdate != javaSelection/updated (javavendors.xml)
538 OString sUpdated = jfw::getElementUpdated();
540 if (sUpdated != settings.getJavaInfoAttrVendorUpdate())
542 ppInfo->reset();
543 return JFW_E_INVALID_SETTINGS;
546 catch (const jfw::FrameworkException& e)
548 errcode = e.errorCode;
549 SAL_WARN( "jfw", e.message );
551 return errcode;
554 bool jfw_isVMRunning()
556 osl::MutexGuard guard(jfw::FwkMutex());
557 return g_pJavaVM != nullptr;
560 javaFrameworkError jfw_getJavaInfoByPath(OUString const & pPath, std::unique_ptr<JavaInfo> *ppInfo)
562 assert(ppInfo != nullptr);
563 javaFrameworkError errcode = JFW_E_NONE;
566 osl::MutexGuard guard(jfw::FwkMutex());
568 jfw::VendorSettings aVendorSettings;
570 //ask all plugins if this is a JRE.
571 //If so check if it meets the version requirements.
572 //Only if it does return a JavaInfo
573 javaPluginError plerr = jfw_plugin_getJavaInfoByPath(
574 pPath,
575 aVendorSettings,
576 ppInfo);
578 if(plerr == javaPluginError::FailedVersion)
579 {//found JRE but it has the wrong version
580 ppInfo->reset();
581 errcode = JFW_E_FAILED_VERSION;
583 OSL_ASSERT(plerr == javaPluginError::NONE || plerr == javaPluginError::NoJre);
584 if (!*ppInfo && errcode != JFW_E_FAILED_VERSION)
585 errcode = JFW_E_NOT_RECOGNIZED;
587 catch (const jfw::FrameworkException& e)
589 errcode = e.errorCode;
590 SAL_WARN( "jfw", e.message );
593 return errcode;
597 javaFrameworkError jfw_setSelectedJRE(JavaInfo const *pInfo)
599 javaFrameworkError errcode = JFW_E_NONE;
602 osl::MutexGuard guard(jfw::FwkMutex());
603 if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
604 return JFW_E_DIRECT_MODE;
605 //check if pInfo is the selected JRE
606 std::unique_ptr<JavaInfo> currentInfo;
607 errcode = jfw_getSelectedJRE( & currentInfo);
608 if (errcode != JFW_E_NONE && errcode != JFW_E_INVALID_SETTINGS)
609 return errcode;
611 if (!jfw_areEqualJavaInfo(currentInfo.get(), pInfo))
613 jfw::NodeJava node(jfw::NodeJava::USER);
614 node.setJavaInfo(pInfo, false);
615 node.write();
616 //remember that the JRE was selected in this process
617 jfw::setJavaSelected();
620 catch (const jfw::FrameworkException& e)
622 errcode = e.errorCode;
623 SAL_WARN( "jfw", e.message );
625 return errcode;
627 javaFrameworkError jfw_setEnabled(bool bEnabled)
629 javaFrameworkError errcode = JFW_E_NONE;
632 osl::MutexGuard guard(jfw::FwkMutex());
633 if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
634 return JFW_E_DIRECT_MODE;
636 if (!g_bEnabledSwitchedOn && bEnabled)
638 //When the process started then Enabled was false.
639 //This is first time enabled is set to true.
640 //That means, no preparational work has been done, such as setting the
641 //LD_LIBRARY_PATH, etc.
643 //check if Enabled is false;
644 const jfw::MergedSettings settings;
645 if (!settings.getEnabled())
646 g_bEnabledSwitchedOn = true;
648 jfw::NodeJava node(jfw::NodeJava::USER);
649 node.setEnabled(bEnabled);
650 node.write();
652 catch (const jfw::FrameworkException& e)
654 errcode = e.errorCode;
655 SAL_WARN( "jfw", e.message );
657 return errcode;
660 javaFrameworkError jfw_getEnabled(bool *pbEnabled)
662 assert(pbEnabled != nullptr);
663 javaFrameworkError errcode = JFW_E_NONE;
666 if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
667 return JFW_E_DIRECT_MODE;
668 osl::MutexGuard guard(jfw::FwkMutex());
669 jfw::MergedSettings settings;
670 *pbEnabled = settings.getEnabled();
672 catch (const jfw::FrameworkException& e)
674 errcode = e.errorCode;
675 SAL_WARN( "jfw", e.message );
677 return errcode;
681 javaFrameworkError jfw_setVMParameters(std::vector<OUString> const & arOptions)
683 javaFrameworkError errcode = JFW_E_NONE;
686 osl::MutexGuard guard(jfw::FwkMutex());
687 if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
688 return JFW_E_DIRECT_MODE;
689 jfw::NodeJava node(jfw::NodeJava::USER);
690 node.setVmParameters(arOptions);
691 node.write();
693 catch (const jfw::FrameworkException& e)
695 errcode = e.errorCode;
696 SAL_WARN( "jfw", e.message );
699 return errcode;
702 javaFrameworkError jfw_getVMParameters(std::vector<OUString> * parOptions)
704 javaFrameworkError errcode = JFW_E_NONE;
707 osl::MutexGuard guard(jfw::FwkMutex());
708 if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
709 return JFW_E_DIRECT_MODE;
711 const jfw::MergedSettings settings;
712 settings.getVmParametersArray(parOptions);
714 catch (const jfw::FrameworkException& e)
716 errcode = e.errorCode;
717 SAL_WARN( "jfw", e.message );
719 return errcode;
722 javaFrameworkError jfw_setUserClassPath(OUString const & pCp)
724 javaFrameworkError errcode = JFW_E_NONE;
727 osl::MutexGuard guard(jfw::FwkMutex());
728 if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
729 return JFW_E_DIRECT_MODE;
730 jfw::NodeJava node(jfw::NodeJava::USER);
731 node.setUserClassPath(pCp);
732 node.write();
734 catch (const jfw::FrameworkException& e)
736 errcode = e.errorCode;
737 SAL_WARN( "jfw", e.message );
739 return errcode;
742 javaFrameworkError jfw_getUserClassPath(OUString * ppCP)
744 assert(ppCP != nullptr);
745 javaFrameworkError errcode = JFW_E_NONE;
748 osl::MutexGuard guard(jfw::FwkMutex());
749 if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
750 return JFW_E_DIRECT_MODE;
751 const jfw::MergedSettings settings;
752 *ppCP = settings.getUserClassPath();
754 catch (const jfw::FrameworkException& e)
756 errcode = e.errorCode;
757 SAL_WARN( "jfw", e.message );
759 return errcode;
762 javaFrameworkError jfw_addJRELocation(OUString const & sLocation)
764 javaFrameworkError errcode = JFW_E_NONE;
767 osl::MutexGuard guard(jfw::FwkMutex());
768 if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
769 return JFW_E_DIRECT_MODE;
770 jfw::NodeJava node(jfw::NodeJava::USER);
771 node.load();
772 node.addJRELocation(sLocation);
773 node.write();
775 catch (const jfw::FrameworkException& e)
777 errcode = e.errorCode;
778 SAL_WARN( "jfw", e.message );
781 return errcode;
785 javaFrameworkError jfw_existJRE(const JavaInfo *pInfo, bool *exist)
787 javaPluginError plerr = jfw_plugin_existJRE(pInfo, exist);
789 javaFrameworkError ret = JFW_E_NONE;
790 switch (plerr)
792 case javaPluginError::NONE:
793 ret = JFW_E_NONE;
794 break;
795 case javaPluginError::Error:
796 ret = JFW_E_ERROR;
797 break;
798 default:
799 ret = JFW_E_ERROR;
801 return ret;
804 void jfw_lock()
806 jfw::FwkMutex().acquire();
809 void jfw_unlock()
811 jfw::FwkMutex().release();
814 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */