summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/installerfw-using.qdoc6
-rw-r--r--doc/installerfw.qdoc10
-rw-r--r--src/libs/installer/commandlineparser.cpp9
-rw-r--r--src/libs/installer/constants.h4
-rw-r--r--src/libs/installer/packagemanagercore.cpp21
-rw-r--r--src/libs/installer/packagemanagercore.h4
-rw-r--r--src/sdk/commandlineinterface.cpp26
-rw-r--r--src/sdk/commandlineinterface.h3
-rw-r--r--tests/auto/installer/cliinterface/data/repository/Updates.xml2
-rw-r--r--tests/auto/installer/cliinterface/tst_cliinterface.cpp18
10 files changed, 91 insertions, 12 deletions
diff --git a/doc/installerfw-using.qdoc b/doc/installerfw-using.qdoc
index f0205755f..5c5bbbbc4 100644
--- a/doc/installerfw-using.qdoc
+++ b/doc/installerfw-using.qdoc
@@ -448,10 +448,12 @@
The \c search command can be used to search components from available repositories, or
from integrated binary content in case of an offline installer. It can be used with
no arguments to list all available components or with a regular expression to get a list
- of only components matching the pattern:
+ of only components matching the pattern. The \c --filter-packages option can be
+ used to specify additional filters for the search operation. For a list of usable
+ information elements with the option, refer to \l{Summary of Package Information File Elements}.
\code
- installer.exe search "expression"
+ installer.exe --filter-packages "DisplayName=MyComponent, Version=1.0" search "expression"
\endcode
\section1 Performing Full Uninstallation
diff --git a/doc/installerfw.qdoc b/doc/installerfw.qdoc
index 4ae62eff6..6f77d8850 100644
--- a/doc/installerfw.qdoc
+++ b/doc/installerfw.qdoc
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2020 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Installer Framework.
@@ -247,6 +247,11 @@
\li Create a local repository inside the installation directory. This option has no
effect on online installers.
\row
+ \li --fp, --filter-packages <element=regex,...>
+ \li [CLI] Comma separated list of additional key-value pair filters used to query packages with the
+ search command. The keys can be any of the possible package information elements, like
+ \c DisplayName and \c Description.
+ \row
\li --am, --accept-messages
\li [CLI] Accepts all message queries without user input.
\row
@@ -316,6 +321,9 @@
\row
\li se, search <regexp>
\li Search available packages. If no search pattern is given, show all available packages.
+
+ \note The \c --filter-packages option can be used to specify additional filters for
+ the search operation. See \l{Summary of Options}.
\row
\li co, create-offline <pkg ...>
\li Create offline installer from selected packages.
diff --git a/src/libs/installer/commandlineparser.cpp b/src/libs/installer/commandlineparser.cpp
index 59d42eefc..4bfc4ad3a 100644
--- a/src/libs/installer/commandlineparser.cpp
+++ b/src/libs/installer/commandlineparser.cpp
@@ -59,6 +59,9 @@ CommandLineParser::CommandLineParser()
.arg(CommandLineOptions::scListShort, CommandLineOptions::scListLong)
+ indent + QString::fromLatin1("%1, %2 - search available packages - <regexp>\n")
.arg(CommandLineOptions::scSearchShort, CommandLineOptions::scSearchLong)
+ + indent + indent + QString::fromLatin1("Note: The --%1 option can be used to specify\n")
+ .arg(CommandLineOptions::scFilterPackagesLong)
+ + indent + indent + QLatin1String("additional filters for the search operation\n")
+ indent + QString::fromLatin1("%1, %2 - create offline installer from selected packages - <pkg ...>\n")
.arg(CommandLineOptions::scCreateOfflineShort, CommandLineOptions::scCreateOfflineLong)
+ indent + QString::fromLatin1("%1, %2 - uninstall all packages and remove entire program directory")
@@ -161,6 +164,12 @@ CommandLineParser::CommandLineParser()
<< CommandLineOptions::scCreateLocalRepositoryShort << CommandLineOptions::scCreateLocalRepositoryLong,
QLatin1String("Create a local repository inside the installation directory. This option "
"has no effect on online installers.")));
+ addOptionWithContext(QCommandLineOption(QStringList()
+ << CommandLineOptions::scFilterPackagesShort << CommandLineOptions::scFilterPackagesLong,
+ QLatin1String("[CLI] Comma separated list of additional key-value pair filters used to query packages with the "
+ "search command. The keys can be any of the possible package information elements, like "
+ "\"DisplayName\" and \"Description\"."),
+ QLatin1String("element=regex,...")), CommandLineOnly);
// Message query options
addOptionWithContext(QCommandLineOption(QStringList() << CommandLineOptions::scAcceptMessageQueryShort
diff --git a/src/libs/installer/constants.h b/src/libs/installer/constants.h
index f1105941b..0e16d4c4b 100644
--- a/src/libs/installer/constants.h
+++ b/src/libs/installer/constants.h
@@ -1,6 +1,6 @@
/**************************************************************************
**
-** Copyright (C) 2020 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Installer Framework.
@@ -203,6 +203,8 @@ static const QLatin1String scCreateLocalRepositoryShort("cl");
static const QLatin1String scCreateLocalRepositoryLong("create-local-repository");
static const QLatin1String scNoDefaultInstallationShort("nd");
static const QLatin1String scNoDefaultInstallationLong("no-default-installations");
+static const QLatin1String scFilterPackagesShort("fp");
+static const QLatin1String scFilterPackagesLong("filter-packages");
// Developer options
static const QLatin1String scScriptShort("s");
diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp
index c512c23b5..26df043a0 100644
--- a/src/libs/installer/packagemanagercore.cpp
+++ b/src/libs/installer/packagemanagercore.cpp
@@ -2179,11 +2179,13 @@ ComponentModel *PackageManagerCore::updaterComponentModel() const
/*!
Lists available packages filtered with \a regexp without GUI. Virtual
- components are not listed unless set visible.
+ components are not listed unless set visible. Optionally, a \a filters
+ hash containing package information elements and regular expressions
+ can be used to further filter listed packages.
\sa setVirtualComponentsVisible()
*/
-void PackageManagerCore::listAvailablePackages(const QString &regexp)
+void PackageManagerCore::listAvailablePackages(const QString &regexp, const QHash<QString, QString> &filters)
{
setPackageViewer();
qCDebug(QInstaller::lcInstallerInstallLog)
@@ -2209,8 +2211,19 @@ void PackageManagerCore::listAvailablePackages(const QString &regexp)
continue;
const QModelIndex &idx = model->indexFromComponentName(component->treeName());
- if (idx.isValid() && re.match(name).hasMatch())
- matchedPackages.append(package);
+ if (idx.isValid() && re.match(name).hasMatch()) {
+ bool ignoreComponent = false;
+ for (auto &key : filters.keys()) {
+ const QString elementValue = component->value(key);
+ QRegularExpression elementRegexp(filters.value(key));
+ if (elementValue.isEmpty() || !elementRegexp.match(elementValue).hasMatch()) {
+ ignoreComponent = true;
+ break;
+ }
+ }
+ if (!ignoreComponent)
+ matchedPackages.append(package);
+ }
}
if (matchedPackages.count() == 0)
qCDebug(QInstaller::lcInstallerInstallLog) << "No matching packages found.";
diff --git a/src/libs/installer/packagemanagercore.h b/src/libs/installer/packagemanagercore.h
index 750c03b15..2c54122f5 100644
--- a/src/libs/installer/packagemanagercore.h
+++ b/src/libs/installer/packagemanagercore.h
@@ -33,6 +33,7 @@
#include "repository.h"
#include "qinstallerglobal.h"
#include "utils.h"
+#include "commandlineparser.h"
#include <QtCore/QHash>
#include <QtCore/QObject>
@@ -242,7 +243,8 @@ public:
ComponentModel *defaultComponentModel() const;
ComponentModel *updaterComponentModel() const;
void listInstalledPackages(const QString &regexp = QString());
- void listAvailablePackages(const QString &regexp);
+ void listAvailablePackages(const QString &regexp = QString(),
+ const QHash<QString, QString> &filters = QHash<QString, QString>());
PackageManagerCore::Status updateComponentsSilently(const QStringList &componentsToUpdate);
PackageManagerCore::Status installSelectedComponentsSilently(const QStringList& components);
PackageManagerCore::Status installDefaultComponentsSilently();
diff --git a/src/sdk/commandlineinterface.cpp b/src/sdk/commandlineinterface.cpp
index 69aa36c43..a6cd22151 100644
--- a/src/sdk/commandlineinterface.cpp
+++ b/src/sdk/commandlineinterface.cpp
@@ -132,7 +132,7 @@ int CommandLineInterface::searchAvailablePackages()
QString regexp;
if (!m_positionalArguments.isEmpty())
regexp = m_positionalArguments.first();
- m_core->listAvailablePackages(regexp);
+ m_core->listAvailablePackages(regexp, parsePackageFilters());
return EXIT_SUCCESS;
}
@@ -271,3 +271,27 @@ bool CommandLineInterface::setTargetDir()
}
return false;
}
+
+QHash<QString, QString> CommandLineInterface::parsePackageFilters()
+{
+ QHash<QString, QString> filterHash;
+ if (m_parser.isSet(CommandLineOptions::scFilterPackagesLong)) {
+ const QStringList filterList = m_parser.value(CommandLineOptions::scFilterPackagesLong)
+ .split(QLatin1Char(','));
+
+ for (auto &filter : filterList) {
+ const int i = filter.indexOf(QLatin1Char('='));
+ const QString element = filter.left(i).trimmed();
+ const QString value = filter.mid(i + 1).trimmed();
+
+ if ((i == -1) || (filter.count(QLatin1Char('=') > 1))
+ || element.isEmpty() || value.isEmpty()) {
+ qCWarning(QInstaller::lcInstallerInstallLog).nospace() << "Ignoring unknown entry "
+ << filter << "in package filter arguments. Please use syntax \"element=regex,...\".";
+ continue;
+ }
+ filterHash.insert(element, value);
+ }
+ }
+ return filterHash;
+}
diff --git a/src/sdk/commandlineinterface.h b/src/sdk/commandlineinterface.h
index 2627bc6f8..29bae74a4 100644
--- a/src/sdk/commandlineinterface.h
+++ b/src/sdk/commandlineinterface.h
@@ -1,6 +1,6 @@
/**************************************************************************
**
-** Copyright (C) 2020 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Installer Framework.
@@ -54,6 +54,7 @@ private:
bool initialize();
bool checkLicense();
bool setTargetDir();
+ QHash<QString, QString> parsePackageFilters();
QStringList m_positionalArguments;
};
diff --git a/tests/auto/installer/cliinterface/data/repository/Updates.xml b/tests/auto/installer/cliinterface/data/repository/Updates.xml
index e5bc4f8af..52707d09d 100644
--- a/tests/auto/installer/cliinterface/data/repository/Updates.xml
+++ b/tests/auto/installer/cliinterface/data/repository/Updates.xml
@@ -19,7 +19,7 @@
<Description>Example component B</Description>
<Version>1.0.0-1</Version>
<ReleaseDate>2015-01-01</ReleaseDate>
- <Default>true</Default>
+ <Default>false</Default>
<UpdateFile CompressedSize="222" OS="Any" UncompressedSize="72"/>
<DownloadableArchives>content.7z</DownloadableArchives>
<SHA1>9170d55a6af81c1a6a63d708a4ab6ed359775cd9</SHA1>
diff --git a/tests/auto/installer/cliinterface/tst_cliinterface.cpp b/tests/auto/installer/cliinterface/tst_cliinterface.cpp
index 98ea99133..d9497d53f 100644
--- a/tests/auto/installer/cliinterface/tst_cliinterface.cpp
+++ b/tests/auto/installer/cliinterface/tst_cliinterface.cpp
@@ -90,6 +90,24 @@ private slots:
"</availablepackages>\n");
core->listAvailablePackages(QLatin1String("^C"));
+ // Test with filters
+ QTest::ignoreMessage(QtDebugMsg, "<availablepackages>\n"
+ " <package name=\"AB\" displayname=\"AB\" version=\"1.0.2-1\"/>\n"
+ " <package name=\"A\" displayname=\"A\" version=\"1.0.2-1\"/>\n"
+ "</availablepackages>\n");
+ QHash<QString, QString> searchHash {
+ { "Version", "1.0.2" },
+ { "DisplayName", "A" }
+ };
+ core->listAvailablePackages(QString(), searchHash);
+
+ QTest::ignoreMessage(QtDebugMsg, "<availablepackages>\n"
+ " <package name=\"B\" displayname=\"B\" version=\"1.0.0-1\"/>\n"
+ "</availablepackages>\n");
+ searchHash.clear();
+ searchHash.insert("Default", "false");
+ core->listAvailablePackages(QString(), searchHash);
+
// Need to change rules here to catch messages
QLoggingCategory::setFilterRules("ifw.* = true\n");