forked from qt-creator/qt-creator
Refactor the incremental deployment to a separate class
Extract incremental deployment caching to a new class. Remove the extra Kit pointer and use target directly. Add incremental deployment class to deploy service private data member. Change-Id: I1e2e0829b9413f647ccfa3a4af23260a54895d83 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "abstractremotelinuxdeployservice.h"
|
||||
#include "deploymenttimeinfo.h"
|
||||
|
||||
#include <projectexplorer/deployablefile.h>
|
||||
#include <projectexplorer/target.h>
|
||||
@@ -44,49 +45,22 @@ namespace RemoteLinux {
|
||||
namespace Internal {
|
||||
|
||||
namespace {
|
||||
class DeployParameters
|
||||
{
|
||||
public:
|
||||
DeployParameters(const DeployableFile &d, const QString &h, const QString &s)
|
||||
: file(d), host(h), sysroot(s) {}
|
||||
|
||||
bool operator==(const DeployParameters &other) const {
|
||||
return file == other.file && host == other.host && sysroot == other.sysroot;
|
||||
}
|
||||
|
||||
DeployableFile file;
|
||||
QString host;
|
||||
QString sysroot;
|
||||
};
|
||||
uint qHash(const DeployParameters &p) {
|
||||
return qHash(qMakePair(qMakePair(p.file, p.host), p.sysroot));
|
||||
}
|
||||
|
||||
enum State { Inactive, SettingUpDevice, Connecting, Deploying };
|
||||
|
||||
// TODO: Just change these...
|
||||
const char LastDeployedHostsKey[] = "Qt4ProjectManager.MaemoRunConfiguration.LastDeployedHosts";
|
||||
const char LastDeployedSysrootsKey[] = "Qt4ProjectManager.MaemoRunConfiguration.LastDeployedSysroots";
|
||||
const char LastDeployedFilesKey[] = "Qt4ProjectManager.MaemoRunConfiguration.LastDeployedFiles";
|
||||
const char LastDeployedRemotePathsKey[] = "Qt4ProjectManager.MaemoRunConfiguration.LastDeployedRemotePaths";
|
||||
const char LastDeployedTimesKey[] = "Qt4ProjectManager.MaemoRunConfiguration.LastDeployedTimes";
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
class AbstractRemoteLinuxDeployServicePrivate
|
||||
{
|
||||
public:
|
||||
AbstractRemoteLinuxDeployServicePrivate()
|
||||
: kit(0), connection(0), state(Inactive), stopRequested(false) {}
|
||||
: connection(0), state(Inactive), stopRequested(false) {}
|
||||
|
||||
IDevice::ConstPtr deviceConfiguration;
|
||||
QPointer<Target> target;
|
||||
Kit *kit;
|
||||
|
||||
DeploymentTimeInfo deployTimes;
|
||||
SshConnection *connection;
|
||||
State state;
|
||||
bool stopRequested;
|
||||
|
||||
QHash<DeployParameters, QDateTime> lastDeployed;
|
||||
};
|
||||
} // namespace Internal
|
||||
|
||||
@@ -109,7 +83,7 @@ const Target *AbstractRemoteLinuxDeployService::target() const
|
||||
|
||||
const Kit *AbstractRemoteLinuxDeployService::profile() const
|
||||
{
|
||||
return d->kit;
|
||||
return d->target ? d->target->kit() : nullptr;
|
||||
}
|
||||
|
||||
IDevice::ConstPtr AbstractRemoteLinuxDeployService::deviceConfiguration() const
|
||||
@@ -124,38 +98,18 @@ SshConnection *AbstractRemoteLinuxDeployService::connection() const
|
||||
|
||||
void AbstractRemoteLinuxDeployService::saveDeploymentTimeStamp(const DeployableFile &deployableFile)
|
||||
{
|
||||
if (!d->target)
|
||||
return;
|
||||
QString systemRoot;
|
||||
if (SysRootKitInformation::hasSysRoot(d->kit))
|
||||
systemRoot = SysRootKitInformation::sysRoot(d->kit).toString();
|
||||
d->lastDeployed.insert(DeployParameters(deployableFile,
|
||||
deviceConfiguration()->sshParameters().host,
|
||||
systemRoot),
|
||||
QDateTime::currentDateTime());
|
||||
d->deployTimes.saveDeploymentTimeStamp(deployableFile, profile());
|
||||
}
|
||||
|
||||
bool AbstractRemoteLinuxDeployService::hasChangedSinceLastDeployment(const DeployableFile &deployableFile) const
|
||||
{
|
||||
if (!target())
|
||||
return true;
|
||||
QString systemRoot;
|
||||
if (SysRootKitInformation::hasSysRoot(d->kit))
|
||||
systemRoot = SysRootKitInformation::sysRoot(d->kit).toString();
|
||||
const QDateTime &lastDeployed = d->lastDeployed.value(DeployParameters(deployableFile,
|
||||
deviceConfiguration()->sshParameters().host, systemRoot));
|
||||
return !lastDeployed.isValid()
|
||||
|| deployableFile.localFilePath().toFileInfo().lastModified() > lastDeployed;
|
||||
return d->deployTimes.hasChangedSinceLastDeployment(deployableFile, profile());
|
||||
}
|
||||
|
||||
void AbstractRemoteLinuxDeployService::setTarget(Target *target)
|
||||
{
|
||||
d->target = target;
|
||||
if (target)
|
||||
d->kit = target->kit();
|
||||
else
|
||||
d->kit = 0;
|
||||
d->deviceConfiguration = DeviceKitInformation::device(d->kit);
|
||||
d->deviceConfiguration = DeviceKitInformation::device(profile());
|
||||
}
|
||||
|
||||
void AbstractRemoteLinuxDeployService::setDevice(const IDevice::ConstPtr &device)
|
||||
@@ -218,44 +172,12 @@ bool AbstractRemoteLinuxDeployService::isDeploymentPossible(QString *whyNot) con
|
||||
|
||||
QVariantMap AbstractRemoteLinuxDeployService::exportDeployTimes() const
|
||||
{
|
||||
QVariantMap map;
|
||||
QVariantList hostList;
|
||||
QVariantList fileList;
|
||||
QVariantList sysrootList;
|
||||
QVariantList remotePathList;
|
||||
QVariantList timeList;
|
||||
typedef QHash<DeployParameters, QDateTime>::ConstIterator DepIt;
|
||||
for (DepIt it = d->lastDeployed.constBegin(); it != d->lastDeployed.constEnd(); ++it) {
|
||||
fileList << it.key().file.localFilePath().toString();
|
||||
remotePathList << it.key().file.remoteDirectory();
|
||||
hostList << it.key().host;
|
||||
sysrootList << it.key().sysroot;
|
||||
timeList << it.value();
|
||||
}
|
||||
map.insert(QLatin1String(LastDeployedHostsKey), hostList);
|
||||
map.insert(QLatin1String(LastDeployedSysrootsKey), sysrootList);
|
||||
map.insert(QLatin1String(LastDeployedFilesKey), fileList);
|
||||
map.insert(QLatin1String(LastDeployedRemotePathsKey), remotePathList);
|
||||
map.insert(QLatin1String(LastDeployedTimesKey), timeList);
|
||||
return map;
|
||||
return d->deployTimes.exportDeployTimes();
|
||||
}
|
||||
|
||||
void AbstractRemoteLinuxDeployService::importDeployTimes(const QVariantMap &map)
|
||||
{
|
||||
const QVariantList &hostList = map.value(QLatin1String(LastDeployedHostsKey)).toList();
|
||||
const QVariantList &sysrootList = map.value(QLatin1String(LastDeployedSysrootsKey)).toList();
|
||||
const QVariantList &fileList = map.value(QLatin1String(LastDeployedFilesKey)).toList();
|
||||
const QVariantList &remotePathList
|
||||
= map.value(QLatin1String(LastDeployedRemotePathsKey)).toList();
|
||||
const QVariantList &timeList = map.value(QLatin1String(LastDeployedTimesKey)).toList();
|
||||
const int elemCount
|
||||
= qMin(qMin(qMin(hostList.size(), fileList.size()),
|
||||
qMin(remotePathList.size(), timeList.size())), sysrootList.size());
|
||||
for (int i = 0; i < elemCount; ++i) {
|
||||
const DeployableFile df(fileList.at(i).toString(), remotePathList.at(i).toString());
|
||||
d->lastDeployed.insert(DeployParameters(df, hostList.at(i).toString(),
|
||||
sysrootList.at(i).toString()), timeList.at(i).toDateTime());
|
||||
}
|
||||
d->deployTimes.importDeployTimes(map);
|
||||
}
|
||||
|
||||
void AbstractRemoteLinuxDeployService::handleDeviceSetupDone(bool success)
|
||||
|
168
src/plugins/remotelinux/deploymenttimeinfo.cpp
Normal file
168
src/plugins/remotelinux/deploymenttimeinfo.cpp
Normal file
@@ -0,0 +1,168 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 "deploymenttimeinfo.h"
|
||||
|
||||
#include <projectexplorer/deployablefile.h>
|
||||
#include <projectexplorer/target.h>
|
||||
#include <qtsupport/qtkitinformation.h>
|
||||
|
||||
#include <ssh/sshconnection.h>
|
||||
#include <ssh/sshconnectionmanager.h>
|
||||
|
||||
#include <QPointer>
|
||||
#include <QDateTime>
|
||||
#include <QFileInfo>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
using namespace QSsh;
|
||||
|
||||
namespace RemoteLinux {
|
||||
|
||||
namespace {
|
||||
const char LastDeployedHostsKey[] = "ProjectExplorer.RunConfiguration.LastDeployedHosts";
|
||||
const char LastDeployedSysrootsKey[] = "ProjectExplorer.RunConfiguration.LastDeployedSysroots";
|
||||
const char LastDeployedFilesKey[] = "ProjectExplorer.RunConfiguration.LastDeployedFiles";
|
||||
const char LastDeployedRemotePathsKey[] = "ProjectExplorer.RunConfiguration.LastDeployedRemotePaths";
|
||||
const char LastDeployedTimesKey[] = "ProjectExplorer.RunConfiguration.LastDeployedTimes";
|
||||
|
||||
class DeployParameters
|
||||
{
|
||||
|
||||
public:
|
||||
DeployParameters(const DeployableFile &d, const QString &h, const QString &s)
|
||||
: file(d), host(h), sysroot(s) {}
|
||||
|
||||
bool operator==(const DeployParameters &other) const {
|
||||
return file == other.file && host == other.host && sysroot == other.sysroot;
|
||||
}
|
||||
|
||||
DeployableFile file;
|
||||
QString host;
|
||||
QString sysroot;
|
||||
};
|
||||
|
||||
uint qHash(const DeployParameters &p) {
|
||||
return qHash(qMakePair(qMakePair(p.file, p.host), p.sysroot));
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
class DeploymentTimeInfoPrivate
|
||||
{
|
||||
public:
|
||||
QHash<DeployParameters, QDateTime> lastDeployed;
|
||||
};
|
||||
|
||||
|
||||
DeploymentTimeInfo::DeploymentTimeInfo() : d(new DeploymentTimeInfoPrivate())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DeploymentTimeInfo::saveDeploymentTimeStamp(const DeployableFile &deployableFile,
|
||||
const Kit *kit)
|
||||
{
|
||||
if (!kit)
|
||||
return;
|
||||
|
||||
QString systemRoot;
|
||||
if (SysRootKitInformation::hasSysRoot(kit))
|
||||
systemRoot = SysRootKitInformation::sysRoot(kit).toString();
|
||||
|
||||
const IDevice::ConstPtr deviceConfiguration = DeviceKitInformation::device(kit);
|
||||
const QString host = deviceConfiguration->sshParameters().host;
|
||||
|
||||
d->lastDeployed.insert(
|
||||
DeployParameters(deployableFile, host, systemRoot),
|
||||
QDateTime::currentDateTime());
|
||||
}
|
||||
|
||||
bool DeploymentTimeInfo::hasChangedSinceLastDeployment(const DeployableFile &deployableFile,
|
||||
const ProjectExplorer::Kit *kit) const
|
||||
{
|
||||
if (!kit)
|
||||
return false;
|
||||
|
||||
QString systemRoot;
|
||||
if (SysRootKitInformation::hasSysRoot(kit))
|
||||
systemRoot = SysRootKitInformation::sysRoot(kit).toString();
|
||||
|
||||
const IDevice::ConstPtr deviceConfiguration = DeviceKitInformation::device(kit);
|
||||
const QString host = deviceConfiguration->sshParameters().host;
|
||||
|
||||
const DeployParameters dp(deployableFile, host, systemRoot);
|
||||
|
||||
const QDateTime &lastDeployed = d->lastDeployed.value(dp);
|
||||
const QDateTime lastModified = deployableFile.localFilePath().toFileInfo().lastModified();
|
||||
|
||||
return !lastDeployed.isValid() || (lastModified > lastDeployed);
|
||||
}
|
||||
|
||||
QVariantMap DeploymentTimeInfo::exportDeployTimes() const
|
||||
{
|
||||
QVariantMap map;
|
||||
QVariantList hostList;
|
||||
QVariantList fileList;
|
||||
QVariantList sysrootList;
|
||||
QVariantList remotePathList;
|
||||
QVariantList timeList;
|
||||
typedef QHash<DeployParameters, QDateTime>::ConstIterator DepIt;
|
||||
|
||||
for (DepIt it = d->lastDeployed.constBegin(); it != d->lastDeployed.constEnd(); ++it) {
|
||||
fileList << it.key().file.localFilePath().toString();
|
||||
remotePathList << it.key().file.remoteDirectory();
|
||||
hostList << it.key().host;
|
||||
sysrootList << it.key().sysroot;
|
||||
timeList << it.value();
|
||||
}
|
||||
map.insert(QLatin1String(LastDeployedHostsKey), hostList);
|
||||
map.insert(QLatin1String(LastDeployedSysrootsKey), sysrootList);
|
||||
map.insert(QLatin1String(LastDeployedFilesKey), fileList);
|
||||
map.insert(QLatin1String(LastDeployedRemotePathsKey), remotePathList);
|
||||
map.insert(QLatin1String(LastDeployedTimesKey), timeList);
|
||||
return map;
|
||||
}
|
||||
|
||||
void DeploymentTimeInfo::importDeployTimes(const QVariantMap &map)
|
||||
{
|
||||
const QVariantList &hostList = map.value(QLatin1String(LastDeployedHostsKey)).toList();
|
||||
const QVariantList &sysrootList = map.value(QLatin1String(LastDeployedSysrootsKey)).toList();
|
||||
const QVariantList &fileList = map.value(QLatin1String(LastDeployedFilesKey)).toList();
|
||||
const QVariantList &remotePathList
|
||||
= map.value(QLatin1String(LastDeployedRemotePathsKey)).toList();
|
||||
const QVariantList &timeList = map.value(QLatin1String(LastDeployedTimesKey)).toList();
|
||||
|
||||
const int elemCount = qMin(qMin(qMin(hostList.size(), fileList.size()),
|
||||
qMin(remotePathList.size(), timeList.size())),
|
||||
sysrootList.size());
|
||||
|
||||
for (int i = 0; i < elemCount; ++i) {
|
||||
const DeployableFile df(fileList.at(i).toString(), remotePathList.at(i).toString());
|
||||
const DeployParameters dp(df, hostList.at(i).toString(), sysrootList.at(i).toString());
|
||||
d->lastDeployed.insert(dp, timeList.at(i).toDateTime());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace RemoteLinux
|
58
src/plugins/remotelinux/deploymenttimeinfo.h
Normal file
58
src/plugins/remotelinux/deploymenttimeinfo.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 <QVariantMap>
|
||||
#include <projectexplorer/devicesupport/idevice.h>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
class DeployableFile;
|
||||
class Kit;
|
||||
}
|
||||
|
||||
namespace RemoteLinux {
|
||||
|
||||
class DeploymentTimeInfoPrivate;
|
||||
|
||||
class DeploymentTimeInfo
|
||||
{
|
||||
public:
|
||||
DeploymentTimeInfo();
|
||||
|
||||
void importDeployTimes(const QVariantMap &map);
|
||||
QVariantMap exportDeployTimes() const;
|
||||
|
||||
void saveDeploymentTimeStamp(const ProjectExplorer::DeployableFile &deployableFile,
|
||||
const ProjectExplorer::Kit *kit);
|
||||
|
||||
bool hasChangedSinceLastDeployment(const ProjectExplorer::DeployableFile &deployableFile,
|
||||
const ProjectExplorer::Kit *kit) const;
|
||||
|
||||
private:
|
||||
DeploymentTimeInfoPrivate *d;
|
||||
};
|
||||
|
||||
} // namespace RemoteLinux
|
@@ -48,7 +48,8 @@ HEADERS += \
|
||||
abstractremotelinuxrunsupport.h \
|
||||
linuxdeviceprocess.h \
|
||||
remotelinuxcustomrunconfiguration.h \
|
||||
remotelinuxsignaloperation.h
|
||||
remotelinuxsignaloperation.h \
|
||||
deploymenttimeinfo.h
|
||||
|
||||
SOURCES += \
|
||||
embeddedlinuxqtversion.cpp \
|
||||
@@ -94,7 +95,8 @@ SOURCES += \
|
||||
abstractremotelinuxrunsupport.cpp \
|
||||
linuxdeviceprocess.cpp \
|
||||
remotelinuxcustomrunconfiguration.cpp \
|
||||
remotelinuxsignaloperation.cpp
|
||||
remotelinuxsignaloperation.cpp \
|
||||
deploymenttimeinfo.cpp
|
||||
|
||||
FORMS += \
|
||||
genericlinuxdeviceconfigurationwizardsetuppage.ui \
|
||||
|
@@ -27,6 +27,8 @@ Project {
|
||||
"abstractremotelinuxrunsupport.h",
|
||||
"abstractuploadandinstallpackageservice.cpp",
|
||||
"abstractuploadandinstallpackageservice.h",
|
||||
"deploymenttimeinfo.cpp",
|
||||
"deploymenttimeinfo.h",
|
||||
"embeddedlinuxqtversion.cpp",
|
||||
"embeddedlinuxqtversion.h",
|
||||
"embeddedlinuxqtversionfactory.cpp",
|
||||
|
Reference in New Issue
Block a user