lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / jvmfwk / plugins / sunmajor / pluginlib / gnujre.cxx
blobce4bc77bc69cf69dbd7b7bd36f680c0a190bdb93
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 = SAL_N_ELEMENTS (ar);
51 return ar;
54 #if defined(MIPS) && defined(OSL_LITENDIAN)
55 #define GCJ_JFW_PLUGIN_ARCH "mipsel"
56 #elif defined(MIPS64) && defined(OSL_LITENDIAN)
57 #define GCJ_JFW_PLUGIN_ARCH "mips64el"
58 #else
59 #define GCJ_JFW_PLUGIN_ARCH JFW_PLUGIN_ARCH
60 #endif
62 char const* const* GnuInfo::getRuntimePaths(int * size)
64 static char const* ar[]= {
65 "/libjvm.so",
66 "/lib/" GCJ_JFW_PLUGIN_ARCH "/client/libjvm.so",
67 "/gcj-4.1.1/libjvm.so",
68 "/gcj-4.3-90/libjvm.so",
69 "/gcj-4.2-81/libjvm.so",
70 "/gcj-4.2/libjvm.so",
71 "/gcj-4.2.1/libjvm.so",
72 "/gcj-4.2.2/libjvm.so",
73 "/gcj-4.2.3/libjvm.so",
74 "/gcj-4.1-71/libjvm.so",
75 "/gcj-4_1/libjvm.so",
76 "/gcj-4.1/libjvm.so",
77 "/libgcj.so.81",
78 "/libgcj.so.80",
79 "/libgcj.so.8",
80 "/libgcj.so.71",
81 "/libgcj.so.70",
82 "/libgcj.so.7",
83 "/libgcj.so.6"
85 *size = SAL_N_ELEMENTS(ar);
86 return ar;
89 char const* const* GnuInfo::getLibraryPaths(int* /*size*/)
91 return nullptr;
94 bool GnuInfo::initialize(vector<pair<OUString, OUString> > props)
96 //get java.vendor, java.version, java.home,
97 //javax.accessibility.assistive_technologies from system properties
99 OUString sJavaLibraryPath;
100 OUString const sVendorProperty("java.vendor");
101 OUString const sVersionProperty("java.version");
102 OUString const sJavaHomeProperty("java.home");
103 OUString const sJavaLibraryPathProperty("java.library.path");
104 OUString const sGNUHomeProperty("gnu.classpath.home.url");
105 OUString const sAccessProperty("javax.accessibility.assistive_technologies");
107 bool bVersion = false;
108 bool bVendor = false;
109 bool bHome = false;
110 bool bJavaHome = false;
111 bool bJavaLibraryPath = false;
112 bool bAccess = false;
114 for (auto const& prop : props)
116 if(! bVendor && sVendorProperty == prop.first)
118 m_sVendor = prop.second;
119 bVendor = true;
121 else if (!bVersion && sVersionProperty == prop.first)
123 m_sVersion = prop.second;
124 bVersion = true;
126 else if (!bHome && sGNUHomeProperty == prop.first)
128 m_sHome = prop.second;
129 bHome = true;
131 else if (!bJavaHome && sJavaHomeProperty == prop.first)
133 OUString fileURL;
134 if (osl_getFileURLFromSystemPath(prop.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 == prop.first)
149 sal_Int32 nIndex = 0;
150 osl_getFileURLFromSystemPath(prop.second.getToken(0, ':', nIndex).pData, &sJavaLibraryPath.pData);
151 bJavaLibraryPath = true;
153 else if (!bAccess && sAccessProperty == prop.first)
155 if (!prop.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 for (auto const& libpath : libpaths)
182 //Construct an absolute path to the possible runtime
183 OUString usRt= m_sHome + libpath;
184 DirectoryItem item;
185 if(DirectoryItem::get(usRt, item) == File::E_None)
187 //found runtime lib
188 m_sRuntimeLibrary = usRt;
189 bRt = true;
190 break;
194 if (!bRt)
196 m_sHome = m_sJavaHome;
197 for (auto const& libpath : libpaths)
199 //Construct an absolute path to the possible runtime
200 OUString usRt= m_sHome + libpath;
201 DirectoryItem item;
202 if(DirectoryItem::get(usRt, item) == File::E_None)
204 //found runtime lib
205 m_sRuntimeLibrary = usRt;
206 bRt = true;
207 break;
212 // try to find it by the java.library.path property
213 if (!bRt && m_sJavaHome != sJavaLibraryPath)
215 m_sHome = sJavaLibraryPath;
216 for (auto const& libpath : libpaths)
218 //Construct an absolute path to the possible runtime
219 OUString usRt= m_sHome + libpath;
220 DirectoryItem item;
221 if(DirectoryItem::get(usRt, item) == File::E_None)
223 //found runtime lib
224 m_sRuntimeLibrary = usRt;
225 bRt = true;
226 break;
231 #ifdef X86_64
232 //Make one last final legacy attempt on x86_64 in case the distro placed it in lib64 instead
233 if (!bRt && m_sJavaHome != "file:///usr/lib")
235 m_sHome = "file:///usr/lib64";
236 for (auto const& libpath : libpaths)
238 //Construct an absolute path to the possible runtime
239 OUString usRt= m_sHome + libpath;
240 DirectoryItem item;
241 if(DirectoryItem::get(usRt, item) == File::E_None)
243 //found runtime lib
244 m_sRuntimeLibrary = usRt;
245 bRt = true;
246 break;
250 #endif
252 if (!bRt)
253 return false;
255 // init m_sLD_LIBRARY_PATH
256 OSL_ASSERT(!m_sHome.isEmpty());
257 size = 0;
258 char const * const * arLDPaths = getLibraryPaths( & size);
259 vector<OUString> ld_paths = getVectorFromCharArray(arLDPaths, size);
261 bool bLdPath = true;
262 int c = 0;
263 for (auto const& ld_path : ld_paths)
265 OUString usAbsUrl= m_sHome + ld_path;
266 // convert to system path
267 OUString usSysPath;
268 if(File::getSystemPathFromFileURL(usAbsUrl, usSysPath) == File::E_None)
271 if(c > 0)
272 m_sLD_LIBRARY_PATH+= OUStringLiteral1(SAL_PATHSEPARATOR);
273 m_sLD_LIBRARY_PATH+= usSysPath;
275 else
277 bLdPath = false;
278 break;
280 ++c;
282 return bLdPath;
285 int GnuInfo::compareVersions(const OUString&) const
287 return 0;
292 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */