LibreOffice Module jvmfwk (master) 1
framework.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21#include <sal/log.hxx>
22
23#include <cassert>
24#include <memory>
25
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>
44
45namespace {
46
47bool g_bEnabledSwitchedOn = false;
48
49JavaVM * g_pJavaVM = nullptr;
50
51bool areEqualJavaInfo(
52 JavaInfo const * pInfoA,JavaInfo const * pInfoB)
53{
54 return jfw_areEqualJavaInfo(pInfoA, pInfoB);
55}
56
57}
58
59javaFrameworkError jfw_findAllJREs(std::vector<std::unique_ptr<JavaInfo>> *pparInfo)
60{
61 assert(pparInfo != nullptr);
62 try
63 {
64 osl::MutexGuard guard(jfw::FwkMutex());
65
66 jfw::VendorSettings aVendorSettings;
67 std::vector<std::unique_ptr<JavaInfo>> vecInfo;
68
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;
73 true,
74 aVendorSettings,
75 & arInfos,
76 infos);
77
78 if (plerr != javaPluginError::NONE)
79 return JFW_E_ERROR;
80
81 for (auto & j: arInfos)
82 vecInfo.push_back(std::move(j));
83
84 // direct mode disregards Java settings, so only retrieve
85 // JREs from settings when application mode is used
87 {
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)
97 {
98 std::unique_ptr<JavaInfo> aInfo;
100 ii,
101 aVendorSettings,
102 &aInfo);
103 if (plerr == javaPluginError::NoJre)
104 continue;
106 continue;
107 if (plerr == javaPluginError::WrongArch)
108 continue;
109 else if (plerr != javaPluginError::NONE)
110 return JFW_E_ERROR;
111
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());
118 }))
119 {
120 vecInfo.push_back(std::move(aInfo));
121 }
122 }
123 }
124
125 *pparInfo = std::move(vecInfo);
126
127 return JFW_E_NONE;
128 }
129 catch (const jfw::FrameworkException& e)
130 {
131 SAL_WARN( "jfw", e.message);
132 return e.errorCode;
133 }
134}
135
136std::vector<OUString> jfw_convertUserPathList(OUString const& sUserPath)
137{
138 std::vector<OUString> result;
139 sal_Int32 nIdx = 0;
140 do
141 {
142 sal_Int32 nextColon = sUserPath.indexOf(SAL_PATHSEPARATOR, nIdx);
143 OUString sToken(sUserPath.subView(nIdx, nextColon > 0 ? nextColon - nIdx
144 : sUserPath.getLength() - nIdx));
145
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("$"))
149 {
150 // Detect open bootstrap variables - they might contain colons - we need to skip those.
151 sal_Int32 nBootstrapVarStart = sToken.indexOf("${");
152 if (nBootstrapVarStart >= 0)
153 {
154 sal_Int32 nBootstrapVarEnd = sToken.indexOf("}", nBootstrapVarStart);
155 if (nBootstrapVarEnd == -1)
156 {
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);
161 }
162 }
163 }
164 result.emplace_back(sToken);
165 nIdx = nextColon + 1;
166 } while (nIdx > 0);
167 return result;
168}
169
171 JavaInfo const * pInfo, std::vector<OUString> const & arOptions,
172 JavaVM ** ppVM, JNIEnv ** ppEnv)
173{
174 assert(ppVM != nullptr);
176
177 try
178 {
179 osl::MutexGuard guard(jfw::FwkMutex());
180
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;
185
186 std::vector<OString> vmParams;
187 OString sUserClassPath;
188 std::unique_ptr<JavaInfo> aInfo;
189 if (pInfo == nullptr)
190 {
193 {
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;
201
202 //check if the javavendors.xml has changed after a Java was selected
203 OString sVendorUpdate = jfw::getElementUpdated();
204
205 if (sVendorUpdate != settings.getJavaInfoAttrVendorUpdate())
207
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;
215
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)
220 return JFW_E_NEED_RESTART;
221
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)
228 {
229 if (!sUserPathExpanded.isEmpty())
230 sUserPathExpanded += OUStringChar(SAL_PATHSEPARATOR);
231 if (path.startsWith("$"))
232 {
233 OUString sURL = path;
234 rtl::Bootstrap::expandMacros(sURL);
235 osl::FileBase::getSystemPathFromFileURL(sURL, path);
236 }
237 sUserPathExpanded += path;
238 }
239 sUserClassPath = jfw::makeClassPathOption(sUserPathExpanded);
240 } // end mode FWK_MODE_OFFICE
241 else if (mode == jfw::JFW_MODE_DIRECT)
242 {
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
249 auto const cp = jfw::BootParams::getClasspath();
250 if (!cp.isEmpty())
251 {
252 sUserClassPath =
253 "-Djava.class.path=" + cp;
254 }
255 }
256 else
257 OSL_ASSERT(false);
258 pInfo = aInfo.get();
259 }
260 assert(pInfo != nullptr);
261
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
277
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;
287
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;
294 }
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;
301
302 // Don't intercept SIGTERM
303 arOpt[index].optionString = const_cast<char *>("-Xrs");
304 arOpt[index].extraInfo = nullptr;
305 ++index;
306
307 //add the options set by options dialog
308 for (auto const & vmParam : vmParams)
309 {
310 arOpt[index].optionString = const_cast<char*>(vmParam.getStr());
311 arOpt[index].extraInfo = nullptr;
312 index ++;
313 }
314 //add all options of the arOptions argument
315 std::vector<OString> convertedOptions;
316 for (auto const & ii: arOptions)
317 {
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++;
325 }
326
327 //start Java
328 JavaVM *pVm = nullptr;
329 SAL_INFO("jfw", "Starting Java");
330 javaPluginError plerr = jfw_plugin_startJavaVirtualMachine(pInfo, arOpt, index, & pVm, ppEnv);
332 {
333 errcode = JFW_E_VM_CREATION_FAILED;
334 }
335 else if (plerr != javaPluginError::NONE )
336 {
337 errcode = JFW_E_ERROR;
338 }
339 else
340 {
341 g_pJavaVM = pVm;
342 *ppVM = pVm;
343 }
344 }
345 catch (const jfw::FrameworkException& e)
346 {
347 errcode = e.errorCode;
348 SAL_WARN( "jfw", e.message);
349 }
350
351 return errcode;
352}
353
360javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo)
361{
363 try
364 {
365 osl::MutexGuard guard(jfw::FwkMutex());
367 return JFW_E_DIRECT_MODE;
368 std::unique_ptr<JavaInfo> aCurrentInfo;
369
370
371 // 'bInfoFound' indicates whether a Java installation has been found
372 bool bInfoFound = false;
373
374 // get list of vendors for Java installations
375 jfw::VendorSettings aVendorSettings;
376
377 std::vector<rtl::Reference<jfw_plugin::VendorBase>> infos;
378
379 // first inspect Java installation that the JAVA_HOME
380 // environment variable points to (if it is set)
382 aVendorSettings, &aCurrentInfo, infos)
384 {
385 bInfoFound = true;
386 }
387
388 // if no Java installation was detected by using JAVA_HOME,
389 // query PATH for Java installations
390 if (!bInfoFound)
391 {
392 std::vector<std::unique_ptr<JavaInfo>> vecJavaInfosFromPath;
394 aVendorSettings, vecJavaInfosFromPath, infos)
396 {
397 assert(!vecJavaInfosFromPath.empty());
398 aCurrentInfo = std::move(vecJavaInfosFromPath[0]);
399 bInfoFound = true;
400 }
401 }
402
403
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)
408 {
409 //get all installations
410 std::vector<std::unique_ptr<JavaInfo>> arInfos;
412 false,
413 aVendorSettings,
414 & arInfos,
415 infos);
416
417 if (plerr == javaPluginError::NONE && !arInfos.empty())
418 {
419 aCurrentInfo = std::move(arInfos[0]);
420 }
421
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)
432 {
433 std::unique_ptr<JavaInfo> aInfo;
435 JRELocation,
436 aVendorSettings,
437 &aInfo);
439 continue;
441 continue;
442 else if (err !=javaPluginError::NONE)
443 return JFW_E_ERROR;
444
445 if (aInfo)
446 {
447 aCurrentInfo = std::move(aInfo);
448 break;
449 }
450 }//end iterate over paths
451 }
452 }
453 if (aCurrentInfo)
454 {
456 javaNode.setJavaInfo(aCurrentInfo.get(),true);
457 javaNode.write();
458 //remember that this JRE was selected in this process
460
461 if (pInfo !=nullptr)
462 {
463 *pInfo = std::move(aCurrentInfo);
464 }
465 }
466 else
467 {
468 errcode = JFW_E_NO_JAVA_FOUND;
469 }
470 }
471 catch (const jfw::FrameworkException& e)
472 {
473 errcode = e.errorCode;
474 SAL_WARN( "jfw", e.message );
475 }
476
477 return errcode;
478}
479
480bool jfw_areEqualJavaInfo(JavaInfo const * pInfoA,JavaInfo const * pInfoB)
481{
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)
491 {
492 return true;
493 }
494 return false;
495}
496
497javaFrameworkError jfw_getSelectedJRE(std::unique_ptr<JavaInfo> *ppInfo)
498{
499 assert(ppInfo != nullptr);
501 try
502 {
503 osl::MutexGuard guard(jfw::FwkMutex());
504
506 {
507 if ((errcode = jfw_getJavaInfoByPath(
509 != JFW_E_NONE)
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.");
516
517 return JFW_E_NONE;
518 }
519
520 const jfw::MergedSettings settings;
521 *ppInfo = settings.createJavaInfo();
522 if (!*ppInfo)
523 {
524 return JFW_E_NONE;
525 }
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();
530
531 if (sUpdated != settings.getJavaInfoAttrVendorUpdate())
532 {
533 ppInfo->reset();
535 }
536 }
537 catch (const jfw::FrameworkException& e)
538 {
539 errcode = e.errorCode;
540 SAL_WARN( "jfw", e.message );
541 }
542 return errcode;
543}
544
546{
547 osl::MutexGuard guard(jfw::FwkMutex());
548 return g_pJavaVM != nullptr;
549}
550
551javaFrameworkError jfw_getJavaInfoByPath(OUString const & pPath, std::unique_ptr<JavaInfo> *ppInfo)
552{
553 assert(ppInfo != nullptr);
555 try
556 {
557 osl::MutexGuard guard(jfw::FwkMutex());
558
559 jfw::VendorSettings aVendorSettings;
560
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
565 pPath,
566 aVendorSettings,
567 ppInfo);
568
570 {//found JRE but it has the wrong version
571 ppInfo->reset();
572 errcode = JFW_E_FAILED_VERSION;
573 }
574 OSL_ASSERT(plerr == javaPluginError::NONE || plerr == javaPluginError::NoJre);
575 if (!*ppInfo && errcode != JFW_E_FAILED_VERSION)
576 errcode = JFW_E_NOT_RECOGNIZED;
577 }
578 catch (const jfw::FrameworkException& e)
579 {
580 errcode = e.errorCode;
581 SAL_WARN( "jfw", e.message );
582 }
583
584 return errcode;
585}
586
587
589{
591 try
592 {
593 osl::MutexGuard guard(jfw::FwkMutex());
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;
601
602 if (!jfw_areEqualJavaInfo(currentInfo.get(), pInfo))
603 {
605 node.setJavaInfo(pInfo, false);
606 node.write();
607 //remember that the JRE was selected in this process
609 }
610 }
611 catch (const jfw::FrameworkException& e)
612 {
613 errcode = e.errorCode;
614 SAL_WARN( "jfw", e.message );
615 }
616 return errcode;
617}
619{
621 try
622 {
623 osl::MutexGuard guard(jfw::FwkMutex());
625 return JFW_E_DIRECT_MODE;
626
627 if (!g_bEnabledSwitchedOn && bEnabled)
628 {
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.
633
634 //check if Enabled is false;
635 const jfw::MergedSettings settings;
636 if (!settings.getEnabled())
637 g_bEnabledSwitchedOn = true;
638 }
640 node.setEnabled(bEnabled);
641 node.write();
642 }
643 catch (const jfw::FrameworkException& e)
644 {
645 errcode = e.errorCode;
646 SAL_WARN( "jfw", e.message );
647 }
648 return errcode;
649}
650
652{
653 assert(pbEnabled != nullptr);
655 try
656 {
658 return JFW_E_DIRECT_MODE;
659 osl::MutexGuard guard(jfw::FwkMutex());
660 jfw::MergedSettings settings;
661 *pbEnabled = settings.getEnabled();
662 }
663 catch (const jfw::FrameworkException& e)
664 {
665 errcode = e.errorCode;
666 SAL_WARN( "jfw", e.message );
667 }
668 return errcode;
669}
670
671
672javaFrameworkError jfw_setVMParameters(std::vector<OUString> const & arOptions)
673{
675 try
676 {
677 osl::MutexGuard guard(jfw::FwkMutex());
679 return JFW_E_DIRECT_MODE;
681 node.setVmParameters(arOptions);
682 node.write();
683 }
684 catch (const jfw::FrameworkException& e)
685 {
686 errcode = e.errorCode;
687 SAL_WARN( "jfw", e.message );
688 }
689
690 return errcode;
691}
692
693javaFrameworkError jfw_getVMParameters(std::vector<OUString> * parOptions)
694{
696 try
697 {
698 osl::MutexGuard guard(jfw::FwkMutex());
700 return JFW_E_DIRECT_MODE;
701
702 const jfw::MergedSettings settings;
703 settings.getVmParametersArray(parOptions);
704 }
705 catch (const jfw::FrameworkException& e)
706 {
707 errcode = e.errorCode;
708 SAL_WARN( "jfw", e.message );
709 }
710 return errcode;
711}
712
714{
716 try
717 {
718 osl::MutexGuard guard(jfw::FwkMutex());
720 return JFW_E_DIRECT_MODE;
722 node.setUserClassPath(pCp);
723 node.write();
724 }
725 catch (const jfw::FrameworkException& e)
726 {
727 errcode = e.errorCode;
728 SAL_WARN( "jfw", e.message );
729 }
730 return errcode;
731}
732
734{
735 assert(ppCP != nullptr);
737 try
738 {
739 osl::MutexGuard guard(jfw::FwkMutex());
741 return JFW_E_DIRECT_MODE;
742 const jfw::MergedSettings settings;
743 *ppCP = settings.getUserClassPath();
744 }
745 catch (const jfw::FrameworkException& e)
746 {
747 errcode = e.errorCode;
748 SAL_WARN( "jfw", e.message );
749 }
750 return errcode;
751}
752
753javaFrameworkError jfw_addJRELocation(OUString const & sLocation)
754{
756 try
757 {
758 osl::MutexGuard guard(jfw::FwkMutex());
760 return JFW_E_DIRECT_MODE;
762 node.load();
763 node.addJRELocation(sLocation);
764 node.write();
765 }
766 catch (const jfw::FrameworkException& e)
767 {
768 errcode = e.errorCode;
769 SAL_WARN( "jfw", e.message );
770 }
771
772 return errcode;
773
774}
775
776javaFrameworkError jfw_existJRE(const JavaInfo *pInfo, bool *exist)
777{
778 javaPluginError plerr = jfw_plugin_existJRE(pInfo, exist);
779
781 switch (plerr)
782 {
784 ret = JFW_E_NONE;
785 break;
787 ret = JFW_E_ERROR;
788 break;
789 default:
790 ret = JFW_E_ERROR;
791 }
792 return ret;
793}
794
796{
797 jfw::FwkMutex().acquire();
798}
799
801{
802 jfw::FwkMutex().release();
803}
804
805/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
merges the settings for shared, user and installation during construction.
Definition: elements.hxx:266
const ::std::vector< OUString > & getJRELocations() const
Definition: elements.hxx:316
bool getEnabled() const
the default is true.
Definition: elements.hxx:289
::std::vector< OString > getVmParametersUtf8() const
Definition: elements.cxx:939
const OUString & getUserClassPath() const
Definition: elements.hxx:291
std::unique_ptr< JavaInfo > createJavaInfo() const
returns a JavaInfo structure representing the node /java/javaInfo.
Definition: elements.cxx:950
OString const & getJavaInfoAttrVendorUpdate() const
returns the value of the attribute /java/javaInfo[@vendorUpdate].
Definition: elements.hxx:303
void getVmParametersArray(std::vector< OUString > *parParameters) const
Definition: elements.cxx:960
this class represents the java settings based on a particular settings file.
Definition: elements.hxx:114
void setUserClassPath(const OUString &sClassPath)
sets m_sUserClassPath.
Definition: elements.cxx:538
void load()
load the values of the settings file.
Definition: elements.cxx:178
void addJRELocation(OUString const &sLocation)
adds a location to the already existing locations.
Definition: elements.cxx:575
void setEnabled(bool bEnabled)
sets m_enabled.
Definition: elements.cxx:532
void write() const
writes the data to user settings.
Definition: elements.cxx:376
void setJavaInfo(const JavaInfo *pInfo, bool bAutoSelect)
sets m_aInfo.
Definition: elements.cxx:543
void setVmParameters(std::vector< OUString > const &arParameters)
sets the /java/vmParameters/param elements.
Definition: elements.cxx:570
#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,...
Definition: framework.cxx:360
javaFrameworkError jfw_setSelectedJRE(JavaInfo const *pInfo)
determines the JRE that is to be used.
Definition: framework.cxx:588
javaFrameworkError jfw_getJavaInfoByPath(OUString const &pPath, std::unique_ptr< JavaInfo > *ppInfo)
determines if a path points to a Java installation.
Definition: framework.cxx:551
void jfw_lock()
locks this API so that it cannot be used by other threads.
Definition: framework.cxx:795
javaFrameworkError jfw_setVMParameters(std::vector< OUString > const &arOptions)
determines parameters which are passed to VM during its creation.
Definition: framework.cxx:672
javaFrameworkError jfw_addJRELocation(OUString const &sLocation)
saves the location of a JRE.
Definition: framework.cxx:753
javaFrameworkError jfw_setUserClassPath(OUString const &pCp)
sets the user class path.
Definition: framework.cxx:713
javaFrameworkError jfw_getSelectedJRE(std::unique_ptr< JavaInfo > *ppInfo)
provides information about the JRE that is to be used.
Definition: framework.cxx:497
javaFrameworkError jfw_getVMParameters(std::vector< OUString > *parOptions)
obtains the currently used start parameters.
Definition: framework.cxx:693
void jfw_unlock()
unlocks this API.
Definition: framework.cxx:800
bool jfw_areEqualJavaInfo(JavaInfo const *pInfoA, JavaInfo const *pInfoB)
compares two JavaInfo objects for equality.
Definition: framework.cxx:480
javaFrameworkError jfw_getUserClassPath(OUString *ppCP)
provides the value of the current user class path.
Definition: framework.cxx:733
javaFrameworkError jfw_startVM(JavaInfo const *pInfo, std::vector< OUString > const &arOptions, JavaVM **ppVM, JNIEnv **ppEnv)
starts a Java Virtual Machine (JVM).
Definition: framework.cxx:170
bool jfw_isVMRunning()
determines if a Java Virtual Machine is already running.
Definition: framework.cxx:545
javaFrameworkError jfw_setEnabled(bool bEnabled)
determines if Java can be used.
Definition: framework.cxx:618
javaFrameworkError jfw_findAllJREs(std::vector< std::unique_ptr< JavaInfo > > *pparInfo)
provides information about all available JRE installations.
Definition: framework.cxx:59
javaFrameworkError jfw_getEnabled(bool *pbEnabled)
provides the information if Java can be used.
Definition: framework.cxx:651
javaFrameworkError jfw_existJRE(const JavaInfo *pInfo, bool *exist)
checks if the installation of the jre still exists.
Definition: framework.cxx:776
std::vector< OUString > jfw_convertUserPathList(OUString const &sUserPath)
Convert colon-separated userClassPath which might contain bootstrap variables (which also might conta...
Definition: framework.cxx:136
#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_INVALID_SETTINGS
@ JFW_E_VM_CREATION_FAILED
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
std::unique_ptr< sal_Int32[]> pData
err
OUString getJREHome()
Definition: fwkbase.cxx:310
::std::vector< OString > getVMParameters()
Definition: fwkbase.cxx:211
OString getClasspath()
Definition: fwkbase.cxx:244
OString getElementUpdated()
gets the value of the updated element from the javavendors.xml.
Definition: elements.cxx:79
void setJavaSelected()
Called from writeJavaInfoData.
Definition: fwkbase.cxx:504
bool wasJavaSelectedInSameProcess()
Determines if the currently selected Java was set in this process.
Definition: fwkbase.cxx:509
osl::Mutex & FwkMutex()
Definition: fwkutil.cxx:65
JFW_MODE getMode()
Definition: fwkbase.cxx:376
JFW_MODE
Definition: fwkbase.hxx:76
@ JFW_MODE_APPLICATION
Definition: fwkbase.hxx:77
@ JFW_MODE_DIRECT
Definition: fwkbase.hxx:79
OString makeClassPathOption(std::u16string_view sUserClassPath)
creates the -Djava.class.path option with the complete classpath, including the paths which are set b...
Definition: fwkbase.cxx:446
index
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
ConversionMode mode
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.
Any result
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
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...