LCOV - code coverage report
Current view: top level - jvmfwk/plugins/sunmajor/pluginlib - vendorbase.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 75 97 77.3 %
Date: 2012-08-25 Functions: 9 18 50.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 65 104 62.5 %

           Branch data     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                 :            : 
      23                 :            : #include "vendorbase.hxx"
      24                 :            : #include "util.hxx"
      25                 :            : #include "sunjre.hxx"
      26                 :            : 
      27                 :            : using namespace std;
      28                 :            : using namespace osl;
      29                 :            : 
      30                 :            : using ::rtl::OUString;
      31                 :            : 
      32                 :            : namespace jfw_plugin
      33                 :            : {
      34                 :            : rtl::Reference<VendorBase> createInstance(createInstance_func pFunc,
      35                 :            :                                           vector<pair<OUString, OUString> > properties);
      36                 :            : 
      37                 :            : 
      38                 :            : 
      39                 :            : 
      40                 :            : 
      41                 :            : 
      42                 :            : 
      43                 :            : //##############################################################################
      44                 :            : 
      45                 :          0 : MalformedVersionException::MalformedVersionException()
      46                 :          0 : {}
      47                 :          0 : MalformedVersionException::MalformedVersionException(
      48                 :          0 :     const MalformedVersionException & )
      49                 :          0 : {}
      50                 :          0 : MalformedVersionException::~MalformedVersionException()
      51         [ #  # ]:          0 : {}
      52                 :            : MalformedVersionException &
      53                 :          0 : MalformedVersionException::operator =(
      54                 :            :     const MalformedVersionException &)
      55                 :            : {
      56                 :          0 :     return *this;
      57                 :            : }
      58                 :            : //##############################################################################
      59                 :            : 
      60                 :            : 
      61                 :          6 : VendorBase::VendorBase(): m_bAccessibility(false)
      62                 :            : {
      63                 :          6 : }
      64                 :            : 
      65                 :          0 : rtl::Reference<VendorBase> VendorBase::createInstance()
      66                 :            : {
      67         [ #  # ]:          0 :     VendorBase *pBase = new VendorBase();
      68                 :          0 :     return rtl::Reference<VendorBase>(pBase);
      69                 :            : }
      70                 :            : 
      71                 :          6 : bool VendorBase::initialize(vector<pair<OUString, OUString> > props)
      72                 :            : {
      73                 :            :     //get java.vendor, java.version, java.home,
      74                 :            :     //javax.accessibility.assistive_technologies from system properties
      75                 :            : 
      76                 :            :     typedef vector<pair<OUString, OUString> >::const_iterator it_prop;
      77                 :            :     OUString sVendorProperty(
      78         [ +  - ]:          6 :         RTL_CONSTASCII_USTRINGPARAM("java.vendor"));
      79                 :            :     OUString sVersionProperty(
      80         [ +  - ]:          6 :         RTL_CONSTASCII_USTRINGPARAM("java.version"));
      81                 :            :     OUString sHomeProperty(
      82         [ +  - ]:          6 :         RTL_CONSTASCII_USTRINGPARAM("java.home"));
      83                 :            :     OUString sAccessProperty(
      84         [ +  - ]:          6 :         RTL_CONSTASCII_USTRINGPARAM("javax.accessibility.assistive_technologies"));
      85                 :            : 
      86                 :          6 :     bool bVersion = false;
      87                 :          6 :     bool bVendor = false;
      88                 :          6 :     bool bHome = false;
      89                 :          6 :     bool bAccess = false;
      90                 :            : 
      91                 :            :     typedef vector<pair<OUString, OUString> >::const_iterator it_prop;
      92 [ +  - ][ +  - ]:        324 :     for (it_prop i = props.begin(); i != props.end(); ++i)
                 [ +  + ]
      93                 :            :     {
      94 [ +  + ][ +  + ]:        318 :         if(! bVendor && sVendorProperty.equals(i->first))
                 [ +  + ]
      95                 :            :         {
      96                 :          6 :             m_sVendor = i->second;
      97                 :          6 :             bVendor = true;
      98                 :            :         }
      99 [ +  + ][ +  + ]:        312 :         else if (!bVersion && sVersionProperty.equals(i->first))
                 [ +  + ]
     100                 :            :         {
     101                 :          6 :             m_sVersion = i->second;
     102                 :          6 :             bVersion = true;
     103                 :            :         }
     104 [ +  + ][ +  + ]:        306 :         else if (!bHome && sHomeProperty.equals(i->first))
                 [ +  + ]
     105                 :            :         {
     106                 :            : #ifndef JVM_ONE_PATH_CHECK
     107                 :          6 :            OUString fileURL;
     108 [ +  - ][ +  - ]:          6 :            if (osl_getFileURLFromSystemPath(i->second.pData,& fileURL.pData) ==
     109                 :            :                osl_File_E_None)
     110                 :            :            {
     111                 :            :                //make sure that the drive letter have all the same case
     112                 :            :                //otherwise file:///c:/jre and file:///C:/jre produce two
     113                 :            :                //different objects!!!
     114 [ +  - ][ +  - ]:          6 :                if (makeDriveLetterSame( & fileURL))
     115                 :            :                {
     116                 :          6 :                    m_sHome = fileURL;
     117                 :          6 :                    bHome = true;
     118                 :            :                }
     119                 :          6 :            }
     120                 :            : #else
     121                 :            :            m_sHome = i->second;
     122                 :            :            bHome = true;
     123                 :            : #endif
     124                 :            :         }
     125 [ +  + ][ +  + ]:        300 :         else if (!bAccess && sAccessProperty.equals(i->first))
                 [ +  + ]
     126                 :            :         {
     127         [ +  - ]:          6 :             if (!i->second.isEmpty())
     128                 :            :             {
     129                 :          6 :                 m_bAccessibility = true;
     130                 :          6 :                 bAccess = true;
     131                 :            :             }
     132                 :            :         }
     133                 :            :         // the javax.accessibility.xxx property may not be set. Therefore we
     134                 :            :         //must search through all properties.
     135                 :            : 
     136                 :            :     }
     137 [ +  - ][ +  - ]:          6 :     if (!bVersion || !bVendor || !bHome)
                 [ -  + ]
     138                 :          0 :         return false;
     139                 :            : 
     140                 :            :     // init m_sRuntimeLibrary
     141                 :            :     OSL_ASSERT(!m_sHome.isEmpty());
     142                 :            :     //call virtual function to get the possible paths to the runtime library.
     143                 :            : 
     144                 :          6 :     int size = 0;
     145         [ +  - ]:          6 :     char const* const* arRtPaths = getRuntimePaths( & size);
     146         [ +  - ]:          6 :     vector<OUString> libpaths = getVectorFromCharArray(arRtPaths, size);
     147                 :            : 
     148                 :          6 :     bool bRt = false;
     149                 :            :     typedef vector<OUString>::const_iterator i_path;
     150 [ +  - ][ +  - ]:         12 :     for(i_path ip = libpaths.begin(); ip != libpaths.end(); ++ip)
                 [ +  - ]
     151                 :            :     {
     152                 :            :         //Construct an absolute path to the possible runtime
     153                 :          6 :         OUString usRt= m_sHome + *ip;
     154                 :          6 :         DirectoryItem item;
     155 [ +  - ][ +  - ]:          6 :         if(DirectoryItem::get(usRt, item) == File::E_None)
     156                 :            :         {
     157                 :            :             //found runtime lib
     158                 :          6 :             m_sRuntimeLibrary = usRt;
     159                 :          6 :             bRt = true;
     160                 :            :             break;
     161                 :            :         }
     162 [ +  - ][ +  - ]:          6 :     }
                 [ -  + ]
     163         [ -  + ]:          6 :     if (!bRt)
     164                 :          0 :         return false;
     165                 :            : 
     166                 :            :     // init m_sLD_LIBRARY_PATH
     167                 :            :     OSL_ASSERT(!m_sHome.isEmpty());
     168                 :          6 :     size = 0;
     169         [ +  - ]:          6 :     char const * const * arLDPaths = getLibraryPaths( & size);
     170         [ +  - ]:          6 :     vector<OUString> ld_paths = getVectorFromCharArray(arLDPaths, size);
     171                 :            : 
     172                 :          6 :     char arSep[]= {SAL_PATHSEPARATOR, 0};
     173                 :          6 :     OUString sPathSep= OUString::createFromAscii(arSep);
     174                 :          6 :     bool bLdPath = true;
     175                 :          6 :     int c = 0;
     176 [ +  - ][ +  + ]:         30 :     for(i_path il = ld_paths.begin(); il != ld_paths.end(); ++il, ++c)
                 [ +  - ]
     177                 :            :     {
     178                 :         24 :         OUString usAbsUrl= m_sHome + *il;
     179                 :            :         // convert to system path
     180                 :         24 :         OUString usSysPath;
     181 [ +  - ][ +  - ]:         24 :         if(File::getSystemPathFromFileURL(usAbsUrl, usSysPath) == File::E_None)
     182                 :            :         {
     183                 :            : 
     184         [ +  + ]:         24 :             if(c > 0)
     185                 :         18 :                 m_sLD_LIBRARY_PATH+= sPathSep;
     186                 :         24 :             m_sLD_LIBRARY_PATH+= usSysPath;
     187                 :            :         }
     188                 :            :         else
     189                 :            :         {
     190                 :          0 :             bLdPath = false;
     191                 :            :             break;
     192                 :            :         }
     193 [ -  + ][ +  - ]:         24 :     }
     194         [ -  + ]:          6 :     if (bLdPath == false)
     195                 :          0 :         return false;
     196                 :            : 
     197                 :          6 :     return true;
     198                 :            : }
     199                 :            : 
     200                 :          0 : char const* const* VendorBase::getRuntimePaths(int* /*size*/)
     201                 :            : {
     202                 :          0 :     return NULL;
     203                 :            : }
     204                 :            : 
     205                 :          0 : char const* const* VendorBase::getLibraryPaths(int* /*size*/)
     206                 :            : {
     207                 :          0 :     return NULL;
     208                 :            : }
     209                 :            : 
     210                 :         18 : const OUString & VendorBase::getVendor() const
     211                 :            : {
     212                 :         18 :     return m_sVendor;
     213                 :            : }
     214                 :         12 : const OUString & VendorBase::getVersion() const
     215                 :            : {
     216                 :         12 :     return m_sVersion;
     217                 :            : }
     218                 :            : 
     219                 :          6 : const OUString & VendorBase::getHome() const
     220                 :            : {
     221                 :          6 :     return m_sHome;
     222                 :            : }
     223                 :            : 
     224                 :         18 : const OUString & VendorBase::getLibraryPaths() const
     225                 :            : {
     226                 :         18 :     return m_sLD_LIBRARY_PATH;
     227                 :            : }
     228                 :            : 
     229                 :          6 : const OUString & VendorBase::getRuntimeLibrary() const
     230                 :            : {
     231                 :          6 :     return m_sRuntimeLibrary;
     232                 :            : }
     233                 :          6 : bool VendorBase::supportsAccessibility() const
     234                 :            : {
     235                 :          6 :     return m_bAccessibility;
     236                 :            : }
     237                 :            : 
     238                 :          6 : bool VendorBase::needsRestart() const
     239                 :            : {
     240         [ +  - ]:          6 :     if (!getLibraryPaths().isEmpty())
     241                 :          6 :         return true;
     242                 :          6 :     return false;
     243                 :            : }
     244                 :            : 
     245                 :          0 : int VendorBase::compareVersions(const rtl::OUString& /*sSecond*/) const
     246                 :            : {
     247                 :            :     OSL_FAIL("[Java framework] VendorBase::compareVersions must be "
     248                 :            :                "overridden in derived class.");
     249                 :          0 :     return 0;
     250                 :            : }
     251                 :            : 
     252                 :            : 
     253                 :            : 
     254                 :            : 
     255                 :            : }
     256                 :            : 
     257                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10