1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
|
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_jvmfwk.hxx"
#if OSL_DEBUG_LEVEL > 0
#include <stdio.h>
#endif
#include <string.h>
#include "boost/scoped_array.hpp"
#include "osl/diagnose.h"
#include "rtl/ustring.hxx"
#include "rtl/ustrbuf.hxx"
#include "osl/module.hxx"
#include "osl/mutex.hxx"
#include "osl/thread.hxx"
#include "osl/file.hxx"
#include "rtl/instance.hxx"
#include "osl/getglobalmutex.hxx"
#include <setjmp.h>
#include <signal.h>
#include <stack>
#include "jni.h"
#include "rtl/byteseq.hxx"
#include "jvmfwk/vendorplugin.h"
#include "util.hxx"
#include "sunversion.hxx"
#include "vendorlist.hxx"
#include "diagnostics.h"
#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
#define SUN_MICRO "Sun Microsystems Inc."
using namespace osl;
using namespace rtl;
using namespace std;
using namespace jfw_plugin;
namespace {
struct PluginMutex: public ::rtl::Static<osl::Mutex, PluginMutex> {};
#if defined UNX
OString getPluginJarPath(
const OUString & sVendor,
const OUString& sLocation,
const OUString& sVersion)
{
OString ret;
OUString sName1(RTL_CONSTASCII_USTRINGPARAM("javaplugin.jar"));
OUString sName2(RTL_CONSTASCII_USTRINGPARAM("plugin.jar"));
OUString sPath;
if (sVendor.equals(OUString(RTL_CONSTASCII_USTRINGPARAM(SUN_MICRO))))
{
SunVersion ver142("1.4.2-ea");
SunVersion ver150("1.5.0-ea");
SunVersion ver(sVersion);
OSL_ASSERT(ver142 && ver150 && ver);
OUString sName;
if (ver < ver142)
{
sName = sName1;
}
else if (ver < ver150)
{//this will cause ea, beta etc. to have plugin.jar in path.
//but this does not harm. 1.5.0-beta < 1.5.0
sName = sName2;
}
if (sName.getLength())
{
sName = sLocation + OUSTR("/lib/") + sName;
OSL_VERIFY(
osl_getSystemPathFromFileURL(sName.pData, & sPath.pData)
== osl_File_E_None);
}
}
else
{
char sep[] = {SAL_PATHSEPARATOR, 0};
OUString sName(sLocation + OUSTR("/lib/") + sName1);
OUString sPath1;
OUString sPath2;
if (osl_getSystemPathFromFileURL(sName.pData, & sPath1.pData)
== osl_File_E_None)
{
sName = sLocation + OUSTR("/lib/") + sName2;
if (osl_getSystemPathFromFileURL(sName.pData, & sPath2.pData)
== osl_File_E_None)
{
sPath = sPath1 + OUString::createFromAscii(sep) + sPath2;
}
}
OSL_ASSERT(sPath.getLength());
}
ret = rtl::OUStringToOString(sPath, osl_getThreadTextEncoding());
return ret;
}
#endif // UNX
JavaInfo* createJavaInfo(const rtl::Reference<VendorBase> & info)
{
JavaInfo* pInfo = (JavaInfo*) rtl_allocateMemory(sizeof(JavaInfo));
if (pInfo == NULL)
return NULL;
rtl::OUString sVendor = info->getVendor();
pInfo->sVendor = sVendor.pData;
rtl_uString_acquire(sVendor.pData);
rtl::OUString sHome = info->getHome();
pInfo->sLocation = sHome.pData;
rtl_uString_acquire(pInfo->sLocation);
rtl::OUString sVersion = info->getVersion();
pInfo->sVersion = sVersion.pData;
rtl_uString_acquire(pInfo->sVersion);
pInfo->nFeatures = info->supportsAccessibility() ? 1 : 0;
pInfo->nRequirements = info->needsRestart() ? JFW_REQUIRE_NEEDRESTART : 0;
rtl::OUStringBuffer buf(1024);
buf.append(info->getRuntimeLibrary());
if (info->getLibraryPaths().getLength() > 0)
{
buf.appendAscii("\n");
buf.append(info->getLibraryPaths());
buf.appendAscii("\n");
}
rtl::OUString sVendorData = buf.makeStringAndClear();
rtl::ByteSequence byteSeq( (sal_Int8*) sVendorData.pData->buffer,
sVendorData.getLength() * sizeof(sal_Unicode));
pInfo->arVendorData = byteSeq.get();
rtl_byte_sequence_acquire(pInfo->arVendorData);
return pInfo;
}
rtl::OUString getRuntimeLib(const rtl::ByteSequence & data)
{
const sal_Unicode* chars = (sal_Unicode*) data.getConstArray();
sal_Int32 len = data.getLength();
rtl::OUString sData(chars, len / 2);
//the runtime lib is on the first line
sal_Int32 index = 0;
rtl::OUString aToken = sData.getToken( 0, '\n', index);
return aToken;
}
jmp_buf jmp_jvm_abort;
sig_atomic_t g_bInGetJavaVM = 0;
extern "C" void JNICALL abort_handler()
{
// If we are within JNI_CreateJavaVM then we jump back into getJavaVM
if( g_bInGetJavaVM != 0 )
{
fprintf( stderr, "JavaVM: JNI_CreateJavaVM called _exit, caught by abort_handler in javavm.cxx\n");
longjmp( jmp_jvm_abort, 0);
}
}
}
extern "C"
javaPluginError jfw_plugin_getAllJavaInfos(
rtl_uString *sVendor,
rtl_uString *sMinVersion,
rtl_uString *sMaxVersion,
rtl_uString * *arExcludeList,
sal_Int32 nLenList,
JavaInfo*** parJavaInfo,
sal_Int32 *nLenInfoList)
{
OSL_ASSERT(sVendor);
OSL_ASSERT(sMinVersion);
OSL_ASSERT(sMaxVersion);
OSL_ASSERT(parJavaInfo);
OSL_ASSERT(parJavaInfo);
OSL_ASSERT(nLenInfoList);
if (!sVendor || !sMinVersion || !sMaxVersion || !parJavaInfo || !nLenInfoList)
return JFW_PLUGIN_E_INVALID_ARG;
//nLenlist contains the number of element in arExcludeList.
//If no exclude list is provided then nLenList must be 0
OSL_ASSERT( ! (arExcludeList == NULL && nLenList > 0));
if (arExcludeList == NULL && nLenList > 0)
return JFW_PLUGIN_E_INVALID_ARG;
OUString ouVendor(sVendor);
OUString ouMinVer(sMinVersion);
OUString ouMaxVer(sMaxVersion);
OSL_ASSERT(ouVendor.getLength() > 0);
if (ouVendor.getLength() == 0)
return JFW_PLUGIN_E_INVALID_ARG;
JavaInfo** arInfo = NULL;
//Find all JREs
vector<rtl::Reference<VendorBase> > vecInfos =
getAllJREInfos();
vector<rtl::Reference<VendorBase> > vecVerifiedInfos;
typedef vector<rtl::Reference<VendorBase> >::iterator it;
for (it i= vecInfos.begin(); i != vecInfos.end(); i++)
{
const rtl::Reference<VendorBase>& cur = *i;
if (ouVendor.equals(cur->getVendor()) == sal_False)
continue;
if (ouMinVer.getLength() > 0)
{
try
{
if (cur->compareVersions(sMinVersion) == -1)
continue;
}
catch (MalformedVersionException&)
{
//The minVersion was not recognized as valid for this vendor.
JFW_ENSURE(
0,OUSTR("[Java framework]sunjavaplugin does not know version: ")
+ ouMinVer + OUSTR(" for vendor: ") + cur->getVendor()
+ OUSTR(" .Check minimum Version.") );
return JFW_PLUGIN_E_WRONG_VERSION_FORMAT;
}
}
if (ouMaxVer.getLength() > 0)
{
try
{
if (cur->compareVersions(sMaxVersion) == 1)
continue;
}
catch (MalformedVersionException&)
{
//The maxVersion was not recognized as valid for this vendor.
JFW_ENSURE(
0,OUSTR("[Java framework]sunjavaplugin does not know version: ")
+ ouMaxVer + OUSTR(" for vendor: ") + cur->getVendor()
+ OUSTR(" .Check maximum Version.") );
return JFW_PLUGIN_E_WRONG_VERSION_FORMAT;
}
}
if (arExcludeList > 0)
{
bool bExclude = false;
for (int j = 0; j < nLenList; j++)
{
rtl::OUString sExVer(arExcludeList[j]);
try
{
if (cur->compareVersions(sExVer) == 0)
{
bExclude = true;
break;
}
}
catch (MalformedVersionException&)
{
//The excluded version was not recognized as valid for this vendor.
JFW_ENSURE(
0,OUSTR("[Java framework]sunjavaplugin does not know version: ")
+ sExVer + OUSTR(" for vendor: ") + cur->getVendor()
+ OUSTR(" .Check excluded versions.") );
return JFW_PLUGIN_E_WRONG_VERSION_FORMAT;
}
}
if (bExclude == true)
continue;
}
vecVerifiedInfos.push_back(*i);
}
//Now vecVerifiedInfos contains all those JREs which meet the version requirements
//Transfer them into the array that is passed out.
arInfo = (JavaInfo**) rtl_allocateMemory(vecVerifiedInfos.size() * sizeof (JavaInfo*));
int j = 0;
typedef vector<rtl::Reference<VendorBase> >::const_iterator cit;
for (cit ii = vecVerifiedInfos.begin(); ii != vecVerifiedInfos.end(); ii++, j++)
{
arInfo[j] = createJavaInfo(*ii);
}
*nLenInfoList = vecVerifiedInfos.size();
*parJavaInfo = arInfo;
return JFW_PLUGIN_E_NONE;
}
extern "C"
javaPluginError jfw_plugin_getJavaInfoByPath(
rtl_uString *path,
rtl_uString *sVendor,
rtl_uString *sMinVersion,
rtl_uString *sMaxVersion,
rtl_uString * *arExcludeList,
sal_Int32 nLenList,
JavaInfo ** ppInfo)
{
javaPluginError errcode = JFW_PLUGIN_E_NONE;
OSL_ASSERT(path);
OSL_ASSERT(sVendor);
OSL_ASSERT(sMinVersion);
OSL_ASSERT(sMaxVersion);
if (!path || !sVendor || !sMinVersion || !sMaxVersion || !ppInfo)
return JFW_PLUGIN_E_INVALID_ARG;
OUString ouPath(path);
OSL_ASSERT(ouPath.getLength() > 0);
if (ouPath.getLength() == 0)
return JFW_PLUGIN_E_INVALID_ARG;
//nLenlist contains the number of element in arExcludeList.
//If no exclude list is provided then nLenList must be 0
OSL_ASSERT( ! (arExcludeList == NULL && nLenList > 0));
if (arExcludeList == NULL && nLenList > 0)
return JFW_PLUGIN_E_INVALID_ARG;
OUString ouVendor(sVendor);
OUString ouMinVer(sMinVersion);
OUString ouMaxVer(sMaxVersion);
OSL_ASSERT(ouVendor.getLength() > 0);
if (ouVendor.getLength() == 0)
return JFW_PLUGIN_E_INVALID_ARG;
rtl::Reference<VendorBase> aVendorInfo = getJREInfoByPath(ouPath);
if (aVendorInfo.is() == sal_False)
return JFW_PLUGIN_E_NO_JRE;
//Check if the detected JRE matches the version requirements
if (ouVendor.equals(aVendorInfo->getVendor()) == sal_False)
return JFW_PLUGIN_E_NO_JRE;
if (ouMinVer.getLength() > 0)
{
int nRes = 0;
try
{
nRes = aVendorInfo->compareVersions(ouMinVer);
}
catch (MalformedVersionException&)
{
//The minVersion was not recognized as valid for this vendor.
JFW_ENSURE(
0,OUSTR("[Java framework]sunjavaplugin does not know version: ")
+ ouMinVer + OUSTR(" for vendor: ") + aVendorInfo->getVendor()
+ OUSTR(" .Check minimum Version.") );
return JFW_PLUGIN_E_WRONG_VERSION_FORMAT;
}
if (nRes < 0)
return JFW_PLUGIN_E_FAILED_VERSION;
}
if (ouMaxVer.getLength() > 0)
{
int nRes = 0;
try
{
nRes = aVendorInfo->compareVersions(ouMaxVer);
}
catch (MalformedVersionException&)
{
//The maxVersion was not recognized as valid for this vendor.
JFW_ENSURE(
0,OUSTR("[Java framework]sunjavaplugin does not know version: ")
+ ouMaxVer + OUSTR(" for vendor: ") + aVendorInfo->getVendor()
+ OUSTR(" .Check maximum Version.") );
return JFW_PLUGIN_E_WRONG_VERSION_FORMAT;
}
if (nRes > 0)
return JFW_PLUGIN_E_FAILED_VERSION;
}
if (arExcludeList > 0)
{
for (int i = 0; i < nLenList; i++)
{
rtl::OUString sExVer(arExcludeList[i]);
int nRes = 0;
try
{
nRes = aVendorInfo->compareVersions(sExVer);
}
catch (MalformedVersionException&)
{
//The excluded version was not recognized as valid for this vendor.
JFW_ENSURE(
0,OUSTR("[Java framework]sunjavaplugin does not know version: ")
+ sExVer + OUSTR(" for vendor: ") + aVendorInfo->getVendor()
+ OUSTR(" .Check excluded versions.") );
return JFW_PLUGIN_E_WRONG_VERSION_FORMAT;
}
if (nRes == 0)
return JFW_PLUGIN_E_FAILED_VERSION;
}
}
*ppInfo = createJavaInfo(aVendorInfo);
return errcode;
}
/** starts a Java Virtual Machine.
<p>
The function shall ensure, that the VM does not abort the process
during instantiation.
</p>
*/
extern "C"
javaPluginError jfw_plugin_startJavaVirtualMachine(
const JavaInfo *pInfo,
const JavaVMOption* arOptions,
sal_Int32 cOptions,
JavaVM ** ppVm,
JNIEnv ** ppEnv)
{
// unless guard is volatile the following warning occurs on gcc:
// warning: variable 't' might be clobbered by `longjmp' or `vfork'
volatile osl::MutexGuard guard(PluginMutex::get());
// unless errcode is volatile the following warning occurs on gcc:
// warning: variable 'errcode' might be clobbered by `longjmp' or `vfork'
volatile javaPluginError errcode = JFW_PLUGIN_E_NONE;
if ( pInfo == NULL || ppVm == NULL || ppEnv == NULL)
return JFW_PLUGIN_E_INVALID_ARG;
//Check if the Vendor (pInfo->sVendor) is supported by this plugin
if ( ! isVendorSupported(pInfo->sVendor))
return JFW_PLUGIN_E_WRONG_VENDOR;
rtl::OUString sRuntimeLib = getRuntimeLib(pInfo->arVendorData);
JFW_TRACE2(OUSTR("[Java framework] Using Java runtime library: ")
+ sRuntimeLib + OUSTR(".\n"));
// On linux we load jvm with RTLD_GLOBAL. This is necessary for debugging, because
// libjdwp.so need a symbol (fork1) from libjvm which it only gets if the jvm is loaded
// witd RTLD_GLOBAL. On Solaris libjdwp.so is correctly linked with libjvm.so
oslModule moduleRt = 0;
#if defined(LINUX)
if ((moduleRt = osl_loadModule(sRuntimeLib.pData,
SAL_LOADMODULE_GLOBAL | SAL_LOADMODULE_NOW)) == 0 )
#else
if ((moduleRt = osl_loadModule(sRuntimeLib.pData, SAL_LOADMODULE_DEFAULT)) == 0)
#endif
{
JFW_ENSURE(0, OUSTR("[Java framework]sunjavaplugin" SAL_DLLEXTENSION
" could not load Java runtime library: \n")
+ sRuntimeLib + OUSTR("\n"));
JFW_TRACE0(OUSTR("[Java framework]sunjavaplugin" SAL_DLLEXTENSION
" could not load Java runtime library: \n")
+ sRuntimeLib + OUSTR("\n"));
return JFW_PLUGIN_E_VM_CREATION_FAILED;
}
#ifdef UNX
//Setting the JAVA_HOME is needed for awt
rtl::OUString javaHome(RTL_CONSTASCII_USTRINGPARAM("JAVA_HOME="));
rtl::OUString sPathLocation;
osl_getSystemPathFromFileURL(pInfo->sLocation, & sPathLocation.pData);
javaHome += sPathLocation;
rtl::OString osJavaHome = rtl::OUStringToOString(
javaHome, osl_getThreadTextEncoding());
putenv(strdup(osJavaHome.getStr()));
#endif
typedef jint JNICALL JNI_InitArgs_Type(void *);
typedef jint JNICALL JNI_CreateVM_Type(JavaVM **, JNIEnv **, void *);
rtl::OUString sSymbolCreateJava(
RTL_CONSTASCII_USTRINGPARAM("JNI_CreateJavaVM"));
JNI_CreateVM_Type * pCreateJavaVM = (JNI_CreateVM_Type *) osl_getFunctionSymbol(
moduleRt, sSymbolCreateJava.pData);
if (!pCreateJavaVM)
{
OSL_ASSERT(0);
rtl::OString sLib = rtl::OUStringToOString(
sRuntimeLib, osl_getThreadTextEncoding());
rtl::OString sSymbol = rtl::OUStringToOString(
sSymbolCreateJava, osl_getThreadTextEncoding());
fprintf(stderr,"[Java framework]sunjavaplugin"SAL_DLLEXTENSION
"Java runtime library: %s does not export symbol %s !\n",
sLib.getStr(), sSymbol.getStr());
return JFW_PLUGIN_E_VM_CREATION_FAILED;
}
// Some testing with Java 1.4 showed that JavaVMOption.optionString has to
// be encoded with the system encoding (i.e., osl_getThreadTextEncoding):
JavaVMInitArgs vm_args;
boost::scoped_array<JavaVMOption> sarOptions(
new JavaVMOption[cOptions + 1]);
JavaVMOption * options = sarOptions.get();
// We set an abort handler which is called when the VM calls _exit during
// JNI_CreateJavaVM. This happens when the LD_LIBRARY_PATH does not contain
// all some directories of the Java installation. This is necessary for
// all versions below 1.5.1
options[0].optionString= (char *) "abort";
options[0].extraInfo= (void* )(sal_IntPtr)abort_handler;
rtl::OString sClassPathProp("-Djava.class.path=");
rtl::OString sClassPathOption;
for (int i = 0; i < cOptions; i++)
{
#ifdef UNX
// Until java 1.5 we need to put a plugin.jar or javaplugin.jar (<1.4.2)
// in the class path in order to have applet support.
rtl::OString sClassPath = arOptions[i].optionString;
if (sClassPath.match(sClassPathProp, 0) == sal_True)
{
char sep[] = {SAL_PATHSEPARATOR, 0};
OString sAddPath = getPluginJarPath(pInfo->sVendor, pInfo->sLocation,pInfo->sVersion);
if (sAddPath.getLength())
sClassPathOption = sClassPath + rtl::OString(sep) + sAddPath;
else
sClassPathOption = sClassPath;
options[i+1].optionString = (char *) sClassPathOption.getStr();
options[i+1].extraInfo = arOptions[i].extraInfo;
}
else
{
#endif
options[i+1].optionString = arOptions[i].optionString;
options[i+1].extraInfo = arOptions[i].extraInfo;
#ifdef UNX
}
#endif
#if OSL_DEBUG_LEVEL >= 2
JFW_TRACE2(OString("VM option: ") + OString(options[i+1].optionString) +
OString("\n"));
#endif
}
#ifdef MACOSX
vm_args.version= JNI_VERSION_1_4; // issue 88987
#else
vm_args.version= JNI_VERSION_1_2;
#endif
vm_args.options= options;
vm_args.nOptions= cOptions + 1;
vm_args.ignoreUnrecognized= JNI_TRUE;
/* We set a global flag which is used by the abort handler in order to
determine whether it is should use longjmp to get back into this function.
That is, the abort handler determines if it is on the same stack as this function
and then jumps back into this function.
*/
g_bInGetJavaVM = 1;
jint err;
JavaVM * pJavaVM = 0;
memset( jmp_jvm_abort, 0, sizeof(jmp_jvm_abort));
int jmpval= setjmp( jmp_jvm_abort );
/* If jmpval is not "0" then this point was reached by a longjmp in the
abort_handler, which was called indirectly by JNI_CreateVM.
*/
if( jmpval == 0)
{
//returns negative number on failure
err= pCreateJavaVM(&pJavaVM, ppEnv, &vm_args);
g_bInGetJavaVM = 0;
}
else
// set err to a positive number, so as or recognize that an abort (longjmp)
//occurred
err= 1;
if(err != 0)
{
rtl::OUString message;
if( err < 0)
{
fprintf(stderr,"[Java framework] sunjavaplugin"SAL_DLLEXTENSION
"Can not create Java Virtual Machine\n");
errcode = JFW_PLUGIN_E_VM_CREATION_FAILED;
}
else if( err > 0)
{
fprintf(stderr,"[Java framework] sunjavaplugin"SAL_DLLEXTENSION
"Can not create JavaVirtualMachine, abort handler was called.\n");
errcode = JFW_PLUGIN_E_VM_CREATION_FAILED;
}
}
else
{
*ppVm = pJavaVM;
JFW_TRACE2("[Java framework] sunjavaplugin"SAL_DLLEXTENSION " has created a VM.\n");
}
return errcode;
}
extern "C"
javaPluginError jfw_plugin_existJRE(const JavaInfo *pInfo, sal_Bool *exist)
{
javaPluginError ret = JFW_PLUGIN_E_NONE;
if (!pInfo || !exist)
return JFW_PLUGIN_E_INVALID_ARG;
::rtl::OUString sLocation(pInfo->sLocation);
if (sLocation.getLength() == 0)
return JFW_PLUGIN_E_INVALID_ARG;
::osl::DirectoryItem item;
::osl::File::RC rc_item = ::osl::DirectoryItem::get(sLocation, item);
if (::osl::File::E_None == rc_item)
{
*exist = sal_True;
}
else if (::osl::File::E_NOENT == rc_item)
{
*exist = sal_False;
}
else
{
ret = JFW_PLUGIN_E_ERROR;
}
#ifdef MACOSX
//We can have the situation that the JavaVM runtime library is not
//contained within JAVA_HOME. Then the check for JAVA_HOME would return
//true although the runtime library may not be loadable.
if (ret == JFW_PLUGIN_E_NONE && *exist == sal_True)
{
rtl::OUString sRuntimeLib = getRuntimeLib(pInfo->arVendorData);
JFW_TRACE2(OUSTR("[Java framework] Checking existence of Java runtime library.\n"));
::osl::DirectoryItem itemRt;
::osl::File::RC rc_itemRt = ::osl::DirectoryItem::get(sRuntimeLib, itemRt);
if (::osl::File::E_None == rc_itemRt)
{
*exist = sal_True;
JFW_TRACE2(OUSTR("[Java framework] Java runtime library exist: ")
+ sRuntimeLib + OUSTR("\n"));
}
else if (::osl::File::E_NOENT == rc_itemRt)
{
*exist = sal_False;
JFW_TRACE2(OUSTR("[Java framework] Java runtime library does not exist: ")
+ sRuntimeLib + OUSTR("\n"));
}
else
{
ret = JFW_PLUGIN_E_ERROR;
JFW_TRACE2(OUSTR("[Java framework] Error while looking for Java runtime library: ")
+ sRuntimeLib + OUSTR(" \n"));
}
}
#endif
return ret;
}
|