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 "util.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include "osl/process.h" 34*cdf0e10cSrcweir #include "osl/security.hxx" 35*cdf0e10cSrcweir #include "osl/thread.hxx" 36*cdf0e10cSrcweir #include "osl/file.hxx" 37*cdf0e10cSrcweir #include "osl/module.hxx" 38*cdf0e10cSrcweir #include "rtl/byteseq.hxx" 39*cdf0e10cSrcweir #include "rtl/ustrbuf.hxx" 40*cdf0e10cSrcweir #include "rtl/instance.hxx" 41*cdf0e10cSrcweir #include "boost/scoped_array.hpp" 42*cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.hxx" 43*cdf0e10cSrcweir #include <utility> 44*cdf0e10cSrcweir #include <algorithm> 45*cdf0e10cSrcweir #include <map> 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir #if defined WNT 48*cdf0e10cSrcweir #if defined _MSC_VER 49*cdf0e10cSrcweir #pragma warning(push, 1) 50*cdf0e10cSrcweir #endif 51*cdf0e10cSrcweir #include <windows.h> 52*cdf0e10cSrcweir #if defined _MSC_VER 53*cdf0e10cSrcweir #pragma warning(pop) 54*cdf0e10cSrcweir #endif 55*cdf0e10cSrcweir #endif 56*cdf0e10cSrcweir #include <string.h> 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir #include "sunjre.hxx" 59*cdf0e10cSrcweir #include "vendorlist.hxx" 60*cdf0e10cSrcweir #include "diagnostics.h" 61*cdf0e10cSrcweir using namespace rtl; 62*cdf0e10cSrcweir using namespace osl; 63*cdf0e10cSrcweir using namespace std; 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir #define CHAR_POINTER(oustr) ::rtl::OUStringToOString(oustr,RTL_TEXTENCODING_UTF8).pData->buffer 66*cdf0e10cSrcweir #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) ) 67*cdf0e10cSrcweir #ifdef WNT 68*cdf0e10cSrcweir #define HKEY_SUN_JRE L"Software\\JavaSoft\\Java Runtime Environment" 69*cdf0e10cSrcweir #define HKEY_SUN_SDK L"Software\\JavaSoft\\Java Development Kit" 70*cdf0e10cSrcweir #endif 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir #ifdef UNX 73*cdf0e10cSrcweir namespace { 74*cdf0e10cSrcweir char const *g_arJavaNames[] = { 75*cdf0e10cSrcweir "", 76*cdf0e10cSrcweir "j2re", 77*cdf0e10cSrcweir "j2se", 78*cdf0e10cSrcweir "j2sdk", 79*cdf0e10cSrcweir "jdk", 80*cdf0e10cSrcweir "jre", 81*cdf0e10cSrcweir "java", 82*cdf0e10cSrcweir "Home", 83*cdf0e10cSrcweir "IBMJava2-ppc-142" 84*cdf0e10cSrcweir }; 85*cdf0e10cSrcweir /* These are directory names which could contain multiple java installations. 86*cdf0e10cSrcweir */ 87*cdf0e10cSrcweir char const *g_arCollectDirs[] = { 88*cdf0e10cSrcweir "", 89*cdf0e10cSrcweir "j2re/", 90*cdf0e10cSrcweir "j2se/", 91*cdf0e10cSrcweir "j2sdk/", 92*cdf0e10cSrcweir "jdk/", 93*cdf0e10cSrcweir "jre/", 94*cdf0e10cSrcweir "java/", 95*cdf0e10cSrcweir "jvm/" 96*cdf0e10cSrcweir }; 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir /* These are directories in which a java installation is 99*cdf0e10cSrcweir looked for. 100*cdf0e10cSrcweir */ 101*cdf0e10cSrcweir char const *g_arSearchPaths[] = { 102*cdf0e10cSrcweir #ifdef MACOSX 103*cdf0e10cSrcweir "", 104*cdf0e10cSrcweir "System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/" 105*cdf0e10cSrcweir #else 106*cdf0e10cSrcweir "", 107*cdf0e10cSrcweir "usr/", 108*cdf0e10cSrcweir "usr/local/", 109*cdf0e10cSrcweir "usr/local/IBMJava2-ppc-142", 110*cdf0e10cSrcweir "usr/local/j2sdk1.3.1", 111*cdf0e10cSrcweir #ifdef X86_64 112*cdf0e10cSrcweir "usr/lib64/", 113*cdf0e10cSrcweir #endif 114*cdf0e10cSrcweir "usr/lib/", 115*cdf0e10cSrcweir "usr/bin/" 116*cdf0e10cSrcweir #endif 117*cdf0e10cSrcweir }; 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir #endif // UNX 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir namespace jfw_plugin 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir extern VendorSupportMapEntry gVendorMap[]; 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir bool getSDKInfoFromRegistry(vector<OUString> & vecHome); 126*cdf0e10cSrcweir bool getJREInfoFromRegistry(vector<OUString>& vecJavaHome); 127*cdf0e10cSrcweir bool decodeOutput(const rtl::OString& s, rtl::OUString* out); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir namespace 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir rtl::OUString getLibraryLocation() 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir rtl::OUString libraryFileUrl; 136*cdf0e10cSrcweir OSL_VERIFY(osl::Module::getUrlFromAddress((void *)(sal_IntPtr)getLibraryLocation, libraryFileUrl)); 137*cdf0e10cSrcweir return getDirFromFile(libraryFileUrl); 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir struct InitBootstrap 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir rtl::Bootstrap * operator()(const OUString& sIni) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir static rtl::Bootstrap aInstance(sIni); 145*cdf0e10cSrcweir return & aInstance; 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir }; 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir struct InitBootstrapData 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir OUString const & operator()() 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir // osl::Guard<osl::Mutex> g(osl::GetGlobalMutex()); 155*cdf0e10cSrcweir static OUString sIni; 156*cdf0e10cSrcweir rtl::OUStringBuffer buf( 255); 157*cdf0e10cSrcweir buf.append( getLibraryLocation()); 158*cdf0e10cSrcweir buf.appendAscii( SAL_CONFIGFILE("/sunjavaplugin") ); 159*cdf0e10cSrcweir sIni = buf.makeStringAndClear(); 160*cdf0e10cSrcweir JFW_TRACE2(OUSTR("[Java framework] sunjavaplugin: " 161*cdf0e10cSrcweir "Using configuration file \n") + sIni); 162*cdf0e10cSrcweir return sIni; 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir }; 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir rtl::Bootstrap * getBootstrap() 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir return rtl_Instance< rtl::Bootstrap, InitBootstrap, 170*cdf0e10cSrcweir ::osl::MutexGuard, ::osl::GetGlobalMutex, 171*cdf0e10cSrcweir OUString, InitBootstrapData >::create( 172*cdf0e10cSrcweir InitBootstrap(), ::osl::GetGlobalMutex(), InitBootstrapData()); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir class FileHandleGuard 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir public: 181*cdf0e10cSrcweir inline FileHandleGuard(oslFileHandle & rHandle) SAL_THROW(()): 182*cdf0e10cSrcweir m_rHandle(rHandle) {} 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir inline ~FileHandleGuard() SAL_THROW(()); 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir inline oslFileHandle & getHandle() SAL_THROW(()) { return m_rHandle; } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir private: 189*cdf0e10cSrcweir oslFileHandle & m_rHandle; 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir FileHandleGuard(FileHandleGuard &); // not implemented 192*cdf0e10cSrcweir void operator =(FileHandleGuard); // not implemented 193*cdf0e10cSrcweir }; 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir inline FileHandleGuard::~FileHandleGuard() SAL_THROW(()) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir if (m_rHandle != 0) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir if (osl_closeFile(m_rHandle) != osl_File_E_None) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir OSL_ENSURE(false, "unexpected situation"); 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir class FileHandleReader 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir public: 210*cdf0e10cSrcweir enum Result 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir RESULT_OK, 213*cdf0e10cSrcweir RESULT_EOF, 214*cdf0e10cSrcweir RESULT_ERROR 215*cdf0e10cSrcweir }; 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir inline FileHandleReader(oslFileHandle & rHandle) SAL_THROW(()): 218*cdf0e10cSrcweir m_aGuard(rHandle), m_nSize(0), m_nIndex(0), m_bLf(false) {} 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir Result readLine(rtl::OString * pLine) SAL_THROW(()); 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir private: 223*cdf0e10cSrcweir enum { BUFFER_SIZE = 1024 }; 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir sal_Char m_aBuffer[BUFFER_SIZE]; 226*cdf0e10cSrcweir FileHandleGuard m_aGuard; 227*cdf0e10cSrcweir int m_nSize; 228*cdf0e10cSrcweir int m_nIndex; 229*cdf0e10cSrcweir bool m_bLf; 230*cdf0e10cSrcweir }; 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir FileHandleReader::Result 233*cdf0e10cSrcweir FileHandleReader::readLine(rtl::OString * pLine) 234*cdf0e10cSrcweir SAL_THROW(()) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir OSL_ENSURE(pLine, "specification violation"); 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir for (bool bEof = true;; bEof = false) 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir if (m_nIndex == m_nSize) 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir sal_uInt64 nRead = 0; 243*cdf0e10cSrcweir switch (osl_readFile( 244*cdf0e10cSrcweir m_aGuard.getHandle(), m_aBuffer, sizeof(m_aBuffer), &nRead)) 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir case osl_File_E_PIPE: //HACK! for windows 247*cdf0e10cSrcweir nRead = 0; 248*cdf0e10cSrcweir case osl_File_E_None: 249*cdf0e10cSrcweir if (nRead == 0) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir m_bLf = false; 252*cdf0e10cSrcweir return bEof ? RESULT_EOF : RESULT_OK; 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir m_nIndex = 0; 255*cdf0e10cSrcweir m_nSize = static_cast< int >(nRead); 256*cdf0e10cSrcweir break; 257*cdf0e10cSrcweir case osl_File_E_INTR: 258*cdf0e10cSrcweir continue; 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir default: 261*cdf0e10cSrcweir return RESULT_ERROR; 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir if (m_bLf && m_aBuffer[m_nIndex] == 0x0A) 266*cdf0e10cSrcweir ++m_nIndex; 267*cdf0e10cSrcweir m_bLf = false; 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir int nStart = m_nIndex; 270*cdf0e10cSrcweir while (m_nIndex != m_nSize) 271*cdf0e10cSrcweir switch (m_aBuffer[m_nIndex++]) 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir case 0x0D: 274*cdf0e10cSrcweir m_bLf = true; 275*cdf0e10cSrcweir case 0x0A: 276*cdf0e10cSrcweir *pLine += rtl::OString(m_aBuffer + nStart, 277*cdf0e10cSrcweir m_nIndex - 1 - nStart); 278*cdf0e10cSrcweir //TODO! check for overflow, and not very efficient 279*cdf0e10cSrcweir return RESULT_OK; 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir *pLine += rtl::OString(m_aBuffer + nStart, m_nIndex - nStart); 283*cdf0e10cSrcweir //TODO! check for overflow, and not very efficient 284*cdf0e10cSrcweir } 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir class AsynchReader: public Thread 288*cdf0e10cSrcweir { 289*cdf0e10cSrcweir size_t m_nDataSize; 290*cdf0e10cSrcweir boost::scoped_array<sal_Char> m_arData; 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir bool m_bError; 293*cdf0e10cSrcweir bool m_bDone; 294*cdf0e10cSrcweir FileHandleGuard m_aGuard; 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir void SAL_CALL run(); 297*cdf0e10cSrcweir public: 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir AsynchReader(oslFileHandle & rHandle); 300*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL >= 2 301*cdf0e10cSrcweir /** only call this function after this thread has finished. 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir That is, call join on this instance and then call getData. 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir */ 306*cdf0e10cSrcweir OString getData(); 307*cdf0e10cSrcweir #endif 308*cdf0e10cSrcweir }; 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir AsynchReader::AsynchReader(oslFileHandle & rHandle): 311*cdf0e10cSrcweir m_nDataSize(0), m_bError(false), m_bDone(false), m_aGuard(rHandle) 312*cdf0e10cSrcweir { 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL >= 2 316*cdf0e10cSrcweir OString AsynchReader::getData() 317*cdf0e10cSrcweir { 318*cdf0e10cSrcweir OSL_ASSERT(isRunning() == sal_False ); 319*cdf0e10cSrcweir return OString(m_arData.get(), m_nDataSize); 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir #endif 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir void AsynchReader::run() 324*cdf0e10cSrcweir { 325*cdf0e10cSrcweir const sal_uInt64 BUFFER_SIZE = 4096; 326*cdf0e10cSrcweir sal_Char aBuffer[BUFFER_SIZE]; 327*cdf0e10cSrcweir while (true) 328*cdf0e10cSrcweir { 329*cdf0e10cSrcweir sal_uInt64 nRead; 330*cdf0e10cSrcweir //the function blocks until something could be read or the pipe closed. 331*cdf0e10cSrcweir switch (osl_readFile( 332*cdf0e10cSrcweir m_aGuard.getHandle(), aBuffer, BUFFER_SIZE, &nRead)) 333*cdf0e10cSrcweir { 334*cdf0e10cSrcweir case osl_File_E_PIPE: //HACK! for windows 335*cdf0e10cSrcweir nRead = 0; 336*cdf0e10cSrcweir case osl_File_E_None: 337*cdf0e10cSrcweir break; 338*cdf0e10cSrcweir default: 339*cdf0e10cSrcweir m_bError = true; 340*cdf0e10cSrcweir return; 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir if (nRead == 0) 344*cdf0e10cSrcweir { 345*cdf0e10cSrcweir m_bDone = true; 346*cdf0e10cSrcweir break; 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir else if (nRead <= BUFFER_SIZE) 349*cdf0e10cSrcweir { 350*cdf0e10cSrcweir //Save the data we have in m_arData into a temporary array 351*cdf0e10cSrcweir boost::scoped_array<sal_Char> arTmp( new sal_Char[m_nDataSize]); 352*cdf0e10cSrcweir memcpy(arTmp.get(), m_arData.get(), m_nDataSize); 353*cdf0e10cSrcweir //Enlarge m_arData to hold the newly read data 354*cdf0e10cSrcweir m_arData.reset(new sal_Char[(size_t)(m_nDataSize + nRead)]); 355*cdf0e10cSrcweir //Copy back the data that was already in m_arData 356*cdf0e10cSrcweir memcpy(m_arData.get(), arTmp.get(), m_nDataSize); 357*cdf0e10cSrcweir //Add the newly read data to m_arData 358*cdf0e10cSrcweir memcpy(m_arData.get() + m_nDataSize, aBuffer, (size_t) nRead); 359*cdf0e10cSrcweir m_nDataSize += (size_t) nRead; 360*cdf0e10cSrcweir } 361*cdf0e10cSrcweir } 362*cdf0e10cSrcweir } 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir 365*cdf0e10cSrcweir bool getJavaProps(const OUString & exePath, 366*cdf0e10cSrcweir std::vector<std::pair<rtl::OUString, rtl::OUString> >& props, 367*cdf0e10cSrcweir bool * bProcessRun) 368*cdf0e10cSrcweir { 369*cdf0e10cSrcweir bool ret = false; 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir OSL_ASSERT( exePath.getLength() > 0); 372*cdf0e10cSrcweir OUString usStartDir; 373*cdf0e10cSrcweir //We need to set the CLASSPATH in case the office is started from 374*cdf0e10cSrcweir //a different directory. The JREProperties.class is expected to reside 375*cdf0e10cSrcweir //next to the plugin. 376*cdf0e10cSrcweir rtl::OUString sThisLib; 377*cdf0e10cSrcweir if (osl_getModuleURLFromAddress((void *) (sal_IntPtr)& getJavaProps, 378*cdf0e10cSrcweir & sThisLib.pData) == sal_False) 379*cdf0e10cSrcweir return false; 380*cdf0e10cSrcweir sThisLib = getDirFromFile(sThisLib); 381*cdf0e10cSrcweir OUString sClassPath; 382*cdf0e10cSrcweir if (osl_getSystemPathFromFileURL(sThisLib.pData, & sClassPath.pData) 383*cdf0e10cSrcweir != osl_File_E_None) 384*cdf0e10cSrcweir return false; 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir //check if we shall examine a Java for accessibility support 387*cdf0e10cSrcweir //If the bootstrap variable is "1" then we pass the argument 388*cdf0e10cSrcweir //"noaccessibility" to JREProperties.class. This will prevent 389*cdf0e10cSrcweir //that it calls java.awt.Toolkit.getDefaultToolkit(); 390*cdf0e10cSrcweir OUString sValue; 391*cdf0e10cSrcweir getBootstrap()->getFrom(OUSTR("JFW_PLUGIN_DO_NOT_CHECK_ACCESSIBILITY"), sValue); 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir //prepare the arguments 394*cdf0e10cSrcweir sal_Int32 cArgs = 3; 395*cdf0e10cSrcweir OUString arg1 = OUString(RTL_CONSTASCII_USTRINGPARAM("-classpath"));// + sClassPath; 396*cdf0e10cSrcweir OUString arg2 = sClassPath; 397*cdf0e10cSrcweir OUString arg3(RTL_CONSTASCII_USTRINGPARAM("JREProperties")); 398*cdf0e10cSrcweir OUString arg4 = OUSTR("noaccessibility"); 399*cdf0e10cSrcweir rtl_uString *args[4] = {arg1.pData, arg2.pData, arg3.pData}; 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir // Only add the fourth param if the bootstrap parameter is set. 402*cdf0e10cSrcweir if (sValue.equals(OUString::valueOf((sal_Int32) 1))) 403*cdf0e10cSrcweir { 404*cdf0e10cSrcweir args[3] = arg4.pData; 405*cdf0e10cSrcweir cArgs = 4; 406*cdf0e10cSrcweir } 407*cdf0e10cSrcweir 408*cdf0e10cSrcweir oslProcess javaProcess= 0; 409*cdf0e10cSrcweir oslFileHandle fileOut= 0; 410*cdf0e10cSrcweir oslFileHandle fileErr= 0; 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir FileHandleReader stdoutReader(fileOut); 413*cdf0e10cSrcweir AsynchReader stderrReader(fileErr); 414*cdf0e10cSrcweir 415*cdf0e10cSrcweir JFW_TRACE2(OUSTR("\n[Java framework] Executing: ") + exePath + OUSTR(".\n")); 416*cdf0e10cSrcweir oslProcessError procErr = 417*cdf0e10cSrcweir osl_executeProcess_WithRedirectedIO( exePath.pData,//usExe.pData, 418*cdf0e10cSrcweir args, 419*cdf0e10cSrcweir cArgs, //sal_uInt32 nArguments, 420*cdf0e10cSrcweir osl_Process_HIDDEN, //oslProcessOption Options, 421*cdf0e10cSrcweir NULL, //oslSecurity Security, 422*cdf0e10cSrcweir usStartDir.pData,//usStartDir.pData,//usWorkDir.pData, //rtl_uString *strWorkDir, 423*cdf0e10cSrcweir NULL, //rtl_uString *strEnvironment[], 424*cdf0e10cSrcweir 0, // sal_uInt32 nEnvironmentVars, 425*cdf0e10cSrcweir &javaProcess, //oslProcess *pProcess, 426*cdf0e10cSrcweir NULL,//oslFileHandle *pChildInputWrite, 427*cdf0e10cSrcweir &fileOut,//oslFileHandle *pChildOutputRead, 428*cdf0e10cSrcweir &fileErr);//oslFileHandle *pChildErrorRead); 429*cdf0e10cSrcweir 430*cdf0e10cSrcweir if( procErr != osl_Process_E_None) 431*cdf0e10cSrcweir { 432*cdf0e10cSrcweir JFW_TRACE2("[Java framework] Execution failed. \n"); 433*cdf0e10cSrcweir *bProcessRun = false; 434*cdf0e10cSrcweir return ret; 435*cdf0e10cSrcweir } 436*cdf0e10cSrcweir else 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir JFW_TRACE2("[Java framework] Java executed successfully.\n"); 439*cdf0e10cSrcweir *bProcessRun = true; 440*cdf0e10cSrcweir } 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir //Start asynchronous reading (different thread) of error stream 443*cdf0e10cSrcweir stderrReader.create(); 444*cdf0e10cSrcweir 445*cdf0e10cSrcweir //Use this thread to read output stream 446*cdf0e10cSrcweir FileHandleReader::Result rs = FileHandleReader::RESULT_OK; 447*cdf0e10cSrcweir while (1) 448*cdf0e10cSrcweir { 449*cdf0e10cSrcweir OString aLine; 450*cdf0e10cSrcweir rs = stdoutReader.readLine( & aLine); 451*cdf0e10cSrcweir if (rs != FileHandleReader::RESULT_OK) 452*cdf0e10cSrcweir break; 453*cdf0e10cSrcweir // JFW_TRACE2(OString("[Java framework] line:\" ") 454*cdf0e10cSrcweir // + aLine + OString(" \".\n")); 455*cdf0e10cSrcweir OUString sLine; 456*cdf0e10cSrcweir if (!decodeOutput(aLine, &sLine)) 457*cdf0e10cSrcweir continue; 458*cdf0e10cSrcweir JFW_TRACE2(OString("[Java framework]:\" ") 459*cdf0e10cSrcweir + OString( CHAR_POINTER(sLine)) + OString(" \".\n")); 460*cdf0e10cSrcweir sLine = sLine.trim(); 461*cdf0e10cSrcweir if (sLine.getLength() == 0) 462*cdf0e10cSrcweir continue; 463*cdf0e10cSrcweir //The JREProperties class writes key value pairs, separated by '=' 464*cdf0e10cSrcweir sal_Int32 index = sLine.indexOf('=', 0); 465*cdf0e10cSrcweir OSL_ASSERT(index != -1); 466*cdf0e10cSrcweir OUString sKey = sLine.copy(0, index); 467*cdf0e10cSrcweir OUString sVal = sLine.copy(index + 1); 468*cdf0e10cSrcweir 469*cdf0e10cSrcweir props.push_back(std::make_pair(sKey, sVal)); 470*cdf0e10cSrcweir } 471*cdf0e10cSrcweir 472*cdf0e10cSrcweir if (rs != FileHandleReader::RESULT_ERROR && props.size()>0) 473*cdf0e10cSrcweir ret = true; 474*cdf0e10cSrcweir 475*cdf0e10cSrcweir //process error stream data 476*cdf0e10cSrcweir stderrReader.join(); 477*cdf0e10cSrcweir JFW_TRACE2(OString("[Java framework] Java wrote to stderr:\" ") 478*cdf0e10cSrcweir + stderrReader.getData() + OString(" \".\n")); 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir TimeValue waitMax= {5 ,0}; 481*cdf0e10cSrcweir procErr = osl_joinProcessWithTimeout(javaProcess, &waitMax); 482*cdf0e10cSrcweir OSL_ASSERT(procErr == osl_Process_E_None); 483*cdf0e10cSrcweir osl_freeProcessHandle(javaProcess); 484*cdf0e10cSrcweir return ret; 485*cdf0e10cSrcweir } 486*cdf0e10cSrcweir 487*cdf0e10cSrcweir /* converts the properties printed by JREProperties.class into 488*cdf0e10cSrcweir readable strings. The strings are encoded as integer values separated 489*cdf0e10cSrcweir by spaces. 490*cdf0e10cSrcweir */ 491*cdf0e10cSrcweir bool decodeOutput(const rtl::OString& s, rtl::OUString* out) 492*cdf0e10cSrcweir { 493*cdf0e10cSrcweir OSL_ASSERT(out != 0); 494*cdf0e10cSrcweir OUStringBuffer buff(512); 495*cdf0e10cSrcweir sal_Int32 nIndex = 0; 496*cdf0e10cSrcweir do 497*cdf0e10cSrcweir { 498*cdf0e10cSrcweir OString aToken = s.getToken( 0, ' ', nIndex ); 499*cdf0e10cSrcweir if (aToken.getLength()) 500*cdf0e10cSrcweir { 501*cdf0e10cSrcweir for (sal_Int32 i = 0; i < aToken.getLength(); ++i) 502*cdf0e10cSrcweir { 503*cdf0e10cSrcweir if (aToken[i] < '0' || aToken[i] > '9') 504*cdf0e10cSrcweir return false; 505*cdf0e10cSrcweir } 506*cdf0e10cSrcweir sal_Unicode value = (sal_Unicode)(aToken.toInt32()); 507*cdf0e10cSrcweir buff.append(value); 508*cdf0e10cSrcweir } 509*cdf0e10cSrcweir } while (nIndex >= 0); 510*cdf0e10cSrcweir 511*cdf0e10cSrcweir *out = buff.makeStringAndClear(); 512*cdf0e10cSrcweir // JFW_TRACE2(*out); 513*cdf0e10cSrcweir return true; 514*cdf0e10cSrcweir } 515*cdf0e10cSrcweir 516*cdf0e10cSrcweir 517*cdf0e10cSrcweir #if defined WNT 518*cdf0e10cSrcweir void createJavaInfoFromWinReg(std::vector<rtl::Reference<VendorBase> > & vecInfos) 519*cdf0e10cSrcweir { 520*cdf0e10cSrcweir // Get Java s from registry 521*cdf0e10cSrcweir std::vector<OUString> vecJavaHome; 522*cdf0e10cSrcweir if(getSDKInfoFromRegistry(vecJavaHome)) 523*cdf0e10cSrcweir { 524*cdf0e10cSrcweir // create impl objects 525*cdf0e10cSrcweir typedef std::vector<OUString>::iterator ItHome; 526*cdf0e10cSrcweir for(ItHome it_home= vecJavaHome.begin(); it_home != vecJavaHome.end(); 527*cdf0e10cSrcweir it_home++) 528*cdf0e10cSrcweir { 529*cdf0e10cSrcweir getJREInfoByPath(*it_home, vecInfos); 530*cdf0e10cSrcweir } 531*cdf0e10cSrcweir } 532*cdf0e10cSrcweir 533*cdf0e10cSrcweir vecJavaHome.clear(); 534*cdf0e10cSrcweir if(getJREInfoFromRegistry(vecJavaHome)) 535*cdf0e10cSrcweir { 536*cdf0e10cSrcweir typedef std::vector<OUString>::iterator ItHome; 537*cdf0e10cSrcweir for(ItHome it_home= vecJavaHome.begin(); it_home != vecJavaHome.end(); 538*cdf0e10cSrcweir it_home++) 539*cdf0e10cSrcweir { 540*cdf0e10cSrcweir getJREInfoByPath(*it_home, vecInfos); 541*cdf0e10cSrcweir } 542*cdf0e10cSrcweir } 543*cdf0e10cSrcweir } 544*cdf0e10cSrcweir 545*cdf0e10cSrcweir 546*cdf0e10cSrcweir bool getJavaInfoFromRegistry(const wchar_t* szRegKey, 547*cdf0e10cSrcweir vector<OUString>& vecJavaHome) 548*cdf0e10cSrcweir { 549*cdf0e10cSrcweir HKEY hRoot; 550*cdf0e10cSrcweir if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szRegKey, 0, KEY_ENUMERATE_SUB_KEYS, &hRoot) 551*cdf0e10cSrcweir == ERROR_SUCCESS) 552*cdf0e10cSrcweir { 553*cdf0e10cSrcweir DWORD dwIndex = 0; 554*cdf0e10cSrcweir const DWORD BUFFSIZE = 1024; 555*cdf0e10cSrcweir wchar_t bufVersion[BUFFSIZE]; 556*cdf0e10cSrcweir // char bufVersion[BUFFSIZE]; 557*cdf0e10cSrcweir DWORD nNameLen = BUFFSIZE; 558*cdf0e10cSrcweir FILETIME fileTime; 559*cdf0e10cSrcweir nNameLen = sizeof(bufVersion); 560*cdf0e10cSrcweir 561*cdf0e10cSrcweir // Iterate over all subkeys of HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment 562*cdf0e10cSrcweir while (RegEnumKeyExW(hRoot, dwIndex, bufVersion, &nNameLen, NULL, NULL, NULL, &fileTime) != ERROR_NO_MORE_ITEMS) 563*cdf0e10cSrcweir { 564*cdf0e10cSrcweir HKEY hKey; 565*cdf0e10cSrcweir // Open a Java Runtime Environment sub key, e.g. "1.4.0" 566*cdf0e10cSrcweir if (RegOpenKeyExW(hRoot, bufVersion, 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) 567*cdf0e10cSrcweir { 568*cdf0e10cSrcweir DWORD dwType; 569*cdf0e10cSrcweir DWORD dwTmpPathLen= 0; 570*cdf0e10cSrcweir // Get the path to the JavaHome every JRE entry 571*cdf0e10cSrcweir // Find out how long the string for JavaHome is and allocate memory to hold the path 572*cdf0e10cSrcweir if( RegQueryValueExW(hKey, L"JavaHome", 0, &dwType, NULL, &dwTmpPathLen)== ERROR_SUCCESS) 573*cdf0e10cSrcweir { 574*cdf0e10cSrcweir char* szTmpPath= (char *) malloc( dwTmpPathLen); 575*cdf0e10cSrcweir // Get the path for the runtime lib 576*cdf0e10cSrcweir if(RegQueryValueExW(hKey, L"JavaHome", 0, &dwType, (unsigned char*) szTmpPath, &dwTmpPathLen) == ERROR_SUCCESS) 577*cdf0e10cSrcweir { 578*cdf0e10cSrcweir // There can be several version entries refering with the same JavaHome,e.g 1.4 and 1.4.1 579*cdf0e10cSrcweir OUString usHome((sal_Unicode*) szTmpPath); 580*cdf0e10cSrcweir // check if there is already an entry with the same JavaHomeruntime lib 581*cdf0e10cSrcweir // if so, we use the one with the more accurate version 582*cdf0e10cSrcweir bool bAppend= true; 583*cdf0e10cSrcweir OUString usHomeUrl; 584*cdf0e10cSrcweir if (osl_getFileURLFromSystemPath(usHome.pData, & usHomeUrl.pData) == 585*cdf0e10cSrcweir osl_File_E_None) 586*cdf0e10cSrcweir { 587*cdf0e10cSrcweir //iterate over the vector with java home strings 588*cdf0e10cSrcweir typedef vector<OUString>::iterator ItHome; 589*cdf0e10cSrcweir for(ItHome itHome= vecJavaHome.begin(); 590*cdf0e10cSrcweir itHome != vecJavaHome.end(); itHome++) 591*cdf0e10cSrcweir { 592*cdf0e10cSrcweir if(usHomeUrl.equals(*itHome)) 593*cdf0e10cSrcweir { 594*cdf0e10cSrcweir bAppend= false; 595*cdf0e10cSrcweir break; 596*cdf0e10cSrcweir } 597*cdf0e10cSrcweir } 598*cdf0e10cSrcweir // Save the home dir 599*cdf0e10cSrcweir if(bAppend) 600*cdf0e10cSrcweir { 601*cdf0e10cSrcweir vecJavaHome.push_back(usHomeUrl); 602*cdf0e10cSrcweir } 603*cdf0e10cSrcweir } 604*cdf0e10cSrcweir } 605*cdf0e10cSrcweir free( szTmpPath); 606*cdf0e10cSrcweir RegCloseKey(hKey); 607*cdf0e10cSrcweir } 608*cdf0e10cSrcweir } 609*cdf0e10cSrcweir dwIndex ++; 610*cdf0e10cSrcweir nNameLen = BUFFSIZE; 611*cdf0e10cSrcweir } 612*cdf0e10cSrcweir RegCloseKey(hRoot); 613*cdf0e10cSrcweir } 614*cdf0e10cSrcweir return true; 615*cdf0e10cSrcweir } 616*cdf0e10cSrcweir 617*cdf0e10cSrcweir 618*cdf0e10cSrcweir 619*cdf0e10cSrcweir bool getSDKInfoFromRegistry(vector<OUString> & vecHome) 620*cdf0e10cSrcweir { 621*cdf0e10cSrcweir return getJavaInfoFromRegistry(HKEY_SUN_SDK, vecHome); 622*cdf0e10cSrcweir } 623*cdf0e10cSrcweir 624*cdf0e10cSrcweir bool getJREInfoFromRegistry(vector<OUString>& vecJavaHome) 625*cdf0e10cSrcweir { 626*cdf0e10cSrcweir return getJavaInfoFromRegistry(HKEY_SUN_JRE, vecJavaHome); 627*cdf0e10cSrcweir } 628*cdf0e10cSrcweir 629*cdf0e10cSrcweir #endif // WNT 630*cdf0e10cSrcweir 631*cdf0e10cSrcweir void bubbleSortVersion(vector<rtl::Reference<VendorBase> >& vec) 632*cdf0e10cSrcweir { 633*cdf0e10cSrcweir if(vec.size() == 0) 634*cdf0e10cSrcweir return; 635*cdf0e10cSrcweir int size= vec.size() - 1; 636*cdf0e10cSrcweir int cIter= 0; 637*cdf0e10cSrcweir // sort for version 638*cdf0e10cSrcweir for(int i= 0; i < size; i++) 639*cdf0e10cSrcweir { 640*cdf0e10cSrcweir for(int j= size; j > 0 + cIter; j--) 641*cdf0e10cSrcweir { 642*cdf0e10cSrcweir rtl::Reference<VendorBase>& cur= vec.at(j); 643*cdf0e10cSrcweir rtl::Reference<VendorBase>& next= vec.at(j-1); 644*cdf0e10cSrcweir 645*cdf0e10cSrcweir int nCmp = 0; 646*cdf0e10cSrcweir // comparing invalid SunVersion s is possible, they will be less than a 647*cdf0e10cSrcweir // valid version 648*cdf0e10cSrcweir 649*cdf0e10cSrcweir //check if version of current is recognized, by comparing it with itself 650*cdf0e10cSrcweir try 651*cdf0e10cSrcweir { 652*cdf0e10cSrcweir cur->compareVersions(cur->getVersion()); 653*cdf0e10cSrcweir } 654*cdf0e10cSrcweir catch (MalformedVersionException &) 655*cdf0e10cSrcweir { 656*cdf0e10cSrcweir nCmp = -1; // current < next 657*cdf0e10cSrcweir } 658*cdf0e10cSrcweir //The version of cur is valid, now compare with the second version 659*cdf0e10cSrcweir if (nCmp == 0) 660*cdf0e10cSrcweir { 661*cdf0e10cSrcweir try 662*cdf0e10cSrcweir { 663*cdf0e10cSrcweir nCmp = cur->compareVersions(next->getVersion()); 664*cdf0e10cSrcweir } 665*cdf0e10cSrcweir catch (MalformedVersionException & ) 666*cdf0e10cSrcweir { 667*cdf0e10cSrcweir //The second version is invalid, therefor it is regardes less. 668*cdf0e10cSrcweir nCmp = 1; 669*cdf0e10cSrcweir } 670*cdf0e10cSrcweir } 671*cdf0e10cSrcweir if(nCmp == 1) // cur > next 672*cdf0e10cSrcweir { 673*cdf0e10cSrcweir rtl::Reference<VendorBase> less = next; 674*cdf0e10cSrcweir vec.at(j-1)= cur; 675*cdf0e10cSrcweir vec.at(j)= less; 676*cdf0e10cSrcweir } 677*cdf0e10cSrcweir } 678*cdf0e10cSrcweir cIter++; 679*cdf0e10cSrcweir } 680*cdf0e10cSrcweir } 681*cdf0e10cSrcweir 682*cdf0e10cSrcweir 683*cdf0e10cSrcweir bool getJREInfoFromBinPath( 684*cdf0e10cSrcweir const rtl::OUString& path, vector<rtl::Reference<VendorBase> > & vecInfos) 685*cdf0e10cSrcweir { 686*cdf0e10cSrcweir // file:///c:/jre/bin 687*cdf0e10cSrcweir //map: jre/bin/java.exe 688*cdf0e10cSrcweir bool ret = false; 689*cdf0e10cSrcweir vector<pair<OUString, OUString> > props; 690*cdf0e10cSrcweir 691*cdf0e10cSrcweir for ( sal_Int32 pos = 0; 692*cdf0e10cSrcweir gVendorMap[pos].sVendorName != NULL; ++pos ) 693*cdf0e10cSrcweir { 694*cdf0e10cSrcweir vector<OUString> vecPaths; 695*cdf0e10cSrcweir getJavaExePaths_func pFunc = gVendorMap[pos].getJavaFunc; 696*cdf0e10cSrcweir 697*cdf0e10cSrcweir int size = 0; 698*cdf0e10cSrcweir char const* const* arExePaths = (*pFunc)(&size); 699*cdf0e10cSrcweir vecPaths = getVectorFromCharArray(arExePaths, size); 700*cdf0e10cSrcweir 701*cdf0e10cSrcweir //make sure argument path does not end with '/' 702*cdf0e10cSrcweir OUString sBinPath = path; 703*cdf0e10cSrcweir if (path.lastIndexOf('/') == (path.getLength() - 1)) 704*cdf0e10cSrcweir sBinPath = path.copy(0, path.getLength() - 1); 705*cdf0e10cSrcweir 706*cdf0e10cSrcweir typedef vector<OUString>::const_iterator c_it; 707*cdf0e10cSrcweir for (c_it i = vecPaths.begin(); i != vecPaths.end(); i++) 708*cdf0e10cSrcweir { 709*cdf0e10cSrcweir //the map contains e.g. jre/bin/java.exe 710*cdf0e10cSrcweir //get the directory where the executable is contained 711*cdf0e10cSrcweir OUString sHome; 712*cdf0e10cSrcweir sal_Int32 index = i->lastIndexOf('/'); 713*cdf0e10cSrcweir if (index == -1) 714*cdf0e10cSrcweir { 715*cdf0e10cSrcweir //map contained only : "java.exe, then the argument 716*cdf0e10cSrcweir //path is already the home directory 717*cdf0e10cSrcweir sHome = sBinPath; 718*cdf0e10cSrcweir } 719*cdf0e10cSrcweir else 720*cdf0e10cSrcweir { 721*cdf0e10cSrcweir // jre/bin/jre -> jre/bin 722*cdf0e10cSrcweir OUString sMapPath(i->getStr(), index); 723*cdf0e10cSrcweir index = sBinPath.lastIndexOf(sMapPath); 724*cdf0e10cSrcweir if (index != -1 725*cdf0e10cSrcweir && (index + sMapPath.getLength() == sBinPath.getLength()) 726*cdf0e10cSrcweir && sBinPath[index - 1] == '/') 727*cdf0e10cSrcweir { 728*cdf0e10cSrcweir sHome = OUString(sBinPath.getStr(), index - 1); 729*cdf0e10cSrcweir } 730*cdf0e10cSrcweir } 731*cdf0e10cSrcweir if (sHome.getLength() > 0) 732*cdf0e10cSrcweir { 733*cdf0e10cSrcweir ret = getJREInfoByPath(sHome, vecInfos); 734*cdf0e10cSrcweir if (ret) 735*cdf0e10cSrcweir break; 736*cdf0e10cSrcweir } 737*cdf0e10cSrcweir } 738*cdf0e10cSrcweir if (ret) 739*cdf0e10cSrcweir break; 740*cdf0e10cSrcweir } 741*cdf0e10cSrcweir return ret; 742*cdf0e10cSrcweir } 743*cdf0e10cSrcweir 744*cdf0e10cSrcweir vector<Reference<VendorBase> > getAllJREInfos() 745*cdf0e10cSrcweir { 746*cdf0e10cSrcweir vector<Reference<VendorBase> > vecInfos; 747*cdf0e10cSrcweir 748*cdf0e10cSrcweir #if defined WNT 749*cdf0e10cSrcweir // Get Javas from the registry 750*cdf0e10cSrcweir createJavaInfoFromWinReg(vecInfos); 751*cdf0e10cSrcweir #endif // WNT 752*cdf0e10cSrcweir 753*cdf0e10cSrcweir createJavaInfoFromJavaHome(vecInfos); 754*cdf0e10cSrcweir //this function should be called after createJavaInfoDirScan. 755*cdf0e10cSrcweir //Otherwise in SDKs Java may be started twice 756*cdf0e10cSrcweir createJavaInfoFromPath(vecInfos); 757*cdf0e10cSrcweir 758*cdf0e10cSrcweir #ifdef UNX 759*cdf0e10cSrcweir createJavaInfoDirScan(vecInfos); 760*cdf0e10cSrcweir #endif 761*cdf0e10cSrcweir 762*cdf0e10cSrcweir bubbleSortVersion(vecInfos); 763*cdf0e10cSrcweir return vecInfos; 764*cdf0e10cSrcweir } 765*cdf0e10cSrcweir 766*cdf0e10cSrcweir 767*cdf0e10cSrcweir vector<OUString> getVectorFromCharArray(char const * const * ar, int size) 768*cdf0e10cSrcweir { 769*cdf0e10cSrcweir vector<OUString> vec; 770*cdf0e10cSrcweir for( int i = 0; i < size; i++) 771*cdf0e10cSrcweir { 772*cdf0e10cSrcweir OUString s(ar[i], strlen(ar[i]), RTL_TEXTENCODING_UTF8); 773*cdf0e10cSrcweir vec.push_back(s); 774*cdf0e10cSrcweir } 775*cdf0e10cSrcweir return vec; 776*cdf0e10cSrcweir } 777*cdf0e10cSrcweir bool getJREInfoByPath(const rtl::OUString& path, 778*cdf0e10cSrcweir std::vector<rtl::Reference<VendorBase> > & vecInfos) 779*cdf0e10cSrcweir { 780*cdf0e10cSrcweir bool ret = false; 781*cdf0e10cSrcweir 782*cdf0e10cSrcweir rtl::Reference<VendorBase> aInfo = getJREInfoByPath(path); 783*cdf0e10cSrcweir if (aInfo.is()) 784*cdf0e10cSrcweir { 785*cdf0e10cSrcweir ret = true; 786*cdf0e10cSrcweir vector<rtl::Reference<VendorBase> >::const_iterator it_impl= std::find_if( 787*cdf0e10cSrcweir vecInfos.begin(),vecInfos.end(), InfoFindSame(aInfo->getHome())); 788*cdf0e10cSrcweir if(it_impl == vecInfos.end()) 789*cdf0e10cSrcweir { 790*cdf0e10cSrcweir vecInfos.push_back(aInfo); 791*cdf0e10cSrcweir } 792*cdf0e10cSrcweir } 793*cdf0e10cSrcweir return ret; 794*cdf0e10cSrcweir } 795*cdf0e10cSrcweir 796*cdf0e10cSrcweir /** Checks if the path is a directory. Links are resolved. 797*cdf0e10cSrcweir In case of an error the returned string has the length 0. 798*cdf0e10cSrcweir Otherwise the returned string is the "resolved" file URL. 799*cdf0e10cSrcweir */ 800*cdf0e10cSrcweir OUString resolveDirPath(const OUString & path) 801*cdf0e10cSrcweir { 802*cdf0e10cSrcweir OUString ret; 803*cdf0e10cSrcweir OUString sResolved; 804*cdf0e10cSrcweir //getAbsoluteFileURL also resolves links 805*cdf0e10cSrcweir if (File::getAbsoluteFileURL( 806*cdf0e10cSrcweir OUSTR("file:///"), path, sResolved) != File::E_None) 807*cdf0e10cSrcweir return OUString(); 808*cdf0e10cSrcweir 809*cdf0e10cSrcweir //check if this is a valid path and if it is a directory 810*cdf0e10cSrcweir DirectoryItem item; 811*cdf0e10cSrcweir if (DirectoryItem::get(sResolved, item) == File::E_None) 812*cdf0e10cSrcweir { 813*cdf0e10cSrcweir FileStatus status(FileStatusMask_Type | 814*cdf0e10cSrcweir FileStatusMask_LinkTargetURL | 815*cdf0e10cSrcweir FileStatusMask_FileURL); 816*cdf0e10cSrcweir 817*cdf0e10cSrcweir if (item.getFileStatus(status) == File::E_None 818*cdf0e10cSrcweir && status.getFileType() == FileStatus::Directory) 819*cdf0e10cSrcweir { 820*cdf0e10cSrcweir ret = sResolved; 821*cdf0e10cSrcweir } 822*cdf0e10cSrcweir } 823*cdf0e10cSrcweir else 824*cdf0e10cSrcweir return OUString(); 825*cdf0e10cSrcweir return ret; 826*cdf0e10cSrcweir } 827*cdf0e10cSrcweir /** Checks if the path is a file. If it is a link to a file than 828*cdf0e10cSrcweir it is resolved. 829*cdf0e10cSrcweir */ 830*cdf0e10cSrcweir OUString resolveFilePath(const OUString & path) 831*cdf0e10cSrcweir { 832*cdf0e10cSrcweir OUString ret; 833*cdf0e10cSrcweir OUString sResolved; 834*cdf0e10cSrcweir 835*cdf0e10cSrcweir if (File::getAbsoluteFileURL( 836*cdf0e10cSrcweir OUSTR("file:///"), path, sResolved) != File::E_None) 837*cdf0e10cSrcweir return OUString(); 838*cdf0e10cSrcweir 839*cdf0e10cSrcweir //check if this is a valid path to a file or and if it is a link 840*cdf0e10cSrcweir DirectoryItem item; 841*cdf0e10cSrcweir if (DirectoryItem::get(sResolved, item) == File::E_None) 842*cdf0e10cSrcweir { 843*cdf0e10cSrcweir FileStatus status(FileStatusMask_Type | 844*cdf0e10cSrcweir FileStatusMask_LinkTargetURL | 845*cdf0e10cSrcweir FileStatusMask_FileURL); 846*cdf0e10cSrcweir if (item.getFileStatus(status) == File::E_None 847*cdf0e10cSrcweir && status.getFileType() == FileStatus::Regular) 848*cdf0e10cSrcweir { 849*cdf0e10cSrcweir ret = sResolved; 850*cdf0e10cSrcweir } 851*cdf0e10cSrcweir } 852*cdf0e10cSrcweir else 853*cdf0e10cSrcweir return OUString(); 854*cdf0e10cSrcweir 855*cdf0e10cSrcweir return ret; 856*cdf0e10cSrcweir } 857*cdf0e10cSrcweir 858*cdf0e10cSrcweir rtl::Reference<VendorBase> getJREInfoByPath( 859*cdf0e10cSrcweir const OUString& path) 860*cdf0e10cSrcweir { 861*cdf0e10cSrcweir rtl::Reference<VendorBase> ret; 862*cdf0e10cSrcweir static vector<OUString> vecBadPaths; 863*cdf0e10cSrcweir 864*cdf0e10cSrcweir static map<OUString, rtl::Reference<VendorBase> > mapJREs; 865*cdf0e10cSrcweir typedef map<OUString, rtl::Reference<VendorBase> >::const_iterator MapIt; 866*cdf0e10cSrcweir typedef map<OUString, rtl::Reference<VendorBase> > MAPJRE; 867*cdf0e10cSrcweir OUString sFilePath; 868*cdf0e10cSrcweir typedef vector<OUString>::const_iterator cit_path; 869*cdf0e10cSrcweir vector<pair<OUString, OUString> > props; 870*cdf0e10cSrcweir 871*cdf0e10cSrcweir OUString sResolvedDir = resolveDirPath(path); 872*cdf0e10cSrcweir // If this path is invalid then there is no chance to find a JRE here 873*cdf0e10cSrcweir if (sResolvedDir.getLength() == 0) 874*cdf0e10cSrcweir return 0; 875*cdf0e10cSrcweir 876*cdf0e10cSrcweir //check if the directory path is good, that is a JRE was already recognized. 877*cdf0e10cSrcweir //Then we need not detect it again 878*cdf0e10cSrcweir //For example, a sun JKD contains <jdk>/bin/java and <jdk>/jre/bin/java. 879*cdf0e10cSrcweir //When <jdk>/bin/java has been found then we need not find <jdk>/jre/bin/java. 880*cdf0e10cSrcweir //Otherwise we would execute java two times for evers JDK found. 881*cdf0e10cSrcweir MapIt entry2 = find_if(mapJREs.begin(), mapJREs.end(), 882*cdf0e10cSrcweir SameOrSubDirJREMap(sResolvedDir)); 883*cdf0e10cSrcweir if (entry2 != mapJREs.end()) 884*cdf0e10cSrcweir { 885*cdf0e10cSrcweir JFW_TRACE2(OUSTR("[Java framework] sunjavaplugin"SAL_DLLEXTENSION ": ") 886*cdf0e10cSrcweir + OUSTR("JRE found again (detected before): ") + sResolvedDir 887*cdf0e10cSrcweir + OUSTR(".\n")); 888*cdf0e10cSrcweir return entry2->second; 889*cdf0e10cSrcweir } 890*cdf0e10cSrcweir 891*cdf0e10cSrcweir for ( sal_Int32 pos = 0; 892*cdf0e10cSrcweir gVendorMap[pos].sVendorName != NULL; ++pos ) 893*cdf0e10cSrcweir { 894*cdf0e10cSrcweir vector<OUString> vecPaths; 895*cdf0e10cSrcweir getJavaExePaths_func pFunc = gVendorMap[pos].getJavaFunc; 896*cdf0e10cSrcweir 897*cdf0e10cSrcweir int size = 0; 898*cdf0e10cSrcweir char const* const* arExePaths = (*pFunc)(&size); 899*cdf0e10cSrcweir vecPaths = getVectorFromCharArray(arExePaths, size); 900*cdf0e10cSrcweir 901*cdf0e10cSrcweir bool bBreak = false; 902*cdf0e10cSrcweir typedef vector<OUString>::const_iterator c_it; 903*cdf0e10cSrcweir for (c_it i = vecPaths.begin(); i != vecPaths.end(); i++) 904*cdf0e10cSrcweir { 905*cdf0e10cSrcweir //if the path is a link, then resolve it 906*cdf0e10cSrcweir //check if the executable exists at all 907*cdf0e10cSrcweir 908*cdf0e10cSrcweir //path can be only "file:///". Then do not append a '/' 909*cdf0e10cSrcweir //sizeof counts the terminating 0 910*cdf0e10cSrcweir OUString sFullPath; 911*cdf0e10cSrcweir if (path.getLength() == sizeof("file:///") - 1) 912*cdf0e10cSrcweir sFullPath = sResolvedDir + (*i); 913*cdf0e10cSrcweir else 914*cdf0e10cSrcweir sFullPath = sResolvedDir + 915*cdf0e10cSrcweir OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + (*i); 916*cdf0e10cSrcweir 917*cdf0e10cSrcweir 918*cdf0e10cSrcweir sFilePath = resolveFilePath(sFullPath); 919*cdf0e10cSrcweir 920*cdf0e10cSrcweir if (sFilePath.getLength() == 0) 921*cdf0e10cSrcweir { 922*cdf0e10cSrcweir //The file path (to java exe) is not valid 923*cdf0e10cSrcweir cit_path ifull = find(vecBadPaths.begin(), vecBadPaths.end(), sFullPath); 924*cdf0e10cSrcweir if (ifull == vecBadPaths.end()) 925*cdf0e10cSrcweir vecBadPaths.push_back(sFullPath); 926*cdf0e10cSrcweir continue; 927*cdf0e10cSrcweir } 928*cdf0e10cSrcweir 929*cdf0e10cSrcweir cit_path ifile = find(vecBadPaths.begin(), vecBadPaths.end(), sFilePath); 930*cdf0e10cSrcweir if (ifile != vecBadPaths.end()) 931*cdf0e10cSrcweir continue; 932*cdf0e10cSrcweir 933*cdf0e10cSrcweir MapIt entry = mapJREs.find(sFilePath); 934*cdf0e10cSrcweir if (entry != mapJREs.end()) 935*cdf0e10cSrcweir { 936*cdf0e10cSrcweir JFW_TRACE2(OUSTR("[Java framework] sunjavaplugin"SAL_DLLEXTENSION ": ") 937*cdf0e10cSrcweir + OUSTR("JRE found again (detected before): ") + sFilePath 938*cdf0e10cSrcweir + OUSTR(".\n")); 939*cdf0e10cSrcweir 940*cdf0e10cSrcweir return entry->second; 941*cdf0e10cSrcweir } 942*cdf0e10cSrcweir 943*cdf0e10cSrcweir bool bProcessRun= false; 944*cdf0e10cSrcweir if (getJavaProps(sFilePath, props, & bProcessRun) == false) 945*cdf0e10cSrcweir { 946*cdf0e10cSrcweir //The java executable could not be run or the system properties 947*cdf0e10cSrcweir //could not be retrieved. We can assume that this java is corrupt. 948*cdf0e10cSrcweir vecBadPaths.push_back(sFilePath); 949*cdf0e10cSrcweir //If there was a java executable, that could be run but we did not get 950*cdf0e10cSrcweir //the system properties, then we also assume that the whole Java installation 951*cdf0e10cSrcweir //does not work. In a jdk there are two executables. One in jdk/bin and the other 952*cdf0e10cSrcweir //in jdk/jre/bin. We do not search any further, because we assume that if one java 953*cdf0e10cSrcweir //does not work then the other does not work as well. This saves us to run java 954*cdf0e10cSrcweir //again which is quite costly. 955*cdf0e10cSrcweir if (bProcessRun == true) 956*cdf0e10cSrcweir { 957*cdf0e10cSrcweir // 1.3.1 special treatment: jdk/bin/java and /jdk/jre/bin/java are links to 958*cdf0e10cSrcweir //a script, named .java_wrapper. The script starts jdk/bin/sparc/native_threads/java 959*cdf0e10cSrcweir //or jdk/jre/bin/sparc/native_threads/java. The script uses the name with which it was 960*cdf0e10cSrcweir //invoked to build the path to the executable. It we start the script directy as .java_wrapper 961*cdf0e10cSrcweir //then it tries to start a jdk/.../native_threads/.java_wrapper. Therefore the link, which 962*cdf0e10cSrcweir //is named java, must be used to start the script. 963*cdf0e10cSrcweir getJavaProps(sFullPath, props, & bProcessRun); 964*cdf0e10cSrcweir // Either we found a working 1.3.1 965*cdf0e10cSrcweir //Or the java is broken. In both cases we stop searchin under this "root" directory 966*cdf0e10cSrcweir bBreak = true; 967*cdf0e10cSrcweir break; 968*cdf0e10cSrcweir } 969*cdf0e10cSrcweir //sFilePath is no working java executable. We continue with another possible 970*cdf0e10cSrcweir //path. 971*cdf0e10cSrcweir else 972*cdf0e10cSrcweir { 973*cdf0e10cSrcweir continue; 974*cdf0e10cSrcweir } 975*cdf0e10cSrcweir } 976*cdf0e10cSrcweir //sFilePath is a java and we could get the system properties. We proceed with this 977*cdf0e10cSrcweir //java. 978*cdf0e10cSrcweir else 979*cdf0e10cSrcweir { 980*cdf0e10cSrcweir bBreak = true; 981*cdf0e10cSrcweir break; 982*cdf0e10cSrcweir } 983*cdf0e10cSrcweir } 984*cdf0e10cSrcweir if (bBreak) 985*cdf0e10cSrcweir break; 986*cdf0e10cSrcweir } 987*cdf0e10cSrcweir 988*cdf0e10cSrcweir if (props.size() == 0) 989*cdf0e10cSrcweir return rtl::Reference<VendorBase>(); 990*cdf0e10cSrcweir 991*cdf0e10cSrcweir //find java.vendor property 992*cdf0e10cSrcweir typedef vector<pair<OUString, OUString> >::const_iterator c_ip; 993*cdf0e10cSrcweir OUString sVendor(RTL_CONSTASCII_USTRINGPARAM("java.vendor")); 994*cdf0e10cSrcweir OUString sVendorName; 995*cdf0e10cSrcweir 996*cdf0e10cSrcweir for (c_ip i = props.begin(); i != props.end(); i++) 997*cdf0e10cSrcweir { 998*cdf0e10cSrcweir if (sVendor.equals(i->first)) 999*cdf0e10cSrcweir { 1000*cdf0e10cSrcweir sVendorName = i->second; 1001*cdf0e10cSrcweir break; 1002*cdf0e10cSrcweir } 1003*cdf0e10cSrcweir } 1004*cdf0e10cSrcweir 1005*cdf0e10cSrcweir if (sVendorName.getLength() > 0) 1006*cdf0e10cSrcweir { 1007*cdf0e10cSrcweir //find the creator func for the respective vendor name 1008*cdf0e10cSrcweir for ( sal_Int32 c = 0; 1009*cdf0e10cSrcweir gVendorMap[c].sVendorName != NULL; ++c ) 1010*cdf0e10cSrcweir { 1011*cdf0e10cSrcweir OUString sNameMap(gVendorMap[c].sVendorName, strlen(gVendorMap[c].sVendorName), 1012*cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US); 1013*cdf0e10cSrcweir if (sNameMap.equals(sVendorName)) 1014*cdf0e10cSrcweir { 1015*cdf0e10cSrcweir ret = createInstance(gVendorMap[c].createFunc, props); 1016*cdf0e10cSrcweir break; 1017*cdf0e10cSrcweir } 1018*cdf0e10cSrcweir } 1019*cdf0e10cSrcweir } 1020*cdf0e10cSrcweir if (ret.is() == false) 1021*cdf0e10cSrcweir vecBadPaths.push_back(sFilePath); 1022*cdf0e10cSrcweir else 1023*cdf0e10cSrcweir { 1024*cdf0e10cSrcweir JFW_TRACE2(OUSTR("[Java framework] sunjavaplugin"SAL_DLLEXTENSION ": ") 1025*cdf0e10cSrcweir + OUSTR("Found JRE: ") + sResolvedDir 1026*cdf0e10cSrcweir + OUSTR(" \n at: ") + path + OUSTR(".\n")); 1027*cdf0e10cSrcweir 1028*cdf0e10cSrcweir mapJREs.insert(MAPJRE::value_type(sResolvedDir, ret)); 1029*cdf0e10cSrcweir mapJREs.insert(MAPJRE::value_type(sFilePath, ret)); 1030*cdf0e10cSrcweir } 1031*cdf0e10cSrcweir 1032*cdf0e10cSrcweir return ret; 1033*cdf0e10cSrcweir } 1034*cdf0e10cSrcweir 1035*cdf0e10cSrcweir Reference<VendorBase> createInstance(createInstance_func pFunc, 1036*cdf0e10cSrcweir vector<pair<OUString, OUString> > properties) 1037*cdf0e10cSrcweir { 1038*cdf0e10cSrcweir 1039*cdf0e10cSrcweir Reference<VendorBase> aBase = (*pFunc)(); 1040*cdf0e10cSrcweir if (aBase.is()) 1041*cdf0e10cSrcweir { 1042*cdf0e10cSrcweir if (aBase->initialize(properties) == false) 1043*cdf0e10cSrcweir aBase = 0; 1044*cdf0e10cSrcweir } 1045*cdf0e10cSrcweir return aBase; 1046*cdf0e10cSrcweir } 1047*cdf0e10cSrcweir 1048*cdf0e10cSrcweir inline OUString getDirFromFile(const OUString& usFilePath) 1049*cdf0e10cSrcweir { 1050*cdf0e10cSrcweir sal_Int32 index= usFilePath.lastIndexOf('/'); 1051*cdf0e10cSrcweir return OUString(usFilePath.getStr(), index); 1052*cdf0e10cSrcweir } 1053*cdf0e10cSrcweir 1054*cdf0e10cSrcweir void createJavaInfoFromPath(vector<rtl::Reference<VendorBase> >& vecInfos) 1055*cdf0e10cSrcweir { 1056*cdf0e10cSrcweir // Get Java from PATH environment variable 1057*cdf0e10cSrcweir static OUString sCurDir(RTL_CONSTASCII_USTRINGPARAM(".")); 1058*cdf0e10cSrcweir static OUString sParentDir(RTL_CONSTASCII_USTRINGPARAM("..")); 1059*cdf0e10cSrcweir char *szPath= getenv("PATH"); 1060*cdf0e10cSrcweir if(szPath) 1061*cdf0e10cSrcweir { 1062*cdf0e10cSrcweir OUString usAllPath(szPath, strlen(szPath), osl_getThreadTextEncoding()); 1063*cdf0e10cSrcweir sal_Int32 nIndex = 0; 1064*cdf0e10cSrcweir do 1065*cdf0e10cSrcweir { 1066*cdf0e10cSrcweir OUString usToken = usAllPath.getToken( 0, SAL_PATHSEPARATOR, nIndex ); 1067*cdf0e10cSrcweir OUString usTokenUrl; 1068*cdf0e10cSrcweir if(File::getFileURLFromSystemPath(usToken, usTokenUrl) == File::E_None) 1069*cdf0e10cSrcweir { 1070*cdf0e10cSrcweir if(usTokenUrl.getLength()) 1071*cdf0e10cSrcweir { 1072*cdf0e10cSrcweir OUString usBin; 1073*cdf0e10cSrcweir // "." 1074*cdf0e10cSrcweir if(usTokenUrl.equals(sCurDir)) 1075*cdf0e10cSrcweir { 1076*cdf0e10cSrcweir OUString usWorkDirUrl; 1077*cdf0e10cSrcweir if(osl_Process_E_None == osl_getProcessWorkingDir(&usWorkDirUrl.pData)) 1078*cdf0e10cSrcweir usBin= usWorkDirUrl; 1079*cdf0e10cSrcweir } 1080*cdf0e10cSrcweir // ".." 1081*cdf0e10cSrcweir else if(usTokenUrl.equals(sParentDir)) 1082*cdf0e10cSrcweir { 1083*cdf0e10cSrcweir OUString usWorkDir; 1084*cdf0e10cSrcweir if(osl_Process_E_None == osl_getProcessWorkingDir(&usWorkDir.pData)) 1085*cdf0e10cSrcweir usBin= getDirFromFile(usWorkDir); 1086*cdf0e10cSrcweir } 1087*cdf0e10cSrcweir else 1088*cdf0e10cSrcweir { 1089*cdf0e10cSrcweir usBin = usTokenUrl; 1090*cdf0e10cSrcweir } 1091*cdf0e10cSrcweir if(usBin.getLength()) 1092*cdf0e10cSrcweir { 1093*cdf0e10cSrcweir getJREInfoFromBinPath(usBin, vecInfos); 1094*cdf0e10cSrcweir } 1095*cdf0e10cSrcweir } 1096*cdf0e10cSrcweir } 1097*cdf0e10cSrcweir } 1098*cdf0e10cSrcweir while ( nIndex >= 0 ); 1099*cdf0e10cSrcweir } 1100*cdf0e10cSrcweir } 1101*cdf0e10cSrcweir 1102*cdf0e10cSrcweir void createJavaInfoFromJavaHome(vector<rtl::Reference<VendorBase> >& vecInfos) 1103*cdf0e10cSrcweir { 1104*cdf0e10cSrcweir // Get Java from JAVA_HOME environment 1105*cdf0e10cSrcweir char *szJavaHome= getenv("JAVA_HOME"); 1106*cdf0e10cSrcweir if(szJavaHome) 1107*cdf0e10cSrcweir { 1108*cdf0e10cSrcweir OUString sHome(szJavaHome,strlen(szJavaHome),osl_getThreadTextEncoding()); 1109*cdf0e10cSrcweir OUString sHomeUrl; 1110*cdf0e10cSrcweir if(File::getFileURLFromSystemPath(sHome, sHomeUrl) == File::E_None) 1111*cdf0e10cSrcweir { 1112*cdf0e10cSrcweir getJREInfoByPath(sHomeUrl, vecInfos); 1113*cdf0e10cSrcweir } 1114*cdf0e10cSrcweir } 1115*cdf0e10cSrcweir } 1116*cdf0e10cSrcweir 1117*cdf0e10cSrcweir bool makeDriveLetterSame(OUString * fileURL) 1118*cdf0e10cSrcweir { 1119*cdf0e10cSrcweir bool ret = false; 1120*cdf0e10cSrcweir DirectoryItem item; 1121*cdf0e10cSrcweir if (DirectoryItem::get(*fileURL, item) == File::E_None) 1122*cdf0e10cSrcweir { 1123*cdf0e10cSrcweir FileStatus status(FileStatusMask_FileURL); 1124*cdf0e10cSrcweir if (item.getFileStatus(status) == File::E_None) 1125*cdf0e10cSrcweir { 1126*cdf0e10cSrcweir *fileURL = status.getFileURL(); 1127*cdf0e10cSrcweir ret = true; 1128*cdf0e10cSrcweir } 1129*cdf0e10cSrcweir } 1130*cdf0e10cSrcweir return ret; 1131*cdf0e10cSrcweir } 1132*cdf0e10cSrcweir 1133*cdf0e10cSrcweir #ifdef UNX 1134*cdf0e10cSrcweir #ifdef SOLARIS 1135*cdf0e10cSrcweir 1136*cdf0e10cSrcweir void createJavaInfoDirScan(vector<rtl::Reference<VendorBase> >& vecInfos) 1137*cdf0e10cSrcweir { 1138*cdf0e10cSrcweir JFW_TRACE2(OUSTR("\n[Java framework] Checking \"/usr/jdk/latest\"\n")); 1139*cdf0e10cSrcweir getJREInfoByPath(OUSTR("file:////usr/jdk/latest"), vecInfos); 1140*cdf0e10cSrcweir } 1141*cdf0e10cSrcweir 1142*cdf0e10cSrcweir #else 1143*cdf0e10cSrcweir void createJavaInfoDirScan(vector<rtl::Reference<VendorBase> >& vecInfos) 1144*cdf0e10cSrcweir { 1145*cdf0e10cSrcweir OUString excMessage = OUSTR("[Java framework] sunjavaplugin: " 1146*cdf0e10cSrcweir "Error in function createJavaInfoDirScan in util.cxx."); 1147*cdf0e10cSrcweir int cJavaNames= sizeof(g_arJavaNames) / sizeof(char*); 1148*cdf0e10cSrcweir boost::scoped_array<OUString> sarJavaNames(new OUString[cJavaNames]); 1149*cdf0e10cSrcweir OUString *arNames = sarJavaNames.get(); 1150*cdf0e10cSrcweir for(int i= 0; i < cJavaNames; i++) 1151*cdf0e10cSrcweir arNames[i] = OUString(g_arJavaNames[i], strlen(g_arJavaNames[i]), 1152*cdf0e10cSrcweir RTL_TEXTENCODING_UTF8); 1153*cdf0e10cSrcweir 1154*cdf0e10cSrcweir int cSearchPaths= sizeof(g_arSearchPaths) / sizeof(char*); 1155*cdf0e10cSrcweir boost::scoped_array<OUString> sarPathNames(new OUString[cSearchPaths]); 1156*cdf0e10cSrcweir OUString *arPaths = sarPathNames.get(); 1157*cdf0e10cSrcweir for(int c = 0; c < cSearchPaths; c++) 1158*cdf0e10cSrcweir arPaths[c] = OUString(g_arSearchPaths[c], strlen(g_arSearchPaths[c]), 1159*cdf0e10cSrcweir RTL_TEXTENCODING_UTF8); 1160*cdf0e10cSrcweir 1161*cdf0e10cSrcweir int cCollectDirs = sizeof(g_arCollectDirs) / sizeof(char*); 1162*cdf0e10cSrcweir boost::scoped_array<OUString> sarCollectDirs(new OUString[cCollectDirs]); 1163*cdf0e10cSrcweir OUString *arCollectDirs = sarCollectDirs.get(); 1164*cdf0e10cSrcweir for(int d = 0; d < cCollectDirs; d++) 1165*cdf0e10cSrcweir arCollectDirs[d] = OUString(g_arCollectDirs[d], strlen(g_arCollectDirs[d]), 1166*cdf0e10cSrcweir RTL_TEXTENCODING_UTF8); 1167*cdf0e10cSrcweir 1168*cdf0e10cSrcweir 1169*cdf0e10cSrcweir 1170*cdf0e10cSrcweir OUString usFile(RTL_CONSTASCII_USTRINGPARAM("file:///")); 1171*cdf0e10cSrcweir for( int ii = 0; ii < cSearchPaths; ii ++) 1172*cdf0e10cSrcweir { 1173*cdf0e10cSrcweir OUString usDir1(usFile + arPaths[ii]); 1174*cdf0e10cSrcweir DirectoryItem item; 1175*cdf0e10cSrcweir if(DirectoryItem::get(usDir1, item) == File::E_None) 1176*cdf0e10cSrcweir { 1177*cdf0e10cSrcweir for(int j= 0; j < cCollectDirs; j++) 1178*cdf0e10cSrcweir { 1179*cdf0e10cSrcweir OUString usDir2(usDir1 + arCollectDirs[j]); 1180*cdf0e10cSrcweir // prevent that we scan the whole /usr, /usr/lib, etc directories 1181*cdf0e10cSrcweir if (arCollectDirs[j] != OUString()) 1182*cdf0e10cSrcweir { 1183*cdf0e10cSrcweir //usr/java/xxx 1184*cdf0e10cSrcweir //Examin every subdirectory 1185*cdf0e10cSrcweir Directory aCollectionDir(usDir2); 1186*cdf0e10cSrcweir 1187*cdf0e10cSrcweir Directory::RC openErr = aCollectionDir.open(); 1188*cdf0e10cSrcweir switch (openErr) 1189*cdf0e10cSrcweir { 1190*cdf0e10cSrcweir case File::E_None: 1191*cdf0e10cSrcweir break; 1192*cdf0e10cSrcweir case File::E_NOENT: 1193*cdf0e10cSrcweir case File::E_NOTDIR: 1194*cdf0e10cSrcweir continue; 1195*cdf0e10cSrcweir case File::E_ACCES: 1196*cdf0e10cSrcweir JFW_TRACE2(OUSTR("[Java framework] sunjavaplugin: " 1197*cdf0e10cSrcweir "Could not read directory ") + usDir2 + 1198*cdf0e10cSrcweir OUSTR(" because of missing access rights.")); 1199*cdf0e10cSrcweir continue; 1200*cdf0e10cSrcweir default: 1201*cdf0e10cSrcweir JFW_TRACE2(OUSTR("[Java framework] sunjavaplugin: " 1202*cdf0e10cSrcweir "Could not read directory ") 1203*cdf0e10cSrcweir + usDir2 + OUSTR(". Osl file error: ") 1204*cdf0e10cSrcweir + OUString::valueOf((sal_Int32) openErr)); 1205*cdf0e10cSrcweir continue; 1206*cdf0e10cSrcweir } 1207*cdf0e10cSrcweir 1208*cdf0e10cSrcweir DirectoryItem curIt; 1209*cdf0e10cSrcweir File::RC errNext = File::E_None; 1210*cdf0e10cSrcweir while( (errNext = aCollectionDir.getNextItem(curIt)) == File::E_None) 1211*cdf0e10cSrcweir { 1212*cdf0e10cSrcweir FileStatus aStatus(FileStatusMask_FileURL); 1213*cdf0e10cSrcweir File::RC errStatus = File::E_None; 1214*cdf0e10cSrcweir if ((errStatus = curIt.getFileStatus(aStatus)) != File::E_None) 1215*cdf0e10cSrcweir { 1216*cdf0e10cSrcweir JFW_TRACE2(excMessage + OUSTR("getFileStatus failed with error ") 1217*cdf0e10cSrcweir + OUString::valueOf((sal_Int32) errStatus)); 1218*cdf0e10cSrcweir continue; 1219*cdf0e10cSrcweir } 1220*cdf0e10cSrcweir JFW_TRACE2(OUSTR("[Java framework] sunjavaplugin: " 1221*cdf0e10cSrcweir "Checking if directory: ") + aStatus.getFileURL() + 1222*cdf0e10cSrcweir OUSTR(" is a Java. \n")); 1223*cdf0e10cSrcweir 1224*cdf0e10cSrcweir getJREInfoByPath(aStatus.getFileURL(),vecInfos); 1225*cdf0e10cSrcweir } 1226*cdf0e10cSrcweir 1227*cdf0e10cSrcweir JFW_ENSURE(errNext == File::E_None || errNext == File::E_NOENT, 1228*cdf0e10cSrcweir OUSTR("[Java framework] sunjavaplugin: " 1229*cdf0e10cSrcweir "Error while iterating over contens of ") 1230*cdf0e10cSrcweir + usDir2 + OUSTR(". Osl file error: ") 1231*cdf0e10cSrcweir + OUString::valueOf((sal_Int32) openErr)); 1232*cdf0e10cSrcweir } 1233*cdf0e10cSrcweir else 1234*cdf0e10cSrcweir { 1235*cdf0e10cSrcweir //usr/java 1236*cdf0e10cSrcweir //When we look directly into a dir like /usr, /usr/lib, etc. then we only 1237*cdf0e10cSrcweir //look for certain java directories, such as jre, jdk, etc. Whe do not want 1238*cdf0e10cSrcweir //to examine the whole directory because of performance reasons. 1239*cdf0e10cSrcweir DirectoryItem item2; 1240*cdf0e10cSrcweir if(DirectoryItem::get(usDir2, item2) == File::E_None) 1241*cdf0e10cSrcweir { 1242*cdf0e10cSrcweir for( int k= 0; k < cJavaNames; k++) 1243*cdf0e10cSrcweir { 1244*cdf0e10cSrcweir // /usr/java/j2re1.4.0 1245*cdf0e10cSrcweir OUString usDir3(usDir2 + arNames[k]); 1246*cdf0e10cSrcweir 1247*cdf0e10cSrcweir DirectoryItem item3; 1248*cdf0e10cSrcweir if(DirectoryItem::get(usDir3, item) == File::E_None) 1249*cdf0e10cSrcweir { 1250*cdf0e10cSrcweir //remove trailing '/' 1251*cdf0e10cSrcweir sal_Int32 islash = usDir3.lastIndexOf('/'); 1252*cdf0e10cSrcweir if (islash == usDir3.getLength() - 1 1253*cdf0e10cSrcweir && (islash 1254*cdf0e10cSrcweir > RTL_CONSTASCII_LENGTH("file://"))) 1255*cdf0e10cSrcweir usDir3 = usDir3.copy(0, islash); 1256*cdf0e10cSrcweir getJREInfoByPath(usDir3,vecInfos); 1257*cdf0e10cSrcweir } 1258*cdf0e10cSrcweir } 1259*cdf0e10cSrcweir } 1260*cdf0e10cSrcweir } 1261*cdf0e10cSrcweir } 1262*cdf0e10cSrcweir } 1263*cdf0e10cSrcweir } 1264*cdf0e10cSrcweir } 1265*cdf0e10cSrcweir #endif // ifdef SOLARIS 1266*cdf0e10cSrcweir #endif // ifdef UNX 1267*cdf0e10cSrcweir } 1268