Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include "osl/file.hxx"
22 : #include "osl/thread.h"
23 : #include "gnujre.hxx"
24 : #include "util.hxx"
25 :
26 : using namespace std;
27 : using namespace osl;
28 : using ::rtl::Reference;
29 :
30 : namespace jfw_plugin
31 : {
32 :
33 0 : Reference<VendorBase> GnuInfo::createInstance()
34 : {
35 0 : return new GnuInfo;
36 : }
37 :
38 66 : char const* const* GnuInfo::getJavaExePaths(int * size)
39 : {
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"
49 : };
50 66 : *size = sizeof (ar) / sizeof (char*);
51 66 : return ar;
52 : }
53 :
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
59 :
60 0 : char const* const* GnuInfo::getRuntimePaths(int * size)
61 : {
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"
82 : };
83 0 : *size = sizeof(ar) / sizeof (char*);
84 0 : return ar;
85 : }
86 :
87 0 : bool GnuInfo::initialize(vector<pair<OUString, OUString> > props)
88 : {
89 : //get java.vendor, java.version, java.home,
90 : //javax.accessibility.assistive_technologies from system properties
91 :
92 0 : OUString sJavaLibraryPath;
93 : typedef vector<pair<OUString, OUString> >::const_iterator it_prop;
94 0 : OUString sVendorProperty("java.vendor");
95 0 : OUString sVersionProperty("java.version");
96 0 : OUString sJavaHomeProperty("java.home");
97 0 : OUString sJavaLibraryPathProperty("java.library.path");
98 0 : OUString sGNUHomeProperty("gnu.classpath.home.url");
99 0 : OUString sAccessProperty("javax.accessibility.assistive_technologies");
100 :
101 0 : bool bVersion = false;
102 0 : bool bVendor = false;
103 0 : bool bHome = false;
104 0 : bool bJavaHome = false;
105 0 : bool bJavaLibraryPath = false;
106 0 : bool bAccess = false;
107 :
108 : typedef vector<pair<OUString, OUString> >::const_iterator it_prop;
109 0 : for (it_prop i = props.begin(); i != props.end(); ++i)
110 : {
111 0 : if(! bVendor && sVendorProperty.equals(i->first))
112 : {
113 0 : m_sVendor = i->second;
114 0 : bVendor = true;
115 : }
116 0 : else if (!bVersion && sVersionProperty.equals(i->first))
117 : {
118 0 : m_sVersion = i->second;
119 0 : bVersion = true;
120 : }
121 0 : else if (!bHome && sGNUHomeProperty.equals(i->first))
122 : {
123 0 : m_sHome = i->second;
124 0 : bHome = true;
125 : }
126 0 : else if (!bJavaHome && sJavaHomeProperty.equals(i->first))
127 : {
128 0 : OUString fileURL;
129 0 : if (osl_getFileURLFromSystemPath(i->second.pData,& fileURL.pData) ==
130 : osl_File_E_None)
131 : {
132 : //make sure that the drive letter have all the same case
133 : //otherwise file:///c:/jre and file:///C:/jre produce two
134 : //different objects!!!
135 0 : if (makeDriveLetterSame( & fileURL))
136 : {
137 0 : m_sJavaHome = fileURL;
138 0 : bJavaHome = true;
139 : }
140 0 : }
141 : }
142 0 : else if (!bJavaLibraryPath && sJavaLibraryPathProperty.equals(i->first))
143 : {
144 0 : sal_Int32 nIndex = 0;
145 0 : osl_getFileURLFromSystemPath(i->second.getToken(0, ':', nIndex).pData, &sJavaLibraryPath.pData);
146 0 : bJavaLibraryPath = true;
147 : }
148 0 : else if (!bAccess && sAccessProperty.equals(i->first))
149 : {
150 0 : if (!i->second.isEmpty())
151 : {
152 0 : m_bAccessibility = true;
153 0 : bAccess = true;
154 : }
155 : }
156 : // the javax.accessibility.xxx property may not be set. Therefore we
157 : //must search through all properties.
158 :
159 : }
160 0 : if (!bVersion || !bVendor || !bHome)
161 0 : return false;
162 :
163 0 : if (m_sJavaHome.isEmpty())
164 0 : m_sJavaHome = "file:///usr/lib";
165 :
166 : // init m_sRuntimeLibrary
167 : OSL_ASSERT(!m_sHome.isEmpty());
168 : //call virtual function to get the possible paths to the runtime library.
169 :
170 0 : int size = 0;
171 0 : char const* const* arRtPaths = getRuntimePaths( & size);
172 0 : vector<OUString> libpaths = getVectorFromCharArray(arRtPaths, size);
173 :
174 0 : bool bRt = false;
175 : typedef vector<OUString>::const_iterator i_path;
176 0 : for(i_path ip = libpaths.begin(); ip != libpaths.end(); ++ip)
177 : {
178 : //Construct an absolute path to the possible runtime
179 0 : OUString usRt= m_sHome + *ip;
180 0 : DirectoryItem item;
181 0 : if(DirectoryItem::get(usRt, item) == File::E_None)
182 : {
183 : //found runtime lib
184 0 : m_sRuntimeLibrary = usRt;
185 0 : bRt = true;
186 0 : break;
187 : }
188 0 : }
189 :
190 0 : if (!bRt)
191 : {
192 0 : m_sHome = m_sJavaHome;
193 0 : for(i_path ip = libpaths.begin(); ip != libpaths.end(); ++ip)
194 : {
195 : //Construct an absolute path to the possible runtime
196 0 : OUString usRt= m_sHome + *ip;
197 0 : DirectoryItem item;
198 0 : if(DirectoryItem::get(usRt, item) == File::E_None)
199 : {
200 : //found runtime lib
201 0 : m_sRuntimeLibrary = usRt;
202 0 : bRt = true;
203 0 : break;
204 : }
205 0 : }
206 : }
207 :
208 : // try to find it by the java.library.path property
209 0 : if (!bRt && m_sJavaHome != sJavaLibraryPath)
210 : {
211 0 : m_sHome = sJavaLibraryPath;
212 0 : for(i_path ip = libpaths.begin(); ip != libpaths.end(); ++ip)
213 : {
214 : //Construct an absolute path to the possible runtime
215 0 : OUString usRt= m_sHome + *ip;
216 0 : DirectoryItem item;
217 0 : if(DirectoryItem::get(usRt, item) == File::E_None)
218 : {
219 : //found runtime lib
220 0 : m_sRuntimeLibrary = usRt;
221 0 : bRt = true;
222 0 : break;
223 : }
224 0 : }
225 : }
226 :
227 : #ifdef X86_64
228 : //Make one last final legacy attempt on x86_64 in case the distro placed it in lib64 instead
229 : if (!bRt && m_sJavaHome != "file:///usr/lib")
230 : {
231 : m_sHome = "file:///usr/lib64";
232 : for(i_path ip = libpaths.begin(); ip != libpaths.end(); ++ip)
233 : {
234 : //Construct an absolute path to the possible runtime
235 : OUString usRt= m_sHome + *ip;
236 : DirectoryItem item;
237 : if(DirectoryItem::get(usRt, item) == File::E_None)
238 : {
239 : //found runtime lib
240 : m_sRuntimeLibrary = usRt;
241 : bRt = true;
242 : break;
243 : }
244 : }
245 : }
246 : #endif
247 :
248 0 : if (!bRt)
249 0 : return false;
250 :
251 : // init m_sLD_LIBRARY_PATH
252 : OSL_ASSERT(!m_sHome.isEmpty());
253 0 : size = 0;
254 0 : char const * const * arLDPaths = getLibraryPaths( & size);
255 0 : vector<OUString> ld_paths = getVectorFromCharArray(arLDPaths, size);
256 :
257 0 : char arSep[]= {SAL_PATHSEPARATOR, 0};
258 0 : OUString sPathSep= OUString::createFromAscii(arSep);
259 0 : bool bLdPath = true;
260 0 : int c = 0;
261 0 : for(i_path il = ld_paths.begin(); il != ld_paths.end(); ++il, ++c)
262 : {
263 0 : OUString usAbsUrl= m_sHome + *il;
264 : // convert to system path
265 0 : OUString usSysPath;
266 0 : if(File::getSystemPathFromFileURL(usAbsUrl, usSysPath) == File::E_None)
267 : {
268 :
269 0 : if(c > 0)
270 0 : m_sLD_LIBRARY_PATH+= sPathSep;
271 0 : m_sLD_LIBRARY_PATH+= usSysPath;
272 : }
273 : else
274 : {
275 0 : bLdPath = false;
276 0 : break;
277 : }
278 0 : }
279 0 : if (bLdPath == false)
280 0 : return false;
281 :
282 0 : return true;
283 : }
284 :
285 0 : int GnuInfo::compareVersions(const OUString&) const
286 : {
287 0 : return 0;
288 : }
289 :
290 : }
291 :
292 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|