1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_jvmfwk.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "osl/file.hxx" 32*cdf0e10cSrcweir #include "osl/thread.h" 33*cdf0e10cSrcweir #include "gnujre.hxx" 34*cdf0e10cSrcweir #include "util.hxx" 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir using namespace rtl; 37*cdf0e10cSrcweir using namespace std; 38*cdf0e10cSrcweir using namespace osl; 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir namespace jfw_plugin 41*cdf0e10cSrcweir { 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir Reference<VendorBase> GnuInfo::createInstance() 44*cdf0e10cSrcweir { 45*cdf0e10cSrcweir return new GnuInfo; 46*cdf0e10cSrcweir } 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir char const* const* GnuInfo::getJavaExePaths(int * size) 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir static char const * ar[] = { 51*cdf0e10cSrcweir "gij", 52*cdf0e10cSrcweir "bin/gij", 53*cdf0e10cSrcweir }; 54*cdf0e10cSrcweir *size = sizeof (ar) / sizeof (char*); 55*cdf0e10cSrcweir return ar; 56*cdf0e10cSrcweir } 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir #if defined(MIPS) && defined(OSL_LITENDIAN) 59*cdf0e10cSrcweir #define GCJ_JFW_PLUGIN_ARCH "mipsel" 60*cdf0e10cSrcweir #else 61*cdf0e10cSrcweir #define GCJ_JFW_PLUGIN_ARCH JFW_PLUGIN_ARCH 62*cdf0e10cSrcweir #endif 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir char const* const* GnuInfo::getRuntimePaths(int * size) 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir static char const* ar[]= { 67*cdf0e10cSrcweir "/libjvm.so", 68*cdf0e10cSrcweir "/lib/" GCJ_JFW_PLUGIN_ARCH "/client/libjvm.so", 69*cdf0e10cSrcweir "/gcj-4.1.1/libjvm.so", 70*cdf0e10cSrcweir "/libgcj.so.7", 71*cdf0e10cSrcweir "/libgcj.so.6" 72*cdf0e10cSrcweir }; 73*cdf0e10cSrcweir *size = sizeof(ar) / sizeof (char*); 74*cdf0e10cSrcweir return ar; 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir bool GnuInfo::initialize(vector<pair<OUString, OUString> > props) 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir //get java.vendor, java.version, java.home, 80*cdf0e10cSrcweir //javax.accessibility.assistive_technologies from system properties 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir OUString sVendor; 83*cdf0e10cSrcweir OUString sJavaLibraryPath; 84*cdf0e10cSrcweir typedef vector<pair<OUString, OUString> >::const_iterator it_prop; 85*cdf0e10cSrcweir OUString sVendorProperty( 86*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("java.vendor")); 87*cdf0e10cSrcweir OUString sVersionProperty( 88*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("java.version")); 89*cdf0e10cSrcweir OUString sJavaHomeProperty( 90*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("java.home")); 91*cdf0e10cSrcweir OUString sJavaLibraryPathProperty( 92*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("java.library.path")); 93*cdf0e10cSrcweir OUString sGNUHomeProperty( 94*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("gnu.classpath.home.url")); 95*cdf0e10cSrcweir OUString sAccessProperty( 96*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("javax.accessibility.assistive_technologies")); 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir bool bVersion = false; 99*cdf0e10cSrcweir bool bVendor = false; 100*cdf0e10cSrcweir bool bHome = false; 101*cdf0e10cSrcweir bool bJavaHome = false; 102*cdf0e10cSrcweir bool bJavaLibraryPath = false; 103*cdf0e10cSrcweir bool bAccess = false; 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir typedef vector<pair<OUString, OUString> >::const_iterator it_prop; 106*cdf0e10cSrcweir for (it_prop i = props.begin(); i != props.end(); i++) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir if(! bVendor && sVendorProperty.equals(i->first)) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir m_sVendor = i->second; 111*cdf0e10cSrcweir bVendor = true; 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir else if (!bVersion && sVersionProperty.equals(i->first)) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir m_sVersion = i->second; 116*cdf0e10cSrcweir bVersion = true; 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir else if (!bHome && sGNUHomeProperty.equals(i->first)) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir m_sHome = i->second; 121*cdf0e10cSrcweir bHome = true; 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir else if (!bJavaHome && sJavaHomeProperty.equals(i->first)) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir OUString fileURL; 126*cdf0e10cSrcweir if (osl_getFileURLFromSystemPath(i->second.pData,& fileURL.pData) == 127*cdf0e10cSrcweir osl_File_E_None) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir //make sure that the drive letter have all the same case 130*cdf0e10cSrcweir //otherwise file:///c:/jre and file:///C:/jre produce two 131*cdf0e10cSrcweir //different objects!!! 132*cdf0e10cSrcweir if (makeDriveLetterSame( & fileURL)) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir m_sJavaHome = fileURL; 135*cdf0e10cSrcweir bJavaHome = true; 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir else if (!bJavaLibraryPath && sJavaLibraryPathProperty.equals(i->first)) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir sal_Int32 nIndex = 0; 142*cdf0e10cSrcweir osl_getFileURLFromSystemPath(i->second.getToken(0, ':', nIndex).pData, &sJavaLibraryPath.pData); 143*cdf0e10cSrcweir bJavaLibraryPath = true; 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir else if (!bAccess && sAccessProperty.equals(i->first)) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir if (i->second.getLength() > 0) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir m_bAccessibility = true; 150*cdf0e10cSrcweir bAccess = true; 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir // the javax.accessibility.xxx property may not be set. Therefore we 154*cdf0e10cSrcweir //must search through all properties. 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir if (!bVersion || !bVendor || !bHome) 158*cdf0e10cSrcweir return false; 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir if (!m_sJavaHome.getLength()) 161*cdf0e10cSrcweir m_sJavaHome = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:///usr/lib")); 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir // init m_sRuntimeLibrary 164*cdf0e10cSrcweir OSL_ASSERT(m_sHome.getLength()); 165*cdf0e10cSrcweir //call virtual function to get the possible paths to the runtime library. 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir int size = 0; 168*cdf0e10cSrcweir char const* const* arRtPaths = getRuntimePaths( & size); 169*cdf0e10cSrcweir vector<OUString> libpaths = getVectorFromCharArray(arRtPaths, size); 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir bool bRt = false; 172*cdf0e10cSrcweir typedef vector<OUString>::const_iterator i_path; 173*cdf0e10cSrcweir for(i_path ip = libpaths.begin(); ip != libpaths.end(); ip++) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir //Construct an absolute path to the possible runtime 176*cdf0e10cSrcweir OUString usRt= m_sHome + *ip; 177*cdf0e10cSrcweir DirectoryItem item; 178*cdf0e10cSrcweir if(DirectoryItem::get(usRt, item) == File::E_None) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir //found runtime lib 181*cdf0e10cSrcweir m_sRuntimeLibrary = usRt; 182*cdf0e10cSrcweir bRt = true; 183*cdf0e10cSrcweir break; 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir if (!bRt) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir m_sHome = m_sJavaHome; 190*cdf0e10cSrcweir for(i_path ip = libpaths.begin(); ip != libpaths.end(); ip++) 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir //Construct an absolute path to the possible runtime 193*cdf0e10cSrcweir OUString usRt= m_sHome + *ip; 194*cdf0e10cSrcweir DirectoryItem item; 195*cdf0e10cSrcweir if(DirectoryItem::get(usRt, item) == File::E_None) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir //found runtime lib 198*cdf0e10cSrcweir m_sRuntimeLibrary = usRt; 199*cdf0e10cSrcweir bRt = true; 200*cdf0e10cSrcweir break; 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir // try to find it by the java.library.path property 206*cdf0e10cSrcweir if (!bRt && m_sJavaHome != sJavaLibraryPath) 207*cdf0e10cSrcweir { 208*cdf0e10cSrcweir m_sHome = sJavaLibraryPath; 209*cdf0e10cSrcweir for(i_path ip = libpaths.begin(); ip != libpaths.end(); ip++) 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir //Construct an absolute path to the possible runtime 212*cdf0e10cSrcweir OUString usRt= m_sHome + *ip; 213*cdf0e10cSrcweir DirectoryItem item; 214*cdf0e10cSrcweir if(DirectoryItem::get(usRt, item) == File::E_None) 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir //found runtime lib 217*cdf0e10cSrcweir m_sRuntimeLibrary = usRt; 218*cdf0e10cSrcweir bRt = true; 219*cdf0e10cSrcweir break; 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir #ifdef X86_64 225*cdf0e10cSrcweir //Make one last final legacy attempt on x86_64 in case the distro placed it in lib64 instead 226*cdf0e10cSrcweir if (!bRt && m_sJavaHome != rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:///usr/lib"))) 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir m_sHome = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:///usr/lib64")); 229*cdf0e10cSrcweir for(i_path ip = libpaths.begin(); ip != libpaths.end(); ip++) 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir //Construct an absolute path to the possible runtime 232*cdf0e10cSrcweir OUString usRt= m_sHome + *ip; 233*cdf0e10cSrcweir DirectoryItem item; 234*cdf0e10cSrcweir if(DirectoryItem::get(usRt, item) == File::E_None) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir //found runtime lib 237*cdf0e10cSrcweir m_sRuntimeLibrary = usRt; 238*cdf0e10cSrcweir bRt = true; 239*cdf0e10cSrcweir break; 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir } 243*cdf0e10cSrcweir #endif 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir if (!bRt) 246*cdf0e10cSrcweir return false; 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir // init m_sLD_LIBRARY_PATH 249*cdf0e10cSrcweir OSL_ASSERT(m_sHome.getLength()); 250*cdf0e10cSrcweir size = 0; 251*cdf0e10cSrcweir char const * const * arLDPaths = getLibraryPaths( & size); 252*cdf0e10cSrcweir vector<OUString> ld_paths = getVectorFromCharArray(arLDPaths, size); 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir char arSep[]= {SAL_PATHSEPARATOR, 0}; 255*cdf0e10cSrcweir OUString sPathSep= OUString::createFromAscii(arSep); 256*cdf0e10cSrcweir bool bLdPath = true; 257*cdf0e10cSrcweir int c = 0; 258*cdf0e10cSrcweir for(i_path il = ld_paths.begin(); il != ld_paths.end(); il ++, c++) 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir OUString usAbsUrl= m_sHome + *il; 261*cdf0e10cSrcweir // convert to system path 262*cdf0e10cSrcweir OUString usSysPath; 263*cdf0e10cSrcweir if(File::getSystemPathFromFileURL(usAbsUrl, usSysPath) == File::E_None) 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir if(c > 0) 267*cdf0e10cSrcweir m_sLD_LIBRARY_PATH+= sPathSep; 268*cdf0e10cSrcweir m_sLD_LIBRARY_PATH+= usSysPath; 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir else 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir bLdPath = false; 273*cdf0e10cSrcweir break; 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir } 276*cdf0e10cSrcweir if (bLdPath == false) 277*cdf0e10cSrcweir return false; 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir return true; 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir int GnuInfo::compareVersions(const rtl::OUString&) const 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir return 0; 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir } 288