ProjectExplorer: Use CommandLine instead of Runnable

Lighter and sufficient for all use cases.

Change-Id: Ic6749a1a9e3e6906ce71b87b237cc94a6d8a4cbf
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2022-01-31 18:08:39 +01:00
parent b822b3f9e2
commit 2be0fc2537
6 changed files with 16 additions and 23 deletions

View File

@@ -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<Utils::Port> usedPorts(const QByteArray &output) const override

View File

@@ -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<Utils::Port> usedPorts(const QByteArray &output) const override

View File

@@ -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);
}

View File

@@ -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<const PortsGatheringMethod>;
virtual ~PortsGatheringMethod() = default;
virtual Runnable runnable(QAbstractSocket::NetworkLayerProtocol protocol) const = 0;
virtual Utils::CommandLine commandLine(QAbstractSocket::NetworkLayerProtocol protocol) const = 0;
virtual QList<Utils::Port> usedPorts(const QByteArray &commandOutput) const = 0;
};

View File

@@ -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<Port> usedPorts(const QByteArray &output) const override

View File

@@ -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<Utils::Port> usedPorts(const QByteArray &output) const override