forked from qt-creator/qt-creator
Get rid of AbstractUploadAndInstallPackageService
We had only one class derived from it (UploadAndInstallTarPackageService), so glue both classes together. Don't export UploadAndInstallTarPackageService class, as it's not used outside. Move the implementation into cpp file. Change-Id: I1521d1badb559e510e11337ace309a867196b251 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -5,7 +5,6 @@ add_qtc_plugin(RemoteLinux
|
||||
abstractpackagingstep.cpp abstractpackagingstep.h
|
||||
abstractremotelinuxdeployservice.cpp abstractremotelinuxdeployservice.h
|
||||
abstractremotelinuxdeploystep.cpp abstractremotelinuxdeploystep.h
|
||||
abstractuploadandinstallpackageservice.cpp abstractuploadandinstallpackageservice.h
|
||||
deploymenttimeinfo.cpp deploymenttimeinfo.h
|
||||
filetransfer.h
|
||||
genericdirectuploadservice.cpp genericdirectuploadservice.h
|
||||
|
@@ -1,163 +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 "abstractuploadandinstallpackageservice.h"
|
||||
|
||||
#include "filetransfer.h"
|
||||
#include "remotelinuxpackageinstaller.h"
|
||||
|
||||
#include <projectexplorer/deployablefile.h>
|
||||
#include <projectexplorer/devicesupport/idevice.h>
|
||||
#include <utils/processinterface.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QDateTime>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
|
||||
namespace RemoteLinux {
|
||||
namespace Internal {
|
||||
namespace {
|
||||
enum State { Inactive, Uploading, Installing };
|
||||
} // anonymous namespace
|
||||
|
||||
class AbstractUploadAndInstallPackageServicePrivate
|
||||
{
|
||||
public:
|
||||
State state = Inactive;
|
||||
FileTransfer uploader;
|
||||
Utils::FilePath packageFilePath;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
using namespace Internal;
|
||||
|
||||
AbstractUploadAndInstallPackageService::AbstractUploadAndInstallPackageService()
|
||||
: d(new AbstractUploadAndInstallPackageServicePrivate)
|
||||
{
|
||||
connect(&d->uploader, &FileTransfer::done, this,
|
||||
&AbstractUploadAndInstallPackageService::handleUploadFinished);
|
||||
connect(&d->uploader, &FileTransfer::progress, this,
|
||||
&AbstractUploadAndInstallPackageService::progressMessage);
|
||||
}
|
||||
|
||||
AbstractUploadAndInstallPackageService::~AbstractUploadAndInstallPackageService()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
void AbstractUploadAndInstallPackageService::setPackageFilePath(const FilePath &filePath)
|
||||
{
|
||||
d->packageFilePath = filePath;
|
||||
}
|
||||
|
||||
QString AbstractUploadAndInstallPackageService::uploadDir() const
|
||||
{
|
||||
return QLatin1String("/tmp");
|
||||
}
|
||||
|
||||
bool AbstractUploadAndInstallPackageService::isDeploymentNecessary() const
|
||||
{
|
||||
return hasLocalFileChanged(DeployableFile(d->packageFilePath, QString()));
|
||||
}
|
||||
|
||||
void AbstractUploadAndInstallPackageService::doDeploy()
|
||||
{
|
||||
QTC_ASSERT(d->state == Inactive, return);
|
||||
|
||||
d->state = Uploading;
|
||||
|
||||
const QString remoteFilePath = uploadDir() + QLatin1Char('/') + d->packageFilePath.fileName();
|
||||
const FilesToTransfer files {{d->packageFilePath,
|
||||
deviceConfiguration()->filePath(remoteFilePath)}};
|
||||
d->uploader.setDevice(deviceConfiguration());
|
||||
d->uploader.setFilesToTransfer(files);
|
||||
d->uploader.start();
|
||||
}
|
||||
|
||||
void AbstractUploadAndInstallPackageService::stopDeployment()
|
||||
{
|
||||
switch (d->state) {
|
||||
case Inactive:
|
||||
qWarning("%s: Unexpected state 'Inactive'.", Q_FUNC_INFO);
|
||||
break;
|
||||
case Uploading:
|
||||
d->uploader.stop();
|
||||
setFinished();
|
||||
break;
|
||||
case Installing:
|
||||
packageInstaller()->cancelInstallation();
|
||||
setFinished();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractUploadAndInstallPackageService::handleUploadFinished(const ProcessResultData &resultData)
|
||||
{
|
||||
QTC_ASSERT(d->state == Uploading, return);
|
||||
|
||||
if (resultData.m_error != QProcess::UnknownError) {
|
||||
emit errorMessage(resultData.m_errorString);
|
||||
setFinished();
|
||||
return;
|
||||
}
|
||||
|
||||
emit progressMessage(tr("Successfully uploaded package file."));
|
||||
const QString remoteFilePath = uploadDir() + '/' + d->packageFilePath.fileName();
|
||||
d->state = Installing;
|
||||
emit progressMessage(tr("Installing package to device..."));
|
||||
connect(packageInstaller(), &AbstractRemoteLinuxPackageInstaller::stdoutData,
|
||||
this, &AbstractRemoteLinuxDeployService::stdOutData);
|
||||
connect(packageInstaller(), &AbstractRemoteLinuxPackageInstaller::stderrData,
|
||||
this, &AbstractRemoteLinuxDeployService::stdErrData);
|
||||
connect(packageInstaller(), &AbstractRemoteLinuxPackageInstaller::finished,
|
||||
this, &AbstractUploadAndInstallPackageService::handleInstallationFinished);
|
||||
packageInstaller()->installPackage(deviceConfiguration(), remoteFilePath, true);
|
||||
}
|
||||
|
||||
void AbstractUploadAndInstallPackageService::handleInstallationFinished(const QString &errorMsg)
|
||||
{
|
||||
QTC_ASSERT(d->state == Installing, return);
|
||||
|
||||
if (errorMsg.isEmpty()) {
|
||||
saveDeploymentTimeStamp(DeployableFile(d->packageFilePath, QString()), QDateTime());
|
||||
emit progressMessage(tr("Package installed."));
|
||||
} else {
|
||||
emit errorMessage(errorMsg);
|
||||
}
|
||||
setFinished();
|
||||
}
|
||||
|
||||
void AbstractUploadAndInstallPackageService::setFinished()
|
||||
{
|
||||
d->state = Inactive;
|
||||
d->uploader.stop();
|
||||
disconnect(packageInstaller(), nullptr, this, nullptr);
|
||||
handleDeploymentDone();
|
||||
}
|
||||
|
||||
} // namespace RemoteLinux
|
@@ -1,68 +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 "abstractremotelinuxdeployservice.h"
|
||||
#include "remotelinux_export.h"
|
||||
|
||||
namespace Utils {
|
||||
class FilePath;
|
||||
class ProcessResultData;
|
||||
}
|
||||
|
||||
namespace RemoteLinux {
|
||||
class AbstractRemoteLinuxPackageInstaller;
|
||||
|
||||
namespace Internal { class AbstractUploadAndInstallPackageServicePrivate; }
|
||||
|
||||
class REMOTELINUX_EXPORT AbstractUploadAndInstallPackageService : public AbstractRemoteLinuxDeployService
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
void setPackageFilePath(const Utils::FilePath &filePath);
|
||||
|
||||
protected:
|
||||
AbstractUploadAndInstallPackageService();
|
||||
~AbstractUploadAndInstallPackageService() override;
|
||||
|
||||
private:
|
||||
void handleUploadFinished(const Utils::ProcessResultData &resultData);
|
||||
void handleInstallationFinished(const QString &errorMsg);
|
||||
|
||||
virtual AbstractRemoteLinuxPackageInstaller *packageInstaller() const = 0;
|
||||
virtual QString uploadDir() const; // Defaults to remote user's home directory.
|
||||
|
||||
bool isDeploymentNecessary() const override;
|
||||
void doDeploy() override;
|
||||
void stopDeployment() override;
|
||||
|
||||
void setFinished();
|
||||
|
||||
Internal::AbstractUploadAndInstallPackageServicePrivate * const d;
|
||||
};
|
||||
|
||||
} // namespace RemoteLinux
|
@@ -19,8 +19,6 @@ Project {
|
||||
"abstractremotelinuxdeployservice.h",
|
||||
"abstractremotelinuxdeploystep.cpp",
|
||||
"abstractremotelinuxdeploystep.h",
|
||||
"abstractuploadandinstallpackageservice.cpp",
|
||||
"abstractuploadandinstallpackageservice.h",
|
||||
"deploymenttimeinfo.cpp",
|
||||
"deploymenttimeinfo.h",
|
||||
"filetransfer.h",
|
||||
|
@@ -25,43 +25,155 @@
|
||||
|
||||
#include "uploadandinstalltarpackagestep.h"
|
||||
|
||||
#include "filetransfer.h"
|
||||
#include "remotelinux_constants.h"
|
||||
#include "remotelinuxdeployconfiguration.h"
|
||||
#include "remotelinuxpackageinstaller.h"
|
||||
#include "tarpackagecreationstep.h"
|
||||
|
||||
#include <projectexplorer/deployconfiguration.h>
|
||||
#include <projectexplorer/devicesupport/idevice.h>
|
||||
|
||||
#include <utils/processinterface.h>
|
||||
|
||||
#include <QDateTime>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
|
||||
namespace RemoteLinux {
|
||||
namespace Internal {
|
||||
|
||||
class UploadAndInstallTarPackageServicePrivate
|
||||
class UploadAndInstallTarPackageService : public AbstractRemoteLinuxDeployService
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RemoteLinuxTarPackageInstaller installer;
|
||||
UploadAndInstallTarPackageService();
|
||||
void setPackageFilePath(const FilePath &filePath);
|
||||
|
||||
private:
|
||||
enum State { Inactive, Uploading, Installing };
|
||||
|
||||
void handleUploadFinished(const ProcessResultData &resultData);
|
||||
void handleInstallationFinished(const QString &errorMsg);
|
||||
|
||||
QString uploadDir() const; // Defaults to remote user's home directory.
|
||||
|
||||
bool isDeploymentNecessary() const override;
|
||||
void doDeploy() override;
|
||||
void stopDeployment() override;
|
||||
|
||||
void setFinished();
|
||||
|
||||
State m_state = Inactive;
|
||||
FileTransfer m_uploader;
|
||||
FilePath m_packageFilePath;
|
||||
RemoteLinuxTarPackageInstaller m_installer;
|
||||
};
|
||||
|
||||
UploadAndInstallTarPackageService::UploadAndInstallTarPackageService()
|
||||
{
|
||||
connect(&m_uploader, &FileTransfer::done, this,
|
||||
&UploadAndInstallTarPackageService::handleUploadFinished);
|
||||
connect(&m_uploader, &FileTransfer::progress, this,
|
||||
&UploadAndInstallTarPackageService::progressMessage);
|
||||
}
|
||||
|
||||
void UploadAndInstallTarPackageService::setPackageFilePath(const FilePath &filePath)
|
||||
{
|
||||
m_packageFilePath = filePath;
|
||||
}
|
||||
|
||||
QString UploadAndInstallTarPackageService::uploadDir() const
|
||||
{
|
||||
return QLatin1String("/tmp");
|
||||
}
|
||||
|
||||
bool UploadAndInstallTarPackageService::isDeploymentNecessary() const
|
||||
{
|
||||
return hasLocalFileChanged(DeployableFile(m_packageFilePath, {}));
|
||||
}
|
||||
|
||||
void UploadAndInstallTarPackageService::doDeploy()
|
||||
{
|
||||
QTC_ASSERT(m_state == Inactive, return);
|
||||
|
||||
m_state = Uploading;
|
||||
|
||||
const QString remoteFilePath = uploadDir() + QLatin1Char('/') + m_packageFilePath.fileName();
|
||||
const FilesToTransfer files {{m_packageFilePath,
|
||||
deviceConfiguration()->filePath(remoteFilePath)}};
|
||||
m_uploader.setDevice(deviceConfiguration());
|
||||
m_uploader.setFilesToTransfer(files);
|
||||
m_uploader.start();
|
||||
}
|
||||
|
||||
void UploadAndInstallTarPackageService::stopDeployment()
|
||||
{
|
||||
switch (m_state) {
|
||||
case Inactive:
|
||||
qWarning("%s: Unexpected state 'Inactive'.", Q_FUNC_INFO);
|
||||
break;
|
||||
case Uploading:
|
||||
m_uploader.stop();
|
||||
setFinished();
|
||||
break;
|
||||
case Installing:
|
||||
m_installer.cancelInstallation();
|
||||
setFinished();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void UploadAndInstallTarPackageService::handleUploadFinished(const ProcessResultData &resultData)
|
||||
{
|
||||
QTC_ASSERT(m_state == Uploading, return);
|
||||
|
||||
if (resultData.m_error != QProcess::UnknownError) {
|
||||
emit errorMessage(resultData.m_errorString);
|
||||
setFinished();
|
||||
return;
|
||||
}
|
||||
|
||||
emit progressMessage(tr("Successfully uploaded package file."));
|
||||
const QString remoteFilePath = uploadDir() + '/' + m_packageFilePath.fileName();
|
||||
m_state = Installing;
|
||||
emit progressMessage(tr("Installing package to device..."));
|
||||
connect(&m_installer, &AbstractRemoteLinuxPackageInstaller::stdoutData,
|
||||
this, &AbstractRemoteLinuxDeployService::stdOutData);
|
||||
connect(&m_installer, &AbstractRemoteLinuxPackageInstaller::stderrData,
|
||||
this, &AbstractRemoteLinuxDeployService::stdErrData);
|
||||
connect(&m_installer, &AbstractRemoteLinuxPackageInstaller::finished,
|
||||
this, &UploadAndInstallTarPackageService::handleInstallationFinished);
|
||||
m_installer.installPackage(deviceConfiguration(), remoteFilePath, true);
|
||||
}
|
||||
|
||||
void UploadAndInstallTarPackageService::handleInstallationFinished(const QString &errorMsg)
|
||||
{
|
||||
QTC_ASSERT(m_state == Installing, return);
|
||||
|
||||
if (errorMsg.isEmpty()) {
|
||||
saveDeploymentTimeStamp(DeployableFile(m_packageFilePath, {}), {});
|
||||
emit progressMessage(tr("Package installed."));
|
||||
} else {
|
||||
emit errorMessage(errorMsg);
|
||||
}
|
||||
setFinished();
|
||||
}
|
||||
|
||||
void UploadAndInstallTarPackageService::setFinished()
|
||||
{
|
||||
m_state = Inactive;
|
||||
m_uploader.stop();
|
||||
disconnect(&m_installer, nullptr, this, nullptr);
|
||||
handleDeploymentDone();
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
using namespace Internal;
|
||||
|
||||
UploadAndInstallTarPackageService::UploadAndInstallTarPackageService()
|
||||
: d(new UploadAndInstallTarPackageServicePrivate)
|
||||
{
|
||||
}
|
||||
|
||||
UploadAndInstallTarPackageService::~UploadAndInstallTarPackageService()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
AbstractRemoteLinuxPackageInstaller *UploadAndInstallTarPackageService::packageInstaller() const
|
||||
{
|
||||
return &d->installer;
|
||||
}
|
||||
|
||||
|
||||
UploadAndInstallTarPackageStep::UploadAndInstallTarPackageStep(BuildStepList *bsl, Utils::Id id)
|
||||
UploadAndInstallTarPackageStep::UploadAndInstallTarPackageStep(BuildStepList *bsl, Id id)
|
||||
: AbstractRemoteLinuxDeployStep(bsl, id)
|
||||
{
|
||||
auto service = createDeployService<UploadAndInstallTarPackageService>();
|
||||
@@ -85,7 +197,7 @@ UploadAndInstallTarPackageStep::UploadAndInstallTarPackageStep(BuildStepList *bs
|
||||
});
|
||||
}
|
||||
|
||||
Utils::Id UploadAndInstallTarPackageStep::stepId()
|
||||
Id UploadAndInstallTarPackageStep::stepId()
|
||||
{
|
||||
return Constants::UploadAndInstallTarPackageStepId;
|
||||
}
|
||||
@@ -96,3 +208,5 @@ QString UploadAndInstallTarPackageStep::displayName()
|
||||
}
|
||||
|
||||
} //namespace RemoteLinux
|
||||
|
||||
#include "uploadandinstalltarpackagestep.moc"
|
||||
|
@@ -25,29 +25,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "abstractuploadandinstallpackageservice.h"
|
||||
#include "abstractremotelinuxdeploystep.h"
|
||||
|
||||
namespace RemoteLinux {
|
||||
class AbstractRemoteLinuxPackageInstaller;
|
||||
|
||||
namespace Internal { class UploadAndInstallTarPackageServicePrivate; }
|
||||
|
||||
class REMOTELINUX_EXPORT UploadAndInstallTarPackageService : public AbstractUploadAndInstallPackageService
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UploadAndInstallTarPackageService();
|
||||
~UploadAndInstallTarPackageService() override;
|
||||
|
||||
private:
|
||||
AbstractRemoteLinuxPackageInstaller *packageInstaller() const override;
|
||||
|
||||
Internal::UploadAndInstallTarPackageServicePrivate *d;
|
||||
};
|
||||
|
||||
|
||||
class REMOTELINUX_EXPORT UploadAndInstallTarPackageStep : public AbstractRemoteLinuxDeployStep
|
||||
{
|
||||
Q_OBJECT
|
||||
|
Reference in New Issue
Block a user