From 2be0fc2537ec06350e4ebb9346282228fcc82473 Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 31 Jan 2022 18:08:39 +0100 Subject: [PATCH] ProjectExplorer: Use CommandLine instead of Runnable Lighter and sufficient for all use cases. Change-Id: Ic6749a1a9e3e6906ce71b87b237cc94a6d8a4cbf Reviewed-by: Reviewed-by: Jarek Kobus --- src/plugins/docker/dockerdevice.cpp | 8 +++----- .../projectexplorer/devicesupport/desktopdevice.cpp | 11 +++++------ .../devicesupport/deviceusedportsgatherer.cpp | 3 ++- src/plugins/projectexplorer/devicesupport/idevice.h | 3 +-- src/plugins/qnx/qnxdevice.cpp | 6 ++---- src/plugins/remotelinux/linuxdevice.cpp | 8 +++----- 6 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/plugins/docker/dockerdevice.cpp b/src/plugins/docker/dockerdevice.cpp index 383f05e9c0d..32597808140 100644 --- a/src/plugins/docker/dockerdevice.cpp +++ b/src/plugins/docker/dockerdevice.cpp @@ -148,7 +148,7 @@ void DockerDeviceProcess::interrupt() class DockerPortsGatheringMethod : public PortsGatheringMethod { - Runnable runnable(QAbstractSocket::NetworkLayerProtocol protocol) const override + CommandLine commandLine(QAbstractSocket::NetworkLayerProtocol protocol) const override { // We might encounter the situation that protocol is given IPv6 // but the consumer of the free port information decides to open @@ -161,10 +161,8 @@ class DockerPortsGatheringMethod : public PortsGatheringMethod Q_UNUSED(protocol) // /proc/net/tcp* covers /proc/net/tcp and /proc/net/tcp6 - Runnable runnable; - runnable.command.setExecutable("sed"); - runnable.command.setArguments("-e 's/.*: [[:xdigit:]]*:\\([[:xdigit:]]\\{4\\}\\).*/\\1/g' /proc/net/tcp*"); - return runnable; + return {"sed", "-e 's/.*: [[:xdigit:]]*:\\([[:xdigit:]]\\{4\\}\\).*/\\1/g' /proc/net/tcp*", + CommandLine::Raw}; } QList usedPorts(const QByteArray &output) const override diff --git a/src/plugins/projectexplorer/devicesupport/desktopdevice.cpp b/src/plugins/projectexplorer/devicesupport/desktopdevice.cpp index 33969239f76..87efde505e9 100644 --- a/src/plugins/projectexplorer/devicesupport/desktopdevice.cpp +++ b/src/plugins/projectexplorer/devicesupport/desktopdevice.cpp @@ -125,7 +125,7 @@ DeviceEnvironmentFetcher::Ptr DesktopDevice::environmentFetcher() const class DesktopPortsGatheringMethod : public PortsGatheringMethod { - Runnable runnable(QAbstractSocket::NetworkLayerProtocol protocol) const override + CommandLine commandLine(QAbstractSocket::NetworkLayerProtocol protocol) const override { // We might encounter the situation that protocol is given IPv6 // but the consumer of the free port information decides to open @@ -137,12 +137,11 @@ class DesktopPortsGatheringMethod : public PortsGatheringMethod Q_UNUSED(protocol) - Runnable runnable; if (HostOsInfo::isWindowsHost() || HostOsInfo::isMacHost()) - runnable.command = CommandLine{"netstat", {"-a", "-n"}}; - else if (HostOsInfo::isLinuxHost()) - runnable.command = CommandLine{"/bin/sh", {"-c", "cat /proc/net/tcp*"}}; - return runnable; + return {"netstat", {"-a", "-n"}}; + if (HostOsInfo::isLinuxHost()) + return {"/bin/sh", {"-c", "cat /proc/net/tcp*"}}; + return {}; } QList usedPorts(const QByteArray &output) const override diff --git a/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp b/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp index d2d3961a015..567cf5d41f5 100644 --- a/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp +++ b/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp @@ -86,7 +86,8 @@ void DeviceUsedPortsGatherer::start(const IDevice::ConstPtr &device) connect(d->process.data(), &DeviceProcess::readyReadStandardError, this, &DeviceUsedPortsGatherer::handleRemoteStdErr); - const Runnable runnable = d->portsGatheringMethod->runnable(protocol); + Runnable runnable; + runnable.command = d->portsGatheringMethod->commandLine(protocol); d->process->start(runnable); } diff --git a/src/plugins/projectexplorer/devicesupport/idevice.h b/src/plugins/projectexplorer/devicesupport/idevice.h index 144daffbfda..8e395368a8c 100644 --- a/src/plugins/projectexplorer/devicesupport/idevice.h +++ b/src/plugins/projectexplorer/devicesupport/idevice.h @@ -63,7 +63,6 @@ class Connection; class DeviceProcess; class DeviceProcessList; class Kit; -class Runnable; class Task; namespace Internal { class IDevicePrivate; } @@ -116,7 +115,7 @@ public: using Ptr = QSharedPointer; virtual ~PortsGatheringMethod() = default; - virtual Runnable runnable(QAbstractSocket::NetworkLayerProtocol protocol) const = 0; + virtual Utils::CommandLine commandLine(QAbstractSocket::NetworkLayerProtocol protocol) const = 0; virtual QList usedPorts(const QByteArray &commandOutput) const = 0; }; diff --git a/src/plugins/qnx/qnxdevice.cpp b/src/plugins/qnx/qnxdevice.cpp index 4c88743f2ad..318761c1255 100644 --- a/src/plugins/qnx/qnxdevice.cpp +++ b/src/plugins/qnx/qnxdevice.cpp @@ -58,12 +58,10 @@ class QnxPortsGatheringMethod : public PortsGatheringMethod { // TODO: The command is probably needlessly complicated because the parsing method // used to be fixed. These two can now be matched to each other. - Runnable runnable(QAbstractSocket::NetworkLayerProtocol protocol) const override + CommandLine commandLine(QAbstractSocket::NetworkLayerProtocol protocol) const override { Q_UNUSED(protocol) - Runnable runnable; - runnable.command = {"netstat", {"-na"}}; - return runnable; + return {"netstat", {"-na"}}; } QList usedPorts(const QByteArray &output) const override diff --git a/src/plugins/remotelinux/linuxdevice.cpp b/src/plugins/remotelinux/linuxdevice.cpp index 63f7e0ff72c..0e1962ae9a9 100644 --- a/src/plugins/remotelinux/linuxdevice.cpp +++ b/src/plugins/remotelinux/linuxdevice.cpp @@ -146,7 +146,7 @@ private: class LinuxPortsGatheringMethod : public PortsGatheringMethod { - Runnable runnable(QAbstractSocket::NetworkLayerProtocol protocol) const override + CommandLine commandLine(QAbstractSocket::NetworkLayerProtocol protocol) const override { // We might encounter the situation that protocol is given IPv6 // but the consumer of the free port information decides to open @@ -159,10 +159,8 @@ class LinuxPortsGatheringMethod : public PortsGatheringMethod Q_UNUSED(protocol) // /proc/net/tcp* covers /proc/net/tcp and /proc/net/tcp6 - Runnable runnable; - runnable.command.setExecutable("sed"); - runnable.command.setArguments("-e 's/.*: [[:xdigit:]]*:\\([[:xdigit:]]\\{4\\}\\).*/\\1/g' /proc/net/tcp*"); - return runnable; + return {"sed", "-e 's/.*: [[:xdigit:]]*:\\([[:xdigit:]]\\{4\\}\\).*/\\1/g' /proc/net/tcp*", + CommandLine::Raw}; } QList usedPorts(const QByteArray &output) const override