From 9ce6ad6a06d11f702317ab3cf7983a09264dcfe3 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Fri, 27 May 2022 13:39:30 +0200 Subject: [PATCH] RemoteLinux: Hide RemoteLinuxPackageInstaller Remove AbstractRemoteLinuxPackageInstaller, as we have only one subclass. Don't export RemoteLinuxPackageInstaller, as it's used only by TarPackageDeployStep. Rename RemoteLinuxPackageInstaller into TarPackageInstaller and hide it inside tarpackagedeploystep.cpp. Change-Id: I1dacdeda58378911cc322b9991f4f584c074db1b Reviewed-by: Christian Kandeler Reviewed-by: Qt CI Bot Reviewed-by: --- src/plugins/remotelinux/CMakeLists.txt | 1 - src/plugins/remotelinux/remotelinux.qbs | 2 - .../remotelinuxpackageinstaller.cpp | 107 ------------------ .../remotelinux/remotelinuxpackageinstaller.h | 79 ------------- .../remotelinux/tarpackagedeploystep.cpp | 71 +++++++++++- .../remotelinux/tarpackagedeploystep.h | 1 - 6 files changed, 66 insertions(+), 195 deletions(-) delete mode 100644 src/plugins/remotelinux/remotelinuxpackageinstaller.cpp delete mode 100644 src/plugins/remotelinux/remotelinuxpackageinstaller.h diff --git a/src/plugins/remotelinux/CMakeLists.txt b/src/plugins/remotelinux/CMakeLists.txt index c9d7b2df0f5..7111f55b767 100644 --- a/src/plugins/remotelinux/CMakeLists.txt +++ b/src/plugins/remotelinux/CMakeLists.txt @@ -29,7 +29,6 @@ add_qtc_plugin(RemoteLinux remotelinuxenvironmentaspect.cpp remotelinuxenvironmentaspect.h remotelinuxenvironmentaspectwidget.cpp remotelinuxenvironmentaspectwidget.h remotelinuxenvironmentreader.cpp remotelinuxenvironmentreader.h - remotelinuxpackageinstaller.cpp remotelinuxpackageinstaller.h remotelinuxplugin.cpp remotelinuxplugin.h remotelinuxqmltoolingsupport.cpp remotelinuxqmltoolingsupport.h remotelinuxrunconfiguration.cpp remotelinuxrunconfiguration.h diff --git a/src/plugins/remotelinux/remotelinux.qbs b/src/plugins/remotelinux/remotelinux.qbs index f7add4f572b..15170415cf4 100644 --- a/src/plugins/remotelinux/remotelinux.qbs +++ b/src/plugins/remotelinux/remotelinux.qbs @@ -63,8 +63,6 @@ Project { "remotelinuxenvironmentaspectwidget.h", "remotelinuxenvironmentreader.cpp", "remotelinuxenvironmentreader.h", - "remotelinuxpackageinstaller.cpp", - "remotelinuxpackageinstaller.h", "remotelinuxplugin.cpp", "remotelinuxplugin.h", "remotelinuxqmltoolingsupport.cpp", diff --git a/src/plugins/remotelinux/remotelinuxpackageinstaller.cpp b/src/plugins/remotelinux/remotelinuxpackageinstaller.cpp deleted file mode 100644 index 828c5a5a361..00000000000 --- a/src/plugins/remotelinux/remotelinuxpackageinstaller.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "remotelinuxpackageinstaller.h" - -#include - -#include -#include -#include - -using namespace ProjectExplorer; -using namespace Utils; - -namespace RemoteLinux { -namespace Internal { - -class AbstractRemoteLinuxPackageInstallerPrivate -{ -public: - IDevice::ConstPtr m_device; - QtcProcess m_installer; - QtcProcess m_killer; -}; - -} // namespace Internal - -AbstractRemoteLinuxPackageInstaller::AbstractRemoteLinuxPackageInstaller(QObject *parent) - : QObject(parent), d(new Internal::AbstractRemoteLinuxPackageInstallerPrivate) -{ - connect(&d->m_installer, &QtcProcess::readyReadStandardOutput, this, [this] { - emit stdoutData(QString::fromUtf8(d->m_installer.readAllStandardOutput())); - }); - connect(&d->m_installer, &QtcProcess::readyReadStandardError, this, [this] { - emit stderrData(QString::fromUtf8(d->m_installer.readAllStandardError())); - }); - connect(&d->m_installer, &QtcProcess::finished, this, [this] { - const QString errorMessage = d->m_installer.result() == ProcessResult::FinishedWithSuccess - ? QString() : tr("Installing package failed.") + d->m_installer.errorString(); - emit finished(errorMessage); - }); -} - -AbstractRemoteLinuxPackageInstaller::~AbstractRemoteLinuxPackageInstaller() = default; - -void AbstractRemoteLinuxPackageInstaller::installPackage(const IDevice::ConstPtr &deviceConfig, - const QString &packageFilePath, bool removePackageFile) -{ - QTC_ASSERT(d->m_installer.state() == QProcess::NotRunning, return); - - d->m_device = deviceConfig; - - QString cmdLine = installCommandLine(packageFilePath); - if (removePackageFile) - cmdLine += QLatin1String(" && (rm ") + packageFilePath + QLatin1String(" || :)"); - d->m_installer.setCommand({d->m_device->filePath("/bin/sh"), {"-c", cmdLine}}); - d->m_installer.start(); -} - -void AbstractRemoteLinuxPackageInstaller::cancelInstallation() -{ - QTC_ASSERT(d->m_installer.state() != QProcess::NotRunning, return); - - d->m_killer.setCommand({d->m_device->filePath("/bin/sh"), - {"-c", cancelInstallationCommandLine()}}); - d->m_killer.start(); - d->m_installer.close(); -} - -RemoteLinuxTarPackageInstaller::RemoteLinuxTarPackageInstaller(QObject *parent) - : AbstractRemoteLinuxPackageInstaller(parent) -{ -} - -QString RemoteLinuxTarPackageInstaller::installCommandLine(const QString &packageFilePath) const -{ - return QLatin1String("cd / && tar xvf ") + packageFilePath; -} - -QString RemoteLinuxTarPackageInstaller::cancelInstallationCommandLine() const -{ - return QLatin1String("pkill tar"); -} - -} // namespace RemoteLinux diff --git a/src/plugins/remotelinux/remotelinuxpackageinstaller.h b/src/plugins/remotelinux/remotelinuxpackageinstaller.h deleted file mode 100644 index 74a5e06b99d..00000000000 --- a/src/plugins/remotelinux/remotelinuxpackageinstaller.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#pragma once - -#include "remotelinux_export.h" - -#include - -#include - -#include - -namespace RemoteLinux { - -namespace Internal { class AbstractRemoteLinuxPackageInstallerPrivate; } - -class REMOTELINUX_EXPORT AbstractRemoteLinuxPackageInstaller : public QObject -{ - Q_OBJECT - Q_DISABLE_COPY(AbstractRemoteLinuxPackageInstaller) -public: - ~AbstractRemoteLinuxPackageInstaller() override; - - void installPackage(const ProjectExplorer::IDeviceConstPtr &deviceConfig, - const QString &packageFilePath, bool removePackageFile); - void cancelInstallation(); - -signals: - void stdoutData(const QString &output); - void stderrData(const QString &output); - void finished(const QString &errorMsg = QString()); - -protected: - explicit AbstractRemoteLinuxPackageInstaller(QObject *parent = nullptr); - -private: - virtual QString installCommandLine(const QString &packageFilePath) const = 0; - virtual QString cancelInstallationCommandLine() const = 0; - - std::unique_ptr d; -}; - - -class REMOTELINUX_EXPORT RemoteLinuxTarPackageInstaller : public AbstractRemoteLinuxPackageInstaller -{ - Q_OBJECT -public: - RemoteLinuxTarPackageInstaller(QObject *parent = nullptr); - -private: - QString installCommandLine(const QString &packageFilePath) const override; - QString cancelInstallationCommandLine() const override; -}; - - -} // namespace RemoteLinux diff --git a/src/plugins/remotelinux/tarpackagedeploystep.cpp b/src/plugins/remotelinux/tarpackagedeploystep.cpp index d6a58c33c32..7247d165c4f 100644 --- a/src/plugins/remotelinux/tarpackagedeploystep.cpp +++ b/src/plugins/remotelinux/tarpackagedeploystep.cpp @@ -26,7 +26,6 @@ #include "tarpackagedeploystep.h" #include "remotelinux_constants.h" -#include "remotelinuxpackageinstaller.h" #include "tarpackagecreationstep.h" #include @@ -34,6 +33,7 @@ #include #include +#include #include @@ -43,6 +43,67 @@ using namespace Utils; namespace RemoteLinux { namespace Internal { +class TarPackageInstaller : public QObject +{ + Q_OBJECT + +public: + TarPackageInstaller(QObject *parent = nullptr); + + void installPackage(const ProjectExplorer::IDeviceConstPtr &deviceConfig, + const QString &packageFilePath, bool removePackageFile); + void cancelInstallation(); + +signals: + void stdoutData(const QString &output); + void stderrData(const QString &output); + void finished(const QString &errorMsg = QString()); + +private: + IDevice::ConstPtr m_device; + QtcProcess m_installer; + QtcProcess m_killer; +}; + +TarPackageInstaller::TarPackageInstaller(QObject *parent) + : QObject(parent) +{ + connect(&m_installer, &QtcProcess::readyReadStandardOutput, this, [this] { + emit stdoutData(QString::fromUtf8(m_installer.readAllStandardOutput())); + }); + connect(&m_installer, &QtcProcess::readyReadStandardError, this, [this] { + emit stderrData(QString::fromUtf8(m_installer.readAllStandardError())); + }); + connect(&m_installer, &QtcProcess::finished, this, [this] { + const QString errorMessage = m_installer.result() == ProcessResult::FinishedWithSuccess + ? QString() : tr("Installing package failed.") + m_installer.errorString(); + emit finished(errorMessage); + }); +} + +void TarPackageInstaller::installPackage(const IDevice::ConstPtr &deviceConfig, + const QString &packageFilePath, bool removePackageFile) +{ + QTC_ASSERT(m_installer.state() == QProcess::NotRunning, return); + + m_device = deviceConfig; + + QString cmdLine = QLatin1String("cd / && tar xvf ") + packageFilePath; + if (removePackageFile) + cmdLine += QLatin1String(" && (rm ") + packageFilePath + QLatin1String(" || :)"); + m_installer.setCommand({m_device->filePath("/bin/sh"), {"-c", cmdLine}}); + m_installer.start(); +} + +void TarPackageInstaller::cancelInstallation() +{ + QTC_ASSERT(m_installer.state() != QProcess::NotRunning, return); + + m_killer.setCommand({m_device->filePath("/bin/sh"), {"-c", "pkill tar"}}); + m_killer.start(); + m_installer.close(); +} + class TarPackageDeployService : public AbstractRemoteLinuxDeployService { Q_OBJECT @@ -68,7 +129,7 @@ private: State m_state = Inactive; FileTransfer m_uploader; FilePath m_packageFilePath; - RemoteLinuxTarPackageInstaller m_installer; + TarPackageInstaller m_installer; }; TarPackageDeployService::TarPackageDeployService() @@ -138,11 +199,11 @@ void TarPackageDeployService::handleUploadFinished(const ProcessResultData &resu const QString remoteFilePath = uploadDir() + '/' + m_packageFilePath.fileName(); m_state = Installing; emit progressMessage(tr("Installing package to device...")); - connect(&m_installer, &AbstractRemoteLinuxPackageInstaller::stdoutData, + connect(&m_installer, &TarPackageInstaller::stdoutData, this, &AbstractRemoteLinuxDeployService::stdOutData); - connect(&m_installer, &AbstractRemoteLinuxPackageInstaller::stderrData, + connect(&m_installer, &TarPackageInstaller::stderrData, this, &AbstractRemoteLinuxDeployService::stdErrData); - connect(&m_installer, &AbstractRemoteLinuxPackageInstaller::finished, + connect(&m_installer, &TarPackageInstaller::finished, this, &TarPackageDeployService::handleInstallationFinished); m_installer.installPackage(deviceConfiguration(), remoteFilePath, true); } diff --git a/src/plugins/remotelinux/tarpackagedeploystep.h b/src/plugins/remotelinux/tarpackagedeploystep.h index 63eee8b2e5b..e1113bebcbc 100644 --- a/src/plugins/remotelinux/tarpackagedeploystep.h +++ b/src/plugins/remotelinux/tarpackagedeploystep.h @@ -28,7 +28,6 @@ #include "abstractremotelinuxdeploystep.h" namespace RemoteLinux { -class AbstractRemoteLinuxPackageInstaller; class TarPackageDeployStep : public AbstractRemoteLinuxDeployStep {