summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKatja Marttila <katja.marttila@qt.io>2020-03-12 15:07:09 +0200
committerKatja Marttila <katja.marttila@qt.io>2020-03-20 15:20:32 +0200
commit4d7c5d092e95f2eb2113780971027e0adfa41440 (patch)
tree4f1ef3c430ac5ea93c15afab3769221165b19a1c
parent559a6b4ed5b23fee084929f9f62fabe223294f49 (diff)
Separate maintenance tool writing for testing purpose
Some unit tests wont work as installer wants to unpack maintenance tool from the installer. As unit tests are not normal installers we need to separate the maintenance unpacking when running tests. Change-Id: I5f2bb60e775a42d1b8dd6ee088ff4f2a694a7a09 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
-rw-r--r--src/libs/installer/packagemanagercore.cpp64
-rw-r--r--src/libs/installer/packagemanagercore.h10
-rw-r--r--src/libs/installer/packagemanagercore_p.cpp24
-rw-r--r--src/libs/installer/packagemanagergui.cpp19
-rw-r--r--src/sdk/commandlineinterface.cpp45
5 files changed, 101 insertions, 61 deletions
diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp
index 4fba56978..085de5049 100644
--- a/src/libs/installer/packagemanagercore.cpp
+++ b/src/libs/installer/packagemanagercore.cpp
@@ -435,6 +435,7 @@ void PackageManagerCore::writeMaintenanceTool()
{
if (d->m_needToWriteMaintenanceTool) {
try {
+ emit titleMessageChanged(tr("Creating Maintenance Tool"));
d->writeMaintenanceTool(d->m_performedOperationsOld + d->m_performedOperationsCurrentSession);
bool gainedAdminRights = false;
@@ -446,6 +447,14 @@ void PackageManagerCore::writeMaintenanceTool()
if (gainedAdminRights)
dropAdminRights();
d->m_needToWriteMaintenanceTool = false;
+
+ // fake a possible wrong value to show a full progress bar
+ const int progress = ProgressCoordinator::instance()->progressInPercentage();
+ // usually this should be only the reserved one from the beginning
+ if (progress < 100)
+ ProgressCoordinator::instance()->addManualPercentagePoints(100 - progress);
+ ProgressCoordinator::instance()->emitLabelAndDetailTextChanged(tr("\nInstallation finished!"));
+ d->setStatus(PackageManagerCore::Success);
} catch (const Error &error) {
qCritical() << "Error writing Maintenance Tool: " << error.message();
MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(),
@@ -2105,10 +2114,16 @@ void PackageManagerCore::listInstalledPackages()
}
}
-void PackageManagerCore::updateComponentsSilently(const QStringList &componentsToUpdate)
+/*!
+ Updates the selected components \a componentsToUpdate without GUI.
+ If essential components are found, then only those will be updated.
+ Returns \c true if components are updated and the maintenance tool needs
+ to be written, otherwise returns \c false.
+*/
+bool PackageManagerCore::updateComponentsSilently(const QStringList &componentsToUpdate)
{
if (d->runningProcessesFound())
- return;
+ throw Error(tr("Running processes found."));
setUpdater();
autoRejectMessageBoxes();
@@ -2118,6 +2133,7 @@ void PackageManagerCore::updateComponentsSilently(const QStringList &componentsT
if (componentList.count() == 0) {
qCDebug(QInstaller::lcInstallerInstallLog) << "No updates available.";
+ return false;
} else {
// Check if essential components are available (essential components are disabled).
// If essential components are found, update first essential updates,
@@ -2151,12 +2167,18 @@ void PackageManagerCore::updateComponentsSilently(const QStringList &componentsT
qCDebug(QInstaller::lcInstallerInstallLog) << "Components updated successfully.";
}
}
+ return true;
}
-void PackageManagerCore::uninstallComponentsSilently(const QStringList& components)
+/*!
+ Uninstalls the selected components \a components without GUI.
+ Returns \c true if components are uninstalled and the maintenance tool
+ needs to be written, otherwise returns \c false.
+*/
+bool PackageManagerCore::uninstallComponentsSilently(const QStringList& components)
{
if (d->runningProcessesFound())
- return;
+ throw Error(tr("Running processes found."));
autoRejectMessageBoxes();
ComponentModel *model = defaultComponentModel();
@@ -2179,22 +2201,27 @@ void PackageManagerCore::uninstallComponentsSilently(const QStringList& componen
}
if (uninstallComponentFound) {
- if (d->calculateComponentsAndRun())
+ if (d->calculateComponentsAndRun()) {
qCDebug(QInstaller::lcInstallerUninstallLog) << "Components uninstalled successfully";
+ return true;
+ }
}
+ return false;
}
/*!
- Installs selected components \a components without user interface. Virtual components
- cannot be installed unless made visible with --show-virtual-components. AutoDependOn
- nor non-checkable components cannot be installed directly.
+ Installs the selected components \a components without displaying a user
+ interface. Virtual components cannot be installed unless made visible with
+ --show-virtual-components. AutoDependOn nor non-checkable components cannot
+ be installed directly. Returns \c true if components are installed and the
+ maintenance tool needs to be written, otherwise returns \c false.
*/
-void PackageManagerCore::installSelectedComponentsSilently(const QStringList& components)
+bool PackageManagerCore::installSelectedComponentsSilently(const QStringList& components)
{
// Check if there are processes running in the install if maintenancetool is in used.
if (!isInstaller()) {
if (d->runningProcessesFound())
- return;
+ throw Error(tr("Running processes found."));
setPackageManager();
}
@@ -2227,27 +2254,36 @@ void PackageManagerCore::installSelectedComponentsSilently(const QStringList& co
}
}
if (installComponentsFound) {
- if (d->calculateComponentsAndRun())
+ if (d->calculateComponentsAndRun()) {
qCDebug(QInstaller::lcInstallerInstallLog) << "Components installed successfully";
+ return true;
+ }
}
+ return false;
}
/*!
Installs components that are checked by default, i.e. those that are set
- with <Default> or <ForcedInstallation> and their respective dependencies.
+ with <Default> or <ForcedInstallation> and their respective dependencies
+ without GUI.
+ Returns \c true if default components are found and the maintenance tool
+ needs to be written, otherwise returns \c false.
*/
-void PackageManagerCore::installDefaultComponentsSilently()
+bool PackageManagerCore::installDefaultComponentsSilently()
{
ComponentModel *model = defaultComponentModel();
fetchRemotePackagesTree();
if (!(model->checkedState() & ComponentModel::AllUnchecked)) {
// There are components that are checked by default, we should install them
- if (d->calculateComponentsAndRun())
+ if (d->calculateComponentsAndRun()) {
qCDebug(QInstaller::lcInstallerInstallLog) << "Components installed successfully.";
+ return true;
+ }
} else {
qCDebug(QInstaller::lcInstallerInstallLog) << "No components available for default installation.";
}
+ return false;
}
/*!
diff --git a/src/libs/installer/packagemanagercore.h b/src/libs/installer/packagemanagercore.h
index 76a0a7341..75bdfb863 100644
--- a/src/libs/installer/packagemanagercore.h
+++ b/src/libs/installer/packagemanagercore.h
@@ -1,6 +1,6 @@
/**************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Installer Framework.
@@ -217,10 +217,10 @@ public:
ComponentModel *updaterComponentModel() const;
void listInstalledPackages();
void listAvailablePackages(const QString &regexp);
- void updateComponentsSilently(const QStringList &componentsToUpdate);
- void installSelectedComponentsSilently(const QStringList& components);
- void installDefaultComponentsSilently();
- void uninstallComponentsSilently(const QStringList& components);
+ bool updateComponentsSilently(const QStringList &componentsToUpdate);
+ bool installSelectedComponentsSilently(const QStringList& components);
+ bool installDefaultComponentsSilently();
+ bool uninstallComponentsSilently(const QStringList& components);
// convenience
Q_INVOKABLE bool isInstaller() const;
diff --git a/src/libs/installer/packagemanagercore_p.cpp b/src/libs/installer/packagemanagercore_p.cpp
index 190d297f0..fa434f289 100644
--- a/src/libs/installer/packagemanagercore_p.cpp
+++ b/src/libs/installer/packagemanagercore_p.cpp
@@ -1,6 +1,6 @@
/**************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Installer Framework.
@@ -1596,22 +1596,7 @@ bool PackageManagerCorePrivate::runInstaller()
}
}
}
-
- emit m_core->titleMessageChanged(tr("Creating Maintenance Tool"));
-
- writeMaintenanceTool(m_performedOperationsOld + m_performedOperationsCurrentSession);
-
- // fake a possible wrong value to show a full progress bar
- const int progress = ProgressCoordinator::instance()->progressInPercentage();
- // usually this should be only the reserved one from the beginning
- if (progress < 100)
- ProgressCoordinator::instance()->addManualPercentagePoints(100 - progress);
- ProgressCoordinator::instance()->emitLabelAndDetailTextChanged(tr("\nInstallation finished!"));
-
- if (adminRightsGained)
- m_core->dropAdminRights();
- setStatus(PackageManagerCore::Success);
- emit installationFinished();
+ m_needToWriteMaintenanceTool = true;
} catch (const Error &err) {
if (m_core->status() != PackageManagerCore::Canceled) {
setStatus(PackageManagerCore::Failure);
@@ -2518,10 +2503,7 @@ bool PackageManagerCorePrivate::calculateComponentsAndRun()
bool componentsOk = m_core->calculateComponents(&htmlOutput);
qCDebug(QInstaller::lcInstallerInstallLog).noquote() << htmlToString(htmlOutput);
if (componentsOk) {
- if (m_core->run()) {
- m_core->writeMaintenanceTool();
- return true;
- }
+ return m_core->run();
}
return false;
}
diff --git a/src/libs/installer/packagemanagergui.cpp b/src/libs/installer/packagemanagergui.cpp
index 793519416..771b2720c 100644
--- a/src/libs/installer/packagemanagergui.cpp
+++ b/src/libs/installer/packagemanagergui.cpp
@@ -1,6 +1,6 @@
/**************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Installer Framework.
@@ -2519,6 +2519,12 @@ void PerformInstallationPage::entering()
{
setComplete(false);
+ m_performInstallationForm->enableDetails();
+ emit setAutomatedPageSwitchEnabled(true);
+
+ if (isVerbose()) {
+ m_performInstallationForm->toggleDetails();
+ }
if (packageManagerCore()->isUninstaller()) {
setButtonText(QWizard::CommitButton, tr("U&ninstall"));
setColoredTitle(tr("Uninstalling %1").arg(productName()));
@@ -2533,14 +2539,11 @@ void PerformInstallationPage::entering()
setButtonText(QWizard::CommitButton, tr("&Install"));
setColoredTitle(tr("Installing %1").arg(productName()));
- QTimer::singleShot(30, packageManagerCore(), SLOT(runInstaller()));
+ if (packageManagerCore()->runInstaller()) {
+ packageManagerCore()->writeMaintenanceTool();
+ emit packageManagerCore()->installationFinished();
+ }
}
-
- m_performInstallationForm->enableDetails();
- emit setAutomatedPageSwitchEnabled(true);
-
- if (isVerbose())
- m_performInstallationForm->toggleDetails();
}
/*!
diff --git a/src/sdk/commandlineinterface.cpp b/src/sdk/commandlineinterface.cpp
index 17e7be6e5..de9332b35 100644
--- a/src/sdk/commandlineinterface.cpp
+++ b/src/sdk/commandlineinterface.cpp
@@ -33,6 +33,7 @@
#include <packagemanagercore.h>
#include <globals.h>
#include <productkeycheck.h>
+#include <errors.h>
#include <QDir>
#include <QDomDocument>
@@ -139,26 +140,38 @@ int CommandLineInterface::updatePackages()
}
if (!checkLicense())
return EXIT_FAILURE;
- m_core->updateComponentsSilently(m_positionalArguments);
- return EXIT_SUCCESS;
+ try {
+ if (m_core->updateComponentsSilently(m_positionalArguments))
+ m_core->writeMaintenanceTool();
+ return EXIT_SUCCESS;
+ } catch (const QInstaller::Error &err) {
+ qCCritical(QInstaller::lcInstallerInstallLog) << err.message();
+ return EXIT_FAILURE;
+ }
}
int CommandLineInterface::installPackages()
{
if (!initialize() || (m_core->isInstaller() && !setTargetDir()) || !checkLicense())
return EXIT_FAILURE;
- if (m_positionalArguments.isEmpty()) {
- if (!m_core->isInstaller()) {
- qCWarning(QInstaller::lcInstallerInstallLog)
- << "Cannot perform default installation with maintenance tool.";
- return EXIT_FAILURE;
+ try {
+ if (m_positionalArguments.isEmpty()) {
+ if (!m_core->isInstaller()) {
+ qCWarning(QInstaller::lcInstallerInstallLog)
+ << "Cannot perform default installation with maintenance tool.";
+ return EXIT_FAILURE;
+ }
+ // No packages provided, install default components
+ if (m_core->installDefaultComponentsSilently())
+ m_core->writeMaintenanceTool();
+ } else if (m_core->installSelectedComponentsSilently(m_positionalArguments)) {
+ m_core->writeMaintenanceTool();
}
- // No packages provided, install default components
- m_core->installDefaultComponentsSilently();
return EXIT_SUCCESS;
+ } catch (const QInstaller::Error &err) {
+ qCCritical(QInstaller::lcInstallerInstallLog) << err.message();
+ return EXIT_FAILURE;
}
- m_core->installSelectedComponentsSilently(m_positionalArguments);
- return EXIT_SUCCESS;
}
int CommandLineInterface::uninstallPackages()
@@ -170,8 +183,14 @@ int CommandLineInterface::uninstallPackages()
return EXIT_FAILURE;
}
m_core->setPackageManager();
- m_core->uninstallComponentsSilently(m_positionalArguments);
- return EXIT_SUCCESS;
+ try {
+ if (m_core->uninstallComponentsSilently(m_positionalArguments))
+ m_core->writeMaintenanceTool();
+ return EXIT_SUCCESS;
+ } catch (const QInstaller::Error &err) {
+ qCCritical(QInstaller::lcInstallerInstallLog) << err.message();
+ return EXIT_FAILURE;
+ }
}
bool CommandLineInterface::checkLicense()