LCOV - code coverage report
Current view: top level - desktop/source/deployment/misc - dp_dependencies.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 26 57 45.6 %
Date: 2014-11-03 Functions: 3 7 42.9 %
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             : #include <config_folders.h>
      21             : 
      22             : #include <sal/config.h>
      23             : 
      24             : #include <com/sun/star/uno/Reference.hxx>
      25             : #include <com/sun/star/uno/Sequence.hxx>
      26             : #include <com/sun/star/xml/dom/XElement.hpp>
      27             : #include <com/sun/star/xml/dom/XNodeList.hpp>
      28             : #include <rtl/bootstrap.hxx>
      29             : #include <rtl/string.h>
      30             : #include <rtl/ustring.h>
      31             : #include <rtl/ustring.hxx>
      32             : #include <sal/types.h>
      33             : #include <tools/resid.hxx>
      34             : #include <unotools/configmgr.hxx>
      35             : 
      36             : #include "deployment.hrc"
      37             : #include "dp_resource.h"
      38             : 
      39             : #include "dp_dependencies.hxx"
      40             : #include "dp_descriptioninfoset.hxx"
      41             : #include "dp_version.hxx"
      42             : 
      43             : namespace {
      44             : 
      45             : static char const namespaceLibreOffice[] =
      46             :     "http://libreoffice.org/extensions/description/2011";
      47             : 
      48             : static char const namespaceOpenOfficeOrg[] =
      49             :     "http://openoffice.org/extensions/description/2006";
      50             : 
      51             : static char const minimalVersionLibreOffice[] = "LibreOffice-minimal-version";
      52             : 
      53             : static char const minimalVersionOpenOfficeOrg[] =
      54             :     "OpenOffice.org-minimal-version";
      55             : 
      56             : static char const maximalVersionOpenOfficeOrg[] =
      57             :     "OpenOffice.org-maximal-version";
      58             : 
      59           0 : OUString getLibreOfficeMajorMinorMicro() {
      60           0 :     return utl::ConfigManager::getAboutBoxProductVersion();
      61             : }
      62             : 
      63           4 : OUString getReferenceOpenOfficeOrgMajorMinor() {
      64             :     OUString v(
      65             :             "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("version")
      66           4 :             ":Version:ReferenceOOoMajorMinor}");
      67           4 :     rtl::Bootstrap::expandMacros(v); //TODO: check for failure
      68           4 :     return v;
      69             : }
      70             : 
      71           4 : bool satisfiesMinimalVersion(
      72             :     OUString const & actual, OUString const & specified)
      73             : {
      74           4 :     return dp_misc::compareVersions(actual, specified) != dp_misc::LESS;
      75             : }
      76             : 
      77           0 : bool satisfiesMaximalVersion(
      78             :     OUString const & actual, OUString const & specified)
      79             : {
      80           0 :     return dp_misc::compareVersions(actual, specified) != dp_misc::GREATER;
      81             : }
      82             : 
      83           0 : OUString produceErrorText(
      84             :     OUString const & reason, OUString const & version)
      85             : {
      86             :     return reason.replaceFirst("%VERSION",
      87           0 :         (version.isEmpty()
      88             :          ?  dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_UNKNOWN).toString()
      89           0 :          : version));
      90             : }
      91             : 
      92             : }
      93             : 
      94             : namespace dp_misc {
      95             : 
      96             : namespace Dependencies {
      97             : 
      98             : css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > >
      99           4 : check(dp_misc::DescriptionInfoset const & infoset) {
     100             :     css::uno::Reference< css::xml::dom::XNodeList > deps(
     101           4 :         infoset.getDependencies());
     102           4 :     sal_Int32 n = deps->getLength();
     103             :     css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > >
     104           4 :         unsatisfied(n);
     105           4 :     sal_Int32 unsat = 0;
     106             :     // check first if minimalVersionLibreOffice is specified -- in that case ignore the legacy OOo dependencies
     107           4 :     bool bIgnoreOoo = false;
     108           8 :     for (sal_Int32 i = 0; i < n; ++i) {
     109             :         css::uno::Reference< css::xml::dom::XElement > e(
     110           4 :             deps->item(i), css::uno::UNO_QUERY_THROW);
     111           4 :         if ( e->getNamespaceURI() == namespaceLibreOffice && e->getTagName() == minimalVersionLibreOffice)
     112             :         {
     113           0 :             bIgnoreOoo = true;
     114           0 :             break;
     115             :         }
     116           4 :     }
     117           8 :     for (sal_Int32 i = 0; i < n; ++i) {
     118             :         css::uno::Reference< css::xml::dom::XElement > e(
     119           4 :             deps->item(i), css::uno::UNO_QUERY_THROW);
     120           4 :         bool sat = false;
     121           4 :         if ( e->getNamespaceURI() == namespaceOpenOfficeOrg && e->getTagName() == minimalVersionOpenOfficeOrg )
     122             :         {
     123          16 :             sat = bIgnoreOoo || satisfiesMinimalVersion(
     124             :                 getReferenceOpenOfficeOrgMajorMinor(),
     125          16 :                 e->getAttribute("value"));
     126           0 :         } else if ( e->getNamespaceURI() == namespaceOpenOfficeOrg && e->getTagName() == maximalVersionOpenOfficeOrg )
     127             :         {
     128           0 :             sat = bIgnoreOoo || satisfiesMaximalVersion(
     129             :                 getReferenceOpenOfficeOrgMajorMinor(),
     130           0 :                 e->getAttribute("value"));
     131           0 :         } else if (e->getNamespaceURI() == namespaceLibreOffice && e->getTagName() == minimalVersionLibreOffice )
     132             :         {
     133             :             sat = satisfiesMinimalVersion(
     134             :                 getLibreOfficeMajorMinorMicro(),
     135           0 :                 e->getAttribute("value"));
     136           0 :         } else if (e->hasAttributeNS(namespaceOpenOfficeOrg,
     137           0 :                        minimalVersionOpenOfficeOrg))
     138             :         {
     139             :             sat = satisfiesMinimalVersion(
     140             :                 getReferenceOpenOfficeOrgMajorMinor(),
     141           0 :                 e->getAttributeNS(namespaceOpenOfficeOrg,
     142           0 :                     minimalVersionOpenOfficeOrg));
     143             :         }
     144           4 :         if (!sat) {
     145           0 :             unsatisfied[unsat++] = e;
     146             :         }
     147           4 :     }
     148           4 :     unsatisfied.realloc(unsat);
     149           4 :     return unsatisfied;
     150             : }
     151             : 
     152           0 : OUString getErrorText(
     153             :     css::uno::Reference< css::xml::dom::XElement > const & dependency)
     154             : {
     155             :     OSL_ASSERT(dependency.is());
     156           0 :     if ( dependency->getNamespaceURI() == namespaceOpenOfficeOrg && dependency->getTagName() == minimalVersionOpenOfficeOrg )
     157             :     {
     158             :         return produceErrorText(
     159             :                 dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MIN).toString(),
     160           0 :             dependency->getAttribute("value"));
     161           0 :     } else if (dependency->getNamespaceURI() == namespaceOpenOfficeOrg && dependency->getTagName() == maximalVersionOpenOfficeOrg )
     162             :     {
     163             :         return produceErrorText(
     164             :                 dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MAX).toString(),
     165           0 :             dependency->getAttribute("value"));
     166           0 :     } else if (dependency->getNamespaceURI() == namespaceLibreOffice && dependency->getTagName() == minimalVersionLibreOffice )
     167             :     {
     168             :         return produceErrorText(
     169             :                 dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_LO_MIN).toString(),
     170           0 :             dependency->getAttribute("value"));
     171           0 :     } else if (dependency->hasAttributeNS(namespaceOpenOfficeOrg,
     172           0 :                    minimalVersionOpenOfficeOrg))
     173             :     {
     174             :         return produceErrorText(
     175             :                 dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MIN).toString(),
     176           0 :             dependency->getAttributeNS(namespaceOpenOfficeOrg,
     177           0 :                 minimalVersionOpenOfficeOrg));
     178             :     } else {
     179           0 :         return dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_UNKNOWN).toString();
     180             :     }
     181             : }
     182             : 
     183             : }
     184             : 
     185             : }
     186             : 
     187             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10