LibreOffice Module desktop (master)  1
dp_dependencies.cxx
Go to the documentation of this file.
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 <osl/diagnose.h>
29 #include <rtl/bootstrap.hxx>
30 #include <rtl/ustring.hxx>
31 #include <sal/types.h>
32 #include <unotools/configmgr.hxx>
33 
34 #include <strings.hrc>
35 #include <dp_shared.hxx>
36 
37 #include <dp_dependencies.hxx>
39 #include <dp_version.hxx>
40 
41 namespace {
42 
43 char const namespaceLibreOffice[] =
44  "http://libreoffice.org/extensions/description/2011";
45 
46 constexpr OUStringLiteral namespaceOpenOfficeOrg =
47  u"http://openoffice.org/extensions/description/2006";
48 
49 char const minimalVersionLibreOffice[] = "LibreOffice-minimal-version";
50 char const maximalVersionLibreOffice[] = "LibreOffice-maximal-version";
51 
52 constexpr OUStringLiteral minimalVersionOpenOfficeOrg =
53  u"OpenOffice.org-minimal-version";
54 
55 char const maximalVersionOpenOfficeOrg[] =
56  "OpenOffice.org-maximal-version";
57 
58 OUString getLibreOfficeMajorMinorMicro() {
60 }
61 
62 OUString getReferenceOpenOfficeOrgMajorMinor() {
63 #ifdef ANDROID
64  // just hardcode the version
65  OUString v("4.1");
66 #else
67  OUString v(
68  "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("version")
69  ":Version:ReferenceOOoMajorMinor}");
70  rtl::Bootstrap::expandMacros(v); //TODO: check for failure
71 #endif
72  return v;
73 }
74 
75 bool satisfiesMinimalVersion(
76  OUString const & actual, OUString const & specified)
77 {
78  return dp_misc::compareVersions(actual, specified) != dp_misc::LESS;
79 }
80 
81 bool satisfiesMaximalVersion(
82  OUString const & actual, OUString const & specified)
83 {
84  return dp_misc::compareVersions(actual, specified) != dp_misc::GREATER;
85 }
86 
87 OUString produceErrorText(
88  OUString const & reason, OUString const & version)
89 {
90  return reason.replaceFirst("%VERSION",
91  (version.isEmpty()
92  ? DpResId(RID_DEPLOYMENT_DEPENDENCIES_UNKNOWN)
93  : version));
94 }
95 
96 }
97 
98 namespace dp_misc::Dependencies {
99 
100 css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > >
102  css::uno::Reference< css::xml::dom::XNodeList > deps(
103  infoset.getDependencies());
104  sal_Int32 n = deps->getLength();
105  css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > >
106  unsatisfied(n);
107  auto unsatisfiedRange = asNonConstRange(unsatisfied);
108  sal_Int32 unsat = 0;
109  // check first if minimalVersionLibreOffice is specified -- in that case ignore the legacy OOo dependencies
110  bool bIgnoreOoo = false;
111  for (sal_Int32 i = 0; i < n; ++i) {
112  css::uno::Reference< css::xml::dom::XElement > e(
113  deps->item(i), css::uno::UNO_QUERY_THROW);
114  if ( e->getNamespaceURI() == namespaceLibreOffice && e->getTagName() == minimalVersionLibreOffice)
115  {
116  bIgnoreOoo = true;
117  break;
118  }
119  }
120  for (sal_Int32 i = 0; i < n; ++i) {
121  css::uno::Reference< css::xml::dom::XElement > e(
122  deps->item(i), css::uno::UNO_QUERY_THROW);
123  bool sat = false;
124  if ( e->getNamespaceURI() == namespaceOpenOfficeOrg && e->getTagName() == minimalVersionOpenOfficeOrg )
125  {
126  sat = bIgnoreOoo || satisfiesMinimalVersion(
127  getReferenceOpenOfficeOrgMajorMinor(),
128  e->getAttribute("value"));
129  } else if ( e->getNamespaceURI() == namespaceOpenOfficeOrg && e->getTagName() == maximalVersionOpenOfficeOrg )
130  {
131  sat = bIgnoreOoo || satisfiesMaximalVersion(
132  getReferenceOpenOfficeOrgMajorMinor(),
133  e->getAttribute("value"));
134  } else if (e->getNamespaceURI() == namespaceLibreOffice && e->getTagName() == minimalVersionLibreOffice )
135  {
136  sat = satisfiesMinimalVersion(
137  getLibreOfficeMajorMinorMicro(),
138  e->getAttribute("value"));
139  } else if (e->getNamespaceURI() == namespaceLibreOffice && e->getTagName() == maximalVersionLibreOffice )
140  {
141  sat = satisfiesMaximalVersion(getLibreOfficeMajorMinorMicro(), e->getAttribute("value"));
142  } else if (e->hasAttributeNS(namespaceOpenOfficeOrg,
143  minimalVersionOpenOfficeOrg))
144  {
145  sat = satisfiesMinimalVersion(
146  getReferenceOpenOfficeOrgMajorMinor(),
147  e->getAttributeNS(namespaceOpenOfficeOrg,
148  minimalVersionOpenOfficeOrg));
149  }
150  if (!sat) {
151  unsatisfiedRange[unsat++] = e;
152  }
153  }
154  unsatisfied.realloc(unsat);
155  return unsatisfied;
156 }
157 
158 OUString getErrorText(
159  css::uno::Reference< css::xml::dom::XElement > const & dependency)
160 {
161  OSL_ASSERT(dependency.is());
162  if ( dependency->getNamespaceURI() == namespaceOpenOfficeOrg && dependency->getTagName() == minimalVersionOpenOfficeOrg )
163  {
164  return produceErrorText(
165  DpResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MIN),
166  dependency->getAttribute("value"));
167  } else if (dependency->getNamespaceURI() == namespaceOpenOfficeOrg && dependency->getTagName() == maximalVersionOpenOfficeOrg )
168  {
169  return produceErrorText(
170  DpResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MAX),
171  dependency->getAttribute("value"));
172  } else if (dependency->getNamespaceURI() == namespaceLibreOffice && dependency->getTagName() == minimalVersionLibreOffice )
173  {
174  return produceErrorText(
175  DpResId(RID_DEPLOYMENT_DEPENDENCIES_LO_MIN),
176  dependency->getAttribute("value"));
177  } else if (dependency->getNamespaceURI() == namespaceLibreOffice && dependency->getTagName() == maximalVersionLibreOffice )
178  {
179  return produceErrorText(
180  DpResId(RID_DEPLOYMENT_DEPENDENCIES_LO_MAX),
181  dependency->getAttribute("value"));
182  } else if (dependency->hasAttributeNS(namespaceOpenOfficeOrg,
183  minimalVersionOpenOfficeOrg))
184  {
185  return produceErrorText(
186  DpResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MIN),
187  dependency->getAttributeNS(namespaceOpenOfficeOrg,
188  minimalVersionOpenOfficeOrg));
189  } else {
190  return DpResId(RID_DEPLOYMENT_DEPENDENCIES_UNKNOWN);
191  }
192 }
193 
194 }
195 
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::xml::dom::XNodeList > getDependencies() const
Return the dependencies.
sal_Int64 n
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC Order compareVersions(OUString const &version1, OUString const &version2)
Definition: dp_version.cxx:41
#define SAL_CONFIGFILE(name)
Dependency handling.
int i
float u
static OUString getAboutBoxProductVersion()
float v
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > > check(dp_misc::DescriptionInfoset const &infoset)
Check for unsatisfied dependencies.
OUString DpResId(TranslateId aId)
Definition: dp_misc.cxx:554
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC OUString getErrorText(css::uno::Reference< css::xml::dom::XElement > const &dependency)
Obtain the (human-readable) error message of a failed dependency.
Access to the content of an XML description element.