136f55ffcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
336f55ffcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
436f55ffcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
536f55ffcSAndrew Rist  * distributed with this work for additional information
636f55ffcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
736f55ffcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
836f55ffcSAndrew Rist  * "License"); you may not use this file except in compliance
936f55ffcSAndrew Rist  * with the License.  You may obtain a copy of the License at
1036f55ffcSAndrew Rist  *
1136f55ffcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1236f55ffcSAndrew Rist  *
1336f55ffcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
1436f55ffcSAndrew Rist  * software distributed under the License is distributed on an
1536f55ffcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1636f55ffcSAndrew Rist  * KIND, either express or implied.  See the License for the
1736f55ffcSAndrew Rist  * specific language governing permissions and limitations
1836f55ffcSAndrew Rist  * under the License.
1936f55ffcSAndrew Rist  *
2036f55ffcSAndrew Rist  *************************************************************/
2136f55ffcSAndrew Rist 
2236f55ffcSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
258cb913c4SDamjan Jovanovic #include "precompiled_plugin.hxx"
26cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
27cdf0e10cSrcweir #include <stdio.h>
28cdf0e10cSrcweir #endif
29cdf0e10cSrcweir #include <string.h>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "boost/scoped_array.hpp"
32cdf0e10cSrcweir #include "osl/diagnose.h"
33cdf0e10cSrcweir #include "rtl/ustring.hxx"
34cdf0e10cSrcweir #include "rtl/ustrbuf.hxx"
35cdf0e10cSrcweir #include "osl/module.hxx"
36cdf0e10cSrcweir #include "osl/mutex.hxx"
37cdf0e10cSrcweir #include "osl/thread.hxx"
38cdf0e10cSrcweir #include "osl/file.hxx"
39cdf0e10cSrcweir #include "rtl/instance.hxx"
40cdf0e10cSrcweir #include "osl/getglobalmutex.hxx"
41cdf0e10cSrcweir #include <setjmp.h>
42cdf0e10cSrcweir #include <signal.h>
43cdf0e10cSrcweir #include <stack>
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #include "jni.h"
46cdf0e10cSrcweir #include "rtl/byteseq.hxx"
47cdf0e10cSrcweir #include "jvmfwk/vendorplugin.h"
48cdf0e10cSrcweir #include "util.hxx"
49cdf0e10cSrcweir #include "sunversion.hxx"
50cdf0e10cSrcweir #include "vendorlist.hxx"
51cdf0e10cSrcweir #include "diagnostics.h"
52cdf0e10cSrcweir 
53cdf0e10cSrcweir #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
54cdf0e10cSrcweir #define SUN_MICRO "Sun Microsystems Inc."
55cdf0e10cSrcweir 
56cdf0e10cSrcweir using namespace osl;
57cdf0e10cSrcweir using namespace rtl;
58cdf0e10cSrcweir using namespace std;
59cdf0e10cSrcweir using namespace jfw_plugin;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir namespace {
62cdf0e10cSrcweir 
63cdf0e10cSrcweir struct PluginMutex: public ::rtl::Static<osl::Mutex, PluginMutex> {};
64cdf0e10cSrcweir 
65cdf0e10cSrcweir #if defined UNX
getPluginJarPath(const OUString & sVendor,const OUString & sLocation,const OUString & sVersion)66cdf0e10cSrcweir OString getPluginJarPath(
67cdf0e10cSrcweir     const OUString & sVendor,
68cdf0e10cSrcweir     const OUString& sLocation,
69cdf0e10cSrcweir     const OUString& sVersion)
70cdf0e10cSrcweir {
71cdf0e10cSrcweir     OString ret;
72cdf0e10cSrcweir     OUString sName1(RTL_CONSTASCII_USTRINGPARAM("javaplugin.jar"));
73cdf0e10cSrcweir     OUString sName2(RTL_CONSTASCII_USTRINGPARAM("plugin.jar"));
74cdf0e10cSrcweir     OUString sPath;
75cdf0e10cSrcweir     if (sVendor.equals(OUString(RTL_CONSTASCII_USTRINGPARAM(SUN_MICRO))))
76cdf0e10cSrcweir     {
77cdf0e10cSrcweir         SunVersion ver142("1.4.2-ea");
78cdf0e10cSrcweir         SunVersion ver150("1.5.0-ea");
79cdf0e10cSrcweir         SunVersion ver(sVersion);
80cdf0e10cSrcweir         OSL_ASSERT(ver142 && ver150 && ver);
81cdf0e10cSrcweir 
82cdf0e10cSrcweir         OUString sName;
83cdf0e10cSrcweir         if (ver < ver142)
84cdf0e10cSrcweir         {
85cdf0e10cSrcweir             sName = sName1;
86cdf0e10cSrcweir         }
87cdf0e10cSrcweir         else if (ver < ver150)
88cdf0e10cSrcweir         {//this will cause ea, beta etc. to have plugin.jar in path.
89cdf0e10cSrcweir             //but this does not harm. 1.5.0-beta < 1.5.0
90cdf0e10cSrcweir             sName = sName2;
91cdf0e10cSrcweir         }
92cdf0e10cSrcweir         if (sName.getLength())
93cdf0e10cSrcweir         {
94cdf0e10cSrcweir             sName = sLocation + OUSTR("/lib/") + sName;
95cdf0e10cSrcweir             OSL_VERIFY(
96cdf0e10cSrcweir                 osl_getSystemPathFromFileURL(sName.pData, & sPath.pData)
97cdf0e10cSrcweir                 == osl_File_E_None);
98cdf0e10cSrcweir         }
99cdf0e10cSrcweir     }
100cdf0e10cSrcweir     else
101cdf0e10cSrcweir     {
102cdf0e10cSrcweir         char sep[] =  {SAL_PATHSEPARATOR, 0};
103cdf0e10cSrcweir         OUString sName(sLocation + OUSTR("/lib/") + sName1);
104cdf0e10cSrcweir         OUString sPath1;
105cdf0e10cSrcweir         OUString sPath2;
106cdf0e10cSrcweir         if (osl_getSystemPathFromFileURL(sName.pData, & sPath1.pData)
107cdf0e10cSrcweir             == osl_File_E_None)
108cdf0e10cSrcweir         {
109cdf0e10cSrcweir             sName = sLocation + OUSTR("/lib/") + sName2;
110cdf0e10cSrcweir             if (osl_getSystemPathFromFileURL(sName.pData, & sPath2.pData)
111cdf0e10cSrcweir                 == osl_File_E_None)
112cdf0e10cSrcweir             {
113cdf0e10cSrcweir                 sPath = sPath1 + OUString::createFromAscii(sep) + sPath2;
114cdf0e10cSrcweir             }
115cdf0e10cSrcweir         }
116cdf0e10cSrcweir         OSL_ASSERT(sPath.getLength());
117cdf0e10cSrcweir     }
118cdf0e10cSrcweir     ret = rtl::OUStringToOString(sPath, osl_getThreadTextEncoding());
119cdf0e10cSrcweir 
120cdf0e10cSrcweir     return ret;
121cdf0e10cSrcweir }
122cdf0e10cSrcweir #endif // UNX
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 
createJavaInfo(const rtl::Reference<VendorBase> & info)125cdf0e10cSrcweir JavaInfo* createJavaInfo(const rtl::Reference<VendorBase> & info)
126cdf0e10cSrcweir {
127cdf0e10cSrcweir     JavaInfo* pInfo = (JavaInfo*) rtl_allocateMemory(sizeof(JavaInfo));
128cdf0e10cSrcweir     if (pInfo == NULL)
129cdf0e10cSrcweir         return NULL;
130cdf0e10cSrcweir     rtl::OUString sVendor = info->getVendor();
131cdf0e10cSrcweir     pInfo->sVendor = sVendor.pData;
132cdf0e10cSrcweir     rtl_uString_acquire(sVendor.pData);
133cdf0e10cSrcweir     rtl::OUString sHome = info->getHome();
134cdf0e10cSrcweir     pInfo->sLocation = sHome.pData;
135cdf0e10cSrcweir     rtl_uString_acquire(pInfo->sLocation);
136cdf0e10cSrcweir     rtl::OUString sVersion = info->getVersion();
137cdf0e10cSrcweir     pInfo->sVersion = sVersion.pData;
138cdf0e10cSrcweir     rtl_uString_acquire(pInfo->sVersion);
139cdf0e10cSrcweir     pInfo->nFeatures = info->supportsAccessibility() ? 1 : 0;
140cdf0e10cSrcweir     pInfo->nRequirements = info->needsRestart() ? JFW_REQUIRE_NEEDRESTART : 0;
141cdf0e10cSrcweir     rtl::OUStringBuffer buf(1024);
142cdf0e10cSrcweir     buf.append(info->getRuntimeLibrary());
143cdf0e10cSrcweir     if (info->getLibraryPaths().getLength() > 0)
144cdf0e10cSrcweir     {
145cdf0e10cSrcweir         buf.appendAscii("\n");
146cdf0e10cSrcweir         buf.append(info->getLibraryPaths());
147cdf0e10cSrcweir         buf.appendAscii("\n");
148cdf0e10cSrcweir     }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     rtl::OUString sVendorData = buf.makeStringAndClear();
151cdf0e10cSrcweir     rtl::ByteSequence byteSeq( (sal_Int8*) sVendorData.pData->buffer,
152cdf0e10cSrcweir                                sVendorData.getLength() * sizeof(sal_Unicode));
153cdf0e10cSrcweir     pInfo->arVendorData = byteSeq.get();
154cdf0e10cSrcweir     rtl_byte_sequence_acquire(pInfo->arVendorData);
155cdf0e10cSrcweir 
156cdf0e10cSrcweir     return pInfo;
157cdf0e10cSrcweir }
158cdf0e10cSrcweir 
getRuntimeLib(const rtl::ByteSequence & data)159cdf0e10cSrcweir rtl::OUString getRuntimeLib(const rtl::ByteSequence & data)
160cdf0e10cSrcweir {
161cdf0e10cSrcweir     const sal_Unicode* chars = (sal_Unicode*) data.getConstArray();
162cdf0e10cSrcweir     sal_Int32 len = data.getLength();
163cdf0e10cSrcweir     rtl::OUString sData(chars, len / 2);
164cdf0e10cSrcweir     //the runtime lib is on the first line
165cdf0e10cSrcweir     sal_Int32 index = 0;
166cdf0e10cSrcweir     rtl::OUString aToken = sData.getToken( 0, '\n', index);
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     return aToken;
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir jmp_buf jmp_jvm_abort;
172cdf0e10cSrcweir sig_atomic_t g_bInGetJavaVM = 0;
173cdf0e10cSrcweir 
abort_handler()174cdf0e10cSrcweir extern "C" void JNICALL abort_handler()
175cdf0e10cSrcweir {
176cdf0e10cSrcweir     // If we are within JNI_CreateJavaVM then we jump back into getJavaVM
177cdf0e10cSrcweir     if( g_bInGetJavaVM != 0 )
178cdf0e10cSrcweir     {
179cdf0e10cSrcweir         fprintf( stderr, "JavaVM: JNI_CreateJavaVM called _exit, caught by abort_handler in javavm.cxx\n");
180cdf0e10cSrcweir         longjmp( jmp_jvm_abort, 0);
181cdf0e10cSrcweir     }
182cdf0e10cSrcweir }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir }
185cdf0e10cSrcweir 
186cdf0e10cSrcweir extern "C"
jfw_plugin_getAllJavaInfos(rtl_uString * sVendor,rtl_uString * sMinVersion,rtl_uString * sMaxVersion,rtl_uString ** arExcludeList,sal_Int32 nLenList,JavaInfo *** parJavaInfo,sal_Int32 * nLenInfoList)187cdf0e10cSrcweir javaPluginError jfw_plugin_getAllJavaInfos(
188cdf0e10cSrcweir     rtl_uString *sVendor,
189cdf0e10cSrcweir     rtl_uString *sMinVersion,
190cdf0e10cSrcweir     rtl_uString *sMaxVersion,
191cdf0e10cSrcweir     rtl_uString  * *arExcludeList,
192cdf0e10cSrcweir     sal_Int32  nLenList,
193cdf0e10cSrcweir     JavaInfo*** parJavaInfo,
194cdf0e10cSrcweir     sal_Int32 *nLenInfoList)
195cdf0e10cSrcweir {
196cdf0e10cSrcweir     OSL_ASSERT(sVendor);
197cdf0e10cSrcweir     OSL_ASSERT(sMinVersion);
198cdf0e10cSrcweir     OSL_ASSERT(sMaxVersion);
199cdf0e10cSrcweir     OSL_ASSERT(parJavaInfo);
200cdf0e10cSrcweir     OSL_ASSERT(parJavaInfo);
201cdf0e10cSrcweir     OSL_ASSERT(nLenInfoList);
202cdf0e10cSrcweir     if (!sVendor || !sMinVersion || !sMaxVersion || !parJavaInfo || !nLenInfoList)
203cdf0e10cSrcweir         return JFW_PLUGIN_E_INVALID_ARG;
204cdf0e10cSrcweir 
205cdf0e10cSrcweir     //nLenlist contains the number of element in arExcludeList.
206cdf0e10cSrcweir     //If no exclude list is provided then nLenList must be 0
207cdf0e10cSrcweir     OSL_ASSERT( ! (arExcludeList == NULL && nLenList > 0));
208cdf0e10cSrcweir     if (arExcludeList == NULL && nLenList > 0)
209cdf0e10cSrcweir         return JFW_PLUGIN_E_INVALID_ARG;
210cdf0e10cSrcweir 
211cdf0e10cSrcweir     OUString ouVendor(sVendor);
212cdf0e10cSrcweir     OUString ouMinVer(sMinVersion);
213cdf0e10cSrcweir     OUString ouMaxVer(sMaxVersion);
214cdf0e10cSrcweir 
215cdf0e10cSrcweir     OSL_ASSERT(ouVendor.getLength() > 0);
216cdf0e10cSrcweir     if (ouVendor.getLength() == 0)
217cdf0e10cSrcweir         return JFW_PLUGIN_E_INVALID_ARG;
218cdf0e10cSrcweir 
219cdf0e10cSrcweir     JavaInfo** arInfo = NULL;
220cdf0e10cSrcweir 
221cdf0e10cSrcweir     //Find all JREs
222cdf0e10cSrcweir     vector<rtl::Reference<VendorBase> > vecInfos =
223cdf0e10cSrcweir         getAllJREInfos();
224cdf0e10cSrcweir     vector<rtl::Reference<VendorBase> > vecVerifiedInfos;
225cdf0e10cSrcweir 
226cdf0e10cSrcweir     typedef vector<rtl::Reference<VendorBase> >::iterator it;
227cdf0e10cSrcweir     for (it i= vecInfos.begin(); i != vecInfos.end(); i++)
228cdf0e10cSrcweir     {
229cdf0e10cSrcweir         const rtl::Reference<VendorBase>& cur = *i;
230cdf0e10cSrcweir 
231cdf0e10cSrcweir         if (ouVendor.equals(cur->getVendor()) == sal_False)
232cdf0e10cSrcweir             continue;
233cdf0e10cSrcweir 
234cdf0e10cSrcweir         if (ouMinVer.getLength() > 0)
235cdf0e10cSrcweir         {
236cdf0e10cSrcweir             try
237cdf0e10cSrcweir             {
238cdf0e10cSrcweir                 if (cur->compareVersions(sMinVersion) == -1)
239cdf0e10cSrcweir                     continue;
240cdf0e10cSrcweir             }
241cdf0e10cSrcweir             catch (MalformedVersionException&)
242cdf0e10cSrcweir             {
243cdf0e10cSrcweir                 //The minVersion was not recognized as valid for this vendor.
244cdf0e10cSrcweir                 JFW_ENSURE(
245cdf0e10cSrcweir                     0,OUSTR("[Java framework]sunjavaplugin does not know version: ")
246cdf0e10cSrcweir                     + ouMinVer + OUSTR(" for vendor: ") + cur->getVendor()
247cdf0e10cSrcweir                     + OUSTR(" .Check minimum Version.") );
248cdf0e10cSrcweir                 return JFW_PLUGIN_E_WRONG_VERSION_FORMAT;
249cdf0e10cSrcweir             }
250cdf0e10cSrcweir         }
251cdf0e10cSrcweir 
252cdf0e10cSrcweir         if (ouMaxVer.getLength() > 0)
253cdf0e10cSrcweir         {
254cdf0e10cSrcweir             try
255cdf0e10cSrcweir             {
256cdf0e10cSrcweir                 if (cur->compareVersions(sMaxVersion) == 1)
257cdf0e10cSrcweir                     continue;
258cdf0e10cSrcweir             }
259cdf0e10cSrcweir             catch (MalformedVersionException&)
260cdf0e10cSrcweir             {
261cdf0e10cSrcweir                 //The maxVersion was not recognized as valid for this vendor.
262cdf0e10cSrcweir                 JFW_ENSURE(
263cdf0e10cSrcweir                     0,OUSTR("[Java framework]sunjavaplugin does not know version: ")
264cdf0e10cSrcweir                     + ouMaxVer + OUSTR(" for vendor: ") + cur->getVendor()
265cdf0e10cSrcweir                     + OUSTR(" .Check maximum Version.") );
266cdf0e10cSrcweir                 return JFW_PLUGIN_E_WRONG_VERSION_FORMAT;
267cdf0e10cSrcweir             }
268cdf0e10cSrcweir         }
269cdf0e10cSrcweir 
27093358cf7SHerbert Dürr         if( arExcludeList != NULL)
271cdf0e10cSrcweir         {
272cdf0e10cSrcweir             bool bExclude = false;
273cdf0e10cSrcweir             for (int j = 0; j < nLenList; j++)
274cdf0e10cSrcweir             {
275cdf0e10cSrcweir                 rtl::OUString sExVer(arExcludeList[j]);
276cdf0e10cSrcweir                 try
277cdf0e10cSrcweir                 {
278cdf0e10cSrcweir                     if (cur->compareVersions(sExVer) == 0)
279cdf0e10cSrcweir                     {
280cdf0e10cSrcweir                         bExclude = true;
281cdf0e10cSrcweir                         break;
282cdf0e10cSrcweir                     }
283cdf0e10cSrcweir                 }
284cdf0e10cSrcweir                 catch (MalformedVersionException&)
285cdf0e10cSrcweir                 {
286cdf0e10cSrcweir                     //The excluded version was not recognized as valid for this vendor.
287cdf0e10cSrcweir                     JFW_ENSURE(
288cdf0e10cSrcweir                         0,OUSTR("[Java framework]sunjavaplugin does not know version: ")
289cdf0e10cSrcweir                         + sExVer + OUSTR(" for vendor: ") + cur->getVendor()
290cdf0e10cSrcweir                         + OUSTR(" .Check excluded versions.") );
291cdf0e10cSrcweir                     return JFW_PLUGIN_E_WRONG_VERSION_FORMAT;
292cdf0e10cSrcweir                 }
293cdf0e10cSrcweir             }
294cdf0e10cSrcweir             if (bExclude == true)
295cdf0e10cSrcweir                 continue;
296cdf0e10cSrcweir         }
297cdf0e10cSrcweir         vecVerifiedInfos.push_back(*i);
298cdf0e10cSrcweir     }
299cdf0e10cSrcweir     //Now vecVerifiedInfos contains all those JREs which meet the version requirements
300cdf0e10cSrcweir     //Transfer them into the array that is passed out.
301cdf0e10cSrcweir     arInfo = (JavaInfo**) rtl_allocateMemory(vecVerifiedInfos.size() * sizeof (JavaInfo*));
302cdf0e10cSrcweir     int j = 0;
303cdf0e10cSrcweir     typedef vector<rtl::Reference<VendorBase> >::const_iterator cit;
304cdf0e10cSrcweir     for (cit ii = vecVerifiedInfos.begin(); ii != vecVerifiedInfos.end(); ii++, j++)
305cdf0e10cSrcweir     {
306cdf0e10cSrcweir         arInfo[j] = createJavaInfo(*ii);
307cdf0e10cSrcweir     }
308cdf0e10cSrcweir     *nLenInfoList = vecVerifiedInfos.size();
309cdf0e10cSrcweir 
310cdf0e10cSrcweir 
311cdf0e10cSrcweir     *parJavaInfo = arInfo;
312cdf0e10cSrcweir     return JFW_PLUGIN_E_NONE;
313cdf0e10cSrcweir }
314cdf0e10cSrcweir 
315cdf0e10cSrcweir extern "C"
jfw_plugin_getJavaInfoByPath(rtl_uString * path,rtl_uString * sVendor,rtl_uString * sMinVersion,rtl_uString * sMaxVersion,rtl_uString ** arExcludeList,sal_Int32 nLenList,JavaInfo ** ppInfo)316cdf0e10cSrcweir javaPluginError jfw_plugin_getJavaInfoByPath(
317cdf0e10cSrcweir     rtl_uString *path,
318cdf0e10cSrcweir     rtl_uString *sVendor,
319cdf0e10cSrcweir     rtl_uString *sMinVersion,
320cdf0e10cSrcweir     rtl_uString *sMaxVersion,
321cdf0e10cSrcweir     rtl_uString  *  *arExcludeList,
322cdf0e10cSrcweir     sal_Int32  nLenList,
323cdf0e10cSrcweir     JavaInfo ** ppInfo)
324cdf0e10cSrcweir {
325cdf0e10cSrcweir     javaPluginError errcode = JFW_PLUGIN_E_NONE;
326cdf0e10cSrcweir 
327cdf0e10cSrcweir     OSL_ASSERT(path);
328cdf0e10cSrcweir     OSL_ASSERT(sVendor);
329cdf0e10cSrcweir     OSL_ASSERT(sMinVersion);
330cdf0e10cSrcweir     OSL_ASSERT(sMaxVersion);
331cdf0e10cSrcweir     if (!path || !sVendor || !sMinVersion || !sMaxVersion || !ppInfo)
332cdf0e10cSrcweir         return JFW_PLUGIN_E_INVALID_ARG;
333cdf0e10cSrcweir     OUString ouPath(path);
334cdf0e10cSrcweir     OSL_ASSERT(ouPath.getLength() > 0);
335cdf0e10cSrcweir     if (ouPath.getLength() == 0)
336cdf0e10cSrcweir         return JFW_PLUGIN_E_INVALID_ARG;
337cdf0e10cSrcweir 
338cdf0e10cSrcweir     //nLenlist contains the number of element in arExcludeList.
339cdf0e10cSrcweir     //If no exclude list is provided then nLenList must be 0
340cdf0e10cSrcweir     OSL_ASSERT( ! (arExcludeList == NULL && nLenList > 0));
341cdf0e10cSrcweir     if (arExcludeList == NULL && nLenList > 0)
342cdf0e10cSrcweir         return JFW_PLUGIN_E_INVALID_ARG;
343cdf0e10cSrcweir 
344cdf0e10cSrcweir     OUString ouVendor(sVendor);
345cdf0e10cSrcweir     OUString ouMinVer(sMinVersion);
346cdf0e10cSrcweir     OUString ouMaxVer(sMaxVersion);
347cdf0e10cSrcweir 
348cdf0e10cSrcweir     OSL_ASSERT(ouVendor.getLength() > 0);
349cdf0e10cSrcweir     if (ouVendor.getLength() == 0)
350cdf0e10cSrcweir         return JFW_PLUGIN_E_INVALID_ARG;
351cdf0e10cSrcweir 
352cdf0e10cSrcweir     rtl::Reference<VendorBase> aVendorInfo = getJREInfoByPath(ouPath);
353cdf0e10cSrcweir     if (aVendorInfo.is() == sal_False)
354cdf0e10cSrcweir         return JFW_PLUGIN_E_NO_JRE;
355cdf0e10cSrcweir 
356cdf0e10cSrcweir     //Check if the detected JRE matches the version requirements
357cdf0e10cSrcweir     if (ouVendor.equals(aVendorInfo->getVendor()) == sal_False)
358cdf0e10cSrcweir         return JFW_PLUGIN_E_NO_JRE;
359cdf0e10cSrcweir 
360cdf0e10cSrcweir     if (ouMinVer.getLength() > 0)
361cdf0e10cSrcweir     {
362cdf0e10cSrcweir         int nRes = 0;
363cdf0e10cSrcweir         try
364cdf0e10cSrcweir         {
365cdf0e10cSrcweir             nRes = aVendorInfo->compareVersions(ouMinVer);
366cdf0e10cSrcweir         }
367cdf0e10cSrcweir         catch (MalformedVersionException&)
368cdf0e10cSrcweir         {
369cdf0e10cSrcweir             //The minVersion was not recognized as valid for this vendor.
370cdf0e10cSrcweir             JFW_ENSURE(
371cdf0e10cSrcweir                 0,OUSTR("[Java framework]sunjavaplugin does not know version: ")
372cdf0e10cSrcweir                 + ouMinVer + OUSTR(" for vendor: ") + aVendorInfo->getVendor()
373cdf0e10cSrcweir                 + OUSTR(" .Check minimum Version.") );
374cdf0e10cSrcweir             return JFW_PLUGIN_E_WRONG_VERSION_FORMAT;
375cdf0e10cSrcweir         }
376cdf0e10cSrcweir         if (nRes < 0)
377cdf0e10cSrcweir             return JFW_PLUGIN_E_FAILED_VERSION;
378cdf0e10cSrcweir     }
379cdf0e10cSrcweir 
380cdf0e10cSrcweir     if (ouMaxVer.getLength() > 0)
381cdf0e10cSrcweir     {
382cdf0e10cSrcweir         int nRes = 0;
383cdf0e10cSrcweir         try
384cdf0e10cSrcweir         {
385cdf0e10cSrcweir             nRes = aVendorInfo->compareVersions(ouMaxVer);
386cdf0e10cSrcweir         }
387cdf0e10cSrcweir         catch (MalformedVersionException&)
388cdf0e10cSrcweir         {
389cdf0e10cSrcweir             //The maxVersion was not recognized as valid for this vendor.
390cdf0e10cSrcweir             JFW_ENSURE(
391cdf0e10cSrcweir                 0,OUSTR("[Java framework]sunjavaplugin does not know version: ")
392cdf0e10cSrcweir                 + ouMaxVer + OUSTR(" for vendor: ") + aVendorInfo->getVendor()
393cdf0e10cSrcweir                 + OUSTR(" .Check maximum Version.") );
394cdf0e10cSrcweir             return JFW_PLUGIN_E_WRONG_VERSION_FORMAT;
395cdf0e10cSrcweir         }
396cdf0e10cSrcweir         if (nRes > 0)
397cdf0e10cSrcweir             return JFW_PLUGIN_E_FAILED_VERSION;
398cdf0e10cSrcweir     }
399cdf0e10cSrcweir 
40093358cf7SHerbert Dürr     if( arExcludeList != NULL)
401cdf0e10cSrcweir     {
402cdf0e10cSrcweir         for (int i = 0; i < nLenList; i++)
403cdf0e10cSrcweir         {
404cdf0e10cSrcweir             rtl::OUString sExVer(arExcludeList[i]);
405cdf0e10cSrcweir             int nRes = 0;
406cdf0e10cSrcweir             try
407cdf0e10cSrcweir             {
408cdf0e10cSrcweir                 nRes = aVendorInfo->compareVersions(sExVer);
409cdf0e10cSrcweir             }
410cdf0e10cSrcweir             catch (MalformedVersionException&)
411cdf0e10cSrcweir             {
412cdf0e10cSrcweir                 //The excluded version was not recognized as valid for this vendor.
413cdf0e10cSrcweir                 JFW_ENSURE(
414cdf0e10cSrcweir                     0,OUSTR("[Java framework]sunjavaplugin does not know version: ")
415cdf0e10cSrcweir                     + sExVer + OUSTR(" for vendor: ") + aVendorInfo->getVendor()
416cdf0e10cSrcweir                     + OUSTR(" .Check excluded versions.") );
417cdf0e10cSrcweir                 return JFW_PLUGIN_E_WRONG_VERSION_FORMAT;
418cdf0e10cSrcweir             }
419cdf0e10cSrcweir             if (nRes == 0)
420cdf0e10cSrcweir                 return JFW_PLUGIN_E_FAILED_VERSION;
421cdf0e10cSrcweir         }
422cdf0e10cSrcweir     }
423cdf0e10cSrcweir     *ppInfo = createJavaInfo(aVendorInfo);
424cdf0e10cSrcweir 
425cdf0e10cSrcweir     return errcode;
426cdf0e10cSrcweir }
427cdf0e10cSrcweir 
428cdf0e10cSrcweir /** starts a Java Virtual Machine.
429cdf0e10cSrcweir     <p>
430cdf0e10cSrcweir     The function shall ensure, that the VM does not abort the process
431cdf0e10cSrcweir     during instantiation.
432cdf0e10cSrcweir     </p>
433cdf0e10cSrcweir  */
434cdf0e10cSrcweir extern "C"
jfw_plugin_startJavaVirtualMachine(const JavaInfo * pInfo,const JavaVMOption * arOptions,sal_Int32 cOptions,JavaVM ** ppVm,JNIEnv ** ppEnv)435cdf0e10cSrcweir javaPluginError jfw_plugin_startJavaVirtualMachine(
436cdf0e10cSrcweir     const JavaInfo *pInfo,
437cdf0e10cSrcweir     const JavaVMOption* arOptions,
438cdf0e10cSrcweir     sal_Int32 cOptions,
439cdf0e10cSrcweir     JavaVM ** ppVm,
440cdf0e10cSrcweir     JNIEnv ** ppEnv)
441cdf0e10cSrcweir {
442cdf0e10cSrcweir     // unless guard is volatile the following warning occurs on gcc:
443cdf0e10cSrcweir     // warning: variable 't' might be clobbered by `longjmp' or `vfork'
444cdf0e10cSrcweir     volatile osl::MutexGuard guard(PluginMutex::get());
445cdf0e10cSrcweir     // unless errcode is volatile the following warning occurs on gcc:
446cdf0e10cSrcweir     // warning: variable 'errcode' might be clobbered by `longjmp' or `vfork'
447cdf0e10cSrcweir     volatile javaPluginError errcode = JFW_PLUGIN_E_NONE;
448cdf0e10cSrcweir     if ( pInfo == NULL || ppVm == NULL || ppEnv == NULL)
449cdf0e10cSrcweir         return JFW_PLUGIN_E_INVALID_ARG;
450cdf0e10cSrcweir     //Check if the Vendor (pInfo->sVendor) is supported by this plugin
451cdf0e10cSrcweir     if ( ! isVendorSupported(pInfo->sVendor))
452cdf0e10cSrcweir         return JFW_PLUGIN_E_WRONG_VENDOR;
453cdf0e10cSrcweir     rtl::OUString sRuntimeLib = getRuntimeLib(pInfo->arVendorData);
454cdf0e10cSrcweir     JFW_TRACE2(OUSTR("[Java framework] Using Java runtime library: ")
455cdf0e10cSrcweir               + sRuntimeLib + OUSTR(".\n"));
456cdf0e10cSrcweir     // On linux we load jvm with RTLD_GLOBAL. This is necessary for debugging, because
457cdf0e10cSrcweir     // libjdwp.so need a symbol (fork1) from libjvm which it only gets if the jvm is loaded
458cdf0e10cSrcweir     // witd RTLD_GLOBAL. On Solaris libjdwp.so is correctly linked with libjvm.so
459cdf0e10cSrcweir     oslModule moduleRt = 0;
460cdf0e10cSrcweir #if defined(LINUX)
461cdf0e10cSrcweir     if ((moduleRt = osl_loadModule(sRuntimeLib.pData,
462cdf0e10cSrcweir                                    SAL_LOADMODULE_GLOBAL | SAL_LOADMODULE_NOW)) == 0 )
463cdf0e10cSrcweir #else
464cdf0e10cSrcweir     if ((moduleRt = osl_loadModule(sRuntimeLib.pData, SAL_LOADMODULE_DEFAULT)) == 0)
465cdf0e10cSrcweir #endif
466cdf0e10cSrcweir      {
467cdf0e10cSrcweir          JFW_ENSURE(0, OUSTR("[Java framework]sunjavaplugin" SAL_DLLEXTENSION
468cdf0e10cSrcweir                              " could not load Java runtime library: \n")
469cdf0e10cSrcweir                     + sRuntimeLib + OUSTR("\n"));
470cdf0e10cSrcweir          JFW_TRACE0(OUSTR("[Java framework]sunjavaplugin" SAL_DLLEXTENSION
471cdf0e10cSrcweir                              " could not load Java runtime library: \n")
472cdf0e10cSrcweir                     + sRuntimeLib +  OUSTR("\n"));
473cdf0e10cSrcweir          return JFW_PLUGIN_E_VM_CREATION_FAILED;
474cdf0e10cSrcweir      }
475cdf0e10cSrcweir 
476cdf0e10cSrcweir #ifdef UNX
477cdf0e10cSrcweir     //Setting the JAVA_HOME is needed for awt
478cdf0e10cSrcweir     rtl::OUString javaHome(RTL_CONSTASCII_USTRINGPARAM("JAVA_HOME="));
479cdf0e10cSrcweir     rtl::OUString sPathLocation;
480cdf0e10cSrcweir     osl_getSystemPathFromFileURL(pInfo->sLocation, & sPathLocation.pData);
481cdf0e10cSrcweir     javaHome += sPathLocation;
482cdf0e10cSrcweir     rtl::OString osJavaHome = rtl::OUStringToOString(
483cdf0e10cSrcweir         javaHome, osl_getThreadTextEncoding());
484cdf0e10cSrcweir     putenv(strdup(osJavaHome.getStr()));
485cdf0e10cSrcweir #endif
486cdf0e10cSrcweir 
487cdf0e10cSrcweir     typedef jint JNICALL JNI_InitArgs_Type(void *);
488cdf0e10cSrcweir     typedef jint JNICALL JNI_CreateVM_Type(JavaVM **, JNIEnv **, void *);
489cdf0e10cSrcweir     rtl::OUString sSymbolCreateJava(
490cdf0e10cSrcweir             RTL_CONSTASCII_USTRINGPARAM("JNI_CreateJavaVM"));
491cdf0e10cSrcweir 
492cdf0e10cSrcweir     JNI_CreateVM_Type * pCreateJavaVM = (JNI_CreateVM_Type *) osl_getFunctionSymbol(
493cdf0e10cSrcweir         moduleRt, sSymbolCreateJava.pData);
494cdf0e10cSrcweir     if (!pCreateJavaVM)
495cdf0e10cSrcweir     {
496cdf0e10cSrcweir         OSL_ASSERT(0);
497cdf0e10cSrcweir         rtl::OString sLib = rtl::OUStringToOString(
498cdf0e10cSrcweir             sRuntimeLib, osl_getThreadTextEncoding());
499cdf0e10cSrcweir         rtl::OString sSymbol = rtl::OUStringToOString(
500cdf0e10cSrcweir             sSymbolCreateJava, osl_getThreadTextEncoding());
5016f51c329SHerbert Dürr         fprintf(stderr,"[Java framework]sunjavaplugin" SAL_DLLEXTENSION
502cdf0e10cSrcweir                 "Java runtime library: %s does not export symbol %s !\n",
503cdf0e10cSrcweir                 sLib.getStr(), sSymbol.getStr());
504cdf0e10cSrcweir         return JFW_PLUGIN_E_VM_CREATION_FAILED;
505cdf0e10cSrcweir     }
506cdf0e10cSrcweir 
507cdf0e10cSrcweir     // Some testing with Java 1.4 showed that JavaVMOption.optionString has to
508cdf0e10cSrcweir     // be encoded with the system encoding (i.e., osl_getThreadTextEncoding):
509cdf0e10cSrcweir     JavaVMInitArgs vm_args;
510cdf0e10cSrcweir 
5119cf33c68SArrigo Marchiori     std::vector<JavaVMOption> vecOptions;
5129cf33c68SArrigo Marchiori     vecOptions.reserve(cOptions + 1);
513cdf0e10cSrcweir 
514cdf0e10cSrcweir     // We set an abort handler which is called when the VM calls _exit during
515cdf0e10cSrcweir     // JNI_CreateJavaVM. This happens when the LD_LIBRARY_PATH does not contain
516cdf0e10cSrcweir     // all some directories of the Java installation. This is necessary for
517cdf0e10cSrcweir     // all versions below 1.5.1
5189cf33c68SArrigo Marchiori     vecOptions.push_back(JavaVMOption());
5199cf33c68SArrigo Marchiori     vecOptions.back().optionString = (char *) "abort";
5209cf33c68SArrigo Marchiori     vecOptions.back().extraInfo = (void* )(sal_IntPtr)abort_handler;
52175db40d1SArrigo Marchiori #if OSL_DEBUG_LEVEL >= 2
52275db40d1SArrigo Marchiori         JFW_TRACE2(OString("VM option: ") + OString(vecOptions.back().optionString) +
52375db40d1SArrigo Marchiori                    OString("\n"));
52475db40d1SArrigo Marchiori #endif
525cdf0e10cSrcweir     rtl::OString sClassPathProp("-Djava.class.path=");
526cdf0e10cSrcweir     rtl::OString sClassPathOption;
527cdf0e10cSrcweir     for (int i = 0; i < cOptions; i++)
528cdf0e10cSrcweir     {
52911bf2766SArrigo Marchiori         rtl::OString sOptionString = arOptions[i].optionString;
53075db40d1SArrigo Marchiori         if (sOptionString.match(sClassPathProp, 0) == sal_True)
531cdf0e10cSrcweir         {
532*6db292b0SArrigo Marchiori             // This option sets the class path
53375db40d1SArrigo Marchiori             bool emptyClassPath = (sOptionString == sClassPathProp);
534cdf0e10cSrcweir             char sep[] =  {SAL_PATHSEPARATOR, 0};
535*6db292b0SArrigo Marchiori             OString sAddPath;
536*6db292b0SArrigo Marchiori             sClassPathOption = sOptionString;
537*6db292b0SArrigo Marchiori             // Add the installation directory as default class path
538*6db292b0SArrigo Marchiori             OUString macro(RTL_CONSTASCII_USTRINGPARAM("$OOO_BASE_DIR/program"));
539*6db292b0SArrigo Marchiori             rtl::Bootstrap::expandMacros(macro);
540*6db292b0SArrigo Marchiori             OUString instDirectory;
541*6db292b0SArrigo Marchiori             osl_getSystemPathFromFileURL(macro.pData, &instDirectory.pData);
542*6db292b0SArrigo Marchiori             sAddPath = rtl::OUStringToOString(instDirectory, RTL_TEXTENCODING_UTF8);
543*6db292b0SArrigo Marchiori             if (sAddPath.getLength()) {
544*6db292b0SArrigo Marchiori                 if (!emptyClassPath) {
545*6db292b0SArrigo Marchiori                     sClassPathOption += rtl::OString(sep);
546*6db292b0SArrigo Marchiori                 }
547*6db292b0SArrigo Marchiori                 sClassPathOption += sAddPath;
548*6db292b0SArrigo Marchiori                 emptyClassPath = false;
549*6db292b0SArrigo Marchiori             }
550*6db292b0SArrigo Marchiori #ifdef UNX
551*6db292b0SArrigo Marchiori             // Until java 1.5 we need to put a plugin.jar or javaplugin.jar (<1.4.2)
552*6db292b0SArrigo Marchiori             // in the class path in order to have applet support.
553*6db292b0SArrigo Marchiori             sAddPath = getPluginJarPath(pInfo->sVendor, pInfo->sLocation,pInfo->sVersion);
5549cf33c68SArrigo Marchiori             if (sAddPath.getLength()) {
5559cf33c68SArrigo Marchiori                 if (!emptyClassPath) {
5569cf33c68SArrigo Marchiori                     sClassPathOption += rtl::OString(sep);
5579cf33c68SArrigo Marchiori                 }
5589cf33c68SArrigo Marchiori                 sClassPathOption += sAddPath;
5599cf33c68SArrigo Marchiori                 emptyClassPath = false;
560*6db292b0SArrigo Marchiori             }
561*6db292b0SArrigo Marchiori #endif
5629cf33c68SArrigo Marchiori             if (!emptyClassPath) {
5639cf33c68SArrigo Marchiori                 vecOptions.push_back(JavaVMOption());
5649cf33c68SArrigo Marchiori                 vecOptions.back().optionString = (char *) sClassPathOption.getStr();
5659cf33c68SArrigo Marchiori                 vecOptions.back().extraInfo = arOptions[i].extraInfo;
5669cf33c68SArrigo Marchiori             } // else avoid empty class path
567cdf0e10cSrcweir         }
568cdf0e10cSrcweir         else
569cdf0e10cSrcweir         {
5709cf33c68SArrigo Marchiori             vecOptions.push_back(JavaVMOption());
5719cf33c68SArrigo Marchiori             vecOptions.back().optionString = arOptions[i].optionString;
5729cf33c68SArrigo Marchiori             vecOptions.back().extraInfo = arOptions[i].extraInfo;
573cdf0e10cSrcweir         }
57475db40d1SArrigo Marchiori         sOptionString = vecOptions.back().optionString;
57575db40d1SArrigo Marchiori         if (sOptionString.match(sClassPathProp, 0) == sal_True) {
57675db40d1SArrigo Marchiori             // Check for empty entries in the class path
57775db40d1SArrigo Marchiori             sal_Int32 nIndex = sClassPathProp.getLength();
57875db40d1SArrigo Marchiori             rtl::OString sToken;
57975db40d1SArrigo Marchiori             char empty1[] = {'.', 0};
58075db40d1SArrigo Marchiori             char empty2[] = {'.', SAL_PATHDELIMITER, 0};
58175db40d1SArrigo Marchiori             const rtl::OString sEmpty1 = rtl::OString(empty1);
58275db40d1SArrigo Marchiori             const rtl::OString sEmpty2 = rtl::OString(empty2);
58375db40d1SArrigo Marchiori             do {
58475db40d1SArrigo Marchiori                 sToken = sOptionString.getToken(0, SAL_PATHSEPARATOR, nIndex);
58575db40d1SArrigo Marchiori                 if ((sToken.getLength() == 0) ||
58675db40d1SArrigo Marchiori                     (sToken == sEmpty1) ||
58775db40d1SArrigo Marchiori                     (sToken == sEmpty2)) {
58875db40d1SArrigo Marchiori                     fprintf(stderr,"[Java framework]sunjavaplugin"
58975db40d1SArrigo Marchiori                             SAL_DLLEXTENSION
59075db40d1SArrigo Marchiori                             " Rejecting empty class path entry !\n");
59175db40d1SArrigo Marchiori                     return JFW_PLUGIN_E_INVALID_ARG;
59275db40d1SArrigo Marchiori                 }
59375db40d1SArrigo Marchiori             } while (nIndex >= 0);
59475db40d1SArrigo Marchiori         }
595cdf0e10cSrcweir #if OSL_DEBUG_LEVEL >= 2
5969cf33c68SArrigo Marchiori         JFW_TRACE2(OString("VM option: ") + OString(vecOptions.back().optionString) +
597cdf0e10cSrcweir                    OString("\n"));
598cdf0e10cSrcweir #endif
599cdf0e10cSrcweir     }
600cdf0e10cSrcweir 
601cdf0e10cSrcweir #ifdef MACOSX
602cdf0e10cSrcweir     vm_args.version= JNI_VERSION_1_4; // issue 88987
603cdf0e10cSrcweir #else
604cdf0e10cSrcweir     vm_args.version= JNI_VERSION_1_2;
605cdf0e10cSrcweir #endif
6069cf33c68SArrigo Marchiori     vm_args.options= &vecOptions[0];
6079cf33c68SArrigo Marchiori     vm_args.nOptions= vecOptions.size();
608cdf0e10cSrcweir     vm_args.ignoreUnrecognized= JNI_TRUE;
609cdf0e10cSrcweir 
610cdf0e10cSrcweir     /* We set a global flag which is used by the abort handler in order to
611cdf0e10cSrcweir        determine whether it is  should use longjmp to get back into this function.
612cdf0e10cSrcweir        That is, the abort handler determines if it is on the same stack as this function
613cdf0e10cSrcweir        and then jumps back into this function.
614cdf0e10cSrcweir     */
615cdf0e10cSrcweir     g_bInGetJavaVM = 1;
616cdf0e10cSrcweir     jint err;
617cdf0e10cSrcweir     JavaVM * pJavaVM = 0;
618cdf0e10cSrcweir     memset( jmp_jvm_abort, 0, sizeof(jmp_jvm_abort));
619cdf0e10cSrcweir     int jmpval= setjmp( jmp_jvm_abort );
620cdf0e10cSrcweir     /* If jmpval is not "0" then this point was reached by a longjmp in the
621cdf0e10cSrcweir        abort_handler, which was called indirectly by JNI_CreateVM.
622cdf0e10cSrcweir     */
623cdf0e10cSrcweir     if( jmpval == 0)
624cdf0e10cSrcweir     {
625cdf0e10cSrcweir         //returns negative number on failure
626cdf0e10cSrcweir         err= pCreateJavaVM(&pJavaVM, ppEnv, &vm_args);
627cdf0e10cSrcweir         g_bInGetJavaVM = 0;
628cdf0e10cSrcweir     }
629cdf0e10cSrcweir     else
630cdf0e10cSrcweir         // set err to a positive number, so as or recognize that an abort (longjmp)
631cdf0e10cSrcweir         //occurred
632cdf0e10cSrcweir         err= 1;
633cdf0e10cSrcweir 
634cdf0e10cSrcweir     if(err != 0)
635cdf0e10cSrcweir     {
636cdf0e10cSrcweir         rtl::OUString message;
637cdf0e10cSrcweir         if( err < 0)
638cdf0e10cSrcweir         {
6396f51c329SHerbert Dürr             fprintf( stderr,"[Java framework] sunjavaplugin" SAL_DLLEXTENSION
640cdf0e10cSrcweir                     "Can not create Java Virtual Machine\n");
641cdf0e10cSrcweir             errcode = JFW_PLUGIN_E_VM_CREATION_FAILED;
642cdf0e10cSrcweir         }
643cdf0e10cSrcweir         else if( err > 0)
644cdf0e10cSrcweir         {
6456f51c329SHerbert Dürr             fprintf( stderr,"[Java framework] sunjavaplugin" SAL_DLLEXTENSION
646cdf0e10cSrcweir                     "Can not create JavaVirtualMachine, abort handler was called.\n");
647cdf0e10cSrcweir             errcode = JFW_PLUGIN_E_VM_CREATION_FAILED;
648cdf0e10cSrcweir         }
649cdf0e10cSrcweir     }
650cdf0e10cSrcweir     else
651cdf0e10cSrcweir     {
652cdf0e10cSrcweir         *ppVm = pJavaVM;
6536f51c329SHerbert Dürr         JFW_TRACE2( "[Java framework] sunjavaplugin" SAL_DLLEXTENSION " has created a VM.\n");
654cdf0e10cSrcweir     }
655cdf0e10cSrcweir 
656cdf0e10cSrcweir 
657cdf0e10cSrcweir    return errcode;
658cdf0e10cSrcweir }
659cdf0e10cSrcweir 
660cdf0e10cSrcweir extern "C"
jfw_plugin_existJRE(const JavaInfo * pInfo,sal_Bool * exist)661cdf0e10cSrcweir javaPluginError jfw_plugin_existJRE(const JavaInfo *pInfo, sal_Bool *exist)
662cdf0e10cSrcweir {
663cdf0e10cSrcweir     javaPluginError ret = JFW_PLUGIN_E_NONE;
664cdf0e10cSrcweir     if (!pInfo || !exist)
665cdf0e10cSrcweir         return JFW_PLUGIN_E_INVALID_ARG;
666cdf0e10cSrcweir     ::rtl::OUString sLocation(pInfo->sLocation);
667cdf0e10cSrcweir 
668cdf0e10cSrcweir     if (sLocation.getLength() == 0)
669cdf0e10cSrcweir         return JFW_PLUGIN_E_INVALID_ARG;
670cdf0e10cSrcweir     ::osl::DirectoryItem item;
671cdf0e10cSrcweir     ::osl::File::RC rc_item = ::osl::DirectoryItem::get(sLocation, item);
672cdf0e10cSrcweir     if (::osl::File::E_None == rc_item)
673cdf0e10cSrcweir     {
674cdf0e10cSrcweir         *exist = sal_True;
675cdf0e10cSrcweir     }
676cdf0e10cSrcweir     else if (::osl::File::E_NOENT == rc_item)
677cdf0e10cSrcweir     {
678cdf0e10cSrcweir         *exist = sal_False;
679cdf0e10cSrcweir     }
680cdf0e10cSrcweir     else
681cdf0e10cSrcweir     {
682cdf0e10cSrcweir         ret = JFW_PLUGIN_E_ERROR;
683cdf0e10cSrcweir     }
684cdf0e10cSrcweir #ifdef MACOSX
685cdf0e10cSrcweir     //We can have the situation that the JavaVM runtime library is not
686cdf0e10cSrcweir     //contained within JAVA_HOME. Then the check for JAVA_HOME would return
687cdf0e10cSrcweir     //true although the runtime library may not be loadable.
688cdf0e10cSrcweir     if (ret == JFW_PLUGIN_E_NONE && *exist == sal_True)
689cdf0e10cSrcweir     {
690cdf0e10cSrcweir         rtl::OUString sRuntimeLib = getRuntimeLib(pInfo->arVendorData);
691cdf0e10cSrcweir         JFW_TRACE2(OUSTR("[Java framework] Checking existence of Java runtime library.\n"));
692cdf0e10cSrcweir 
693cdf0e10cSrcweir         ::osl::DirectoryItem itemRt;
694cdf0e10cSrcweir         ::osl::File::RC rc_itemRt = ::osl::DirectoryItem::get(sRuntimeLib, itemRt);
695cdf0e10cSrcweir         if (::osl::File::E_None == rc_itemRt)
696cdf0e10cSrcweir         {
697cdf0e10cSrcweir             *exist = sal_True;
698cdf0e10cSrcweir             JFW_TRACE2(OUSTR("[Java framework] Java runtime library exist: ")
699cdf0e10cSrcweir               + sRuntimeLib + OUSTR("\n"));
700cdf0e10cSrcweir 
701cdf0e10cSrcweir         }
702cdf0e10cSrcweir         else if (::osl::File::E_NOENT == rc_itemRt)
703cdf0e10cSrcweir         {
704cdf0e10cSrcweir             *exist = sal_False;
705cdf0e10cSrcweir             JFW_TRACE2(OUSTR("[Java framework] Java runtime library does not exist: ")
706cdf0e10cSrcweir                        + sRuntimeLib + OUSTR("\n"));
707cdf0e10cSrcweir         }
708cdf0e10cSrcweir         else
709cdf0e10cSrcweir         {
710cdf0e10cSrcweir             ret = JFW_PLUGIN_E_ERROR;
711cdf0e10cSrcweir             JFW_TRACE2(OUSTR("[Java framework] Error while looking for Java runtime library: ")
712cdf0e10cSrcweir                        + sRuntimeLib + OUSTR(" \n"));
713cdf0e10cSrcweir         }
714cdf0e10cSrcweir     }
715cdf0e10cSrcweir #endif
716cdf0e10cSrcweir     return ret;
717cdf0e10cSrcweir }
718cdf0e10cSrcweir 
719cdf0e10cSrcweir 
720