1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "boost/scoped_array.hpp"
21 #include "rtl/ustring.hxx"
22 #include "rtl/bootstrap.hxx"
23 #include "osl/thread.hxx"
24 #include "osl/file.hxx"
25 #include "jvmfwk/framework.h"
26 #include "vendorplugin.hxx"
31 #include "framework.hxx"
32 #include "fwkutil.hxx"
33 #include "elements.hxx"
34 #include "fwkbase.hxx"
38 static bool g_bEnabledSwitchedOn
= false;
40 static JavaVM
* g_pJavaVM
= NULL
;
42 bool areEqualJavaInfo(
43 JavaInfo
const * pInfoA
,JavaInfo
const * pInfoB
)
45 return jfw_areEqualJavaInfo(pInfoA
, pInfoB
);
50 javaFrameworkError SAL_CALL
jfw_findAllJREs(JavaInfo
***pparInfo
, sal_Int32
*pSize
)
52 javaFrameworkError retVal
= JFW_E_NONE
;
55 osl::MutexGuard
guard(jfw::FwkMutex::get());
56 javaFrameworkError errcode
= JFW_E_NONE
;
57 if (pparInfo
== NULL
|| pSize
== NULL
)
58 return JFW_E_INVALID_ARG
;
60 jfw::VendorSettings aVendorSettings
;
61 std::vector
<OUString
> vecVendors
=
62 aVendorSettings
.getSupportedVendors();
63 //Add the JavaInfos found by jfw_plugin_getAllJavaInfos to the vector
64 //Make sure that the contents are destroyed if this
65 //function returns with an error
66 std::vector
<jfw::CJavaInfo
> vecInfo
;
67 //Add the JavaInfos found by jfw_plugin_getJavaInfoByPath to this vector
68 //Make sure that the contents are destroyed if this
69 //function returns with an error
70 std::vector
<jfw::CJavaInfo
> vecInfoManual
;
71 typedef std::vector
<jfw::CJavaInfo
>::iterator it_info
;
72 //get the list of paths to jre locations which have been
74 const jfw::MergedSettings settings
;
75 const std::vector
<OUString
>& vecJRELocations
=
76 settings
.getJRELocations();
77 //Use every plug-in library to get Java installations.
78 typedef std::vector
<OUString
>::const_iterator ci_pl
;
79 for (ci_pl i
= vecVendors
.begin(); i
!= vecVendors
.end(); ++i
)
81 const OUString
& vendor
= *i
;
82 jfw::VersionInfo versionInfo
=
83 aVendorSettings
.getVersionInformation(vendor
);
85 //get all installations of one vendor according to minVersion,
86 //maxVersion and excludeVersions
88 JavaInfo
** arInfos
= NULL
;
89 std::vector
<rtl::Reference
<jfw_plugin::VendorBase
>> infos
;
90 javaPluginError plerr
= jfw_plugin_getAllJavaInfos(
93 versionInfo
.sMinVersion
,
94 versionInfo
.sMaxVersion
,
95 versionInfo
.getExcludeVersions(),
96 versionInfo
.getExcludeVersionSize(),
101 if (plerr
!= JFW_PLUGIN_E_NONE
)
104 for (int j
= 0; j
< cInfos
; j
++)
105 vecInfo
.push_back(jfw::CJavaInfo::createWrapper(arInfos
[j
]));
107 rtl_freeMemory(arInfos
);
109 //Check if the current plugin can detect JREs at the location
110 // of the paths added by jfw_addJRELocation
111 //get the function from the plugin
112 typedef std::vector
<OUString
>::const_iterator citLoc
;
113 //Check every manually added location
114 for (citLoc ii
= vecJRELocations
.begin();
115 ii
!= vecJRELocations
.end(); ++ii
)
117 jfw::CJavaInfo aInfo
;
118 plerr
= jfw_plugin_getJavaInfoByPath(
121 versionInfo
.sMinVersion
,
122 versionInfo
.sMaxVersion
,
123 versionInfo
.getExcludeVersions(),
124 versionInfo
.getExcludeVersionSize(),
126 if (plerr
== JFW_PLUGIN_E_NO_JRE
)
128 if (plerr
== JFW_PLUGIN_E_FAILED_VERSION
)
130 else if (plerr
!=JFW_PLUGIN_E_NONE
)
135 //Was this JRE already added?. Different plugins could detect
137 it_info it_duplicate
=
138 std::find_if(vecInfoManual
.begin(), vecInfoManual
.end(),
139 std::bind(areEqualJavaInfo
, std::placeholders::_1
, aInfo
));
140 if (it_duplicate
== vecInfoManual
.end())
141 vecInfoManual
.push_back(aInfo
);
145 //Make sure vecInfoManual contains only JavaInfos for the vendors for which
146 //there is a javaSelection/plugins/library entry in the javavendors.xml
147 //To obtain the JavaInfos for the manually added JRE locations the function
148 //jfw_getJavaInfoByPath is called which can return a JavaInfo of any vendor.
149 std::vector
<jfw::CJavaInfo
> vecInfoManual2
;
150 for (it_info ivm
= vecInfoManual
.begin(); ivm
!= vecInfoManual
.end(); ++ivm
)
152 for (ci_pl ii
= vecVendors
.begin(); ii
!= vecVendors
.end(); ++ii
)
154 if ( ii
->equals((*ivm
)->sVendor
))
156 vecInfoManual2
.push_back(*ivm
);
161 //Check which JavaInfo from vector vecInfoManual2 is already
162 //contained in vecInfo. If it already exists then remove it from
164 for (it_info j
= vecInfo
.begin(); j
!= vecInfo
.end(); ++j
)
166 it_info it_duplicate
=
167 std::find_if(vecInfoManual2
.begin(), vecInfoManual2
.end(),
168 std::bind(areEqualJavaInfo
, std::placeholders::_1
, *j
));
169 if (it_duplicate
!= vecInfoManual2
.end())
170 vecInfoManual2
.erase(it_duplicate
);
172 //create an fill the array of JavaInfo*
173 sal_Int32 nSize
= vecInfo
.size() + vecInfoManual2
.size();
174 *pparInfo
= static_cast<JavaInfo
**>(rtl_allocateMemory(
175 nSize
* sizeof(JavaInfo
*)));
176 if (*pparInfo
== NULL
)
179 typedef std::vector
<jfw::CJavaInfo
>::iterator it
;
181 //Add the automatically detected JREs
182 for (it k
= vecInfo
.begin(); k
!= vecInfo
.end(); ++k
)
183 (*pparInfo
)[index
++] = k
->detach();
184 //Add the manually detected JREs
185 for (it l
= vecInfoManual2
.begin(); l
!= vecInfoManual2
.end(); ++l
)
186 (*pparInfo
)[index
++] = l
->detach();
191 catch (const jfw::FrameworkException
& e
)
193 retVal
= e
.errorCode
;
194 fprintf(stderr
, "%s\n", e
.message
.getStr());
195 OSL_FAIL(e
.message
.getStr());
200 javaFrameworkError SAL_CALL
jfw_startVM(
201 JavaInfo
const * pInfo
, JavaVMOption
* arOptions
, sal_Int32 cOptions
,
202 JavaVM
** ppVM
, JNIEnv
** ppEnv
)
204 javaFrameworkError errcode
= JFW_E_NONE
;
205 if (cOptions
> 0 && arOptions
== NULL
)
206 return JFW_E_INVALID_ARG
;
210 osl::MutexGuard
guard(jfw::FwkMutex::get());
212 //We keep this pointer so we can determine if a VM has already
214 if (g_pJavaVM
!= NULL
)
215 return JFW_E_RUNNING_JVM
;
218 return JFW_E_INVALID_ARG
;
220 std::vector
<OString
> vmParams
;
221 OString sUserClassPath
;
222 jfw::CJavaInfo aInfo
;
225 jfw::JFW_MODE mode
= jfw::getMode();
226 if (mode
== jfw::JFW_MODE_APPLICATION
)
228 const jfw::MergedSettings settings
;
229 if (!settings
.getEnabled())
230 return JFW_E_JAVA_DISABLED
;
231 aInfo
.attach(settings
.createJavaInfo());
232 //check if a Java has ever been selected
234 return JFW_E_NO_SELECT
;
237 //Because on Windows there is no system setting that we can use to determine
238 //if Assistive Technology Tool support is needed, we ship a .reg file that the
239 //user can use to create a registry setting. When the user forgets to set
240 //the key before he starts the office then a JRE may be selected without access bridge.
241 //When he later sets the key then we select a JRE with accessibility support but
242 //only if the user has not manually changed the selected JRE in the options dialog.
243 if (jfw::isAccessibilitySupportDesired())
245 // If no JRE has been selected then we do not select one. This function shall then
246 //return JFW_E_NO_SELECT
248 (aInfo
->nFeatures
& JFW_FEATURE_ACCESSBRIDGE
) == 0)
250 //has the user manually selected a JRE?
251 if (settings
.getJavaInfoAttrAutoSelect() == true)
253 // if not then the automatism has previously selected a JRE
254 //without accessibility support. We return JFW_E_NO_SELECT
255 //to cause that we search for another JRE. The search code will
256 //then prefer a JRE with accessibility support.
257 return JFW_E_NO_SELECT
;
262 //check if the javavendors.xml has changed after a Java was selected
263 OString sVendorUpdate
= jfw::getElementUpdated();
265 if (sVendorUpdate
!= settings
.getJavaInfoAttrVendorUpdate())
266 return JFW_E_INVALID_SETTINGS
;
268 //check if JAVA is disabled
269 //If Java is enabled, but it was disabled when this process was started
270 // then no preparational work, such as setting the LD_LIBRARY_PATH, was
271 //done. Therefore if a JRE needs it, it must not be started.
272 if (g_bEnabledSwitchedOn
&&
273 (aInfo
->nRequirements
& JFW_REQUIRE_NEEDRESTART
))
274 return JFW_E_NEED_RESTART
;
276 //Check if the selected Java was set in this process. If so it
277 //must not have the requirments flag JFW_REQUIRE_NEEDRESTART
278 if ((aInfo
->nRequirements
& JFW_REQUIRE_NEEDRESTART
)
279 && jfw::wasJavaSelectedInSameProcess())
280 return JFW_E_NEED_RESTART
;
282 vmParams
= settings
.getVmParametersUtf8();
283 sUserClassPath
= jfw::makeClassPathOption(settings
.getUserClassPath());
284 } // end mode FWK_MODE_OFFICE
285 else if (mode
== jfw::JFW_MODE_DIRECT
)
287 errcode
= jfw_getSelectedJRE(&aInfo
.pInfo
);
288 if (errcode
!= JFW_E_NONE
)
290 //In direct mode the options are specified by bootstrap variables
291 //of the form UNO_JAVA_JFW_PARAMETER_1 .. UNO_JAVA_JFW_PARAMETER_n
292 vmParams
= jfw::BootParams::getVMParameters();
294 "-Djava.class.path=" + jfw::BootParams::getClasspath();
300 assert(pInfo
!= NULL
);
302 //get the function jfw_plugin_startJavaVirtualMachine
303 jfw::VendorSettings aVendorSettings
;
305 // create JavaVMOptions array that is passed to the plugin
306 // it contains the classpath and all options set in the
308 boost::scoped_array
<JavaVMOption
> sarJOptions(
309 new JavaVMOption
[cOptions
+ 2 + vmParams
.size()]);
310 JavaVMOption
* arOpt
= sarJOptions
.get();
314 //The first argument is the classpath
315 arOpt
[0].optionString
= const_cast<char*>(sUserClassPath
.getStr());
316 arOpt
[0].extraInfo
= NULL
;
317 // Set a flag that this JVM has been created via the JNI Invocation API
318 // (used, for example, by UNO remote bridges to share a common thread pool
319 // factory among Java and native bridge implementations):
320 arOpt
[1].optionString
= const_cast<char *>("-Dorg.openoffice.native=");
321 arOpt
[1].extraInfo
= 0;
323 //add the options set by options dialog
325 typedef std::vector
<OString
>::const_iterator cit
;
326 for (cit i
= vmParams
.begin(); i
!= vmParams
.end(); ++i
)
328 arOpt
[index
].optionString
= const_cast<sal_Char
*>(i
->getStr());
329 arOpt
[index
].extraInfo
= 0;
332 //add all options of the arOptions argument
333 for (int ii
= 0; ii
< cOptions
; ii
++)
335 arOpt
[index
].optionString
= arOptions
[ii
].optionString
;
336 arOpt
[index
].extraInfo
= arOptions
[ii
].extraInfo
;
342 SAL_INFO("jfw", "Starting Java");
343 javaPluginError plerr
= jfw_plugin_startJavaVirtualMachine(pInfo
, arOpt
, index
, & pVm
, ppEnv
);
344 if (plerr
== JFW_PLUGIN_E_VM_CREATION_FAILED
)
346 errcode
= JFW_E_VM_CREATION_FAILED
;
348 else if (plerr
!= JFW_PLUGIN_E_NONE
)
350 errcode
= JFW_E_ERROR
;
357 OSL_ASSERT(plerr
!= JFW_PLUGIN_E_WRONG_VENDOR
);
359 catch (const jfw::FrameworkException
& e
)
361 errcode
= e
.errorCode
;
362 fprintf(stderr
, "%s\n", e
.message
.getStr());
363 OSL_FAIL(e
.message
.getStr());
369 /** We do not use here jfw_findAllJREs and then check if a JavaInfo
370 meets the requirements, because that means using all plug-ins, which
371 may take quite a while. The implementation first inspects JAVA_HOME and
372 PATH environment variables. If no suitable JavaInfo is found there, it
373 inspects all JavaInfos found by the jfw_plugin_get* functions.
375 javaFrameworkError SAL_CALL
jfw_findAndSelectJRE(JavaInfo
**pInfo
)
377 javaFrameworkError errcode
= JFW_E_NONE
;
380 osl::MutexGuard
guard(jfw::FwkMutex::get());
381 if (jfw::getMode() == jfw::JFW_MODE_DIRECT
)
382 return JFW_E_DIRECT_MODE
;
383 sal_uInt64 nFeatureFlags
= 0;
384 jfw::CJavaInfo aCurrentInfo
;
385 //Determine if accessibility support is needed
386 bool bSupportAccessibility
= jfw::isAccessibilitySupportDesired();
387 nFeatureFlags
= bSupportAccessibility
?
388 JFW_FEATURE_ACCESSBRIDGE
: 0L;
391 // 'bInfoFound' indicates whether a Java installation has been found
392 // that supports all desired features
393 bool bInfoFound
= false;
395 // get list of vendors for Java installations
396 jfw::VendorSettings aVendorSettings
;
397 std::vector
<OUString
> vecVendors
=
398 aVendorSettings
.getSupportedVendors();
400 // save vendors and respective version requirements pair-wise in a vector
401 std::vector
<std::pair
<OUString
, jfw::VersionInfo
>> versionInfos
;
402 typedef std::vector
<OUString
>::const_iterator ciVendor
;
403 for (ciVendor i
= vecVendors
.begin(); i
!= vecVendors
.end(); ++i
)
405 const OUString
& vendor
= *i
;
406 jfw::VersionInfo versionInfo
=
407 aVendorSettings
.getVersionInformation(vendor
);
409 versionInfos
.push_back(
410 std::pair
<OUString
, jfw::VersionInfo
>(vendor
, versionInfo
));
413 std::vector
<rtl::Reference
<jfw_plugin::VendorBase
>> infos
;
415 // first inspect Java installation that the JAVA_HOME
416 // environment variable points to (if it is set)
417 JavaInfo
* pHomeInfo
= NULL
;
418 if (jfw_plugin_getJavaInfoFromJavaHome(versionInfos
, &pHomeInfo
, infos
)
419 == JFW_PLUGIN_E_NONE
)
421 aCurrentInfo
= pHomeInfo
;
424 // if the user does not require any features (nFeatureFlags = 0)
425 // or the Java installation provides all features, then this installation is used
426 if ((pHomeInfo
->nFeatures
& nFeatureFlags
) == nFeatureFlags
)
430 jfw_freeJavaInfo(pHomeInfo
);
433 // if no Java installation providing all features was detected by using JAVA_HOME,
434 // query PATH for Java installations
437 std::vector
<JavaInfo
*> vecJavaInfosFromPath
;
438 if (jfw_plugin_getJavaInfosFromPath(
439 versionInfos
, vecJavaInfosFromPath
, infos
)
440 == JFW_PLUGIN_E_NONE
)
442 std::vector
<JavaInfo
*>::const_iterator it
= vecJavaInfosFromPath
.begin();
443 while(it
!= vecJavaInfosFromPath
.end() && !bInfoFound
)
445 JavaInfo
* pJInfo
= *it
;
448 // if the current Java installation implements all required features: use it
449 if ((pJInfo
->nFeatures
& nFeatureFlags
) == nFeatureFlags
)
451 aCurrentInfo
= pJInfo
;
454 else if ((JavaInfo
*) aCurrentInfo
== NULL
)
456 // current Java installation does not provide all features
457 // but no Java installation has been detected before
458 // -> remember the current one until one is found
459 // that provides all features
460 aCurrentInfo
= pJInfo
;
463 jfw_freeJavaInfo(pJInfo
);
471 // if no suitable Java installation has been found yet:
472 // first iterate over all vendors to find a suitable Java installation,
473 // then try paths that have been added manually
476 //Use every vendor to get Java installations. At the first usable
477 //Java the loop will break
478 typedef std::vector
<OUString
>::const_iterator ci_pl
;
479 for (ci_pl i
= vecVendors
.begin(); i
!= vecVendors
.end(); ++i
)
481 const OUString
& vendor
= *i
;
482 jfw::VersionInfo versionInfo
=
483 aVendorSettings
.getVersionInformation(vendor
);
485 //get all installations of one vendor according to minVersion,
486 //maxVersion and excludeVersions
487 sal_Int32 cInfos
= 0;
488 JavaInfo
** arInfos
= NULL
;
489 javaPluginError plerr
= jfw_plugin_getAllJavaInfos(
492 versionInfo
.sMinVersion
,
493 versionInfo
.sMaxVersion
,
494 versionInfo
.getExcludeVersions(),
495 versionInfo
.getExcludeVersionSize(),
500 if (plerr
!= JFW_PLUGIN_E_NONE
)
502 //iterate over all installations to find the best which has
506 rtl_freeMemory(arInfos
);
509 for (int ii
= 0; ii
< cInfos
; ii
++)
511 JavaInfo
* pJInfo
= arInfos
[ii
];
513 //We remember the first installation in aCurrentInfo
514 // if no JavaInfo has been found before
515 if (aCurrentInfo
.getLocation().isEmpty())
516 aCurrentInfo
= pJInfo
;
518 // If the user does not require any features (nFeatureFlags = 0)
519 // then the first installation is used
520 if ((pJInfo
->nFeatures
& nFeatureFlags
) == nFeatureFlags
)
522 //the just found Java implements all required features
523 //currently there is only accessibility!!!
524 aCurrentInfo
= pJInfo
;
529 //The array returned by jfw_plugin_getAllJavaInfos must be freed as well as
531 for (int j
= 0; j
< cInfos
; j
++)
532 jfw_freeJavaInfo(arInfos
[j
]);
533 rtl_freeMemory(arInfos
);
537 //All Java installations found by the current plug-in lib
538 //do not provide the required features. Try the next plug-in
540 if ((JavaInfo
*) aCurrentInfo
== NULL
)
541 {//The plug-ins did not find a suitable Java. Now try the paths which have been
543 //get the list of paths to jre locations which have been added manually
544 const jfw::MergedSettings settings
;
545 //node.loadFromSettings();
546 const std::vector
<OUString
> & vecJRELocations
=
547 settings
.getJRELocations();
548 //use every plug-in to determine the JavaInfo objects
549 for (ci_pl i
= vecVendors
.begin(); i
!= vecVendors
.end(); ++i
)
551 const OUString
& vendor
= *i
;
552 jfw::VersionInfo versionInfo
=
553 aVendorSettings
.getVersionInformation(vendor
);
555 typedef std::vector
<OUString
>::const_iterator citLoc
;
556 for (citLoc it
= vecJRELocations
.begin();
557 it
!= vecJRELocations
.end(); ++it
)
559 jfw::CJavaInfo aInfo
;
560 javaPluginError err
= jfw_plugin_getJavaInfoByPath(
563 versionInfo
.sMinVersion
,
564 versionInfo
.sMaxVersion
,
565 versionInfo
.getExcludeVersions(),
566 versionInfo
.getExcludeVersionSize(),
568 if (err
== JFW_PLUGIN_E_NO_JRE
)
570 if (err
== JFW_PLUGIN_E_FAILED_VERSION
)
572 else if (err
!=JFW_PLUGIN_E_NONE
)
577 //We remember the very first installation in aCurrentInfo
578 if (aCurrentInfo
.getLocation().isEmpty())
579 aCurrentInfo
= aInfo
;
581 // If the user does not require any features (nFeatureFlags = 0)
582 // then the first installation is used
583 if ((aInfo
.getFeatures() & nFeatureFlags
) == nFeatureFlags
)
585 //the just found Java implements all required features
586 //currently there is only accessibility!!!
587 aCurrentInfo
= aInfo
;
592 }//end iterate over paths
595 }// end iterate plug-ins
598 if ((JavaInfo
*) aCurrentInfo
)
600 jfw::NodeJava
javaNode(jfw::NodeJava::USER
);
601 javaNode
.setJavaInfo(aCurrentInfo
,true);
603 //remember that this JRE was selected in this process
604 jfw::setJavaSelected();
609 *pInfo
= aCurrentInfo
.cloneJavaInfo();
614 errcode
= JFW_E_NO_JAVA_FOUND
;
617 catch (const jfw::FrameworkException
& e
)
619 errcode
= e
.errorCode
;
620 fprintf(stderr
, "%s\n", e
.message
.getStr());
621 OSL_FAIL(e
.message
.getStr());
627 sal_Bool SAL_CALL
jfw_areEqualJavaInfo(
628 JavaInfo
const * pInfoA
,JavaInfo
const * pInfoB
)
630 if (pInfoA
== pInfoB
)
632 if (pInfoA
== NULL
|| pInfoB
== NULL
)
634 OUString
sVendor(pInfoA
->sVendor
);
635 OUString
sLocation(pInfoA
->sLocation
);
636 OUString
sVersion(pInfoA
->sVersion
);
637 rtl::ByteSequence
sData(pInfoA
->arVendorData
);
638 if (sVendor
.equals(pInfoB
->sVendor
)
639 && sLocation
.equals(pInfoB
->sLocation
)
640 && sVersion
.equals(pInfoB
->sVersion
)
641 && pInfoA
->nFeatures
== pInfoB
->nFeatures
642 && pInfoA
->nRequirements
== pInfoB
->nRequirements
643 && sData
== pInfoB
->arVendorData
)
651 void SAL_CALL
jfw_freeJavaInfo(JavaInfo
*pInfo
)
655 rtl_uString_release(pInfo
->sVendor
);
656 rtl_uString_release(pInfo
->sLocation
);
657 rtl_uString_release(pInfo
->sVersion
);
658 rtl_byte_sequence_release(pInfo
->arVendorData
);
659 rtl_freeMemory(pInfo
);
662 javaFrameworkError SAL_CALL
jfw_getSelectedJRE(JavaInfo
**ppInfo
)
664 javaFrameworkError errcode
= JFW_E_NONE
;
667 osl::MutexGuard
guard(jfw::FwkMutex::get());
669 return JFW_E_INVALID_ARG
;
671 if (jfw::getMode() == jfw::JFW_MODE_DIRECT
)
673 OUString sJRE
= jfw::BootParams::getJREHome();
675 jfw::CJavaInfo aInfo
;
676 if ((errcode
= jfw_getJavaInfoByPath(sJRE
.pData
, & aInfo
.pInfo
))
678 throw jfw::FrameworkException(
681 "[Java framework] The JRE specified by the bootstrap "
682 "variable UNO_JAVA_JFW_JREHOME or UNO_JAVA_JFW_ENV_JREHOME "
683 " could not be recognized. Check the values and make sure that you "
684 "use a plug-in library that can recognize that JRE."));
686 *ppInfo
= aInfo
.detach();
690 const jfw::MergedSettings settings
;
691 jfw::CJavaInfo aInfo
;
692 aInfo
.attach(settings
.createJavaInfo());
698 //If the javavendors.xml has changed, then the current selected
699 //Java is not valid anymore
700 // /java/javaInfo/@vendorUpdate != javaSelection/updated (javavendors.xml)
701 OString sUpdated
= jfw::getElementUpdated();
703 if (!sUpdated
.equals(settings
.getJavaInfoAttrVendorUpdate()))
704 return JFW_E_INVALID_SETTINGS
;
705 *ppInfo
= aInfo
.detach();
707 catch (const jfw::FrameworkException
& e
)
709 errcode
= e
.errorCode
;
710 fprintf(stderr
, "%s\n", e
.message
.getStr());
711 OSL_FAIL(e
.message
.getStr());
716 javaFrameworkError SAL_CALL
jfw_isVMRunning(sal_Bool
*bRunning
)
718 osl::MutexGuard
guard(jfw::FwkMutex::get());
719 if (bRunning
== NULL
)
720 return JFW_E_INVALID_ARG
;
721 if (g_pJavaVM
== NULL
)
722 *bRunning
= sal_False
;
724 *bRunning
= sal_True
;
728 javaFrameworkError SAL_CALL
jfw_getJavaInfoByPath(
729 rtl_uString
*pPath
, JavaInfo
**ppInfo
)
731 javaFrameworkError errcode
= JFW_E_NONE
;
734 osl::MutexGuard
guard(jfw::FwkMutex::get());
735 if (pPath
== NULL
|| ppInfo
== NULL
)
736 return JFW_E_INVALID_ARG
;
738 OUString
ouPath(pPath
);
740 jfw::VendorSettings aVendorSettings
;
741 std::vector
<OUString
> vecVendors
=
742 aVendorSettings
.getSupportedVendors();
744 //Use every plug-in library to determine if the path represents a
745 //JRE. If a plugin recognized it then the loop will break
746 typedef std::vector
<OUString
>::const_iterator ci_pl
;
747 for (ci_pl i
= vecVendors
.begin(); i
!= vecVendors
.end(); ++i
)
749 const OUString
& vendor
= *i
;
750 jfw::VersionInfo versionInfo
=
751 aVendorSettings
.getVersionInformation(vendor
);
753 //ask the plugin if this is a JRE.
754 //If so check if it meets the version requirements.
755 //Only if it does return a JavaInfo
756 JavaInfo
* pInfo
= NULL
;
757 javaPluginError plerr
= jfw_plugin_getJavaInfoByPath(
760 versionInfo
.sMinVersion
,
761 versionInfo
.sMaxVersion
,
762 versionInfo
.getExcludeVersions(),
763 versionInfo
.getExcludeVersionSize(),
766 if (plerr
== JFW_PLUGIN_E_NONE
)
771 else if(plerr
== JFW_PLUGIN_E_FAILED_VERSION
)
772 {//found JRE but it has the wrong version
774 errcode
= JFW_E_FAILED_VERSION
;
777 else if (plerr
== JFW_PLUGIN_E_NO_JRE
)
778 {// plugin does not recognize this path as belonging to JRE
783 if (*ppInfo
== NULL
&& errcode
!= JFW_E_FAILED_VERSION
)
784 errcode
= JFW_E_NOT_RECOGNIZED
;
786 catch (const jfw::FrameworkException
& e
)
788 errcode
= e
.errorCode
;
789 fprintf(stderr
, "%s\n", e
.message
.getStr());
790 OSL_FAIL(e
.message
.getStr());
797 javaFrameworkError SAL_CALL
jfw_setSelectedJRE(JavaInfo
const *pInfo
)
799 javaFrameworkError errcode
= JFW_E_NONE
;
802 osl::MutexGuard
guard(jfw::FwkMutex::get());
803 if (jfw::getMode() == jfw::JFW_MODE_DIRECT
)
804 return JFW_E_DIRECT_MODE
;
805 //check if pInfo is the selected JRE
806 JavaInfo
*currentInfo
= NULL
;
807 errcode
= jfw_getSelectedJRE( & currentInfo
);
808 if (errcode
!= JFW_E_NONE
&& errcode
!= JFW_E_INVALID_SETTINGS
)
811 if (jfw_areEqualJavaInfo(currentInfo
, pInfo
) == sal_False
)
813 jfw::NodeJava
node(jfw::NodeJava::USER
);
814 node
.setJavaInfo(pInfo
, false);
816 //remember that the JRE was selected in this process
817 jfw::setJavaSelected();
820 jfw_freeJavaInfo(currentInfo
);
822 catch (const jfw::FrameworkException
& e
)
824 errcode
= e
.errorCode
;
825 fprintf(stderr
, "%s\n", e
.message
.getStr());
826 OSL_FAIL(e
.message
.getStr());
830 javaFrameworkError SAL_CALL
jfw_setEnabled(sal_Bool bEnabled
)
832 javaFrameworkError errcode
= JFW_E_NONE
;
835 osl::MutexGuard
guard(jfw::FwkMutex::get());
836 if (jfw::getMode() == jfw::JFW_MODE_DIRECT
)
837 return JFW_E_DIRECT_MODE
;
839 if (!g_bEnabledSwitchedOn
&& bEnabled
== sal_True
)
841 //When the process started then Enabled was false.
842 //This is first time enabled is set to true.
843 //That means, no preparational work has been done, such as setting the
844 //LD_LIBRARY_PATH, etc.
846 //check if Enabled is false;
847 const jfw::MergedSettings settings
;
848 if (!settings
.getEnabled())
849 g_bEnabledSwitchedOn
= true;
851 jfw::NodeJava
node(jfw::NodeJava::USER
);
852 node
.setEnabled(bEnabled
);
855 catch (const jfw::FrameworkException
& e
)
857 errcode
= e
.errorCode
;
858 fprintf(stderr
, "%s\n", e
.message
.getStr());
859 OSL_FAIL(e
.message
.getStr());
864 javaFrameworkError SAL_CALL
jfw_getEnabled(sal_Bool
*pbEnabled
)
866 javaFrameworkError errcode
= JFW_E_NONE
;
869 if (jfw::getMode() == jfw::JFW_MODE_DIRECT
)
870 return JFW_E_DIRECT_MODE
;
871 osl::MutexGuard
guard(jfw::FwkMutex::get());
872 if (pbEnabled
== NULL
)
873 return JFW_E_INVALID_ARG
;
874 jfw::MergedSettings settings
;
875 *pbEnabled
= settings
.getEnabled();
877 catch (const jfw::FrameworkException
& e
)
879 errcode
= e
.errorCode
;
880 fprintf(stderr
, "%s\n", e
.message
.getStr());
881 OSL_FAIL(e
.message
.getStr());
887 javaFrameworkError SAL_CALL
jfw_setVMParameters(
888 rtl_uString
* * arOptions
, sal_Int32 nLen
)
890 javaFrameworkError errcode
= JFW_E_NONE
;
893 osl::MutexGuard
guard(jfw::FwkMutex::get());
894 if (jfw::getMode() == jfw::JFW_MODE_DIRECT
)
895 return JFW_E_DIRECT_MODE
;
896 jfw::NodeJava
node(jfw::NodeJava::USER
);
897 if (arOptions
== NULL
&& nLen
!= 0)
898 return JFW_E_INVALID_ARG
;
899 node
.setVmParameters(arOptions
, nLen
);
902 catch (const jfw::FrameworkException
& e
)
904 errcode
= e
.errorCode
;
905 fprintf(stderr
, "%s\n", e
.message
.getStr());
906 OSL_FAIL(e
.message
.getStr());
912 javaFrameworkError SAL_CALL
jfw_getVMParameters(
913 rtl_uString
*** parOptions
, sal_Int32
* pLen
)
915 javaFrameworkError errcode
= JFW_E_NONE
;
918 osl::MutexGuard
guard(jfw::FwkMutex::get());
919 if (jfw::getMode() == jfw::JFW_MODE_DIRECT
)
920 return JFW_E_DIRECT_MODE
;
922 if (parOptions
== NULL
|| pLen
== NULL
)
923 return JFW_E_INVALID_ARG
;
924 const jfw::MergedSettings settings
;
925 settings
.getVmParametersArray(parOptions
, pLen
);
927 catch (const jfw::FrameworkException
& e
)
929 errcode
= e
.errorCode
;
930 fprintf(stderr
, "%s\n", e
.message
.getStr());
931 OSL_FAIL(e
.message
.getStr());
936 javaFrameworkError SAL_CALL
jfw_setUserClassPath(rtl_uString
* pCp
)
938 javaFrameworkError errcode
= JFW_E_NONE
;
941 osl::MutexGuard
guard(jfw::FwkMutex::get());
942 if (jfw::getMode() == jfw::JFW_MODE_DIRECT
)
943 return JFW_E_DIRECT_MODE
;
944 jfw::NodeJava
node(jfw::NodeJava::USER
);
946 return JFW_E_INVALID_ARG
;
947 node
.setUserClassPath(pCp
);
950 catch (const jfw::FrameworkException
& e
)
952 errcode
= e
.errorCode
;
953 fprintf(stderr
, "%s\n", e
.message
.getStr());
954 OSL_FAIL(e
.message
.getStr());
959 javaFrameworkError SAL_CALL
jfw_getUserClassPath(rtl_uString
** ppCP
)
961 javaFrameworkError errcode
= JFW_E_NONE
;
964 osl::MutexGuard
guard(jfw::FwkMutex::get());
965 if (jfw::getMode() == jfw::JFW_MODE_DIRECT
)
966 return JFW_E_DIRECT_MODE
;
968 return JFW_E_INVALID_ARG
;
969 const jfw::MergedSettings settings
;
970 *ppCP
= settings
.getUserClassPath().pData
;
971 rtl_uString_acquire(*ppCP
);
973 catch (const jfw::FrameworkException
& e
)
975 errcode
= e
.errorCode
;
976 fprintf(stderr
, "%s\n", e
.message
.getStr());
977 OSL_FAIL(e
.message
.getStr());
982 javaFrameworkError SAL_CALL
jfw_addJRELocation(rtl_uString
* sLocation
)
984 javaFrameworkError errcode
= JFW_E_NONE
;
987 osl::MutexGuard
guard(jfw::FwkMutex::get());
988 if (jfw::getMode() == jfw::JFW_MODE_DIRECT
)
989 return JFW_E_DIRECT_MODE
;
990 jfw::NodeJava
node(jfw::NodeJava::USER
);
991 if (sLocation
== NULL
)
992 return JFW_E_INVALID_ARG
;
994 node
.addJRELocation(sLocation
);
997 catch (const jfw::FrameworkException
& e
)
999 errcode
= e
.errorCode
;
1000 fprintf(stderr
, "%s\n", e
.message
.getStr());
1001 OSL_FAIL(e
.message
.getStr());
1008 javaFrameworkError SAL_CALL
jfw_getJRELocations(
1009 rtl_uString
*** parLocations
, sal_Int32
*pLen
)
1011 javaFrameworkError errcode
= JFW_E_NONE
;
1014 osl::MutexGuard
guard(jfw::FwkMutex::get());
1015 if (jfw::getMode() == jfw::JFW_MODE_DIRECT
)
1016 return JFW_E_DIRECT_MODE
;
1018 if (parLocations
== NULL
|| pLen
== NULL
)
1019 return JFW_E_INVALID_ARG
;
1020 const jfw::MergedSettings settings
;
1021 settings
.getJRELocations(parLocations
, pLen
);
1023 catch (const jfw::FrameworkException
& e
)
1025 errcode
= e
.errorCode
;
1026 fprintf(stderr
, "%s\n", e
.message
.getStr());
1027 OSL_FAIL(e
.message
.getStr());
1034 javaFrameworkError
jfw_existJRE(const JavaInfo
*pInfo
, sal_Bool
*exist
)
1036 //get the function jfw_plugin_existJRE
1037 jfw::VendorSettings aVendorSettings
;
1038 jfw::CJavaInfo aInfo
;
1039 aInfo
= (const ::JavaInfo
*) pInfo
; //makes a copy of pInfo
1040 javaPluginError plerr
= jfw_plugin_existJRE(pInfo
, exist
);
1042 javaFrameworkError ret
= JFW_E_NONE
;
1045 case JFW_PLUGIN_E_NONE
:
1048 case JFW_PLUGIN_E_INVALID_ARG
:
1049 ret
= JFW_E_INVALID_ARG
;
1051 case JFW_PLUGIN_E_ERROR
:
1060 void SAL_CALL
jfw_lock()
1062 jfw::FwkMutex::get().acquire();
1065 void SAL_CALL
jfw_unlock()
1067 jfw::FwkMutex::get().release();
1073 CJavaInfo::CJavaInfo(): pInfo(0)
1077 CJavaInfo::CJavaInfo(const CJavaInfo
& info
)
1079 pInfo
= copyJavaInfo(info
.pInfo
);
1082 CJavaInfo::CJavaInfo(::JavaInfo
* info
, _transfer_ownership
)
1086 CJavaInfo
CJavaInfo::createWrapper(::JavaInfo
* info
)
1088 return CJavaInfo(info
, TRANSFER
);
1090 void CJavaInfo::attach(::JavaInfo
* info
)
1092 jfw_freeJavaInfo(pInfo
);
1095 ::JavaInfo
* CJavaInfo::detach()
1097 JavaInfo
* tmp
= pInfo
;
1102 CJavaInfo::~CJavaInfo()
1104 jfw_freeJavaInfo(pInfo
);
1108 JavaInfo
* CJavaInfo::copyJavaInfo(const JavaInfo
* pInfo
)
1113 static_cast<JavaInfo
*>(rtl_allocateMemory(sizeof(JavaInfo
)));
1116 memcpy(newInfo
, pInfo
, sizeof(JavaInfo
));
1117 rtl_uString_acquire(pInfo
->sVendor
);
1118 rtl_uString_acquire(pInfo
->sLocation
);
1119 rtl_uString_acquire(pInfo
->sVersion
);
1120 rtl_byte_sequence_acquire(pInfo
->arVendorData
);
1126 JavaInfo
* CJavaInfo::cloneJavaInfo() const
1130 return copyJavaInfo(pInfo
);
1133 CJavaInfo
& CJavaInfo::operator = (const CJavaInfo
& info
)
1138 jfw_freeJavaInfo(pInfo
);
1139 pInfo
= copyJavaInfo(info
.pInfo
);
1142 CJavaInfo
& CJavaInfo::operator = (const ::JavaInfo
* info
)
1147 jfw_freeJavaInfo(pInfo
);
1148 pInfo
= copyJavaInfo(info
);
1152 OUString
CJavaInfo::getLocation() const
1155 return OUString(pInfo
->sLocation
);
1160 sal_uInt64
CJavaInfo::getFeatures() const
1163 return pInfo
->nFeatures
;
1170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */