Linux x86 build fix
[LibreOffice.git] / jvmfwk / plugins / sunmajor / pluginlib / gnujre.cxx
blob07ec21e85270bf55fe8c5d35dfd07e233137f8e2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include "osl/file.hxx"
22 #include "osl/thread.h"
23 #include "gnujre.hxx"
24 #include "util.hxx"
26 using namespace std;
27 using namespace osl;
28 using ::rtl::Reference;
30 namespace jfw_plugin
33 Reference<VendorBase> GnuInfo::createInstance()
35 return new GnuInfo;
38 char const* const* GnuInfo::getJavaExePaths(int * size)
40 static char const * ar[] = {
41 "gij",
42 "bin/gij",
43 "gij-4.3",
44 "bin/gij-4.3",
45 "gij-4.2",
46 "bin/gij-4.2",
47 "gij-4.1",
48 "bin/gij-4.1"
50 *size = sizeof (ar) / sizeof (char*);
51 return ar;
54 #if defined(MIPS) && defined(OSL_LITENDIAN)
55 #define GCJ_JFW_PLUGIN_ARCH "mipsel"
56 #else
57 #define GCJ_JFW_PLUGIN_ARCH JFW_PLUGIN_ARCH
58 #endif
60 char const* const* GnuInfo::getRuntimePaths(int * size)
62 static char const* ar[]= {
63 "/libjvm.so",
64 "/lib/" GCJ_JFW_PLUGIN_ARCH "/client/libjvm.so",
65 "/gcj-4.1.1/libjvm.so",
66 "/gcj-4.3-90/libjvm.so",
67 "/gcj-4.2-81/libjvm.so",
68 "/gcj-4.2/libjvm.so",
69 "/gcj-4.2.1/libjvm.so",
70 "/gcj-4.2.2/libjvm.so",
71 "/gcj-4.2.3/libjvm.so",
72 "/gcj-4.1-71/libjvm.so",
73 "/gcj-4_1/libjvm.so",
74 "/gcj-4.1/libjvm.so",
75 "/libgcj.so.81",
76 "/libgcj.so.80",
77 "/libgcj.so.8",
78 "/libgcj.so.71",
79 "/libgcj.so.70",
80 "/libgcj.so.7",
81 "/libgcj.so.6"
83 *size = sizeof(ar) / sizeof (char*);
84 return ar;
87 char const* const* GnuInfo::getLibraryPaths(int* /*size*/)
89 return NULL;
92 bool GnuInfo::initialize(vector<pair<OUString, OUString> > props)
94 //get java.vendor, java.version, java.home,
95 //javax.accessibility.assistive_technologies from system properties
97 OUString sJavaLibraryPath;
98 typedef vector<pair<OUString, OUString> >::const_iterator it_prop;
99 OUString sVendorProperty("java.vendor");
100 OUString sVersionProperty("java.version");
101 OUString sJavaHomeProperty("java.home");
102 OUString sJavaLibraryPathProperty("java.library.path");
103 OUString sGNUHomeProperty("gnu.classpath.home.url");
104 OUString sAccessProperty("javax.accessibility.assistive_technologies");
106 bool bVersion = false;
107 bool bVendor = false;
108 bool bHome = false;
109 bool bJavaHome = false;
110 bool bJavaLibraryPath = false;
111 bool bAccess = false;
113 typedef vector<pair<OUString, OUString> >::const_iterator it_prop;
114 for (it_prop i = props.begin(); i != props.end(); ++i)
116 if(! bVendor && sVendorProperty.equals(i->first))
118 m_sVendor = i->second;
119 bVendor = true;
121 else if (!bVersion && sVersionProperty.equals(i->first))
123 m_sVersion = i->second;
124 bVersion = true;
126 else if (!bHome && sGNUHomeProperty.equals(i->first))
128 m_sHome = i->second;
129 bHome = true;
131 else if (!bJavaHome && sJavaHomeProperty.equals(i->first))
133 OUString fileURL;
134 if (osl_getFileURLFromSystemPath(i->second.pData,& fileURL.pData) ==
135 osl_File_E_None)
137 //make sure that the drive letter have all the same case
138 //otherwise file:///c:/jre and file:///C:/jre produce two
139 //different objects!!!
140 if (makeDriveLetterSame( & fileURL))
142 m_sJavaHome = fileURL;
143 bJavaHome = true;
147 else if (!bJavaLibraryPath && sJavaLibraryPathProperty.equals(i->first))
149 sal_Int32 nIndex = 0;
150 osl_getFileURLFromSystemPath(i->second.getToken(0, ':', nIndex).pData, &sJavaLibraryPath.pData);
151 bJavaLibraryPath = true;
153 else if (!bAccess && sAccessProperty.equals(i->first))
155 if (!i->second.isEmpty())
157 m_bAccessibility = true;
158 bAccess = true;
161 // the javax.accessibility.xxx property may not be set. Therefore we
162 //must search through all properties.
165 if (!bVersion || !bVendor || !bHome)
166 return false;
168 if (m_sJavaHome.isEmpty())
169 m_sJavaHome = "file:///usr/lib";
171 // init m_sRuntimeLibrary
172 OSL_ASSERT(!m_sHome.isEmpty());
173 //call virtual function to get the possible paths to the runtime library.
175 int size = 0;
176 char const* const* arRtPaths = getRuntimePaths( & size);
177 vector<OUString> libpaths = getVectorFromCharArray(arRtPaths, size);
179 bool bRt = false;
180 typedef vector<OUString>::const_iterator i_path;
181 for(i_path ip = libpaths.begin(); ip != libpaths.end(); ++ip)
183 //Construct an absolute path to the possible runtime
184 OUString usRt= m_sHome + *ip;
185 DirectoryItem item;
186 if(DirectoryItem::get(usRt, item) == File::E_None)
188 //found runtime lib
189 m_sRuntimeLibrary = usRt;
190 bRt = true;
191 break;
195 if (!bRt)
197 m_sHome = m_sJavaHome;
198 for(i_path ip = libpaths.begin(); ip != libpaths.end(); ++ip)
200 //Construct an absolute path to the possible runtime
201 OUString usRt= m_sHome + *ip;
202 DirectoryItem item;
203 if(DirectoryItem::get(usRt, item) == File::E_None)
205 //found runtime lib
206 m_sRuntimeLibrary = usRt;
207 bRt = true;
208 break;
213 // try to find it by the java.library.path property
214 if (!bRt && m_sJavaHome != sJavaLibraryPath)
216 m_sHome = sJavaLibraryPath;
217 for(i_path ip = libpaths.begin(); ip != libpaths.end(); ++ip)
219 //Construct an absolute path to the possible runtime
220 OUString usRt= m_sHome + *ip;
221 DirectoryItem item;
222 if(DirectoryItem::get(usRt, item) == File::E_None)
224 //found runtime lib
225 m_sRuntimeLibrary = usRt;
226 bRt = true;
227 break;
232 #ifdef X86_64
233 //Make one last final legacy attempt on x86_64 in case the distro placed it in lib64 instead
234 if (!bRt && m_sJavaHome != "file:///usr/lib")
236 m_sHome = "file:///usr/lib64";
237 for(i_path ip = libpaths.begin(); ip != libpaths.end(); ++ip)
239 //Construct an absolute path to the possible runtime
240 OUString usRt= m_sHome + *ip;
241 DirectoryItem item;
242 if(DirectoryItem::get(usRt, item) == File::E_None)
244 //found runtime lib
245 m_sRuntimeLibrary = usRt;
246 bRt = true;
247 break;
251 #endif
253 if (!bRt)
254 return false;
256 // init m_sLD_LIBRARY_PATH
257 OSL_ASSERT(!m_sHome.isEmpty());
258 size = 0;
259 char const * const * arLDPaths = getLibraryPaths( & size);
260 vector<OUString> ld_paths = getVectorFromCharArray(arLDPaths, size);
262 char arSep[]= {SAL_PATHSEPARATOR, 0};
263 OUString sPathSep= OUString::createFromAscii(arSep);
264 bool bLdPath = true;
265 int c = 0;
266 for(i_path il = ld_paths.begin(); il != ld_paths.end(); ++il, ++c)
268 OUString usAbsUrl= m_sHome + *il;
269 // convert to system path
270 OUString usSysPath;
271 if(File::getSystemPathFromFileURL(usAbsUrl, usSysPath) == File::E_None)
274 if(c > 0)
275 m_sLD_LIBRARY_PATH+= sPathSep;
276 m_sLD_LIBRARY_PATH+= usSysPath;
278 else
280 bLdPath = false;
281 break;
284 if (!bLdPath)
285 return false;
287 return true;
290 int GnuInfo::compareVersions(const OUString&) const
292 return 0;
297 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */