From 2d0b2fd464089656429bd20bc477859b9d85e4b1 Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 22 Mar 2023 10:05:26 +0100 Subject: [PATCH] RemoteLinux: simplify AbstractRemoteLinuxDeployStep interface Effectively inline four functions that are used only once. Change-Id: I2cc96205e457a16a1f68f2bcda1cdf4945cec93e Reviewed-by: Reviewed-by: Marcus Tillmanns --- .../abstractremotelinuxdeploystep.cpp | 126 ++++++++---------- .../abstractremotelinuxdeploystep.h | 5 - 2 files changed, 54 insertions(+), 77 deletions(-) diff --git a/src/plugins/remotelinux/abstractremotelinuxdeploystep.cpp b/src/plugins/remotelinux/abstractremotelinuxdeploystep.cpp index e5b6415f348..60982c32872 100644 --- a/src/plugins/remotelinux/abstractremotelinuxdeploystep.cpp +++ b/src/plugins/remotelinux/abstractremotelinuxdeploystep.cpp @@ -71,8 +71,56 @@ bool AbstractRemoteLinuxDeployStep::hasRemoteFileChanged( return d->deployTimes.hasRemoteFileChanged(deployableFile, kit(), remoteTimestamp); } -void AbstractRemoteLinuxDeployStep::start() +CheckResult AbstractRemoteLinuxDeployStep::isDeploymentPossible() const { + if (!deviceConfiguration()) + return CheckResult::failure(Tr::tr("No device configuration set.")); + return CheckResult::success(); +} + +void AbstractRemoteLinuxDeployStep::setInternalInitializer(const std::function &init) +{ + d->internalInit = init; +} + +void AbstractRemoteLinuxDeployStep::setRunPreparer(const std::function &prep) +{ + d->runPreparer = prep; +} + +bool AbstractRemoteLinuxDeployStep::fromMap(const QVariantMap &map) +{ + if (!BuildStep::fromMap(map)) + return false; + d->deployTimes.importDeployTimes(map); + return true; +} + +QVariantMap AbstractRemoteLinuxDeployStep::toMap() const +{ + QVariantMap map = BuildStep::toMap(); + map.insert(d->deployTimes.exportDeployTimes()); + return map; +} + +bool AbstractRemoteLinuxDeployStep::init() +{ + QTC_ASSERT(d->internalInit, return false); + const CheckResult canDeploy = d->internalInit(); + if (!canDeploy) { + emit addOutput(Tr::tr("Cannot deploy: %1").arg(canDeploy.errorMessage()), + OutputFormat::ErrorMessage); + } + return canDeploy; +} + +void AbstractRemoteLinuxDeployStep::doRun() +{ + if (d->runPreparer) + d->runPreparer(); + + d->hasError = false; + QTC_ASSERT(!d->m_taskTree, return); const CheckResult check = isDeploymentPossible(); @@ -98,76 +146,6 @@ void AbstractRemoteLinuxDeployStep::start() d->m_taskTree->start(); } -void AbstractRemoteLinuxDeployStep::stop() -{ - if (!d->m_taskTree) - return; - d->m_taskTree.reset(); - handleFinished(); -} - -CheckResult AbstractRemoteLinuxDeployStep::isDeploymentPossible() const -{ - if (!deviceConfiguration()) - return CheckResult::failure(Tr::tr("No device configuration set.")); - return CheckResult::success(); -} - -QVariantMap AbstractRemoteLinuxDeployStep::exportDeployTimes() const -{ - return d->deployTimes.exportDeployTimes(); -} - -void AbstractRemoteLinuxDeployStep::importDeployTimes(const QVariantMap &map) -{ - d->deployTimes.importDeployTimes(map); -} - -void AbstractRemoteLinuxDeployStep::setInternalInitializer(const std::function &init) -{ - d->internalInit = init; -} - -void AbstractRemoteLinuxDeployStep::setRunPreparer(const std::function &prep) -{ - d->runPreparer = prep; -} - -bool AbstractRemoteLinuxDeployStep::fromMap(const QVariantMap &map) -{ - if (!BuildStep::fromMap(map)) - return false; - importDeployTimes(map); - return true; -} - -QVariantMap AbstractRemoteLinuxDeployStep::toMap() const -{ - QVariantMap map = BuildStep::toMap(); - map.insert(exportDeployTimes()); - return map; -} - -bool AbstractRemoteLinuxDeployStep::init() -{ - QTC_ASSERT(d->internalInit, return false); - const CheckResult canDeploy = d->internalInit(); - if (!canDeploy) { - emit addOutput(Tr::tr("Cannot deploy: %1").arg(canDeploy.errorMessage()), - OutputFormat::ErrorMessage); - } - return canDeploy; -} - -void AbstractRemoteLinuxDeployStep::doRun() -{ - if (d->runPreparer) - d->runPreparer(); - - d->hasError = false; - start(); -} - void AbstractRemoteLinuxDeployStep::doCancel() { if (d->hasError) @@ -176,7 +154,11 @@ void AbstractRemoteLinuxDeployStep::doCancel() emit addOutput(Tr::tr("User requests deployment to stop; cleaning up."), OutputFormat::NormalMessage); d->hasError = true; - stop(); + + if (!d->m_taskTree) + return; + d->m_taskTree.reset(); + handleFinished(); } void AbstractRemoteLinuxDeployStep::addProgressMessage(const QString &message) diff --git a/src/plugins/remotelinux/abstractremotelinuxdeploystep.h b/src/plugins/remotelinux/abstractremotelinuxdeploystep.h index 8131a997d0a..a0db68664ab 100644 --- a/src/plugins/remotelinux/abstractremotelinuxdeploystep.h +++ b/src/plugins/remotelinux/abstractremotelinuxdeploystep.h @@ -49,11 +49,6 @@ public: explicit AbstractRemoteLinuxDeployStep(ProjectExplorer::BuildStepList *bsl, Utils::Id id); ~AbstractRemoteLinuxDeployStep() override; - void start(); - void stop(); - - QVariantMap exportDeployTimes() const; - void importDeployTimes(const QVariantMap &map); ProjectExplorer::IDeviceConstPtr deviceConfiguration() const; virtual CheckResult isDeploymentPossible() const;