Update ooo320-m1
[ooovba.git] / jvmfwk / plugins / sunmajor / pluginlib / gnujre.cxx
blob4666ab72d03567cee685addee9bec505b6166ad9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gnujre.cxx,v $
10 * $Revision: 1.16 $
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"
36 #include "gnujre.hxx"
37 #include "util.hxx"
39 using namespace rtl;
40 using namespace std;
41 using namespace osl;
43 namespace jfw_plugin
46 Reference<VendorBase> GnuInfo::createInstance()
48 return new GnuInfo;
51 char const* const* GnuInfo::getJavaExePaths(int * size)
53 static char const * ar[] = {
54 #if defined(__i386__)
55 "gij32",
56 "bin/gij32",
57 "gij32-4.2",
58 "bin/gij32-4.2",
59 "gij32-4.1",
60 "bin/gij32-4.1,"
61 #endif
62 "gij",
63 "bin/gij",
64 "gij-4.3",
65 "bin/gij-4.3",
66 "gij-4.2",
67 "bin/gij-4.2",
68 "gij-4.1",
69 "bin/gij-4.1"
71 *size = sizeof (ar) / sizeof (char*);
72 return ar;
75 #if defined(MIPS) && defined(OSL_LITENDIAN)
76 #define GCJ_JFW_PLUGIN_ARCH "mipsel"
77 #else
78 #define GCJ_JFW_PLUGIN_ARCH JFW_PLUGIN_ARCH
79 #endif
81 char const* const* GnuInfo::getRuntimePaths(int * size)
83 static char const* ar[]= {
84 "/libjvm.so",
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",
89 "/gcj-4.2/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",
94 "/gcj-4_1/libjvm.so",
95 "/gcj-4.1/libjvm.so",
96 "/libgcj.so.81",
97 "/libgcj.so.80",
98 "/libgcj.so.8",
99 "/libgcj.so.71",
100 "/libgcj.so.70",
101 "/libgcj.so.7",
102 "/libgcj.so.6"
104 *size = sizeof(ar) / sizeof (char*);
105 return ar;
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
113 OUString sVendor;
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;
131 bool bHome = 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;
142 bVendor = true;
144 else if (!bVersion && sVersionProperty.equals(i->first))
146 m_sVersion = i->second;
147 bVersion = true;
149 else if (!bHome && sGNUHomeProperty.equals(i->first))
151 m_sHome = i->second;
152 bHome = true;
154 else if (!bJavaHome && sJavaHomeProperty.equals(i->first))
156 OUString fileURL;
157 if (osl_getFileURLFromSystemPath(i->second.pData,& fileURL.pData) ==
158 osl_File_E_None)
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;
166 bJavaHome = true;
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;
181 bAccess = true;
184 // the javax.accessibility.xxx property may not be set. Therefore we
185 //must search through all properties.
188 if (!bVersion || !bVendor || !bHome)
189 return false;
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.
198 int size = 0;
199 char const* const* arRtPaths = getRuntimePaths( & size);
200 vector<OUString> libpaths = getVectorFromCharArray(arRtPaths, size);
202 bool bRt = false;
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;
208 DirectoryItem item;
209 if(DirectoryItem::get(usRt, item) == File::E_None)
211 //found runtime lib
212 m_sRuntimeLibrary = usRt;
213 bRt = true;
214 break;
218 if (!bRt)
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;
225 DirectoryItem item;
226 if(DirectoryItem::get(usRt, item) == File::E_None)
228 //found runtime lib
229 m_sRuntimeLibrary = usRt;
230 bRt = true;
231 break;
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;
244 DirectoryItem item;
245 if(DirectoryItem::get(usRt, item) == File::E_None)
247 //found runtime lib
248 m_sRuntimeLibrary = usRt;
249 bRt = true;
250 break;
255 #ifdef X86_64
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;
264 DirectoryItem item;
265 if(DirectoryItem::get(usRt, item) == File::E_None)
267 //found runtime lib
268 m_sRuntimeLibrary = usRt;
269 bRt = true;
270 break;
274 #endif
276 if (!bRt)
277 return false;
279 // init m_sLD_LIBRARY_PATH
280 OSL_ASSERT(m_sHome.getLength());
281 size = 0;
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);
287 bool bLdPath = true;
288 int c = 0;
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
293 OUString usSysPath;
294 if(File::getSystemPathFromFileURL(usAbsUrl, usSysPath) == File::E_None)
297 if(c > 0)
298 m_sLD_LIBRARY_PATH+= sPathSep;
299 m_sLD_LIBRARY_PATH+= usSysPath;
301 else
303 bLdPath = false;
304 break;
307 if (bLdPath == false)
308 return false;
310 return true;
313 int GnuInfo::compareVersions(const rtl::OUString&) const
315 return 0;