forked from qt-creator/qt-creator
AbstractRemoteLinuxDeployService: Refactor API
Instead of implementing two virtual methods: - doDeploy - stopDeployment provide just one to be implemented: - deployRecipe The new method returns task tree description enclosed in Group recipe. The abstract deploy service constructs the TaskTree when needed, applies the recipe and starts the tree. Change-Id: I36e52935f98736dafeea6be32fde5595410db077 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -34,10 +34,8 @@ public:
|
||||
private:
|
||||
bool isDeploymentNecessary() const final { return true; }
|
||||
|
||||
void doDeploy() final
|
||||
Group deployRecipe() final
|
||||
{
|
||||
QTC_ASSERT(!m_taskTree, return);
|
||||
|
||||
const auto setupHandler = [this](QtcProcess &process) {
|
||||
QString remoteExe;
|
||||
if (RunConfiguration *rc = target()->activeRunConfiguration()) {
|
||||
@@ -63,27 +61,10 @@ private:
|
||||
const auto errorHandler = [this](const QtcProcess &process) {
|
||||
emit errorMessage(tr("Remote process failed: %1").arg(process.errorString()));
|
||||
};
|
||||
const auto endHandler = [this] {
|
||||
m_taskTree.release()->deleteLater();
|
||||
stopDeployment();
|
||||
};
|
||||
const Group root {
|
||||
Process(setupHandler, doneHandler, errorHandler),
|
||||
OnGroupDone(endHandler),
|
||||
OnGroupError(endHandler)
|
||||
};
|
||||
m_taskTree.reset(new TaskTree(root));
|
||||
m_taskTree->start();
|
||||
}
|
||||
|
||||
void stopDeployment() final
|
||||
{
|
||||
m_taskTree.reset();
|
||||
handleDeploymentDone();
|
||||
return Group { Process(setupHandler, doneHandler, errorHandler) };
|
||||
}
|
||||
|
||||
bool m_makeDefault = true;
|
||||
std::unique_ptr<TaskTree> m_taskTree;
|
||||
};
|
||||
|
||||
// QdbMakeDefaultAppStep
|
||||
|
@@ -30,16 +30,11 @@ class QdbStopApplicationService : public RemoteLinux::AbstractRemoteLinuxDeployS
|
||||
|
||||
private:
|
||||
bool isDeploymentNecessary() const final { return true; }
|
||||
void doDeploy() final;
|
||||
void stopDeployment() final;
|
||||
|
||||
std::unique_ptr<TaskTree> m_taskTree;
|
||||
Group deployRecipe() final;
|
||||
};
|
||||
|
||||
void QdbStopApplicationService::doDeploy()
|
||||
Group QdbStopApplicationService::deployRecipe()
|
||||
{
|
||||
QTC_ASSERT(!m_taskTree, return);
|
||||
|
||||
const auto setupHandler = [this](QtcProcess &process) {
|
||||
const auto device = DeviceKitAspect::device(target()->kit());
|
||||
QTC_CHECK(device);
|
||||
@@ -75,24 +70,11 @@ void QdbStopApplicationService::doDeploy()
|
||||
}
|
||||
return GroupConfig();
|
||||
};
|
||||
const auto rootEndHandler = [this] {
|
||||
m_taskTree.release()->deleteLater();
|
||||
stopDeployment();
|
||||
};
|
||||
const Group root {
|
||||
DynamicSetup(rootSetupHandler),
|
||||
Process(setupHandler, doneHandler, errorHandler),
|
||||
OnGroupDone(rootEndHandler),
|
||||
OnGroupError(rootEndHandler)
|
||||
Process(setupHandler, doneHandler, errorHandler)
|
||||
};
|
||||
m_taskTree.reset(new TaskTree(root));
|
||||
m_taskTree->start();
|
||||
}
|
||||
|
||||
void QdbStopApplicationService::stopDeployment()
|
||||
{
|
||||
m_taskTree.reset();
|
||||
handleDeploymentDone();
|
||||
return root;
|
||||
}
|
||||
|
||||
// QdbStopApplicationStep
|
||||
|
@@ -12,12 +12,13 @@
|
||||
#include <projectexplorer/target.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/tasktree.h>
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QFileInfo>
|
||||
#include <QPointer>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
|
||||
namespace RemoteLinux {
|
||||
namespace Internal {
|
||||
@@ -34,6 +35,7 @@ public:
|
||||
|
||||
DeploymentTimeInfo deployTimes;
|
||||
State state = Inactive;
|
||||
std::unique_ptr<TaskTree> m_taskTree;
|
||||
};
|
||||
} // namespace Internal
|
||||
|
||||
@@ -146,4 +148,23 @@ void AbstractRemoteLinuxDeployService::handleDeploymentDone()
|
||||
emit finished();
|
||||
}
|
||||
|
||||
void AbstractRemoteLinuxDeployService::doDeploy()
|
||||
{
|
||||
QTC_ASSERT(!d->m_taskTree, return);
|
||||
d->m_taskTree.reset(new TaskTree(deployRecipe()));
|
||||
const auto endHandler = [this] {
|
||||
d->m_taskTree.release()->deleteLater();
|
||||
handleDeploymentDone();
|
||||
};
|
||||
connect(d->m_taskTree.get(), &TaskTree::done, this, endHandler);
|
||||
connect(d->m_taskTree.get(), &TaskTree::errorOccurred, this, endHandler);
|
||||
d->m_taskTree->start();
|
||||
}
|
||||
|
||||
void AbstractRemoteLinuxDeployService::stopDeployment()
|
||||
{
|
||||
d->m_taskTree.reset();
|
||||
handleDeploymentDone();
|
||||
}
|
||||
|
||||
} // namespace RemoteLinux
|
||||
|
@@ -16,6 +16,8 @@ class Kit;
|
||||
class Target;
|
||||
}
|
||||
|
||||
namespace Utils::Tasking { class Group; }
|
||||
|
||||
namespace RemoteLinux {
|
||||
namespace Internal { class AbstractRemoteLinuxDeployServicePrivate; }
|
||||
|
||||
@@ -77,8 +79,9 @@ protected:
|
||||
|
||||
private:
|
||||
virtual bool isDeploymentNecessary() const = 0;
|
||||
virtual void doDeploy() = 0;
|
||||
virtual void stopDeployment() = 0;
|
||||
virtual Utils::Tasking::Group deployRecipe() = 0;
|
||||
void doDeploy();
|
||||
void stopDeployment();
|
||||
|
||||
Internal::AbstractRemoteLinuxDeployServicePrivate * const d;
|
||||
};
|
||||
|
@@ -24,17 +24,15 @@ class CustomCommandDeployService : public AbstractRemoteLinuxDeployService
|
||||
{
|
||||
public:
|
||||
void setCommandLine(const QString &commandLine);
|
||||
CheckResult isDeploymentPossible() const override;
|
||||
CheckResult isDeploymentPossible() const final;
|
||||
|
||||
protected:
|
||||
void doDeploy() override;
|
||||
void stopDeployment() override;
|
||||
Group deployRecipe() final;
|
||||
|
||||
private:
|
||||
bool isDeploymentNecessary() const override { return true; }
|
||||
bool isDeploymentNecessary() const final { return true; }
|
||||
|
||||
QString m_commandLine;
|
||||
std::unique_ptr<TaskTree> m_taskTree;
|
||||
};
|
||||
|
||||
void CustomCommandDeployService::setCommandLine(const QString &commandLine)
|
||||
@@ -50,10 +48,8 @@ CheckResult CustomCommandDeployService::isDeploymentPossible() const
|
||||
return AbstractRemoteLinuxDeployService::isDeploymentPossible();
|
||||
}
|
||||
|
||||
void CustomCommandDeployService::doDeploy()
|
||||
Group CustomCommandDeployService::deployRecipe()
|
||||
{
|
||||
QTC_ASSERT(!m_taskTree, return);
|
||||
|
||||
const auto setupHandler = [this](QtcProcess &process) {
|
||||
emit progressMessage(Tr::tr("Starting remote command \"%1\"...").arg(m_commandLine));
|
||||
process.setCommand({deviceConfiguration()->filePath("/bin/sh"),
|
||||
@@ -78,23 +74,7 @@ void CustomCommandDeployService::doDeploy()
|
||||
.arg(process.exitCode()));
|
||||
}
|
||||
};
|
||||
const auto endHandler = [this] {
|
||||
m_taskTree.release()->deleteLater();
|
||||
stopDeployment();
|
||||
};
|
||||
const Group root {
|
||||
Process(setupHandler, doneHandler, errorHandler),
|
||||
OnGroupDone(endHandler),
|
||||
OnGroupError(endHandler)
|
||||
};
|
||||
m_taskTree.reset(new TaskTree(root));
|
||||
m_taskTree->start();
|
||||
}
|
||||
|
||||
void CustomCommandDeployService::stopDeployment()
|
||||
{
|
||||
m_taskTree.reset();
|
||||
handleDeploymentDone();
|
||||
return Group { Process(setupHandler, doneHandler, errorHandler) };
|
||||
}
|
||||
|
||||
class CustomCommandDeployStep : public AbstractRemoteLinuxDeployStep
|
||||
|
@@ -16,7 +16,6 @@
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDir>
|
||||
#include <QList>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
@@ -55,7 +54,6 @@ public:
|
||||
IncrementalDeployment incremental = IncrementalDeployment::NotSupported;
|
||||
bool ignoreMissingFiles = false;
|
||||
QList<DeployableFile> deployableFiles;
|
||||
std::unique_ptr<TaskTree> m_taskTree;
|
||||
};
|
||||
|
||||
QList<DeployableFile> collectFilesToUpload(const DeployableFile &deployable)
|
||||
@@ -125,12 +123,6 @@ bool GenericDirectUploadService::isDeploymentNecessary() const
|
||||
return !d->deployableFiles.isEmpty();
|
||||
}
|
||||
|
||||
void GenericDirectUploadService::stopDeployment()
|
||||
{
|
||||
d->m_taskTree.reset();
|
||||
handleDeploymentDone();
|
||||
}
|
||||
|
||||
QDateTime GenericDirectUploadServicePrivate::timestampFromStat(const DeployableFile &file,
|
||||
QtcProcess *statProc)
|
||||
{
|
||||
@@ -291,19 +283,8 @@ TaskItem GenericDirectUploadServicePrivate::chmodTree(const TreeStorage<UploadSt
|
||||
return Tree {setupChmodHandler};
|
||||
}
|
||||
|
||||
void GenericDirectUploadService::doDeploy()
|
||||
Group GenericDirectUploadService::deployRecipe()
|
||||
{
|
||||
QTC_ASSERT(!d->m_taskTree, return);
|
||||
|
||||
const auto endHandler = [this] {
|
||||
d->m_taskTree.release()->deleteLater();
|
||||
stopDeployment();
|
||||
};
|
||||
const auto doneHandler = [this, endHandler] {
|
||||
emit progressMessage(Tr::tr("All files successfully deployed."));
|
||||
endHandler();
|
||||
};
|
||||
|
||||
const auto preFilesToStat = [this](UploadStorage *storage) {
|
||||
QList<DeployableFile> filesToStat;
|
||||
for (const DeployableFile &file : std::as_const(d->deployableFiles)) {
|
||||
@@ -333,6 +314,9 @@ void GenericDirectUploadService::doDeploy()
|
||||
if (timestamp.isValid())
|
||||
saveDeploymentTimeStamp(file, timestamp);
|
||||
};
|
||||
const auto doneHandler = [this] {
|
||||
emit progressMessage(Tr::tr("All files successfully deployed."));
|
||||
};
|
||||
|
||||
const TreeStorage<UploadStorage> storage;
|
||||
const Group root {
|
||||
@@ -343,12 +327,9 @@ void GenericDirectUploadService::doDeploy()
|
||||
d->chmodTree(storage),
|
||||
d->statTree(storage, postFilesToStat, postStatEndHandler)
|
||||
},
|
||||
OnGroupDone(doneHandler),
|
||||
OnGroupError(endHandler)
|
||||
OnGroupDone(doneHandler)
|
||||
};
|
||||
|
||||
d->m_taskTree.reset(new TaskTree(root));
|
||||
d->m_taskTree->start();
|
||||
return root;
|
||||
}
|
||||
|
||||
} //namespace RemoteLinux
|
||||
|
@@ -21,18 +21,16 @@ class REMOTELINUX_EXPORT GenericDirectUploadService : public AbstractRemoteLinux
|
||||
Q_OBJECT
|
||||
public:
|
||||
GenericDirectUploadService(QObject *parent = nullptr);
|
||||
~GenericDirectUploadService() override;
|
||||
~GenericDirectUploadService();
|
||||
|
||||
void setDeployableFiles(const QList<ProjectExplorer::DeployableFile> &deployableFiles);
|
||||
void setIncrementalDeployment(IncrementalDeployment incremental);
|
||||
void setIgnoreMissingFiles(bool ignoreMissingFiles);
|
||||
|
||||
protected:
|
||||
bool isDeploymentNecessary() const override;
|
||||
void doDeploy() override;
|
||||
void stopDeployment() override;
|
||||
|
||||
private:
|
||||
bool isDeploymentNecessary() const final;
|
||||
Utils::Tasking::Group deployRecipe() final;
|
||||
|
||||
friend class Internal::GenericDirectUploadServicePrivate;
|
||||
Internal::GenericDirectUploadServicePrivate * const d;
|
||||
};
|
||||
|
@@ -27,19 +27,14 @@ public:
|
||||
void setRemoteExecutable(const FilePath &filePath) { m_remoteExecutable = filePath; }
|
||||
|
||||
private:
|
||||
bool isDeploymentNecessary() const override { return !m_remoteExecutable.isEmpty(); }
|
||||
|
||||
void doDeploy() override;
|
||||
void stopDeployment() override;
|
||||
bool isDeploymentNecessary() const final { return !m_remoteExecutable.isEmpty(); }
|
||||
Group deployRecipe() final;
|
||||
|
||||
FilePath m_remoteExecutable;
|
||||
std::unique_ptr<TaskTree> m_taskTree;
|
||||
};
|
||||
|
||||
void KillAppService::doDeploy()
|
||||
Group KillAppService::deployRecipe()
|
||||
{
|
||||
QTC_ASSERT(!m_taskTree, return);
|
||||
|
||||
const auto setupHandler = [this](DeviceProcessKiller &killer) {
|
||||
killer.setProcessPath(m_remoteExecutable);
|
||||
emit progressMessage(Tr::tr("Trying to kill \"%1\" on remote device...")
|
||||
@@ -52,25 +47,7 @@ void KillAppService::doDeploy()
|
||||
emit progressMessage(Tr::tr("Failed to kill remote application. "
|
||||
"Assuming it was not running."));
|
||||
};
|
||||
|
||||
const auto endHandler = [this] {
|
||||
m_taskTree.release()->deleteLater();
|
||||
stopDeployment();
|
||||
};
|
||||
|
||||
const Group root {
|
||||
Killer(setupHandler, doneHandler, errorHandler),
|
||||
OnGroupDone(endHandler),
|
||||
OnGroupError(endHandler)
|
||||
};
|
||||
m_taskTree.reset(new TaskTree(root));
|
||||
m_taskTree->start();
|
||||
}
|
||||
|
||||
void KillAppService::stopDeployment()
|
||||
{
|
||||
m_taskTree.reset();
|
||||
handleDeploymentDone();
|
||||
return Group { Killer(setupHandler, doneHandler, errorHandler) };
|
||||
}
|
||||
|
||||
class KillAppStep : public AbstractRemoteLinuxDeployStep
|
||||
|
@@ -35,16 +35,14 @@ public:
|
||||
void setFlags(const QString &flags) { m_flags = flags; }
|
||||
|
||||
private:
|
||||
bool isDeploymentNecessary() const override;
|
||||
void doDeploy() override;
|
||||
void stopDeployment() override;
|
||||
bool isDeploymentNecessary() const final;
|
||||
Group deployRecipe() final;
|
||||
TaskItem mkdirTask();
|
||||
TaskItem transferTask();
|
||||
|
||||
mutable FilesToTransfer m_files;
|
||||
bool m_ignoreMissingFiles = false;
|
||||
QString m_flags;
|
||||
std::unique_ptr<TaskTree> m_taskTree;
|
||||
};
|
||||
|
||||
void RsyncDeployService::setDeployableFiles(const QList<DeployableFile> &files)
|
||||
@@ -110,28 +108,9 @@ TaskItem RsyncDeployService::transferTask()
|
||||
return Transfer(setupHandler, {}, errorHandler);
|
||||
}
|
||||
|
||||
void RsyncDeployService::doDeploy()
|
||||
Group RsyncDeployService::deployRecipe()
|
||||
{
|
||||
const auto finishHandler = [this] {
|
||||
m_taskTree.release()->deleteLater();
|
||||
stopDeployment();
|
||||
};
|
||||
|
||||
const Group root {
|
||||
mkdirTask(),
|
||||
transferTask(),
|
||||
OnGroupDone(finishHandler),
|
||||
OnGroupError(finishHandler),
|
||||
};
|
||||
|
||||
m_taskTree.reset(new TaskTree(root));
|
||||
m_taskTree->start();
|
||||
}
|
||||
|
||||
void RsyncDeployService::stopDeployment()
|
||||
{
|
||||
m_taskTree.reset();
|
||||
handleDeploymentDone();
|
||||
return Group { mkdirTask(), transferTask() };
|
||||
}
|
||||
|
||||
// RsyncDeployStep
|
||||
|
@@ -16,8 +16,6 @@
|
||||
#include <utils/processinterface.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
|
||||
#include <QDateTime>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
using namespace Utils::Tasking;
|
||||
@@ -31,15 +29,12 @@ public:
|
||||
|
||||
private:
|
||||
QString remoteFilePath() const;
|
||||
|
||||
bool isDeploymentNecessary() const override;
|
||||
void doDeploy() override;
|
||||
void stopDeployment() override;
|
||||
bool isDeploymentNecessary() const final;
|
||||
Group deployRecipe() final;
|
||||
TaskItem uploadTask();
|
||||
TaskItem installTask();
|
||||
|
||||
FilePath m_packageFilePath;
|
||||
std::unique_ptr<TaskTree> m_taskTree;
|
||||
};
|
||||
|
||||
void TarPackageDeployService::setPackageFilePath(const FilePath &filePath)
|
||||
@@ -102,28 +97,9 @@ TaskItem TarPackageDeployService::installTask()
|
||||
return Process(setupHandler, doneHandler, errorHandler);
|
||||
}
|
||||
|
||||
void TarPackageDeployService::doDeploy()
|
||||
Group TarPackageDeployService::deployRecipe()
|
||||
{
|
||||
QTC_ASSERT(!m_taskTree, return);
|
||||
|
||||
const auto finishHandler = [this] {
|
||||
m_taskTree.release()->deleteLater();
|
||||
stopDeployment();
|
||||
};
|
||||
const Group root {
|
||||
uploadTask(),
|
||||
installTask(),
|
||||
OnGroupDone(finishHandler),
|
||||
OnGroupError(finishHandler),
|
||||
};
|
||||
m_taskTree.reset(new TaskTree(root));
|
||||
m_taskTree->start();
|
||||
}
|
||||
|
||||
void TarPackageDeployService::stopDeployment()
|
||||
{
|
||||
m_taskTree.reset();
|
||||
handleDeploymentDone();
|
||||
return Group { uploadTask(), installTask() };
|
||||
}
|
||||
|
||||
// TarPackageDeployStep
|
||||
|
Reference in New Issue
Block a user