1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_jvmfwk.hxx" 26 27 #include "osl/file.hxx" 28 #include "osl/thread.h" 29 #include "gnujre.hxx" 30 #include "util.hxx" 31 32 using namespace rtl; 33 using namespace std; 34 using namespace osl; 35 36 namespace jfw_plugin 37 { 38 39 Reference<VendorBase> GnuInfo::createInstance() 40 { 41 return new GnuInfo; 42 } 43 44 char const* const* GnuInfo::getJavaExePaths(int * size) 45 { 46 static char const * ar[] = { 47 "gij", 48 "bin/gij", 49 }; 50 *size = sizeof (ar) / sizeof (char*); 51 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 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 "/libgcj.so.7", 67 "/libgcj.so.6" 68 }; 69 *size = sizeof(ar) / sizeof (char*); 70 return ar; 71 } 72 73 bool GnuInfo::initialize(vector<pair<OUString, OUString> > props) 74 { 75 //get java.vendor, java.version, java.home, 76 //javax.accessibility.assistive_technologies from system properties 77 78 OUString sVendor; 79 OUString sJavaLibraryPath; 80 typedef vector<pair<OUString, OUString> >::const_iterator it_prop; 81 OUString sVendorProperty( 82 RTL_CONSTASCII_USTRINGPARAM("java.vendor")); 83 OUString sVersionProperty( 84 RTL_CONSTASCII_USTRINGPARAM("java.version")); 85 OUString sJavaHomeProperty( 86 RTL_CONSTASCII_USTRINGPARAM("java.home")); 87 OUString sJavaLibraryPathProperty( 88 RTL_CONSTASCII_USTRINGPARAM("java.library.path")); 89 OUString sGNUHomeProperty( 90 RTL_CONSTASCII_USTRINGPARAM("gnu.classpath.home.url")); 91 OUString sAccessProperty( 92 RTL_CONSTASCII_USTRINGPARAM("javax.accessibility.assistive_technologies")); 93 94 bool bVersion = false; 95 bool bVendor = false; 96 bool bHome = false; 97 bool bJavaHome = false; 98 bool bJavaLibraryPath = false; 99 bool bAccess = false; 100 101 typedef vector<pair<OUString, OUString> >::const_iterator it_prop; 102 for (it_prop i = props.begin(); i != props.end(); i++) 103 { 104 if(! bVendor && sVendorProperty.equals(i->first)) 105 { 106 m_sVendor = i->second; 107 bVendor = true; 108 } 109 else if (!bVersion && sVersionProperty.equals(i->first)) 110 { 111 m_sVersion = i->second; 112 bVersion = true; 113 } 114 else if (!bHome && sGNUHomeProperty.equals(i->first)) 115 { 116 m_sHome = i->second; 117 bHome = true; 118 } 119 else if (!bJavaHome && sJavaHomeProperty.equals(i->first)) 120 { 121 OUString fileURL; 122 if (osl_getFileURLFromSystemPath(i->second.pData,& fileURL.pData) == 123 osl_File_E_None) 124 { 125 //make sure that the drive letter have all the same case 126 //otherwise file:///c:/jre and file:///C:/jre produce two 127 //different objects!!! 128 if (makeDriveLetterSame( & fileURL)) 129 { 130 m_sJavaHome = fileURL; 131 bJavaHome = true; 132 } 133 } 134 } 135 else if (!bJavaLibraryPath && sJavaLibraryPathProperty.equals(i->first)) 136 { 137 sal_Int32 nIndex = 0; 138 osl_getFileURLFromSystemPath(i->second.getToken(0, ':', nIndex).pData, &sJavaLibraryPath.pData); 139 bJavaLibraryPath = true; 140 } 141 else if (!bAccess && sAccessProperty.equals(i->first)) 142 { 143 if (i->second.getLength() > 0) 144 { 145 m_bAccessibility = true; 146 bAccess = true; 147 } 148 } 149 // the javax.accessibility.xxx property may not be set. Therefore we 150 //must search through all properties. 151 152 } 153 if (!bVersion || !bVendor || !bHome) 154 return false; 155 156 if (!m_sJavaHome.getLength()) 157 m_sJavaHome = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:///usr/lib")); 158 159 // init m_sRuntimeLibrary 160 OSL_ASSERT(m_sHome.getLength()); 161 //call virtual function to get the possible paths to the runtime library. 162 163 int size = 0; 164 char const* const* arRtPaths = getRuntimePaths( & size); 165 vector<OUString> libpaths = getVectorFromCharArray(arRtPaths, size); 166 167 bool bRt = false; 168 typedef vector<OUString>::const_iterator i_path; 169 for(i_path ip = libpaths.begin(); ip != libpaths.end(); ip++) 170 { 171 //Construct an absolute path to the possible runtime 172 OUString usRt= m_sHome + *ip; 173 DirectoryItem item; 174 if(DirectoryItem::get(usRt, item) == File::E_None) 175 { 176 //found runtime lib 177 m_sRuntimeLibrary = usRt; 178 bRt = true; 179 break; 180 } 181 } 182 183 if (!bRt) 184 { 185 m_sHome = m_sJavaHome; 186 for(i_path ip = libpaths.begin(); ip != libpaths.end(); ip++) 187 { 188 //Construct an absolute path to the possible runtime 189 OUString usRt= m_sHome + *ip; 190 DirectoryItem item; 191 if(DirectoryItem::get(usRt, item) == File::E_None) 192 { 193 //found runtime lib 194 m_sRuntimeLibrary = usRt; 195 bRt = true; 196 break; 197 } 198 } 199 } 200 201 // try to find it by the java.library.path property 202 if (!bRt && m_sJavaHome != sJavaLibraryPath) 203 { 204 m_sHome = sJavaLibraryPath; 205 for(i_path ip = libpaths.begin(); ip != libpaths.end(); ip++) 206 { 207 //Construct an absolute path to the possible runtime 208 OUString usRt= m_sHome + *ip; 209 DirectoryItem item; 210 if(DirectoryItem::get(usRt, item) == File::E_None) 211 { 212 //found runtime lib 213 m_sRuntimeLibrary = usRt; 214 bRt = true; 215 break; 216 } 217 } 218 } 219 220 #ifdef X86_64 221 //Make one last final legacy attempt on x86_64 in case the distro placed it in lib64 instead 222 if (!bRt && m_sJavaHome != rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:///usr/lib"))) 223 { 224 m_sHome = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:///usr/lib64")); 225 for(i_path ip = libpaths.begin(); ip != libpaths.end(); ip++) 226 { 227 //Construct an absolute path to the possible runtime 228 OUString usRt= m_sHome + *ip; 229 DirectoryItem item; 230 if(DirectoryItem::get(usRt, item) == File::E_None) 231 { 232 //found runtime lib 233 m_sRuntimeLibrary = usRt; 234 bRt = true; 235 break; 236 } 237 } 238 } 239 #endif 240 241 if (!bRt) 242 return false; 243 244 // init m_sLD_LIBRARY_PATH 245 OSL_ASSERT(m_sHome.getLength()); 246 size = 0; 247 char const * const * arLDPaths = getLibraryPaths( & size); 248 vector<OUString> ld_paths = getVectorFromCharArray(arLDPaths, size); 249 250 char arSep[]= {SAL_PATHSEPARATOR, 0}; 251 OUString sPathSep= OUString::createFromAscii(arSep); 252 bool bLdPath = true; 253 int c = 0; 254 for(i_path il = ld_paths.begin(); il != ld_paths.end(); il ++, c++) 255 { 256 OUString usAbsUrl= m_sHome + *il; 257 // convert to system path 258 OUString usSysPath; 259 if(File::getSystemPathFromFileURL(usAbsUrl, usSysPath) == File::E_None) 260 { 261 262 if(c > 0) 263 m_sLD_LIBRARY_PATH+= sPathSep; 264 m_sLD_LIBRARY_PATH+= usSysPath; 265 } 266 else 267 { 268 bLdPath = false; 269 break; 270 } 271 } 272 if (bLdPath == false) 273 return false; 274 275 return true; 276 } 277 278 int GnuInfo::compareVersions(const rtl::OUString&) const 279 { 280 return 0; 281 } 282 283 } 284