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 <christian.kandeler@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Jarek Kobus
2022-05-27 13:39:30 +02:00
parent cda2e97ce5
commit 9ce6ad6a06
6 changed files with 66 additions and 195 deletions

View File

@@ -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

View File

@@ -63,8 +63,6 @@ Project {
"remotelinuxenvironmentaspectwidget.h",
"remotelinuxenvironmentreader.cpp",
"remotelinuxenvironmentreader.h",
"remotelinuxpackageinstaller.cpp",
"remotelinuxpackageinstaller.h",
"remotelinuxplugin.cpp",
"remotelinuxplugin.h",
"remotelinuxqmltoolingsupport.cpp",

View File

@@ -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 <projectexplorer/devicesupport/idevice.h>
#include <utils/fileutils.h>
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
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

View File

@@ -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 <projectexplorer/devicesupport/idevicefwd.h>
#include <QObject>
#include <memory>
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<Internal::AbstractRemoteLinuxPackageInstallerPrivate> 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

View File

@@ -26,7 +26,6 @@
#include "tarpackagedeploystep.h"
#include "remotelinux_constants.h"
#include "remotelinuxpackageinstaller.h"
#include "tarpackagecreationstep.h"
#include <projectexplorer/deployconfiguration.h>
@@ -34,6 +33,7 @@
#include <projectexplorer/devicesupport/idevice.h>
#include <utils/processinterface.h>
#include <utils/qtcprocess.h>
#include <QDateTime>
@@ -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);
}

View File

@@ -28,7 +28,6 @@
#include "abstractremotelinuxdeploystep.h"
namespace RemoteLinux {
class AbstractRemoteLinuxPackageInstaller;
class TarPackageDeployStep : public AbstractRemoteLinuxDeployStep
{