LCOV - code coverage report
Current view: top level - jvmfwk/plugins/sunmajor/pluginlib - vendorbase.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 72 90 80.0 %
Date: 2014-11-03 Functions: 9 14 64.3 %
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             : 
      23             : #include "vendorbase.hxx"
      24             : #include "util.hxx"
      25             : #include "sunjre.hxx"
      26             : 
      27             : using namespace std;
      28             : using namespace osl;
      29             : 
      30             : 
      31             : namespace jfw_plugin
      32             : {
      33             : 
      34           0 : MalformedVersionException::MalformedVersionException()
      35           0 : {}
      36             : 
      37           0 : MalformedVersionException::MalformedVersionException(
      38           0 :     const MalformedVersionException & )
      39           0 : {}
      40             : 
      41           0 : MalformedVersionException::~MalformedVersionException()
      42           0 : {}
      43             : 
      44             : MalformedVersionException &
      45           0 : MalformedVersionException::operator =(
      46             :     const MalformedVersionException &)
      47             : {
      48           0 :     return *this;
      49             : }
      50             : 
      51             : 
      52             : 
      53         130 : VendorBase::VendorBase(): m_bAccessibility(false)
      54             : {
      55         130 : }
      56             : 
      57         130 : bool VendorBase::initialize(vector<pair<OUString, OUString> > props)
      58             : {
      59             :     //get java.vendor, java.version, java.home,
      60             :     //javax.accessibility.assistive_technologies from system properties
      61             : 
      62             :     typedef vector<pair<OUString, OUString> >::const_iterator it_prop;
      63         130 :     OUString sVendorProperty("java.vendor");
      64         260 :     OUString sVersionProperty("java.version");
      65         260 :     OUString sHomeProperty("java.home");
      66         260 :     OUString sAccessProperty("javax.accessibility.assistive_technologies");
      67             : 
      68         130 :     bool bVersion = false;
      69         130 :     bool bVendor = false;
      70         130 :     bool bHome = false;
      71         130 :     bool bAccess = false;
      72             : 
      73             :     typedef vector<pair<OUString, OUString> >::const_iterator it_prop;
      74        6760 :     for (it_prop i = props.begin(); i != props.end(); ++i)
      75             :     {
      76        6630 :         if(! bVendor && sVendorProperty.equals(i->first))
      77             :         {
      78         130 :             m_sVendor = i->second;
      79         130 :             bVendor = true;
      80             :         }
      81        6500 :         else if (!bVersion && sVersionProperty.equals(i->first))
      82             :         {
      83         130 :             m_sVersion = i->second;
      84         130 :             bVersion = true;
      85             :         }
      86        6370 :         else if (!bHome && sHomeProperty.equals(i->first))
      87             :         {
      88             : #ifndef JVM_ONE_PATH_CHECK
      89         130 :            OUString fileURL;
      90         130 :            if (osl_getFileURLFromSystemPath(i->second.pData,& fileURL.pData) ==
      91             :                osl_File_E_None)
      92             :            {
      93             :                //make sure that the drive letter have all the same case
      94             :                //otherwise file:///c:/jre and file:///C:/jre produce two
      95             :                //different objects!!!
      96         130 :                if (makeDriveLetterSame( & fileURL))
      97             :                {
      98         130 :                    m_sHome = fileURL;
      99         130 :                    bHome = true;
     100             :                }
     101         130 :            }
     102             : #else
     103             :            m_sHome = i->second;
     104             :            bHome = true;
     105             : #endif
     106             :         }
     107        6240 :         else if (!bAccess && sAccessProperty.equals(i->first))
     108             :         {
     109           0 :             if (!i->second.isEmpty())
     110             :             {
     111           0 :                 m_bAccessibility = true;
     112           0 :                 bAccess = true;
     113             :             }
     114             :         }
     115             :         // the javax.accessibility.xxx property may not be set. Therefore we
     116             :         //must search through all properties.
     117             : 
     118             :     }
     119         130 :     if (!bVersion || !bVendor || !bHome)
     120           0 :         return false;
     121             : 
     122             :     // init m_sRuntimeLibrary
     123             :     OSL_ASSERT(!m_sHome.isEmpty());
     124             :     //call virtual function to get the possible paths to the runtime library.
     125             : 
     126         130 :     int size = 0;
     127         130 :     char const* const* arRtPaths = getRuntimePaths( & size);
     128         260 :     vector<OUString> libpaths = getVectorFromCharArray(arRtPaths, size);
     129             : 
     130         130 :     bool bRt = false;
     131             :     typedef vector<OUString>::const_iterator i_path;
     132         260 :     for(i_path ip = libpaths.begin(); ip != libpaths.end(); ++ip)
     133             :     {
     134             :         //Construct an absolute path to the possible runtime
     135         260 :         OUString usRt= m_sHome + *ip;
     136         390 :         DirectoryItem item;
     137         260 :         if(DirectoryItem::get(usRt, item) == File::E_None)
     138             :         {
     139             :             //found runtime lib
     140         130 :             m_sRuntimeLibrary = usRt;
     141         130 :             bRt = true;
     142         130 :             break;
     143             :         }
     144         130 :     }
     145         130 :     if (!bRt)
     146           0 :         return false;
     147             : 
     148             :     // init m_sLD_LIBRARY_PATH
     149             :     OSL_ASSERT(!m_sHome.isEmpty());
     150         130 :     size = 0;
     151         130 :     char const * const * arLDPaths = getLibraryPaths( & size);
     152         260 :     vector<OUString> ld_paths = getVectorFromCharArray(arLDPaths, size);
     153             : 
     154         130 :     char arSep[]= {SAL_PATHSEPARATOR, 0};
     155         260 :     OUString sPathSep= OUString::createFromAscii(arSep);
     156         130 :     bool bLdPath = true;
     157         130 :     int c = 0;
     158         650 :     for(i_path il = ld_paths.begin(); il != ld_paths.end(); ++il, ++c)
     159             :     {
     160         520 :         OUString usAbsUrl= m_sHome + *il;
     161             :         // convert to system path
     162        1040 :         OUString usSysPath;
     163         520 :         if(File::getSystemPathFromFileURL(usAbsUrl, usSysPath) == File::E_None)
     164             :         {
     165             : 
     166         520 :             if(c > 0)
     167         390 :                 m_sLD_LIBRARY_PATH+= sPathSep;
     168         520 :             m_sLD_LIBRARY_PATH+= usSysPath;
     169             :         }
     170             :         else
     171             :         {
     172           0 :             bLdPath = false;
     173           0 :             break;
     174             :         }
     175         520 :     }
     176         130 :     if (bLdPath == false)
     177           0 :         return false;
     178             : 
     179         260 :     return true;
     180             : }
     181             : 
     182         348 : const OUString & VendorBase::getVendor() const
     183             : {
     184         348 :     return m_sVendor;
     185             : }
     186         232 : const OUString & VendorBase::getVersion() const
     187             : {
     188         232 :     return m_sVersion;
     189             : }
     190             : 
     191         984 : const OUString & VendorBase::getHome() const
     192             : {
     193         984 :     return m_sHome;
     194             : }
     195             : 
     196         348 : const OUString & VendorBase::getLibraryPath() const
     197             : {
     198         348 :     return m_sLD_LIBRARY_PATH;
     199             : }
     200             : 
     201         116 : const OUString & VendorBase::getRuntimeLibrary() const
     202             : {
     203         116 :     return m_sRuntimeLibrary;
     204             : }
     205         116 : bool VendorBase::supportsAccessibility() const
     206             : {
     207         116 :     return m_bAccessibility;
     208             : }
     209             : 
     210         116 : bool VendorBase::needsRestart() const
     211             : {
     212         116 :     if (!getLibraryPath().isEmpty())
     213         116 :         return true;
     214           0 :     return false;
     215             : }
     216             : 
     217             : }
     218             : 
     219             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10