1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
28 using ::rtl::Reference
;
33 Reference
<VendorBase
> GnuInfo::createInstance()
38 char const* const* GnuInfo::getJavaExePaths(int * size
)
40 static char const * ar
[] = {
50 *size
= sizeof (ar
) / sizeof (char*);
54 #if defined(MIPS) && defined(OSL_LITENDIAN)
55 #define GCJ_JFW_PLUGIN_ARCH "mipsel"
57 #define GCJ_JFW_PLUGIN_ARCH JFW_PLUGIN_ARCH
60 char const* const* GnuInfo::getRuntimePaths(int * size
)
62 static char const* ar
[]= {
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",
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",
83 *size
= sizeof(ar
) / sizeof (char*);
87 char const* const* GnuInfo::getLibraryPaths(int* /*size*/)
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;
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
;
121 else if (!bVersion
&& sVersionProperty
.equals(i
->first
))
123 m_sVersion
= i
->second
;
126 else if (!bHome
&& sGNUHomeProperty
.equals(i
->first
))
131 else if (!bJavaHome
&& sJavaHomeProperty
.equals(i
->first
))
134 if (osl_getFileURLFromSystemPath(i
->second
.pData
,& fileURL
.pData
) ==
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
;
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;
161 // the javax.accessibility.xxx property may not be set. Therefore we
162 //must search through all properties.
165 if (!bVersion
|| !bVendor
|| !bHome
)
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.
176 char const* const* arRtPaths
= getRuntimePaths( & size
);
177 vector
<OUString
> libpaths
= getVectorFromCharArray(arRtPaths
, size
);
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
;
186 if(DirectoryItem::get(usRt
, item
) == File::E_None
)
189 m_sRuntimeLibrary
= usRt
;
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
;
203 if(DirectoryItem::get(usRt
, item
) == File::E_None
)
206 m_sRuntimeLibrary
= usRt
;
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
;
222 if(DirectoryItem::get(usRt
, item
) == File::E_None
)
225 m_sRuntimeLibrary
= usRt
;
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
;
242 if(DirectoryItem::get(usRt
, item
) == File::E_None
)
245 m_sRuntimeLibrary
= usRt
;
256 // init m_sLD_LIBRARY_PATH
257 OSL_ASSERT(!m_sHome
.isEmpty());
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
);
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
271 if(File::getSystemPathFromFileURL(usAbsUrl
, usSysPath
) == File::E_None
)
275 m_sLD_LIBRARY_PATH
+= sPathSep
;
276 m_sLD_LIBRARY_PATH
+= usSysPath
;
290 int GnuInfo::compareVersions(const OUString
&) const
297 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */