LCOV - code coverage report
Current view: top level - jvmfwk/plugins/sunmajor/pluginlib - vendorbase.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 72 90 80.0 %
Date: 2015-06-13 12:38:46 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          77 : VendorBase::VendorBase(): m_bAccessibility(false)
      54             : {
      55          77 : }
      56             : 
      57          77 : 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          77 :     OUString sVendorProperty("java.vendor");
      64         154 :     OUString sVersionProperty("java.version");
      65         154 :     OUString sHomeProperty("java.home");
      66         154 :     OUString sAccessProperty("javax.accessibility.assistive_technologies");
      67             : 
      68          77 :     bool bVersion = false;
      69          77 :     bool bVendor = false;
      70          77 :     bool bHome = false;
      71          77 :     bool bAccess = false;
      72             : 
      73             :     typedef vector<pair<OUString, OUString> >::const_iterator it_prop;
      74        4004 :     for (it_prop i = props.begin(); i != props.end(); ++i)
      75             :     {
      76        3927 :         if(! bVendor && sVendorProperty.equals(i->first))
      77             :         {
      78          77 :             m_sVendor = i->second;
      79          77 :             bVendor = true;
      80             :         }
      81        3850 :         else if (!bVersion && sVersionProperty.equals(i->first))
      82             :         {
      83          77 :             m_sVersion = i->second;
      84          77 :             bVersion = true;
      85             :         }
      86        3773 :         else if (!bHome && sHomeProperty.equals(i->first))
      87             :         {
      88             : #ifndef JVM_ONE_PATH_CHECK
      89          77 :            OUString fileURL;
      90          77 :            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          77 :                if (makeDriveLetterSame( & fileURL))
      97             :                {
      98          77 :                    m_sHome = fileURL;
      99          77 :                    bHome = true;
     100             :                }
     101          77 :            }
     102             : #else
     103             :            m_sHome = i->second;
     104             :            bHome = true;
     105             : #endif
     106             :         }
     107        3696 :         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          77 :     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          77 :     int size = 0;
     127          77 :     char const* const* arRtPaths = getRuntimePaths( & size);
     128         154 :     vector<OUString> libpaths = getVectorFromCharArray(arRtPaths, size);
     129             : 
     130          77 :     bool bRt = false;
     131             :     typedef vector<OUString>::const_iterator i_path;
     132         154 :     for(i_path ip = libpaths.begin(); ip != libpaths.end(); ++ip)
     133             :     {
     134             :         //Construct an absolute path to the possible runtime
     135         154 :         OUString usRt= m_sHome + *ip;
     136         231 :         DirectoryItem item;
     137         154 :         if(DirectoryItem::get(usRt, item) == File::E_None)
     138             :         {
     139             :             //found runtime lib
     140          77 :             m_sRuntimeLibrary = usRt;
     141          77 :             bRt = true;
     142          77 :             break;
     143             :         }
     144          77 :     }
     145          77 :     if (!bRt)
     146           0 :         return false;
     147             : 
     148             :     // init m_sLD_LIBRARY_PATH
     149             :     OSL_ASSERT(!m_sHome.isEmpty());
     150          77 :     size = 0;
     151          77 :     char const * const * arLDPaths = getLibraryPaths( & size);
     152         154 :     vector<OUString> ld_paths = getVectorFromCharArray(arLDPaths, size);
     153             : 
     154          77 :     char arSep[]= {SAL_PATHSEPARATOR, 0};
     155         154 :     OUString sPathSep= OUString::createFromAscii(arSep);
     156          77 :     bool bLdPath = true;
     157          77 :     int c = 0;
     158         385 :     for(i_path il = ld_paths.begin(); il != ld_paths.end(); ++il, ++c)
     159             :     {
     160         308 :         OUString usAbsUrl= m_sHome + *il;
     161             :         // convert to system path
     162         616 :         OUString usSysPath;
     163         308 :         if(File::getSystemPathFromFileURL(usAbsUrl, usSysPath) == File::E_None)
     164             :         {
     165             : 
     166         308 :             if(c > 0)
     167         231 :                 m_sLD_LIBRARY_PATH+= sPathSep;
     168         308 :             m_sLD_LIBRARY_PATH+= usSysPath;
     169             :         }
     170             :         else
     171             :         {
     172           0 :             bLdPath = false;
     173           0 :             break;
     174             :         }
     175         308 :     }
     176          77 :     if (!bLdPath)
     177           0 :         return false;
     178             : 
     179         154 :     return true;
     180             : }
     181             : 
     182         231 : const OUString & VendorBase::getVendor() const
     183             : {
     184         231 :     return m_sVendor;
     185             : }
     186         154 : const OUString & VendorBase::getVersion() const
     187             : {
     188         154 :     return m_sVersion;
     189             : }
     190             : 
     191          81 : const OUString & VendorBase::getHome() const
     192             : {
     193          81 :     return m_sHome;
     194             : }
     195             : 
     196         231 : const OUString & VendorBase::getLibraryPath() const
     197             : {
     198         231 :     return m_sLD_LIBRARY_PATH;
     199             : }
     200             : 
     201          77 : const OUString & VendorBase::getRuntimeLibrary() const
     202             : {
     203          77 :     return m_sRuntimeLibrary;
     204             : }
     205          77 : bool VendorBase::supportsAccessibility() const
     206             : {
     207          77 :     return m_bAccessibility;
     208             : }
     209             : 
     210          77 : bool VendorBase::needsRestart() const
     211             : {
     212          77 :     if (!getLibraryPath().isEmpty())
     213          77 :         return true;
     214           0 :     return false;
     215             : }
     216             : 
     217             : }
     218             : 
     219             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11