Commit 1656335e authored by Christian Kandeler's avatar Christian Kandeler
Browse files

RemoteLinux: Remove Maemo dependency from generic package installation.

Change-Id: I3c62fe77656fed22b4de287430b0b13190e274a9
Reviewed-on: http://codereview.qt.nokia.com/1839

Reviewed-by: default avatarChristian Kandeler <christian.kandeler@nokia.com>
parent 410d5bd0
......@@ -33,9 +33,8 @@
#include "deployablefile.h"
#include "linuxdeviceconfiguration.h"
#include "maemopackagecreationstep.h"
#include "maemopackageinstaller.h"
#include "maemopackageuploader.h"
#include "remotelinuxpackageinstaller.h"
#include <utils/qtcassert.h>
#include <utils/ssh/sshconnection.h>
......@@ -163,7 +162,7 @@ void AbstractUploadAndInstallPackageService::handleUploadFinished(const QString
connect(packageInstaller(), SIGNAL(stderrData(QString)), SIGNAL(stdErrData(QString)));
connect(packageInstaller(), SIGNAL(finished(QString)),
SLOT(handleInstallationFinished(QString)));
packageInstaller()->installPackage(connection(), deviceConfiguration(), remoteFilePath, true);
packageInstaller()->installPackage(connection(), remoteFilePath, true);
}
void AbstractUploadAndInstallPackageService::handleInstallationFinished(const QString &errorMsg)
......
......@@ -36,8 +36,9 @@
#include "remotelinux_export.h"
namespace RemoteLinux {
class AbstractRemoteLinuxPackageInstaller;
namespace Internal {
class AbstractMaemoPackageInstaller;
class AbstractUploadAndInstallPackageServicePrivate;
}
......@@ -59,7 +60,7 @@ private slots:
void handleInstallationFinished(const QString &errorMsg);
private:
virtual Internal::AbstractMaemoPackageInstaller *packageInstaller() const=0;
virtual AbstractRemoteLinuxPackageInstaller *packageInstaller() const=0;
virtual QString uploadDir() const; // Defaults to remote user's home directory.
bool isDeploymentNecessary() const;
......
......@@ -94,7 +94,7 @@ public:
{
}
AbstractMaemoPackageInstaller *packageInstaller() const { return m_installer; }
AbstractRemoteLinuxPackageInstaller *packageInstaller() const { return m_installer; }
private:
MaemoDebianPackageInstaller * const m_installer;
......@@ -111,7 +111,7 @@ public:
{
}
AbstractMaemoPackageInstaller *packageInstaller() const { return m_installer; }
AbstractRemoteLinuxPackageInstaller *packageInstaller() const { return m_installer; }
private:
MaemoRpmPackageInstaller * const m_installer;
......
......@@ -307,7 +307,7 @@ void MaemoMountAndInstallPackageService::doInstall()
{
const QString remoteFilePath = deployMountPoint() + QLatin1Char('/')
+ QFileInfo(m_packageFilePath).fileName();
m_installer->installPackage(connection(), deviceConfiguration(), remoteFilePath, false);
m_installer->installPackage(connection(), remoteFilePath, false);
}
void MaemoMountAndInstallPackageService::cancelInstallation()
......
......@@ -43,7 +43,6 @@
#include <qt4projectmanager/qt4target.h>
#include <utils/environment.h>
#include <QtCore/QDateTime>
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
#include <QtCore/QProcess>
......
......@@ -50,7 +50,6 @@
MaemoGlobal::assertState<State>(expected, actual, Q_FUNC_INFO)
QT_BEGIN_NAMESPACE
class QDateTime;
class QProcess;
class QString;
QT_END_NAMESPACE
......
......@@ -34,113 +34,13 @@
#include "maemoglobal.h"
#include <utils/ssh/sshconnection.h>
#include <utils/ssh/sshremoteprocessrunner.h>
using namespace Utils;
namespace RemoteLinux {
namespace Internal {
AbstractMaemoPackageInstaller::AbstractMaemoPackageInstaller(QObject *parent)
: QObject(parent), m_isRunning(false)
{
}
AbstractMaemoPackageInstaller::~AbstractMaemoPackageInstaller() {}
void AbstractMaemoPackageInstaller::installPackage(const SshConnection::Ptr &connection,
const LinuxDeviceConfiguration::ConstPtr &devConf, const QString &packageFilePath,
bool removePackageFile)
{
Q_ASSERT(connection && connection->state() == SshConnection::Connected);
Q_ASSERT(!m_isRunning);
prepareInstallation();
m_installer = SshRemoteProcessRunner::create(connection);
connect(m_installer.data(), SIGNAL(connectionError(Utils::SshError)),
SLOT(handleConnectionError()));
connect(m_installer.data(), SIGNAL(processOutputAvailable(QByteArray)),
SLOT(handleInstallerOutput(QByteArray)));
connect(m_installer.data(), SIGNAL(processErrorOutputAvailable(QByteArray)),
SLOT(handleInstallerErrorOutput(QByteArray)));
connect(m_installer.data(), SIGNAL(processClosed(int)),
SLOT(handleInstallationFinished(int)));
const QString space = QLatin1String(" ");
QString cmdLine = QLatin1String("cd ") + workingDirectory()
+ QLatin1String(" && ")
+ MaemoGlobal::remoteSudo(devConf->osType(),
m_installer->connection()->connectionParameters().userName)
+ space + installCommand()
+ space + installCommandArguments().join(space) + space
+ packageFilePath;
if (removePackageFile) {
cmdLine += QLatin1String(" && (rm ") + packageFilePath
+ QLatin1String(" || :)");
}
m_installer->run(cmdLine.toUtf8());
m_isRunning = true;
}
void AbstractMaemoPackageInstaller::cancelInstallation()
{
Q_ASSERT(m_isRunning);
const SshRemoteProcessRunner::Ptr killProcess
= SshRemoteProcessRunner::create(m_installer->connection());
killProcess->run("pkill " + installCommand().toUtf8());
setFinished();
}
void AbstractMaemoPackageInstaller::handleConnectionError()
{
if (!m_isRunning)
return;
emit finished(tr("Connection failure: %1")
.arg(m_installer->connection()->errorString()));
setFinished();
}
void AbstractMaemoPackageInstaller::handleInstallationFinished(int exitStatus)
{
if (!m_isRunning)
return;
if (exitStatus != SshRemoteProcess::ExitedNormally
|| m_installer->process()->exitCode() != 0) {
emit finished(tr("Installing package failed."));
} else if (!errorString().isEmpty()) {
emit finished(errorString());
} else {
emit finished();
}
setFinished();
}
void AbstractMaemoPackageInstaller::handleInstallerOutput(const QByteArray &output)
{
emit stdoutData(QString::fromUtf8(output));
}
void AbstractMaemoPackageInstaller::handleInstallerErrorOutput(const QByteArray &output)
{
emit stderrData(QString::fromUtf8(output));
}
void AbstractMaemoPackageInstaller::setFinished()
{
disconnect(m_installer.data(), 0, this, 0);
m_installer.clear();
m_isRunning = false;
}
MaemoDebianPackageInstaller::MaemoDebianPackageInstaller(QObject *parent)
: AbstractMaemoPackageInstaller(parent)
: AbstractRemoteLinuxPackageInstaller(parent)
{
connect(this, SIGNAL(stderrData(QString)),
SLOT(handleInstallerErrorOutput(QString)));
connect(this, SIGNAL(stderrData(QString)), SLOT(handleInstallerErrorOutput(QString)));
}
void MaemoDebianPackageInstaller::prepareInstallation()
......@@ -148,15 +48,15 @@ void MaemoDebianPackageInstaller::prepareInstallation()
m_installerStderr.clear();
}
QString MaemoDebianPackageInstaller::installCommand() const
QString MaemoDebianPackageInstaller::installCommandLine(const QString &packageFilePath) const
{
return QLatin1String("dpkg");
return MaemoGlobal::devrootshPath() + QLatin1String(" dpkg -i --no-force-downgrade ")
+ packageFilePath;
}
QStringList MaemoDebianPackageInstaller::installCommandArguments() const
QString MaemoDebianPackageInstaller::cancelInstallationCommandLine() const
{
return QStringList() << QLatin1String("-i")
<< QLatin1String("--no-force-downgrade");
return QLatin1String("pkill dpkg");
}
void MaemoDebianPackageInstaller::handleInstallerErrorOutput(const QString &output)
......@@ -176,16 +76,11 @@ QString MaemoDebianPackageInstaller::errorString() const
MaemoRpmPackageInstaller::MaemoRpmPackageInstaller(QObject *parent)
: AbstractMaemoPackageInstaller(parent)
{
}
QString MaemoRpmPackageInstaller::installCommand() const
: AbstractRemoteLinuxPackageInstaller(parent)
{
return QLatin1String("rpm");
}
QStringList MaemoRpmPackageInstaller::installCommandArguments() const
QString MaemoRpmPackageInstaller::installCommandLine(const QString &packageFilePath) const
{
// rpm -U does not allow to re-install a package with the same version
// number, so we need --replacepkgs. Even then, it inexplicably reports
......@@ -193,23 +88,13 @@ QStringList MaemoRpmPackageInstaller::installCommandArguments() const
// so we need --replacefiles as well.
// TODO: --replacefiles is dangerous. Is there perhaps a way around it
// after all?
return QStringList() << QLatin1String("-Uhv") << QLatin1String("--replacepkgs") << QLatin1String("--replacefiles");
}
MaemoTarPackageInstaller::MaemoTarPackageInstaller(QObject *parent)
: AbstractMaemoPackageInstaller(parent)
{
}
QString MaemoTarPackageInstaller::installCommand() const
{
return QLatin1String("tar");
return MaemoGlobal::devrootshPath() + QLatin1String(" rpm -Uhv --replacepkgs --replacefiles ")
+ packageFilePath;
}
QStringList MaemoTarPackageInstaller::installCommandArguments() const
QString MaemoRpmPackageInstaller::cancelInstallationCommandLine() const
{
return QStringList() << QLatin1String("xvf");
return QLatin1String("pkill rpm");
}
} // namespace Internal
......
......@@ -33,103 +33,41 @@
#ifndef ABSTRACTMAEMOPACKAGEINSTALLER_H
#define ABSTRACTMAEMOPACKAGEINSTALLER_H
namespace Utils {
class SshConnection;
class SshRemoteProcessRunner;
}
#include <QtCore/QObject>
#include <QtCore/QSharedPointer>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <remotelinux/remotelinuxpackageinstaller.h>
namespace RemoteLinux {
class LinuxDeviceConfiguration;
namespace Internal {
class AbstractMaemoPackageInstaller : public QObject
{
Q_OBJECT
public:
~AbstractMaemoPackageInstaller();
void installPackage(const QSharedPointer<Utils::SshConnection> &connection,
const QSharedPointer<const LinuxDeviceConfiguration> &devConfig,
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 AbstractMaemoPackageInstaller(QObject *parent = 0);
bool isRunning() const { return m_isRunning; }
private slots:
void handleConnectionError();
void handleInstallationFinished(int exitStatus);
void handleInstallerOutput(const QByteArray &output);
void handleInstallerErrorOutput(const QByteArray &output);
private:
virtual void prepareInstallation() {}
virtual QString workingDirectory() const { return QLatin1String("/tmp"); }
virtual QString installCommand() const=0;
virtual QStringList installCommandArguments() const=0;
virtual QString errorString() const { return QString(); }
void setFinished();
bool m_isRunning;
QSharedPointer<Utils::SshRemoteProcessRunner> m_installer;
};
class MaemoDebianPackageInstaller: public AbstractMaemoPackageInstaller
class MaemoDebianPackageInstaller: public RemoteLinux::AbstractRemoteLinuxPackageInstaller
{
Q_OBJECT
public:
explicit MaemoDebianPackageInstaller(QObject *parent);
private slots:
virtual void prepareInstallation();
virtual QString installCommand() const;
virtual QStringList installCommandArguments() const;
virtual QString errorString() const;
void handleInstallerErrorOutput(const QString &output);
private:
void prepareInstallation();
QString errorString() const;
QString installCommandLine(const QString &packageFilePath) const;
QString cancelInstallationCommandLine() const;
QString m_installerStderr;
};
class MaemoRpmPackageInstaller : public AbstractMaemoPackageInstaller
class MaemoRpmPackageInstaller : public RemoteLinux::AbstractRemoteLinuxPackageInstaller
{
Q_OBJECT
public:
MaemoRpmPackageInstaller(QObject *parent);
private:
virtual QString installCommand() const;
virtual QStringList installCommandArguments() const;
QString installCommandLine(const QString &packageFilePath) const;
QString cancelInstallationCommandLine() const;
};
class MaemoTarPackageInstaller : public AbstractMaemoPackageInstaller
{
Q_OBJECT
public:
MaemoTarPackageInstaller(QObject *parent = 0);
private:
virtual QString installCommand() const;
virtual QStringList installCommandArguments() const;
virtual QString workingDirectory() const { return QLatin1String("/"); }
};
} // namespace Internal
} // namespace RemoteLinux
......
......@@ -91,7 +91,8 @@ HEADERS += \
remotelinuxdeployconfigurationfactory.h \
genericremotelinuxdeploystepfactory.h \
abstractpackagingstep.h \
tarpackagecreationstep.h
tarpackagecreationstep.h \
remotelinuxpackageinstaller.h
SOURCES += \
remotelinuxplugin.cpp \
......@@ -176,7 +177,8 @@ SOURCES += \
remotelinuxdeployconfigurationfactory.cpp \
genericremotelinuxdeploystepfactory.cpp \
abstractpackagingstep.cpp \
tarpackagecreationstep.cpp
tarpackagecreationstep.cpp \
remotelinuxpackageinstaller.cpp
FORMS += \
maemoconfigtestdialog.ui \
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#include "remotelinuxpackageinstaller.h"
#include <QtCore/QByteArray>
#include <utils/qtcassert.h>
#include <utils/ssh/sshconnection.h>
#include <utils/ssh/sshremoteprocessrunner.h>
using namespace Utils;
namespace RemoteLinux {
namespace Internal {
class AbstractRemoteLinuxPackageInstallerPrivate
{
public:
AbstractRemoteLinuxPackageInstallerPrivate() : isRunning(false) {}
bool isRunning;
Utils::SshRemoteProcessRunner::Ptr installer;
};
} // namespace Internal
AbstractRemoteLinuxPackageInstaller::AbstractRemoteLinuxPackageInstaller(QObject *parent)
: QObject(parent), m_d(new Internal::AbstractRemoteLinuxPackageInstallerPrivate)
{
}
AbstractRemoteLinuxPackageInstaller::~AbstractRemoteLinuxPackageInstaller()
{
delete m_d;
}
void AbstractRemoteLinuxPackageInstaller::installPackage(const SshConnection::Ptr &connection,
const QString &packageFilePath, bool removePackageFile)
{
QTC_ASSERT(connection && connection->state() == SshConnection::Connected
&& !m_d->isRunning, return);
prepareInstallation();
m_d->installer = SshRemoteProcessRunner::create(connection);
connect(m_d->installer.data(), SIGNAL(connectionError(Utils::SshError)),
SLOT(handleConnectionError()));
connect(m_d->installer.data(), SIGNAL(processOutputAvailable(QByteArray)),
SLOT(handleInstallerOutput(QByteArray)));
connect(m_d->installer.data(), SIGNAL(processErrorOutputAvailable(QByteArray)),
SLOT(handleInstallerErrorOutput(QByteArray)));
connect(m_d->installer.data(), SIGNAL(processClosed(int)), SLOT(handleInstallationFinished(int)));
QString cmdLine = installCommandLine(packageFilePath);
if (removePackageFile)
cmdLine += QLatin1String(" && (rm ") + packageFilePath + QLatin1String(" || :)");
m_d->installer->run(cmdLine.toUtf8());
m_d->isRunning = true;
}
void AbstractRemoteLinuxPackageInstaller::cancelInstallation()
{
QTC_ASSERT(m_d->installer && m_d->installer->connection()->state() == SshConnection::Connected
&& m_d->isRunning, return);
const SshRemoteProcessRunner::Ptr killProcess
= SshRemoteProcessRunner::create(m_d->installer->connection());
killProcess->run(cancelInstallationCommandLine().toUtf8());
setFinished();
}
void AbstractRemoteLinuxPackageInstaller::handleConnectionError()
{
if (!m_d->isRunning)
return;
emit finished(tr("Connection failure: %1").arg(m_d->installer->connection()->errorString()));
setFinished();
}
void AbstractRemoteLinuxPackageInstaller::handleInstallationFinished(int exitStatus)
{
if (!m_d->isRunning)
return;
if (exitStatus != SshRemoteProcess::ExitedNormally
|| m_d->installer->process()->exitCode() != 0) {
emit finished(tr("Installing package failed."));
} else if (!errorString().isEmpty()) {
emit finished(errorString());
} else {
emit finished();
}
setFinished();
}
void AbstractRemoteLinuxPackageInstaller::handleInstallerOutput(const QByteArray &output)
{
emit stdoutData(QString::fromUtf8(output));
}
void AbstractRemoteLinuxPackageInstaller::handleInstallerErrorOutput(const QByteArray &output)
{
emit stderrData(QString::fromUtf8(output));
}
void AbstractRemoteLinuxPackageInstaller::setFinished()
{
disconnect(m_d->installer.data(), 0, this, 0);
m_d->installer.clear();
m_d->isRunning = false;
}
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
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#ifndef REMOTELINUXPACKAGEINSTALLER_H
#define REMOTELINUXPACKAGEINSTALLER_H