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

Generated by: LCOV version 1.10