diff --git a/src/plugins/qnx/blackberryabstractdeploystep.cpp b/src/plugins/qnx/blackberryabstractdeploystep.cpp index 2eab527a861d125ecac30c28eca072724809c4b3..8b4b0252b30a2742ca5ab002c1c918687587e0d6 100644 --- a/src/plugins/qnx/blackberryabstractdeploystep.cpp +++ b/src/plugins/qnx/blackberryabstractdeploystep.cpp @@ -53,6 +53,8 @@ BlackBerryAbstractDeployStep::BlackBerryAbstractDeployStep(ProjectExplorer::Buil , m_futureInterface(0) , m_eventLoop(0) { + connect(&m_outputParser, SIGNAL(addTask(ProjectExplorer::Task)), this, SIGNAL(addTask(ProjectExplorer::Task))); + connect(&m_outputParser, SIGNAL(progressParsed(int)), this, SLOT(reportProgress(int))); } BlackBerryAbstractDeployStep::BlackBerryAbstractDeployStep(ProjectExplorer::BuildStepList *bsl, BlackBerryAbstractDeployStep *bs) @@ -63,6 +65,8 @@ BlackBerryAbstractDeployStep::BlackBerryAbstractDeployStep(ProjectExplorer::Buil , m_futureInterface(0) , m_eventLoop(0) { + connect(&m_outputParser, SIGNAL(addTask(ProjectExplorer::Task)), this, SIGNAL(addTask(ProjectExplorer::Task))); + connect(&m_outputParser, SIGNAL(progressParsed(int)), this, SLOT(reportProgress(int))); } BlackBerryAbstractDeployStep::~BlackBerryAbstractDeployStep() @@ -196,6 +200,7 @@ void BlackBerryAbstractDeployStep::processReadyReadStdOutput() void BlackBerryAbstractDeployStep::stdOutput(const QString &line) { + m_outputParser.stdOutput(line); emit addOutput(line, BuildStep::NormalOutput, BuildStep::DontAppendNewline); } @@ -238,5 +243,6 @@ void BlackBerryAbstractDeployStep::handleProcessFinished(int exitCode, QProcess: void BlackBerryAbstractDeployStep::stdError(const QString &line) { + m_outputParser.stdError(line); emit addOutput(line, BuildStep::ErrorOutput, BuildStep::DontAppendNewline); } diff --git a/src/plugins/qnx/blackberryabstractdeploystep.h b/src/plugins/qnx/blackberryabstractdeploystep.h index 5f8da4a53eb3717243369ef2ccd2b9adfceb7f7f..1f3cfb3e75dfb42c3c40ec7ec4ab11998a9d0110 100644 --- a/src/plugins/qnx/blackberryabstractdeploystep.h +++ b/src/plugins/qnx/blackberryabstractdeploystep.h @@ -32,6 +32,8 @@ #ifndef QNX_INTERNAL_BLACKBERRYABSTRACTDEPLOYSTEP_H #define QNX_INTERNAL_BLACKBERRYABSTRACTDEPLOYSTEP_H +#include "blackberryprocessparser.h" + #include <projectexplorer/buildstep.h> #include <projectexplorer/processparameters.h> @@ -62,7 +64,6 @@ protected: BlackBerryAbstractDeployStep(ProjectExplorer::BuildStepList *bsl, BlackBerryAbstractDeployStep *bs); void addCommand(const QString &command, const QStringList &arguments); - void reportProgress(int progress); virtual void stdOutput(const QString &line); virtual void stdError(const QString &line); @@ -74,6 +75,8 @@ protected: void raiseError(const QString &errorMessage); private slots: + void reportProgress(int progress); + void processReadyReadStdOutput(); void processReadyReadStdError(); @@ -97,6 +100,8 @@ private: QTimer *m_timer; QFutureInterface<bool> *m_futureInterface; QEventLoop *m_eventLoop; + + BlackBerryProcessParser m_outputParser; }; } // namespace Internal diff --git a/src/plugins/qnx/blackberryapplicationrunner.cpp b/src/plugins/qnx/blackberryapplicationrunner.cpp index c51895747a01d22ed891e7c00b34d49b334ccd23..1943a0374e37c5e2cb01b151096fcfc7f6051ce7 100644 --- a/src/plugins/qnx/blackberryapplicationrunner.cpp +++ b/src/plugins/qnx/blackberryapplicationrunner.cpp @@ -44,31 +44,6 @@ #include <QDir> namespace { -qint64 parsePid(const QString &line) -{ - QTC_ASSERT(line.startsWith(QLatin1String("result::")), return -1); - - int pidIndex = -1; - if (line.contains(QLatin1String("running"))) // "result::running,<pid>" - pidIndex = 16; - else // "result::<pid>" - pidIndex = 8; - - bool ok; - const qint64 pid = line.mid(pidIndex).toInt(&ok); - if (!ok) - return -1; - return pid; -} - -QString parseAppId(const QString &line) -{ - QTC_ASSERT(line.startsWith(QLatin1String("Info: Launching")), return QString()); - - const int endOfId = line.indexOf(QLatin1String("...")); - return line.mid(16, endOfId - 16); -} - bool parseRunningState(const QString &line) { QTC_ASSERT(line.startsWith(QLatin1String("result::")), return false); @@ -115,6 +90,9 @@ BlackBerryApplicationRunner::BlackBerryApplicationRunner(bool debugMode, BlackBe m_runningStateTimer->setSingleShot(true); connect(m_runningStateTimer, SIGNAL(timeout()), this, SLOT(determineRunningState())); connect(this, SIGNAL(started()), this, SLOT(checkSlog2Info())); + + connect(&m_launchStopProcessParser, SIGNAL(pidParsed(qint64)), this, SLOT(setPid(qint64))); + connect(&m_launchStopProcessParser, SIGNAL(applicationIdParsed(QString)), this, SLOT(setApplicationId(QString))); } void BlackBerryApplicationRunner::start() @@ -229,12 +207,8 @@ void BlackBerryApplicationRunner::readStandardOutput() process->setReadChannel(QProcess::StandardOutput); while (process->canReadLine()) { QString line = QString::fromLocal8Bit(process->readLine()); + m_launchStopProcessParser.stdOutput(line); emit output(line, Utils::StdOutFormat); - - if (line.startsWith(QLatin1String("result::"))) - m_pid = parsePid(line); - else if (line.startsWith(QLatin1String("Info: Launching"))) - m_appId = parseAppId(line); } } @@ -244,6 +218,7 @@ void BlackBerryApplicationRunner::readStandardError() process->setReadChannel(QProcess::StandardError); while (process->canReadLine()) { const QString line = QString::fromLocal8Bit(process->readLine()); + m_launchStopProcessParser.stdError(line); emit output(line, Utils::StdErrFormat); } } @@ -318,6 +293,16 @@ void BlackBerryApplicationRunner::readLaunchTime() m_launchDateTimeProcess->run("date +\"%d %H:%M:%S\"", m_sshParams); } +void BlackBerryApplicationRunner::setPid(qint64 pid) +{ + m_pid = pid; +} + +void BlackBerryApplicationRunner::setApplicationId(const QString &applicationId) +{ + m_appId = applicationId; +} + void BlackBerryApplicationRunner::handleTailOutput() { QSsh::SshRemoteProcessRunner *process = qobject_cast<QSsh::SshRemoteProcessRunner *>(sender()); diff --git a/src/plugins/qnx/blackberryapplicationrunner.h b/src/plugins/qnx/blackberryapplicationrunner.h index c6c3929b74e84ccc685759469eb89ee419832631..3b8eec9097e91b1d2d5157d46d19efc34336578c 100644 --- a/src/plugins/qnx/blackberryapplicationrunner.h +++ b/src/plugins/qnx/blackberryapplicationrunner.h @@ -33,6 +33,7 @@ #define QNX_INTERNAL_BLACKBERRYAPPLICATIONRUNNER_H #include "blackberrydeviceconfiguration.h" +#include "blackberryprocessparser.h" #include <projectexplorer/runconfiguration.h> @@ -94,6 +95,9 @@ private slots: void handleSlog2InfoFound(); void readLaunchTime(); + void setPid(qint64 pid); + void setApplicationId(const QString &applicationId); + private: void reset(); void killTailProcess(); @@ -118,6 +122,8 @@ private: QProcess *m_launchProcess; QProcess *m_stopProcess; + BlackBerryProcessParser m_launchStopProcessParser; + QSsh::SshRemoteProcessRunner *m_tailProcess; QSsh::SshRemoteProcessRunner *m_testSlog2Process; QSsh::SshRemoteProcessRunner *m_launchDateTimeProcess; diff --git a/src/plugins/qnx/blackberrycheckdevmodestep.cpp b/src/plugins/qnx/blackberrycheckdevmodestep.cpp index 885d4c7a24ef917fc77b4eb24e62182eb0779bdb..1d61d068e3ec231c6623b7b603afdbaa07396db7 100644 --- a/src/plugins/qnx/blackberrycheckdevmodestep.cpp +++ b/src/plugins/qnx/blackberrycheckdevmodestep.cpp @@ -42,11 +42,6 @@ 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)) { @@ -96,26 +91,6 @@ ProjectExplorer::BuildStepConfigWidget *BlackBerryCheckDevModeStep::createConfig 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()); diff --git a/src/plugins/qnx/blackberrycheckdevmodestep.h b/src/plugins/qnx/blackberrycheckdevmodestep.h index e99be40cf4e37a1d50be33b825257eb87a8d3868..52324b5e89768202c4112b5723f20d43364c66b9 100644 --- a/src/plugins/qnx/blackberrycheckdevmodestep.h +++ b/src/plugins/qnx/blackberrycheckdevmodestep.h @@ -48,17 +48,12 @@ public: 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 ¶ms); private: - void handleErrorOutput(const QString &line); - QString password() const; }; diff --git a/src/plugins/qnx/blackberrydeploystep.cpp b/src/plugins/qnx/blackberrydeploystep.cpp index 8d98278a41d8e2c05ab4182534332ca274f21d79..9c1b71a59db31822e5a1bca89a2546ac32b7771a 100644 --- a/src/plugins/qnx/blackberrydeploystep.cpp +++ b/src/plugins/qnx/blackberrydeploystep.cpp @@ -48,25 +48,6 @@ using namespace Qnx; using namespace Qnx::Internal; -namespace { -int parseProgress(const QString &line) -{ - const QString startOfLine = QLatin1String("Info: Progress "); - if (!line.startsWith(startOfLine)) - return -1; - - const int percentPos = line.indexOf(QLatin1Char('%')); - const QString progressStr = line.mid(startOfLine.length(), percentPos - startOfLine.length()); - - bool ok; - const int progress = progressStr.toInt(&ok); - if (!ok) - return -1; - - return progress; -} -} - BlackBerryDeployStep::BlackBerryDeployStep(ProjectExplorer::BuildStepList *bsl) : BlackBerryAbstractDeployStep(bsl, Core::Id(Constants::QNX_DEPLOY_PACKAGE_BS_ID)) { @@ -144,15 +125,6 @@ void BlackBerryDeployStep::cleanup() { } -void BlackBerryDeployStep::stdOutput(const QString &line) -{ - const int progress = parseProgress(line); - if (progress > -1) - reportProgress(progress); - - BlackBerryAbstractDeployStep::stdOutput(line); -} - void BlackBerryDeployStep::processStarted(const ProjectExplorer::ProcessParameters ¶ms) { QString arguments = params.prettyArguments(); diff --git a/src/plugins/qnx/blackberrydeploystep.h b/src/plugins/qnx/blackberrydeploystep.h index 732f6c73c25839caa4ab699558e38326620c8d5d..83a4394844a1c86d365883a07da3ec6149507a2e 100644 --- a/src/plugins/qnx/blackberrydeploystep.h +++ b/src/plugins/qnx/blackberrydeploystep.h @@ -55,7 +55,6 @@ public: protected: BlackBerryDeployStep(ProjectExplorer::BuildStepList *bsl, BlackBerryDeployStep *bs); - void stdOutput(const QString &line); void processStarted(const ProjectExplorer::ProcessParameters ¶ms); private: diff --git a/src/plugins/qnx/blackberryprocessparser.cpp b/src/plugins/qnx/blackberryprocessparser.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c3ca1b3deee9e56183ea91c39a89aea966f5724c --- /dev/null +++ b/src/plugins/qnx/blackberryprocessparser.cpp @@ -0,0 +1,133 @@ +/************************************************************************** +** +** 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 "blackberryprocessparser.h" + +#include <projectexplorer/projectexplorerconstants.h> +#include <projectexplorer/task.h> + +using namespace Qnx; +using namespace Qnx::Internal; + +namespace { +const char ERROR_MESSAGE_START[] = "Error: "; +const char WARNING_MESSAGE_START[] = "Warning: "; +const char PROGRESS_MESSAGE_START[] = "Info: Progress "; +const char PID_MESSAGE_START[] = "result::"; +const char APPLICATION_ID_MESSAGE_START[] = "Info: Launching "; + +const char AUTHENTICATION_ERROR[] = "Authentication failed."; +} + +BlackBerryProcessParser::BlackBerryProcessParser() +{ + m_messageReplacements[QLatin1String(AUTHENTICATION_ERROR)] = + tr("Authentication failed. Please make sure the password for the device is correct."); +} + +void BlackBerryProcessParser::stdOutput(const QString &line) +{ + parse(line); + IOutputParser::stdOutput(line); +} + +void BlackBerryProcessParser::stdError(const QString &line) +{ + parse(line); + IOutputParser::stdError(line); +} + +void BlackBerryProcessParser::parse(const QString &line) +{ + bool isErrorMessage = line.startsWith(QLatin1String(ERROR_MESSAGE_START)); + bool isWarningMessage = line.startsWith(QLatin1String(WARNING_MESSAGE_START)); + if (isErrorMessage || isWarningMessage) + parseErrorAndWarningMessage(line, isErrorMessage); + else if (line.startsWith(QLatin1String(PROGRESS_MESSAGE_START))) + parseProgress(line); + else if (line.startsWith(QLatin1String(PID_MESSAGE_START))) + parsePid(line); + else if (line.startsWith(QLatin1String(APPLICATION_ID_MESSAGE_START))) + parseApplicationId(line); +} + +void BlackBerryProcessParser::parseErrorAndWarningMessage(const QString &line, bool isErrorMessage) +{ + QString message = line.mid(line.indexOf(QLatin1String(": ")) + 2).trimmed(); + + foreach (const QString &key, m_messageReplacements.keys()) { + if (message.startsWith(key)) { + message = m_messageReplacements[key]; + break; + } + } + + ProjectExplorer::Task task(isErrorMessage ? ProjectExplorer::Task::Error : ProjectExplorer::Task::Warning, + message, + Utils::FileName(), + -1, + Core::Id(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM)); + emit addTask(task); +} + +void BlackBerryProcessParser::parseProgress(const QString &line) +{ + const QString startOfLine = QLatin1String(PROGRESS_MESSAGE_START); + + const int percentPos = line.indexOf(QLatin1Char('%')); + const QString progressStr = line.mid(startOfLine.length(), percentPos - startOfLine.length()); + + bool ok; + const int progress = progressStr.toInt(&ok); + if (ok) + emit progressParsed(progress); +} + +void BlackBerryProcessParser::parsePid(const QString &line) +{ + int pidIndex = -1; + if (line.contains(QLatin1String("running"))) // "result::running,<pid>" + pidIndex = 16; + else // "result::<pid>" + pidIndex = 8; + + bool ok; + const qint64 pid = line.mid(pidIndex).toInt(&ok); + if (ok) + emit pidParsed(pid); +} + +void BlackBerryProcessParser::parseApplicationId(const QString &line) +{ + const int endOfId = line.indexOf(QLatin1String("...")); + const QString applicationId = line.mid(16, endOfId - 16); + emit applicationIdParsed(applicationId); +} diff --git a/src/plugins/qnx/blackberryprocessparser.h b/src/plugins/qnx/blackberryprocessparser.h new file mode 100644 index 0000000000000000000000000000000000000000..e59f8aafe17d6566042cc44e986dc18b5eab3fe1 --- /dev/null +++ b/src/plugins/qnx/blackberryprocessparser.h @@ -0,0 +1,69 @@ +/************************************************************************** +** +** 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_BLACKBERRYPROCESSPARSER_H +#define QNX_INTERNAL_BLACKBERRYPROCESSPARSER_H + +#include <projectexplorer/ioutputparser.h> + +namespace Qnx { +namespace Internal { + +class BlackBerryProcessParser : public ProjectExplorer::IOutputParser +{ + Q_OBJECT + +public: + BlackBerryProcessParser(); + + void stdOutput(const QString &line); + void stdError(const QString &line); + +signals: + void progressParsed(int progress); + void pidParsed(qint64 pid); + void applicationIdParsed(const QString &applicationId); + +private: + void parse(const QString &line); + + void parseErrorAndWarningMessage(const QString &line, bool isErrorMessage); + void parseProgress(const QString &line); + void parsePid(const QString &line); + void parseApplicationId(const QString &line); + + QMap<QString, QString> m_messageReplacements; +}; + +} // namespace Internal +} // namespace Qnx + +#endif // QNX_INTERNAL_BLACKBERRYPROCESSPARSER_H diff --git a/src/plugins/qnx/qnx.pro b/src/plugins/qnx/qnx.pro index 5c9271bb54cfa0eb25ed085a159965bb7d6b8f9b..36bcfc6a8949a40bad7dd33179cf9575594c6596 100644 --- a/src/plugins/qnx/qnx.pro +++ b/src/plugins/qnx/qnx.pro @@ -77,7 +77,8 @@ SOURCES += qnxplugin.cpp \ blackberrydeviceconnection.cpp \ blackberrydeviceconnectionmanager.cpp \ blackberrydeviceinformation.cpp \ - blackberrysshkeysgenerator.cpp + blackberrysshkeysgenerator.cpp \ + blackberryprocessparser.cpp HEADERS += qnxplugin.h\ qnxconstants.h \ @@ -154,7 +155,8 @@ HEADERS += qnxplugin.h\ blackberrydeviceconnection.h \ blackberrydeviceconnectionmanager.h \ blackberrydeviceinformation.h \ - blackberrysshkeysgenerator.h + blackberrysshkeysgenerator.h \ + blackberryprocessparser.h FORMS += \ blackberrydeviceconfigurationwizardsetuppage.ui \ diff --git a/src/plugins/qnx/qnx.qbs b/src/plugins/qnx/qnx.qbs index 0aac4ce906fe37448de6e4402cfe5ceea681c94d..aafca584f9000b53e09b01bb76f5b906781305f3 100644 --- a/src/plugins/qnx/qnx.qbs +++ b/src/plugins/qnx/qnx.qbs @@ -93,6 +93,8 @@ QtcPlugin { "blackberryqtversion.h", "blackberryqtversionfactory.cpp", "blackberryqtversionfactory.h", + "blackberryprocessparser.cpp", + "blackberryprocessparser.h", "blackberryrunconfiguration.cpp", "blackberryrunconfiguration.h", "blackberryrunconfigurationfactory.cpp",