1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gnujre.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_jvmfwk.hxx"
34 #include "osl/file.hxx"
35 #include "osl/thread.h"
46 Reference
<VendorBase
> GnuInfo::createInstance()
51 char const* const* GnuInfo::getJavaExePaths(int * size
)
53 static char const * ar
[] = {
71 *size
= sizeof (ar
) / sizeof (char*);
75 #if defined(MIPS) && defined(OSL_LITENDIAN)
76 #define GCJ_JFW_PLUGIN_ARCH "mipsel"
78 #define GCJ_JFW_PLUGIN_ARCH JFW_PLUGIN_ARCH
81 char const* const* GnuInfo::getRuntimePaths(int * size
)
83 static char const* ar
[]= {
85 "/lib/" GCJ_JFW_PLUGIN_ARCH
"/client/libjvm.so",
86 "/gcj-4.1.1/libjvm.so",
87 "/gcj-4.3-90/libjvm.so",
88 "/gcj-4.2-81/libjvm.so",
90 "/gcj-4.2.1/libjvm.so",
91 "/gcj-4.2.2/libjvm.so",
92 "/gcj-4.2.3/libjvm.so",
93 "/gcj-4.1-71/libjvm.so",
104 *size
= sizeof(ar
) / sizeof (char*);
108 bool GnuInfo::initialize(vector
<pair
<OUString
, OUString
> > props
)
110 //get java.vendor, java.version, java.home,
111 //javax.accessibility.assistive_technologies from system properties
114 OUString sJavaLibraryPath
;
115 typedef vector
<pair
<OUString
, OUString
> >::const_iterator it_prop
;
116 OUString
sVendorProperty(
117 RTL_CONSTASCII_USTRINGPARAM("java.vendor"));
118 OUString
sVersionProperty(
119 RTL_CONSTASCII_USTRINGPARAM("java.version"));
120 OUString
sJavaHomeProperty(
121 RTL_CONSTASCII_USTRINGPARAM("java.home"));
122 OUString
sJavaLibraryPathProperty(
123 RTL_CONSTASCII_USTRINGPARAM("java.library.path"));
124 OUString
sGNUHomeProperty(
125 RTL_CONSTASCII_USTRINGPARAM("gnu.classpath.home.url"));
126 OUString
sAccessProperty(
127 RTL_CONSTASCII_USTRINGPARAM("javax.accessibility.assistive_technologies"));
129 bool bVersion
= false;
130 bool bVendor
= false;
132 bool bJavaHome
= false;
133 bool bJavaLibraryPath
= false;
134 bool bAccess
= false;
136 typedef vector
<pair
<OUString
, OUString
> >::const_iterator it_prop
;
137 for (it_prop i
= props
.begin(); i
!= props
.end(); i
++)
139 if(! bVendor
&& sVendorProperty
.equals(i
->first
))
141 m_sVendor
= i
->second
;
144 else if (!bVersion
&& sVersionProperty
.equals(i
->first
))
146 m_sVersion
= i
->second
;
149 else if (!bHome
&& sGNUHomeProperty
.equals(i
->first
))
154 else if (!bJavaHome
&& sJavaHomeProperty
.equals(i
->first
))
157 if (osl_getFileURLFromSystemPath(i
->second
.pData
,& fileURL
.pData
) ==
160 //make sure that the drive letter have all the same case
161 //otherwise file:///c:/jre and file:///C:/jre produce two
162 //different objects!!!
163 if (makeDriveLetterSame( & fileURL
))
165 m_sJavaHome
= fileURL
;
170 else if (!bJavaLibraryPath
&& sJavaLibraryPathProperty
.equals(i
->first
))
172 sal_Int32 nIndex
= 0;
173 osl_getFileURLFromSystemPath(i
->second
.getToken(0, ':', nIndex
).pData
, &sJavaLibraryPath
.pData
);
174 bJavaLibraryPath
= true;
176 else if (!bAccess
&& sAccessProperty
.equals(i
->first
))
178 if (i
->second
.getLength() > 0)
180 m_bAccessibility
= true;
184 // the javax.accessibility.xxx property may not be set. Therefore we
185 //must search through all properties.
188 if (!bVersion
|| !bVendor
|| !bHome
)
191 if (!m_sJavaHome
.getLength())
192 m_sJavaHome
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:///usr/lib"));
194 // init m_sRuntimeLibrary
195 OSL_ASSERT(m_sHome
.getLength());
196 //call virtual function to get the possible paths to the runtime library.
199 char const* const* arRtPaths
= getRuntimePaths( & size
);
200 vector
<OUString
> libpaths
= getVectorFromCharArray(arRtPaths
, size
);
203 typedef vector
<OUString
>::const_iterator i_path
;
204 for(i_path ip
= libpaths
.begin(); ip
!= libpaths
.end(); ip
++)
206 //Construct an absolute path to the possible runtime
207 OUString usRt
= m_sHome
+ *ip
;
209 if(DirectoryItem::get(usRt
, item
) == File::E_None
)
212 m_sRuntimeLibrary
= usRt
;
220 m_sHome
= m_sJavaHome
;
221 for(i_path ip
= libpaths
.begin(); ip
!= libpaths
.end(); ip
++)
223 //Construct an absolute path to the possible runtime
224 OUString usRt
= m_sHome
+ *ip
;
226 if(DirectoryItem::get(usRt
, item
) == File::E_None
)
229 m_sRuntimeLibrary
= usRt
;
236 // try to find it by the java.library.path property
237 if (!bRt
&& m_sJavaHome
!= sJavaLibraryPath
)
239 m_sHome
= sJavaLibraryPath
;
240 for(i_path ip
= libpaths
.begin(); ip
!= libpaths
.end(); ip
++)
242 //Construct an absolute path to the possible runtime
243 OUString usRt
= m_sHome
+ *ip
;
245 if(DirectoryItem::get(usRt
, item
) == File::E_None
)
248 m_sRuntimeLibrary
= usRt
;
256 //Make one last final legacy attempt on x86_64 in case the distro placed it in lib64 instead
257 if (!bRt
&& m_sJavaHome
!= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:///usr/lib")))
259 m_sHome
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:///usr/lib64"));
260 for(i_path ip
= libpaths
.begin(); ip
!= libpaths
.end(); ip
++)
262 //Construct an absolute path to the possible runtime
263 OUString usRt
= m_sHome
+ *ip
;
265 if(DirectoryItem::get(usRt
, item
) == File::E_None
)
268 m_sRuntimeLibrary
= usRt
;
279 // init m_sLD_LIBRARY_PATH
280 OSL_ASSERT(m_sHome
.getLength());
282 char const * const * arLDPaths
= getLibraryPaths( & size
);
283 vector
<OUString
> ld_paths
= getVectorFromCharArray(arLDPaths
, size
);
285 char arSep
[]= {SAL_PATHSEPARATOR
, 0};
286 OUString sPathSep
= OUString::createFromAscii(arSep
);
289 for(i_path il
= ld_paths
.begin(); il
!= ld_paths
.end(); il
++, c
++)
291 OUString usAbsUrl
= m_sHome
+ *il
;
292 // convert to system path
294 if(File::getSystemPathFromFileURL(usAbsUrl
, usSysPath
) == File::E_None
)
298 m_sLD_LIBRARY_PATH
+= sPathSep
;
299 m_sLD_LIBRARY_PATH
+= usSysPath
;
307 if (bLdPath
== false)
313 int GnuInfo::compareVersions(const rtl::OUString
&) const