Commit e72d41cb authored by Tobias Nätterlund's avatar Tobias Nätterlund Committed by Tobias Nätterlund
Browse files

QNX: Abort deployment if device is not in Development Mode



This adds a new deploy step (BlackBerryCheckDevModeStep), which
checks for Development Mode being set on the device. If not set,
the deployment stops early on in the process. Without this step,
the deployment would not fail until after uploading the package.

Moved blackberry-deploy into a constant, as it's used in
multiple places by now.

Change-Id: I813754108fb4be281e752b12ac56d4f0b302077d
Reviewed-by: default avatarMehdi Fekari <mfekari@rim.com>
Reviewed-by: default avatarRafael Roquetto <rafael.roquetto@kdab.com>
Reviewed-by: Nicolas Arnaud-Cormos's avatarNicolas Arnaud-Cormos <nicolas@kdab.com>
parent 3e373927
......@@ -32,7 +32,9 @@
#include "blackberryabstractdeploystep.h"
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/target.h>
#include <projectexplorer/task.h>
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
......@@ -176,6 +178,13 @@ void BlackBerryAbstractDeployStep::emitOutputInfo(const ProjectExplorer::Process
BuildStep::MessageOutput);
}
void BlackBerryAbstractDeployStep::raiseError(const QString &errorMessage)
{
emit addOutput(errorMessage, BuildStep::ErrorMessageOutput);
emit addTask(ProjectExplorer::Task(ProjectExplorer::Task::Error, errorMessage, Utils::FileName(), -1,
Core::Id(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM)));
}
void BlackBerryAbstractDeployStep::processReadyReadStdOutput()
{
m_process->setReadChannel(QProcess::StandardOutput);
......
......@@ -71,6 +71,8 @@ protected:
void emitOutputInfo(const ProjectExplorer::ProcessParameters &params, const QString& arguments);
void raiseError(const QString &errorMessage);
private slots:
void processReadyReadStdOutput();
void processReadyReadStdError();
......
......@@ -33,6 +33,7 @@
#include "blackberrydeployconfiguration.h"
#include "blackberryrunconfiguration.h"
#include "qnxconstants.h"
#include <projectexplorer/target.h>
#include <qt4projectmanager/qt4buildconfiguration.h>
......@@ -43,8 +44,6 @@
#include <QDir>
namespace {
const char DEPLOY_CMD[] = "blackberry-deploy";
qint64 parsePid(const QString &line)
{
QTC_ASSERT(line.startsWith(QLatin1String("result::")), return -1);
......@@ -103,7 +102,7 @@ BlackBerryApplicationRunner::BlackBerryApplicationRunner(bool debugMode, BlackBe
Target *target = runConfiguration->target();
BuildConfiguration *buildConfig = target->activeBuildConfiguration();
m_environment = buildConfig->environment();
m_deployCmd = m_environment.searchInPath(QLatin1String(DEPLOY_CMD));
m_deployCmd = m_environment.searchInPath(QLatin1String(Constants::QNX_BLACKBERRY_DEPLOY_CMD));
m_device = BlackBerryDeviceConfiguration::device(target->kit());
m_barPackage = runConfiguration->barPackage();
......
/**************************************************************************
**
** Copyright (C) 2011 - 2013 Research In Motion
**
** Contact: Research In Motion (blackberry-qt@qnx.com)
** Contact: KDAB (info@kdab.com)
**
** 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 Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, 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, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "blackberrycheckdevmodestep.h"
#include "blackberrycheckdevmodestepconfigwidget.h"
#include "blackberrydeviceconfiguration.h"
#include "qnxconstants.h"
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/target.h>
#include <ssh/sshconnection.h>
using namespace Qnx;
using namespace Qnx::Internal;
namespace {
const char ERROR_MESSAGE_START[] = "Error: ";
const char AUTHENTICATION_ERROR[] = "Authentication failed.";
}
BlackBerryCheckDevModeStep::BlackBerryCheckDevModeStep(ProjectExplorer::BuildStepList *bsl) :
BlackBerryAbstractDeployStep(bsl, Core::Id(Constants::QNX_CHECK_DEVELOPMENT_MODE_BS_ID))
{
setDisplayName(tr("Check Development Mode"));
}
BlackBerryCheckDevModeStep::BlackBerryCheckDevModeStep(ProjectExplorer::BuildStepList *bsl, BlackBerryCheckDevModeStep *bs) :
BlackBerryAbstractDeployStep(bsl, bs)
{
setDisplayName(tr("Check Development Mode"));
}
bool BlackBerryCheckDevModeStep::init()
{
if (!BlackBerryAbstractDeployStep::init())
return false;
QString deployCmd = target()->activeBuildConfiguration()->environment().searchInPath(QLatin1String(Constants::QNX_BLACKBERRY_DEPLOY_CMD));
if (deployCmd.isEmpty()) {
raiseError(tr("Could not find command '%1' in the build environment")
.arg(QLatin1String(Constants::QNX_BLACKBERRY_DEPLOY_CMD)));
return false;
}
BlackBerryDeviceConfiguration::ConstPtr device = BlackBerryDeviceConfiguration::device(target()->kit());
QString deviceHost = device ? device->sshParameters().host : QString();
if (deviceHost.isEmpty()) {
raiseError(tr("No hostname specified for device"));
return false;
}
QStringList args;
args << QLatin1String("-listDeviceInfo");
args << deviceHost;
if (!device->sshParameters().password.isEmpty()) {
args << QLatin1String("-password");
args << device->sshParameters().password;
}
addCommand(deployCmd, args);
return true;
}
ProjectExplorer::BuildStepConfigWidget *BlackBerryCheckDevModeStep::createConfigWidget()
{
return new BlackBerryCheckDevModeStepConfigWidget();
}
void BlackBerryCheckDevModeStep::stdOutput(const QString &line)
{
handleErrorOutput(line);
}
void BlackBerryCheckDevModeStep::stdError(const QString &line)
{
handleErrorOutput(line);
}
void BlackBerryCheckDevModeStep::handleErrorOutput(const QString &line)
{
if (line.startsWith(QLatin1String(ERROR_MESSAGE_START))) {
if (line.contains(QLatin1String(AUTHENTICATION_ERROR)))
raiseError(tr("Authentication failed. Please make sure the password for the device is correct."));
else
raiseError(line);
}
}
QString BlackBerryCheckDevModeStep::password() const
{
BlackBerryDeviceConfiguration::ConstPtr device = BlackBerryDeviceConfiguration::device(target()->kit());
return device ? device->sshParameters().password : QString();
}
void BlackBerryCheckDevModeStep::processStarted(const ProjectExplorer::ProcessParameters &params)
{
QString arguments = params.prettyArguments();
if (!password().isEmpty()) {
const QString passwordLine = QLatin1String(" -password ") + password();
const QString hiddenPasswordLine = QLatin1String(" -password <hidden>");
arguments.replace(passwordLine, hiddenPasswordLine);
}
emitOutputInfo(params, arguments);
}
/**************************************************************************
**
** Copyright (C) 2011 - 2013 Research In Motion
**
** Contact: Research In Motion (blackberry-qt@qnx.com)
** Contact: KDAB (info@kdab.com)
**
** 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 Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, 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, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef QNX_INTERNAL_BLACKBERRYCHECKDEVMODESTEP_H
#define QNX_INTERNAL_BLACKBERRYCHECKDEVMODESTEP_H
#include "blackberryabstractdeploystep.h"
namespace Qnx {
namespace Internal {
class BlackBerryCheckDevModeStep : public BlackBerryAbstractDeployStep
{
Q_OBJECT
friend class BlackBerryCheckDevModeStepFactory;
public:
explicit BlackBerryCheckDevModeStep(ProjectExplorer::BuildStepList *bsl);
bool init();
ProjectExplorer::BuildStepConfigWidget *createConfigWidget();
void stdOutput(const QString &line);
void stdError(const QString &line);
protected:
BlackBerryCheckDevModeStep(ProjectExplorer::BuildStepList *bsl, BlackBerryCheckDevModeStep *bs);
void processStarted(const ProjectExplorer::ProcessParameters &params);
private:
void handleErrorOutput(const QString &line);
QString password() const;
};
} // namespace Internal
} // namespace Qnx
#endif // QNX_INTERNAL_BLACKBERRYCHECKDEVMODESTEP_H
/**************************************************************************
**
** Copyright (C) 2011 - 2013 Research In Motion
**
** Contact: Research In Motion (blackberry-qt@qnx.com)
** Contact: KDAB (info@kdab.com)
**
** 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 Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, 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, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "blackberrycheckdevmodestepconfigwidget.h"
using namespace Qnx;
using namespace Qnx::Internal;
BlackBerryCheckDevModeStepConfigWidget::BlackBerryCheckDevModeStepConfigWidget() :
ProjectExplorer::BuildStepConfigWidget()
{
}
QString BlackBerryCheckDevModeStepConfigWidget::displayName() const
{
return tr("<b>Check development mode</b>");
}
QString BlackBerryCheckDevModeStepConfigWidget::summaryText() const
{
return displayName();
}
bool BlackBerryCheckDevModeStepConfigWidget::showWidget() const
{
return false;
}
/**************************************************************************
**
** Copyright (C) 2011 - 2013 Research In Motion
**
** Contact: Research In Motion (blackberry-qt@qnx.com)
** Contact: KDAB (info@kdab.com)
**
** 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 Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, 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, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef QNX_INTERNAL_BLACKBERRYCHECKDEVMODESTEPCONFIGWIDGET_H
#define QNX_INTERNAL_BLACKBERRYCHECKDEVMODESTEPCONFIGWIDGET_H
#include <projectexplorer/buildstep.h>
namespace Qnx {
namespace Internal {
class BlackBerryCheckDevModeStepConfigWidget : public ProjectExplorer::BuildStepConfigWidget
{
Q_OBJECT
public:
explicit BlackBerryCheckDevModeStepConfigWidget();
QString displayName() const;
QString summaryText() const;
bool showWidget() const;
};
} // namespace Internal
} // namespace Qnx
#endif // QNX_INTERNAL_BLACKBERRYCHECKDEVMODESTEPCONFIGWIDGET_H
/**************************************************************************
**
** Copyright (C) 2011 - 2013 Research In Motion
**
** Contact: Research In Motion (blackberry-qt@qnx.com)
** Contact: KDAB (info@kdab.com)
**
** 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 Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, 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, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "blackberrycheckdevmodestepfactory.h"
#include "blackberrycheckdevmodestep.h"
#include "blackberrydeviceconfigurationfactory.h"
#include "qnxconstants.h"
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/target.h>
using namespace Qnx;
using namespace Qnx::Internal;
BlackBerryCheckDevModeStepFactory::BlackBerryCheckDevModeStepFactory(QObject *parent) :
ProjectExplorer::IBuildStepFactory(parent)
{
}
QList<Core::Id> BlackBerryCheckDevModeStepFactory::availableCreationIds(ProjectExplorer::BuildStepList *parent) const
{
if (parent->id() != ProjectExplorer::Constants::BUILDSTEPS_DEPLOY)
return QList<Core::Id>();
Core::Id deviceType = ProjectExplorer::DeviceTypeKitInformation::deviceTypeId(parent->target()->kit());
if (deviceType != BlackBerryDeviceConfigurationFactory::deviceType())
return QList<Core::Id>();
return QList<Core::Id>() << Core::Id(Constants::QNX_CHECK_DEVELOPMENT_MODE_BS_ID);
}
QString BlackBerryCheckDevModeStepFactory::displayNameForId(const Core::Id id) const
{
if (id == Constants::QNX_CHECK_DEVELOPMENT_MODE_BS_ID)
return tr("Check Development Mode");
return QString();
}
bool BlackBerryCheckDevModeStepFactory::canCreate(ProjectExplorer::BuildStepList *parent, const Core::Id id) const
{
return availableCreationIds(parent).contains(id);
}
ProjectExplorer::BuildStep *BlackBerryCheckDevModeStepFactory::create(ProjectExplorer::BuildStepList *parent, const Core::Id id)
{
if (!canCreate(parent, id))
return 0;
return new BlackBerryCheckDevModeStep(parent);
}
bool BlackBerryCheckDevModeStepFactory::canRestore(ProjectExplorer::BuildStepList *parent, const QVariantMap &map) const
{
return canCreate(parent, ProjectExplorer::idFromMap(map));
}
ProjectExplorer::BuildStep *BlackBerryCheckDevModeStepFactory::restore(ProjectExplorer::BuildStepList *parent, const QVariantMap &map)
{
if (!canRestore(parent, map))
return 0;
BlackBerryCheckDevModeStep *bs = new BlackBerryCheckDevModeStep(parent);
if (bs->fromMap(map))
return bs;
delete bs;
return 0;
}
bool BlackBerryCheckDevModeStepFactory::canClone(ProjectExplorer::BuildStepList *parent, ProjectExplorer::BuildStep *product) const
{
return canCreate(parent, product->id());
}
ProjectExplorer::BuildStep *BlackBerryCheckDevModeStepFactory::clone(ProjectExplorer::BuildStepList *parent, ProjectExplorer::BuildStep *product)
{
if (!canClone(parent, product))
return 0;
return new BlackBerryCheckDevModeStep(parent, static_cast<BlackBerryCheckDevModeStep *>(product));
}
/**************************************************************************
**
** Copyright (C) 2011 - 2013 Research In Motion
**
** Contact: Research In Motion (blackberry-qt@qnx.com)
** Contact: KDAB (info@kdab.com)
**
** 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 Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, 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, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef QNX_INTERNAL_BLACKBERRYCHECKDEVMODESTEPFACTORY_H
#define QNX_INTERNAL_BLACKBERRYCHECKDEVMODESTEPFACTORY_H
#include <projectexplorer/buildstep.h>
namespace Qnx {
namespace Internal {
class BlackBerryCheckDevModeStepFactory : public ProjectExplorer::IBuildStepFactory
{
Q_OBJECT
public:
explicit BlackBerryCheckDevModeStepFactory(QObject *parent = 0);
QList<Core::Id> availableCreationIds(ProjectExplorer::BuildStepList *parent) const;
QString displayNameForId(const Core::Id id) const;
bool canCreate(ProjectExplorer::BuildStepList *parent, const Core::Id id) const;
ProjectExplorer::BuildStep *create(ProjectExplorer::BuildStepList *parent, const Core::Id id);
bool canRestore(ProjectExplorer::BuildStepList *parent, const QVariantMap &map) const;
ProjectExplorer::BuildStep *restore(ProjectExplorer::BuildStepList *parent,
const QVariantMap &map);
bool canClone(ProjectExplorer::BuildStepList *parent, ProjectExplorer::BuildStep *product) const;
ProjectExplorer::BuildStep *clone(ProjectExplorer::BuildStepList *parent,
ProjectExplorer::BuildStep *product);
};
} // namespace Internal
} // namespace Qnx
#endif // QNX_INTERNAL_BLACKBERRYCHECKDEVMODESTEPFACTORY_H
......@@ -153,13 +153,6 @@ QString BlackBerryCreatePackageStep::debugToken() const
return device->debugToken();
}
void BlackBerryCreatePackageStep::raiseError(const QString &errorMessage)
{
emit addOutput(errorMessage, BuildStep::ErrorMessageOutput);
emit addTask(ProjectExplorer::Task(ProjectExplorer::Task::Error, errorMessage, Utils::FileName(), -1,
Core::Id(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM)));
}
bool BlackBerryCreatePackageStep::prepareAppDescriptorFile(const QString &appDescriptorPath, const QString &preparedFilePath)
{
BlackBerryQtVersion *qtVersion = dynamic_cast<BlackBerryQtVersion *>(QtSupport::QtKitInformation::qtVersion(target()->kit()));
......
......@@ -57,8 +57,6 @@ public:
protected:
BlackBerryCreatePackageStep(ProjectExplorer::BuildStepList *bsl, BlackBerryCreatePackageStep *bs);
void raiseError(const QString &errorMessage);
private:
bool prepareAppDescriptorFile(const QString &appDescriptorPath, const QString &preparedFilePath);
};
......
......@@ -31,8 +31,9 @@
#include "blackberrydebugtokenuploader.h"
#include "qnxconstants.h"
namespace {
static const char PROCESS_NAME[] = "blackberry-deploy";
static const char ERR_NO_ROUTE_HOST[] = "Cannot connect";
static const char ERR_AUTH_FAILED[] = "Authentication failed";
static const char ERR_DEVELOPMENT_MODE_DISABLED[] = "Device is not in the Development Mode";
......@@ -42,7 +43,7 @@ namespace Qnx {
namespace Internal {
BlackBerryDebugTokenUploader::BlackBerryDebugTokenUploader(QObject *parent) :
BlackBerryNdkProcess(QLatin1String(PROCESS_NAME), parent)
BlackBerryNdkProcess(QLatin1String(Constants::QNX_BLACKBERRY_DEPLOY_CMD), parent)
{
addErrorStringMapping(QLatin1String(ERR_NO_ROUTE_HOST), NoRouteToHost);