1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Author: Andreas Hartmetz, KDAB (andreas.hartmetz@kdab.com)
9 ** Contact: Nokia Corporation (info@qt.nokia.com)
12 ** GNU Lesser General Public License Usage
14 ** This file may be used under the terms of the GNU Lesser General Public
15 ** License version 2.1 as published by the Free Software Foundation and
16 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
17 ** Please review the following information to ensure the GNU Lesser General
18 ** Public License version 2.1 requirements will be met:
19 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
21 ** In addition, as a special exception, Nokia gives you certain additional
22 ** rights. These rights are described in the Nokia Qt LGPL Exception
23 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 ** Alternatively, this file may be used in accordance with the terms and
28 ** conditions contained in a signed written agreement between you and Nokia.
30 ** If you have questions regarding the use of this file, please contact
31 ** Nokia at qt-info@nokia.com.
33 **************************************************************************/
35 #include "analyzerruncontrol.h"
36 #include "analyzerconstants.h"
37 #include "ianalyzerengine.h"
38 #include "ianalyzertool.h"
39 #include "analyzerplugin.h"
40 #include "analyzermanager.h"
41 #include "analyzerrunconfigwidget.h"
42 #include "analyzersettings.h"
44 #include <extensionsystem/pluginmanager.h>
45 #include <projectexplorer/applicationrunconfiguration.h>
46 #include <projectexplorer/projectexplorerconstants.h>
47 #include <projectexplorer/task.h>
48 #include <projectexplorer/taskhub.h>
49 #include <coreplugin/ioutputpane.h>
51 #include <QtCore/QDebug>
52 #include <QtGui/QHBoxLayout>
53 #include <QtGui/QLabel>
54 #include <QtGui/QMessageBox>
56 using namespace Analyzer;
57 using namespace Analyzer::Internal;
59 // AnalyzerRunControlFactory ////////////////////////////////////////////////////
60 AnalyzerRunControlFactory::AnalyzerRunControlFactory(QObject *parent)
61 : IRunControlFactory(parent)
65 bool AnalyzerRunControlFactory::canRun(RunConfiguration *runConfiguration, const QString &mode) const
67 if (!qobject_cast<ProjectExplorer::LocalApplicationRunConfiguration *>(runConfiguration))
69 return mode == Constants::MODE_ANALYZE;
72 ProjectExplorer::RunControl *AnalyzerRunControlFactory::create(RunConfiguration *runConfiguration,
75 if (!qobject_cast<ProjectExplorer::LocalApplicationRunConfiguration *>(runConfiguration) ||
76 mode != Constants::MODE_ANALYZE) {
79 AnalyzerRunControl *rc = new AnalyzerRunControl(runConfiguration);
80 emit runControlCreated(rc);
84 QString AnalyzerRunControlFactory::displayName() const
86 return tr("Analyzer");
89 ProjectExplorer::IRunConfigurationAspect *AnalyzerRunControlFactory::createRunConfigurationAspect()
91 return new AnalyzerProjectSettings;
94 ProjectExplorer::RunConfigWidget *AnalyzerRunControlFactory::createConfigurationWidget(RunConfiguration
97 ProjectExplorer::LocalApplicationRunConfiguration *localRc =
98 qobject_cast<ProjectExplorer::LocalApplicationRunConfiguration *>(runConfiguration);
101 AnalyzerProjectSettings *settings = runConfiguration->extraAspect<AnalyzerProjectSettings>();
105 AnalyzerRunConfigWidget *ret = new AnalyzerRunConfigWidget;
106 ret->setRunConfiguration(runConfiguration);
110 // AnalyzerRunControl ////////////////////////////////////////////////////
111 AnalyzerRunControl::AnalyzerRunControl(RunConfiguration *runConfiguration)
112 : RunControl(runConfiguration, Constants::MODE_ANALYZE),
116 IAnalyzerTool *tool = AnalyzerManager::instance()->currentTool();
117 m_engine = tool->createEngine(runConfiguration);
119 connect(m_engine, SIGNAL(standardErrorReceived(QString)),
120 SLOT(receiveStandardError(QString)));
121 connect(m_engine, SIGNAL(standardOutputReceived(QString)),
122 SLOT(receiveStandardOutput(QString)));
123 connect(m_engine, SIGNAL(taskToBeAdded(ProjectExplorer::Task::TaskType,QString,QString,int)),
124 SLOT(addTask(ProjectExplorer::Task::TaskType,QString,QString,int)));
125 connect(m_engine, SIGNAL(finished()),
126 SLOT(engineFinished()));
129 AnalyzerRunControl::~AnalyzerRunControl()
135 void AnalyzerRunControl::start()
137 // clear about-to-be-outdated tasks
138 ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
139 ProjectExplorer::TaskHub *hub = pm->getObject<ProjectExplorer::TaskHub>();
140 hub->clearTasks(Constants::ANALYZERTASK_ID);
147 ProjectExplorer::RunControl::StopResult AnalyzerRunControl::stop()
151 return AsynchronousStop;
154 void AnalyzerRunControl::engineFinished()
160 bool AnalyzerRunControl::isRunning() const
165 QString AnalyzerRunControl::displayName() const
167 return AnalyzerManager::instance()->currentTool()->displayName();
170 void AnalyzerRunControl::receiveStandardOutput(const QString &text)
172 appendMessage(text, ProjectExplorer::StdOutFormat);
175 void AnalyzerRunControl::receiveStandardError(const QString &text)
177 appendMessage(text, ProjectExplorer::StdErrFormat);
180 void AnalyzerRunControl::addTask(ProjectExplorer::Task::TaskType type, const QString &description,
181 const QString &file, int line)
183 ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
184 ProjectExplorer::TaskHub *hub = pm->getObject<ProjectExplorer::TaskHub>();
185 hub->addTask(ProjectExplorer::Task(type, description, file, line, Constants::ANALYZERTASK_ID));
187 ///FIXME: get a better API for this into Qt Creator
188 QList<Core::IOutputPane *> panes = pm->getObjects<Core::IOutputPane>();
189 foreach (Core::IOutputPane *pane, panes) {
190 if (pane->displayName() == tr("Build Issues")) {