LCOV - code coverage report
Current view: top level - jvmfwk/plugins/sunmajor/pluginlib - gnujre.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 3 119 2.5 %
Date: 2014-11-03 Functions: 1 6 16.7 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10