tizendeploypackageinstallationstep.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**************************************************************************
  2. **
  3. ** Copyright (c) 2014 Tomasz Olszak <olszak.tomasz@gmail.com>
  4. ** Contact: http://www.qt-project.org/legal
  5. **
  6. ** This file is part of Qt Creator.
  7. **
  8. ** Commercial License Usage
  9. ** Licensees holding valid commercial Qt licenses may use this file in
  10. ** accordance with the commercial license agreement provided with the
  11. ** Software or, alternatively, in accordance with the terms contained in
  12. ** a written agreement between you and Digia. For licensing terms and
  13. ** conditions see http://qt.digia.com/licensing. For further information
  14. ** use the contact form at http://qt.digia.com/contact-us.
  15. **
  16. ** GNU Lesser General Public License Usage
  17. ** Alternatively, this file may be used under the terms of the GNU Lesser
  18. ** General Public License version 2.1 as published by the Free Software
  19. ** Foundation and appearing in the file LICENSE.LGPL included in the
  20. ** packaging of this file. Please review the following information to
  21. ** ensure the GNU Lesser General Public License version 2.1 requirements
  22. ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  23. **
  24. ** In addition, as a special exception, Digia gives you certain additional
  25. ** rights. These rights are described in the Digia Qt LGPL Exception
  26. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
  27. **
  28. ****************************************************************************/
  29. #include "tizendebug.h"
  30. #include "tizenconfigurations.h"
  31. #include "tizendeploypackageinstallationstep.h"
  32. #include "tizendeploypackageinstallationconfigwidget.h"
  33. #include "tizenmanager.h"
  34. #include "processoutputhandler.h"
  35. #include <projectexplorer/buildsteplist.h>
  36. #include <projectexplorer/deployconfiguration.h>
  37. #include <projectexplorer/target.h>
  38. #include <projectexplorer/buildconfiguration.h>
  39. #include <projectexplorer/kitinformation.h>
  40. #include <utils/hostosinfo.h>
  41. #include <QDebug>
  42. #include <QDir>
  43. #include <QThread>
  44. using namespace Tizen::Internal;
  45. const Core::Id TizenDeployPackageInstallationStep::Id = Core::Id("Qt4ProjectManager.TizenDeployPackageInstallationStep");
  46. TizenDeployPackageInstallationStep::TizenDeployPackageInstallationStep(ProjectExplorer::BuildStepList *bsl)
  47. : BuildStep(bsl, Id)
  48. {
  49. const QString name = tr("Install package(tpk)");
  50. setDefaultDisplayName(name);
  51. setDisplayName(name);
  52. }
  53. bool TizenDeployPackageInstallationStep::init()
  54. {
  55. return true;
  56. }
  57. ProjectExplorer::BuildStepConfigWidget *TizenDeployPackageInstallationStep::createConfigWidget()
  58. {
  59. TizenDeployPackageInstallationConfigWidget *configWidget = new TizenDeployPackageInstallationConfigWidget();
  60. TizenConfig tc = TizenConfigurations::currentConfig();
  61. Utils::FileName packageFileName = TizenManager::commandLineBuildPath(target())
  62. .appendPath(TizenManager::packageName(target()));
  63. configWidget->setAdditionalSummaryText(QString::fromLatin1("%1 install %2")
  64. .arg(tc.sdbLocation().toString())
  65. .arg(packageFileName.toString()));
  66. return configWidget;
  67. }
  68. TizenDeployPackageInstallationStep::TizenDeployPackageInstallationStep(ProjectExplorer::BuildStepList *bc, TizenDeployPackageInstallationStep *other)
  69. : BuildStep(bc, other)
  70. { }
  71. void TizenDeployPackageInstallationStep::run(QFutureInterface<bool> &fi)
  72. {
  73. emit addOutput(tr("Installing package."), BuildStep::MessageOutput);
  74. QProcess *sdbProcess = new QProcess;
  75. connect(new ProcessOutputHandler(sdbProcess),
  76. SIGNAL(output(QString,ProjectExplorer::BuildStep::OutputFormat,ProjectExplorer::BuildStep::OutputNewlineSetting)),
  77. SIGNAL(addOutput(QString,ProjectExplorer::BuildStep::OutputFormat,ProjectExplorer::BuildStep::OutputNewlineSetting)));
  78. QStringList arguments;
  79. ProjectExplorer::IDevice::ConstPtr device = ProjectExplorer::DeviceKitInformation::device(target()->kit());
  80. if (device.isNull()) {
  81. emit addOutput(tr("No device. Package %1 can't be installed.").arg(TizenManager::packageName(target())), BuildStep::ErrorOutput);
  82. fi.reportResult(false);
  83. sdbProcess->deleteLater();
  84. return;
  85. }
  86. arguments << QLatin1String("--serial")
  87. << device->id().toString()
  88. << QLatin1String("install")
  89. << TizenManager::commandLineBuildPath(target()).appendPath(TizenManager::packageName(target())).toString();
  90. TizenConfig tc = TizenConfigurations::currentConfig();
  91. sdbProcess->start(tc.sdbLocation().toString(), arguments);
  92. if(!sdbProcess->waitForStarted(5000) || !sdbProcess->waitForFinished(360000)) {
  93. addOutput(tr("Can't start %1.").arg(tc.sdbLocation().toString()), BuildStep::ErrorOutput);
  94. fi.reportResult(false);
  95. sdbProcess->deleteLater();
  96. return;
  97. }
  98. if (sdbProcess->exitCode() != 0) {
  99. emit addOutput(tr("Error while installing package."), BuildStep::ErrorOutput);
  100. fi.reportResult(false);
  101. } else {
  102. emit addOutput(tr("Package installed."), BuildStep::MessageOutput);
  103. fi.reportResult(true);
  104. }
  105. disconnect(sdbProcess, 0, this, 0);
  106. sdbProcess->deleteLater();
  107. }