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