CustomCommandDeployService: Reuse TaskTree

Change-Id: I9ed0a9279bbbf88b810331e100c7799191d93602
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Jarek Kobus
2022-11-24 18:27:49 +01:00
parent c01ab460c8
commit bec3b9279b

View File

@@ -16,48 +16,26 @@
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils; using namespace Utils;
using namespace Utils::Tasking;
namespace RemoteLinux::Internal { namespace RemoteLinux::Internal {
class CustomCommandDeployService : public AbstractRemoteLinuxDeployService class CustomCommandDeployService : public AbstractRemoteLinuxDeployService
{ {
public: public:
CustomCommandDeployService();
void setCommandLine(const QString &commandLine); void setCommandLine(const QString &commandLine);
bool isDeploymentNecessary() const override { return true; }
CheckResult isDeploymentPossible() const override; CheckResult isDeploymentPossible() const override;
protected: protected:
void doDeploy() override; void doDeploy() override;
void stopDeployment() override; void stopDeployment() override;
QString m_commandLine; private:
QtcProcess m_process; bool isDeploymentNecessary() const override { return true; }
};
CustomCommandDeployService::CustomCommandDeployService() QString m_commandLine;
{ std::unique_ptr<TaskTree> m_taskTree;
connect(&m_process, &QtcProcess::readyReadStandardOutput, this, [this] { };
emit stdOutData(QString::fromUtf8(m_process.readAllStandardOutput()));
});
connect(&m_process, &QtcProcess::readyReadStandardError, this, [this] {
emit stdErrData(QString::fromUtf8(m_process.readAllStandardError()));
});
connect(&m_process, &QtcProcess::done, this, [this] {
if (m_process.error() != QProcess::UnknownError
|| m_process.exitStatus() != QProcess::NormalExit) {
emit errorMessage(Tr::tr("Remote process failed: %1").arg(m_process.errorString()));
} else if (m_process.exitCode() != 0) {
emit errorMessage(Tr::tr("Remote process finished with exit code %1.")
.arg(m_process.exitCode()));
} else {
emit progressMessage(Tr::tr("Remote command finished successfully."));
}
stopDeployment();
});
}
void CustomCommandDeployService::setCommandLine(const QString &commandLine) void CustomCommandDeployService::setCommandLine(const QString &commandLine)
{ {
@@ -74,15 +52,48 @@ CheckResult CustomCommandDeployService::isDeploymentPossible() const
void CustomCommandDeployService::doDeploy() void CustomCommandDeployService::doDeploy()
{ {
QTC_ASSERT(!m_taskTree, return);
const auto setupHandler = [this](QtcProcess &process) {
emit progressMessage(Tr::tr("Starting remote command \"%1\"...").arg(m_commandLine)); emit progressMessage(Tr::tr("Starting remote command \"%1\"...").arg(m_commandLine));
m_process.setCommand({deviceConfiguration()->filePath("/bin/sh"), process.setCommand({deviceConfiguration()->filePath("/bin/sh"),
{"-c", m_commandLine}}); {"-c", m_commandLine}});
m_process.start(); QtcProcess *proc = &process;
connect(proc, &QtcProcess::readyReadStandardOutput, this, [this, proc] {
emit stdOutData(QString::fromUtf8(proc->readAllStandardOutput()));
});
connect(proc, &QtcProcess::readyReadStandardError, this, [this, proc] {
emit stdErrData(QString::fromUtf8(proc->readAllStandardError()));
});
};
const auto doneHandler = [this](const QtcProcess &) {
emit progressMessage(Tr::tr("Remote command finished successfully."));
};
const auto errorHandler = [this](const QtcProcess &process) {
if (process.error() != QProcess::UnknownError
|| process.exitStatus() != QProcess::NormalExit) {
emit errorMessage(Tr::tr("Remote process failed: %1").arg(process.errorString()));
} else if (process.exitCode() != 0) {
emit errorMessage(Tr::tr("Remote process finished with exit code %1.")
.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() void CustomCommandDeployService::stopDeployment()
{ {
m_process.close(); m_taskTree.reset();
handleDeploymentDone(); handleDeploymentDone();
} }