summaryrefslogtreecommitdiff
path: root/desktop/source
diff options
context:
space:
mode:
authorJoachim Lingner <jl@openoffice.org>2010-02-11 11:24:50 +0100
committerJoachim Lingner <jl@openoffice.org>2010-02-11 11:24:50 +0100
commite033b7ec66dcc250ed801da3cea61aba3d4749bb (patch)
tree7533631851321a8e6c17e98cd0cdecffcfdb6321 /desktop/source
parentc3f6618d781936a21ee5b25b4be1edc27921e39e (diff)
native0: #i100282# Support unopkg --suppress-license option
Diffstat (limited to 'desktop/source')
-rw-r--r--desktop/source/deployment/inc/dp_descriptioninfoset.hxx16
-rw-r--r--desktop/source/deployment/misc/dp_descriptioninfoset.cxx44
-rw-r--r--desktop/source/deployment/registry/package/dp_package.cxx68
-rw-r--r--desktop/source/pkgchk/unopkg/unopkg_app.cxx11
-rw-r--r--desktop/source/pkgchk/unopkg/unopkg_cmdenv.cxx34
-rw-r--r--desktop/source/pkgchk/unopkg/unopkg_shared.h3
6 files changed, 121 insertions, 55 deletions
diff --git a/desktop/source/deployment/inc/dp_descriptioninfoset.hxx b/desktop/source/deployment/inc/dp_descriptioninfoset.hxx
index 3ee49627ef..f2cb02c238 100644
--- a/desktop/source/deployment/inc/dp_descriptioninfoset.hxx
+++ b/desktop/source/deployment/inc/dp_descriptioninfoset.hxx
@@ -56,6 +56,15 @@ namespace rtl { class OUString; }
namespace dp_misc {
+struct DESKTOP_DEPLOYMENTMISC_DLLPUBLIC SimpleLicenseAttributes
+{
+ ::rtl::OUString acceptBy;
+ //Attribute suppress-on-update. Default is false.
+ bool suppressOnUpdate;
+ //Attribute suppress-if-required. Default is false.
+ bool suppressIfRequired;
+};
+
/**
Access to the content of an XML <code>description</code> element.
@@ -135,6 +144,13 @@ public:
*/
::rtl::OUString getLocalizedLicenseURL() const;
+ /** returns the attributes of the simple-license element
+
+ As long as there is a simple-license element, the function will return
+ the structure. If it does not exist, then the optional object is uninitialized.
+ */
+ ::boost::optional<SimpleLicenseAttributes> getSimpleLicenseAttributes() const;
+
/** returns the localized display name of the extensions.
In case there is no localized display-name then an empty string is returned.
diff --git a/desktop/source/deployment/misc/dp_descriptioninfoset.cxx b/desktop/source/deployment/misc/dp_descriptioninfoset.cxx
index d3c7f28115..0479c70845 100644
--- a/desktop/source/deployment/misc/dp_descriptioninfoset.cxx
+++ b/desktop/source/deployment/misc/dp_descriptioninfoset.cxx
@@ -373,6 +373,50 @@ css::uno::Sequence< ::rtl::OUString > DescriptionInfoset::getUrls(
}
+::boost::optional<SimpleLicenseAttributes>
+DescriptionInfoset::getSimpleLicenseAttributes() const
+{
+ //Check if the node exist
+ css::uno::Reference< css::xml::dom::XNode > n;
+ if (m_element.is()) {
+ try {
+ n = m_xpath->selectSingleNode(m_element,
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
+ "/desc:description/desc:registration/desc:simple-license/@accept-by")));
+ } catch (css::xml::xpath::XPathException &) {
+ // ignore
+ }
+ if (n.is())
+ {
+ SimpleLicenseAttributes attributes;
+ attributes.acceptBy =
+ getNodeValueFromExpression(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
+ "/desc:description/desc:registration/desc:simple-license/@accept-by")));
+
+ ::boost::optional< ::rtl::OUString > suppressOnUpdate = getOptionalValue(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
+ "/desc:description/desc:registration/desc:simple-license/@suppress-on-update")));
+ if (suppressOnUpdate)
+ attributes.suppressOnUpdate = (*suppressOnUpdate).trim().equalsIgnoreAsciiCase(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("true")));
+ else
+ attributes.suppressOnUpdate = false;
+
+ ::boost::optional< ::rtl::OUString > suppressIfRequired = getOptionalValue(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
+ "/desc:description/desc:registration/desc:simple-license/@suppress-if-required")));
+ if (suppressIfRequired)
+ attributes.suppressIfRequired = (*suppressIfRequired).trim().equalsIgnoreAsciiCase(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("true")));
+ else
+ attributes.suppressIfRequired = false;
+
+ return ::boost::optional<SimpleLicenseAttributes>(attributes);
+ }
+ }
+ return ::boost::optional<SimpleLicenseAttributes>();
+}
+
::rtl::OUString DescriptionInfoset::getLocalizedDescriptionURL() const
{
return getLocalizedHREFAttrFromChild(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
diff --git a/desktop/source/deployment/registry/package/dp_package.cxx b/desktop/source/deployment/registry/package/dp_package.cxx
index aef0d516cc..af792565be 100644
--- a/desktop/source/deployment/registry/package/dp_package.cxx
+++ b/desktop/source/deployment/registry/package/dp_package.cxx
@@ -73,7 +73,7 @@
#include "com/sun/star/xml/dom/XDocumentBuilder.hpp"
#include "com/sun/star/xml/xpath/XXPathAPI.hpp"
#include "com/sun/star/deployment/XPackageManager.hpp"
-
+#include "boost/optional.hpp"
#include <vector>
#include <stdio.h>
@@ -593,21 +593,12 @@ bool BackendImpl::PackageImpl::checkDependencies(
{
try
{
- css::uno::Reference<css::xml::dom::XNode> xRoot = desc.getRootElement();
- css::uno::Reference<css::xml::xpath::XXPathAPI> xPath =
- getDescriptionInfoset().getXpath();
-
- css::uno::Reference<css::xml::dom::XNode> nodeSimpleLic;
- try {
- nodeSimpleLic = xPath->selectSingleNode(xRoot,
- OUSTR("/desc:description/desc:registration/desc:simple-license"));
- } catch (css::xml::xpath::XPathException &) {
- // ignore
- }
-
- if (!nodeSimpleLic.is())
+ DescriptionInfoset info = getDescriptionInfoset();
+ ::boost::optional<SimpleLicenseAttributes> simplLicAttr
+ = info.getSimpleLicenseAttributes();
+ if (! simplLicAttr)
return true;
- OUString sLic = getDescriptionInfoset().getLocalizedLicenseURL();
+ OUString sLic = info.getLocalizedLicenseURL();
//If we do not get a localized licence then there is an error in the description.xml
//This should be handled by using a validating parser. Therefore we assume that no
//license is available.
@@ -616,23 +607,20 @@ bool BackendImpl::PackageImpl::checkDependencies(
OUSTR("Could not obtain path to license. Possible error in description.xml"), 0, Any());
OUString sHref = desc.getExtensionRootUrl() + OUSTR("/") + sLic;
OUString sLicense = getTextFromURL(xCmdEnv, sHref);
- //determine who has to agree to the license
- css::uno::Reference<css::xml::xpath::XXPathObject> nodeAttribWho3 =
- xPath->eval(nodeSimpleLic,
- OUSTR("@accept-by"));
- OUString sAccept = nodeAttribWho3->getString().trim();
+ ////determine who has to agree to the license
//check correct value for attribute
- if ( ! (sAccept.equals(OUSTR("user")) || sAccept.equals(OUSTR("admin"))))
+ if ( ! (simplLicAttr->acceptBy.equals(OUSTR("user")) || simplLicAttr->acceptBy.equals(OUSTR("admin"))))
throw css::deployment::DeploymentException(
OUSTR("Could not obtain attribute simple-lincense@accept-by or it has no valid value"), 0, Any());
//If if @accept-by="user" then every user needs to accept the license before it can be installed.
- //Therefore we must prevent the installation as shared extension.
+ //Therefore we must prevent the installation as shared extension unless suppress-if-required="true"
OSL_ASSERT(aContextName.getLength());
- if (sAccept.equals(OUSTR("user")) && aContextName.equals(OUSTR("shared")))
+ if (simplLicAttr->acceptBy.equals(OUSTR("user")) && aContextName.equals(OUSTR("shared")))
{
- css::deployment::LicenseIndividualAgreementException exc =
- css::deployment::LicenseIndividualAgreementException(OUString(), 0, m_name);
+ css::deployment::LicenseIndividualAgreementException
+ exc = css::deployment::LicenseIndividualAgreementException(
+ OUString(), 0, m_name, simplLicAttr->suppressIfRequired);
bool approve = false;
bool abort = false;
@@ -642,32 +630,24 @@ bool BackendImpl::PackageImpl::checkDependencies(
OUSTR("Could not interact with user."), 0, Any());
if (abort == true)
return false;
- //We should always prevent installation
- OSL_ASSERT(0);
- }
-
- //determine optional attribute simple-license@suppressOnUpdate
- css::uno::Reference<css::xml::dom::XElement> elemSimpleLic(nodeSimpleLic, css::uno::UNO_QUERY_THROW);
- sal_Bool bSuppress = sal_False;
- if (elemSimpleLic->hasAttribute(OUSTR("suppress-on-update")))
- {
- if (elemSimpleLic->getAttribute(OUSTR("suppress-on-update")).equals(OUSTR("true")))
- bSuppress = sal_True;
+
+ //If the unopkg --suppress-license was used and simplLicAttr->suppressIfRequired == true,
+ //then the user implicitely accepts the license
}
//Only use interaction if there is no version of this extension already installed
//and the suppress-on-update flag is not set for the new extension
- // bInstalled | bSuppress | show license
+ // bInstalled | bSuppressOnUpdate | show license
//----------------------------------------
- // 0 | 0 | 1
- // 0 | 1 | 1
- // 1 | 0 | 1
- // 1 | 1 | 0
+ // 0 | 0 | 1
+ // 0 | 1 | 1
+ // 1 | 0 | 1
+ // 1 | 1 | 0
- if ( !(bInstalled && bSuppress))
+ if ( !(bInstalled && simplLicAttr->suppressOnUpdate))
{
- css::deployment::LicenseException licExc =
- css::deployment::LicenseException(OUString(), 0, m_name, sLicense);
+ css::deployment::LicenseException licExc(
+ OUString(), 0, m_name, sLicense, simplLicAttr->suppressIfRequired);
bool approve = false;
bool abort = false;
if (! interactContinuation(
diff --git a/desktop/source/pkgchk/unopkg/unopkg_app.cxx b/desktop/source/pkgchk/unopkg/unopkg_app.cxx
index 2a1c71288c..fc56984781 100644
--- a/desktop/source/pkgchk/unopkg/unopkg_app.cxx
+++ b/desktop/source/pkgchk/unopkg/unopkg_app.cxx
@@ -85,6 +85,8 @@ const char s_usingText [] =
" -V, --version version information\n"
" -v, --verbose verbose output to stdout\n"
" -f, --force force overwriting existing extensions\n"
+" -s, --suppress-license prevents showing the license provided that\n"
+" the extension allows it\n"
" --log-file <file> custom log file; default: <cache-dir>/log.txt\n"
" --shared expert feature: operate on shared installation\n"
" deployment context;\n"
@@ -106,6 +108,7 @@ const OptionInfo s_option_infos [] = {
{ RTL_CONSTASCII_STRINGPARAM("shared"), '\0', false },
{ RTL_CONSTASCII_STRINGPARAM("deployment-context"), '\0', true },
{ RTL_CONSTASCII_STRINGPARAM("bundled"), '\0', false},
+ { RTL_CONSTASCII_STRINGPARAM("suppress-license"), 's', false},
{ 0, 0, '\0', false }
};
@@ -210,6 +213,7 @@ extern "C" int unopkg_main()
bool option_force = false;
bool option_verbose = false;
bool option_bundled = false;
+ bool option_suppressLicense = false;
bool subcmd_add = false;
bool subcmd_gui = false;
OUString logFile;
@@ -233,6 +237,9 @@ extern "C" int unopkg_main()
s_option_infos, OUSTR("version") );
OptionInfo const * info_bundled = getOptionInfo(
s_option_infos, OUSTR("bundled") );
+ OptionInfo const * info_suppressLicense = getOptionInfo(
+ s_option_infos, OUSTR("suppress-license") );
+
Reference<XComponentContext> xComponentContext;
Reference<XComponentContext> xLocalComponentContext;
@@ -274,6 +281,7 @@ extern "C" int unopkg_main()
!readOption( &option_shared, info_shared, &nPos ) &&
!readOption( &option_force, info_force, &nPos ) &&
!readOption( &option_bundled, info_bundled, &nPos ) &&
+ !readOption( &option_suppressLicense, info_suppressLicense, &nPos ) &&
!readArgument( &deploymentContext, info_context, &nPos ) &&
!isBootstrapVariable(&nPos))
{
@@ -345,7 +353,8 @@ extern "C" int unopkg_main()
Reference< ::com::sun::star::ucb::XCommandEnvironment > xCmdEnv(
createCmdEnv( xComponentContext, logFile,
- option_force, option_verbose, option_bundled) );
+ option_force, option_verbose, option_bundled,
+ option_suppressLicense) );
if (subcmd_add ||
subCommand.equalsAsciiL(
diff --git a/desktop/source/pkgchk/unopkg/unopkg_cmdenv.cxx b/desktop/source/pkgchk/unopkg/unopkg_cmdenv.cxx
index 7dbce92fd1..4c542445c4 100644
--- a/desktop/source/pkgchk/unopkg/unopkg_cmdenv.cxx
+++ b/desktop/source/pkgchk/unopkg/unopkg_cmdenv.cxx
@@ -89,6 +89,7 @@ class CommandEnvironmentImpl
bool m_option_force_overwrite;
bool m_option_verbose;
bool m_option_bundled;
+ bool m_option_suppressLicense;
Reference< XComponentContext > m_xComponentContext;
Reference< XProgressHandler > m_xLogFile;
@@ -102,7 +103,8 @@ public:
OUString const & log_file,
bool option_force_overwrite,
bool option_verbose,
- bool option_bundled);
+ bool option_bundled,
+ bool option_suppressLicense);
// XCommandEnvironment
virtual Reference< task::XInteractionHandler > SAL_CALL
@@ -127,11 +129,13 @@ CommandEnvironmentImpl::CommandEnvironmentImpl(
OUString const & log_file,
bool option_force_overwrite,
bool option_verbose,
- bool option_bundled)
+ bool option_bundled,
+ bool option_suppressLicense)
: m_logLevel(0),
m_option_force_overwrite( option_force_overwrite ),
m_option_verbose( option_verbose ),
m_option_bundled( option_bundled),
+ m_option_suppressLicense( option_suppressLicense),
m_xComponentContext(xComponentContext)
{
if (log_file.getLength() > 0) {
@@ -282,15 +286,25 @@ void CommandEnvironmentImpl::handle(
}
else if (request >>= licAgreementExc)
{
- String sResMsg( ResId( RID_STR_UNOPKG_NO_SHARED_ALLOWED, *DeploymentResMgr::get() ) );
- sResMsg.SearchAndReplaceAllAscii( "%NAME", licAgreementExc.ExtensionName );
- dp_misc::writeConsole(OUSTR("\n") + sResMsg + OUSTR("\n\n"));
- abort = true;
+ if (m_option_suppressLicense && licAgreementExc.SuppressIfRequired)
+ {
+ approve = true;
+ }
+ else
+ {
+ String sResMsg( ResId( RID_STR_UNOPKG_NO_SHARED_ALLOWED, *DeploymentResMgr::get() ) );
+ sResMsg.SearchAndReplaceAllAscii( "%NAME", licAgreementExc.ExtensionName );
+ dp_misc::writeConsole(OUSTR("\n") + sResMsg + OUSTR("\n\n"));
+ abort = true;
+ }
}
else if (request >>= licExc)
{
bLicenseException = true;
- printLicense(licExc.Text, approve, abort);
+ if (m_option_suppressLicense && licExc.SuppressIfRequired)
+ approve = true;
+ else
+ printLicense(licExc.Text, approve, abort);
}
else if (request >>= instExc)
{
@@ -435,10 +449,12 @@ Reference< XCommandEnvironment > createCmdEnv(
OUString const & logFile,
bool option_force_overwrite,
bool option_verbose,
- bool option_bundled)
+ bool option_bundled,
+ bool option_suppressLicense)
{
return new CommandEnvironmentImpl(
- xContext, logFile, option_force_overwrite, option_verbose, option_bundled);
+ xContext, logFile, option_force_overwrite, option_verbose, option_bundled,
+ option_suppressLicense);
}
} // unopkg
diff --git a/desktop/source/pkgchk/unopkg/unopkg_shared.h b/desktop/source/pkgchk/unopkg/unopkg_shared.h
index b17b89ead1..31cbd48398 100644
--- a/desktop/source/pkgchk/unopkg/unopkg_shared.h
+++ b/desktop/source/pkgchk/unopkg/unopkg_shared.h
@@ -166,7 +166,8 @@ css::uno::Reference<css::ucb::XCommandEnvironment> createCmdEnv(
::rtl::OUString const & logFile,
bool option_force_overwrite,
bool option_verbose,
- bool option_bundled);
+ bool option_bundled,
+ bool option_suppressLicense);
//==============================================================================
void printf_packages(