From 478a8a1db3eed2c41d46da966003cc1722bd347d Mon Sep 17 00:00:00 2001 From: Karsten Heimrich Date: Wed, 6 May 2015 15:23:53 +0200 Subject: Remove pseudo static core instance, fixes autotests. We need the core engine in operations anyway, so pass the pointer to the create function instead of setting it on our own after the operation was created. The only reason to introduce the static was the ~UpdateOperation() destructor, which now can get the value from its internal data instead of using the static instance call. Change-Id: Ide27542837355ec8c642a6687ca02977983f84fa Reviewed-by: Jarek Kobus --- src/libs/installer/component.cpp | 9 ++++----- src/libs/installer/packagemanagercore.cpp | 13 ++----------- src/libs/installer/packagemanagercore.h | 6 ------ src/libs/installer/packagemanagercore_p.cpp | 10 +++------- src/libs/kdtools/kdupdaterupdateoperation.cpp | 4 ++-- src/libs/kdtools/kdupdaterupdateoperationfactory.cpp | 13 +++++++++++-- src/libs/kdtools/kdupdaterupdateoperationfactory.h | 7 ++++++- tools/devtool/operationrunner.cpp | 4 +--- 8 files changed, 29 insertions(+), 37 deletions(-) diff --git a/src/libs/installer/component.cpp b/src/libs/installer/component.cpp index 43ad5031e..090bfa501 100644 --- a/src/libs/installer/component.cpp +++ b/src/libs/installer/component.cpp @@ -901,15 +901,14 @@ OperationList Component::operations() const if (!d->m_minimumProgressOperation) { d->m_minimumProgressOperation = KDUpdater::UpdateOperationFactory::instance() - .create(QLatin1String("MinimumProgress")); + .create(QLatin1String("MinimumProgress"), d->m_core); d->m_minimumProgressOperation->setValue(QLatin1String("component"), name()); d->m_operations.append(d->m_minimumProgressOperation); } if (!d->m_licenses.isEmpty()) { d->m_licenseOperation = KDUpdater::UpdateOperationFactory::instance() - .create(QLatin1String("License")); - d->m_licenseOperation->setValue(QLatin1String("installer"), QVariant::fromValue(d->m_core)); + .create(QLatin1String("License"), d->m_core); d->m_licenseOperation->setValue(QLatin1String("component"), name()); QVariantMap licenses; @@ -983,7 +982,8 @@ Operation *Component::createOperation(const QString &operationName, const QStrin Operation *Component::createOperation(const QString &operationName, const QStringList ¶meters) { - Operation *operation = KDUpdater::UpdateOperationFactory::instance().create(operationName); + Operation *operation = KDUpdater::UpdateOperationFactory::instance().create(operationName, + d->m_core); if (operation == 0) { const QMessageBox::StandardButton button = MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(), @@ -996,7 +996,6 @@ Operation *Component::createOperation(const QString &operationName, const QStrin if (operation->name() == QLatin1String("Delete")) operation->setValue(QLatin1String("performUndo"), false); - operation->setValue(QLatin1String("installer"), qVariantFromValue(d->m_core)); operation->setArguments(d->m_core->replaceVariables(parameters)); operation->setValue(QLatin1String("component"), name()); diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp index a3a7aae97..7ab12d855 100644 --- a/src/libs/installer/packagemanagercore.cpp +++ b/src/libs/installer/packagemanagercore.cpp @@ -335,8 +335,6 @@ static bool sNoForceInstallation = false; static bool sVirtualComponentsVisible = false; static bool sCreateLocalRepositoryFromBinary = false; -PackageManagerCore *PackageManagerCore::m_instance = 0; - static bool componentMatches(const Component *component, const QString &name, const QString &version = QString()) { @@ -720,9 +718,6 @@ bool PackageManagerCore::fileExists(const QString &filePath) const PackageManagerCore::PackageManagerCore() : d(new PackageManagerCorePrivate(this)) { - Q_ASSERT_X(m_instance == 0, Q_FUNC_INFO, "PackageManagerCore called more then once."); - m_instance = this; - Repository::registerMetaType(); // register, cause we stream the type as QVariant qRegisterMetaType("QInstaller::PackageManagerCore::Status"); qRegisterMetaType("QInstaller::PackageManagerCore::WizardPage"); @@ -732,9 +727,6 @@ PackageManagerCore::PackageManagerCore(qint64 magicmaker, const QList("QInstaller::PackageManagerCore::Status"); qRegisterMetaType("QInstaller::PackageManagerCore::WizardPage"); @@ -783,7 +775,6 @@ PackageManagerCore::~PackageManagerCore() QInstaller::VerboseWriter::instance()->setFileName(logFileName); } delete d; - m_instance = 0; RemoteClient::instance().setActive(false); RemoteClient::instance().shutdown(); @@ -1681,7 +1672,7 @@ bool PackageManagerCore::operationExists(const QString &name) static QSet existingOperations; if (existingOperations.contains(name)) return true; - QScopedPointer op(KDUpdater::UpdateOperationFactory::instance().create(name)); + QScopedPointer op(KDUpdater::UpdateOperationFactory::instance().create(name, this)); if (!op.data()) return false; existingOperations.insert(name); @@ -1695,7 +1686,7 @@ bool PackageManagerCore::operationExists(const QString &name) */ bool PackageManagerCore::performOperation(const QString &name, const QStringList &arguments) { - QScopedPointer op(KDUpdater::UpdateOperationFactory::instance().create(name)); + QScopedPointer op(KDUpdater::UpdateOperationFactory::instance().create(name, this)); if (!op.data()) return false; diff --git a/src/libs/installer/packagemanagercore.h b/src/libs/installer/packagemanagercore.h index e768174bb..5160b0588 100644 --- a/src/libs/installer/packagemanagercore.h +++ b/src/libs/installer/packagemanagercore.h @@ -71,11 +71,6 @@ public: Protocol::Mode mode = Protocol::Mode::Production); ~PackageManagerCore(); - static PackageManagerCore *instance() { - Q_ASSERT_X(m_instance != 0, Q_FUNC_INFO, "PackageManagerCore call to instance before " - "constructor call."); return m_instance; - } - // status enum Status { Success = EXIT_SUCCESS, @@ -346,7 +341,6 @@ private: private: PackageManagerCorePrivate *const d; friend class PackageManagerCorePrivate; - static PackageManagerCore *m_instance; private: // remove once we deprecate isSelected, setSelected etc... diff --git a/src/libs/installer/packagemanagercore_p.cpp b/src/libs/installer/packagemanagercore_p.cpp index 0295454d6..7ef25a36c 100644 --- a/src/libs/installer/packagemanagercore_p.cpp +++ b/src/libs/installer/packagemanagercore_p.cpp @@ -233,7 +233,7 @@ PackageManagerCorePrivate::PackageManagerCorePrivate(PackageManagerCore *core, q { foreach (const OperationBlob &operation, performedOperations) { QScopedPointer op(KDUpdater::UpdateOperationFactory::instance() - .create(operation.name)); + .create(operation.name, core)); if (op.isNull()) { qWarning() << QString::fromLatin1("Failed to load unknown operation %1") .arg(operation.name); @@ -551,9 +551,6 @@ void PackageManagerCorePrivate::initialize(const QHash ¶ms } processFilesForDelayedDeletion(); - foreach (Operation *currentOperation, m_performedOperationsOld) - currentOperation->setValue(QLatin1String("installer"), QVariant::fromValue(m_core)); - disconnect(this, SIGNAL(installationStarted()), ProgressCoordinator::instance(), SLOT(reset())); connect(this, SIGNAL(installationStarted()), ProgressCoordinator::instance(), SLOT(reset())); disconnect(this, SIGNAL(uninstallationStarted()), ProgressCoordinator::instance(), SLOT(reset())); @@ -649,7 +646,7 @@ QByteArray PackageManagerCorePrivate::replaceVariables(const QByteArray &ba) con */ Operation *PackageManagerCorePrivate::createOwnedOperation(const QString &type) { - m_ownedOperations.append(KDUpdater::UpdateOperationFactory::instance().create(type)); + m_ownedOperations.append(KDUpdater::UpdateOperationFactory::instance().create(type, m_core)); return m_ownedOperations.last(); } @@ -1512,7 +1509,6 @@ bool PackageManagerCorePrivate::runInstaller() binaryFile = resourcePath.filePath(QLatin1String("installer.dat")); #endif createRepo->setValue(QLatin1String("uninstall-only"), true); - createRepo->setValue(QLatin1String("installer"), QVariant::fromValue(m_core)); createRepo->setArguments(QStringList() << binaryFile << target + QLatin1String("/repository")); @@ -1892,7 +1888,7 @@ void PackageManagerCorePrivate::installComponent(Component *component, double pr if (!component->stopProcessForUpdateRequests().isEmpty()) { Operation *stopProcessForUpdatesOp = KDUpdater::UpdateOperationFactory::instance() - .create(QLatin1String("FakeStopProcessForUpdate")); + .create(QLatin1String("FakeStopProcessForUpdate"), m_core); const QStringList arguments(component->stopProcessForUpdateRequests().join(QLatin1String(","))); stopProcessForUpdatesOp->setArguments(arguments); addPerformed(stopProcessForUpdatesOp); diff --git a/src/libs/kdtools/kdupdaterupdateoperation.cpp b/src/libs/kdtools/kdupdaterupdateoperation.cpp index 2807012d2..fed0f2cc9 100644 --- a/src/libs/kdtools/kdupdaterupdateoperation.cpp +++ b/src/libs/kdtools/kdupdaterupdateoperation.cpp @@ -99,8 +99,8 @@ UpdateOperation::UpdateOperation() UpdateOperation::~UpdateOperation() { using namespace QInstaller; - if (PackageManagerCore *app = PackageManagerCore::instance()) - app->addFilesForDelayedDeletion(filesForDelayedDeletion()); + if (auto *core = value(QLatin1String("installer")).value()) + core->addFilesForDelayedDeletion(filesForDelayedDeletion()); } /*! diff --git a/src/libs/kdtools/kdupdaterupdateoperationfactory.cpp b/src/libs/kdtools/kdupdaterupdateoperationfactory.cpp index f70134f36..2671a405d 100644 --- a/src/libs/kdtools/kdupdaterupdateoperationfactory.cpp +++ b/src/libs/kdtools/kdupdaterupdateoperationfactory.cpp @@ -33,11 +33,12 @@ ****************************************************************************/ #include "kdupdaterupdateoperationfactory.h" -#include "kdupdaterupdateoperations.h" -#include +#include "kdupdaterupdateoperations.h" +#include "packagemanagercore.h" using namespace KDUpdater; +using namespace QInstaller; /*! \inmodule kdupdater @@ -92,3 +93,11 @@ UpdateOperationFactory::UpdateOperationFactory() registerUpdateOperation(QLatin1String("AppendFile")); registerUpdateOperation(QLatin1String("PrependFile")); } + +UpdateOperation *UpdateOperationFactory::create(const QString &name, PackageManagerCore *core) const +{ + UpdateOperation *operation = KDGenericFactory::create(name); + if (operation) + operation->setValue(QLatin1String("installer"), QVariant::fromValue(core)); + return operation; +} diff --git a/src/libs/kdtools/kdupdaterupdateoperationfactory.h b/src/libs/kdtools/kdupdaterupdateoperationfactory.h index 394cc56e5..9fc5554a2 100644 --- a/src/libs/kdtools/kdupdaterupdateoperationfactory.h +++ b/src/libs/kdtools/kdupdaterupdateoperationfactory.h @@ -35,10 +35,14 @@ #ifndef KD_UPDATER_UPDATE_OPERATION_FACTORY_H #define KD_UPDATER_UPDATE_OPERATION_FACTORY_H -#include +#include "kdgenericfactory.h" #include "kdupdater.h" +namespace QInstaller { +class PackageManagerCore; +} + namespace KDUpdater { class UpdateOperation; @@ -55,6 +59,7 @@ public: { registerProduct(name); } + UpdateOperation *create(const QString &name, QInstaller::PackageManagerCore *core) const; protected: UpdateOperationFactory(); diff --git a/tools/devtool/operationrunner.cpp b/tools/devtool/operationrunner.cpp index 723d65cdf..8e232ef2e 100644 --- a/tools/devtool/operationrunner.cpp +++ b/tools/devtool/operationrunner.cpp @@ -60,7 +60,7 @@ int OperationRunner::runOperation(QStringList arguments, RunMode mode) try { const QString name = arguments.takeFirst(); QScopedPointer op(KDUpdater::UpdateOperationFactory::instance() - .create(name)); + .create(name, m_core)); if (!op) { std::cerr << "Cannot instantiate operation: " << qPrintable(name) << std::endl; return EXIT_FAILURE; @@ -72,8 +72,6 @@ int OperationRunner::runOperation(QStringList arguments, RunMode mode) connect(object, SIGNAL(outputTextChanged(QString)), this, SLOT(print(QString))); } op->setArguments(arguments); - op->setValue(QLatin1String("installer"), QVariant::fromValue(m_core)); - bool readyPerformed = false; if (mode == RunMode::Do) -- cgit v1.2.3