File indexing completed on 2022-11-22 13:51:27

0001 /* This file is part of KDevelop
0002    Copyright 2006-2008 Hamish Rodda <rodda@kde.org>
0003    Copyright 2009 Andreas Pakulat <apaku@gmx.de>
0004    Copyright 2011 Lionel Duc <lionel.data@gmail.com>
0005    Copyright 2011 Mathieu Lornac <mathieu.lornac@gmail.com>
0006    Copyright 2011 Sebastien Rannou <mxs@sbrk.org>
0007    Copyright 2016-2017 Anton Anikin <anton@anikin.xyz>
0008 
0009    This program is free software; you can redistribute it and/or
0010    modify it under the terms of the GNU General Public
0011    License as published by the Free Software Foundation; either
0012    version 2 of the License, or (at your option) any later version.
0013 
0014    This program is distributed in the hope that it will be useful,
0015    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0017    General Public License for more details.
0018 
0019    You should have received a copy of the GNU General Public License
0020    along with this program; see the file COPYING.  If not, write to
0021    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0022    Boston, MA 02110-1301, USA.
0023 */
0024 
0025 #include "launcher.h"
0026 
0027 #include "common_configpage.h"
0028 #include "configpage.h"
0029 #include "debug.h"
0030 #include "job.h"
0031 #include "launchmode.h"
0032 #include "plugin.h"
0033 #include "tool.h"
0034 
0035 #include <execute/iexecuteplugin.h>
0036 #include <interfaces/icore.h>
0037 #include <interfaces/iplugincontroller.h>
0038 #include <interfaces/iruncontroller.h>
0039 #include <interfaces/iuicontroller.h>
0040 #include <util/executecompositejob.h>
0041 
0042 #include <KLocalizedString>
0043 
0044 namespace Valgrind
0045 {
0046 
0047 Launcher::Launcher(const Tool* tool)
0048     : m_tool(tool)
0049 {
0050     Q_ASSERT(tool);
0051 
0052     m_configPageFactories += tool->createConfigPageFactory();
0053     m_configPageFactories += new CommonConfigPageFactory;
0054 }
0055 
0056 Launcher::~Launcher()
0057 {
0058     qDeleteAll(m_configPageFactories);
0059 }
0060 
0061 KJob* Launcher::start(const QString& launchMode, KDevelop::ILaunchConfiguration* launchConfig)
0062 {
0063     Q_ASSERT(launchConfig);
0064 
0065     if (Plugin::self()->launchMode()->id() != launchMode) {
0066         return nullptr;
0067     }
0068 
0069     auto iface = KDevelop::ICore::self()->pluginController()->pluginForExtension("org.kdevelop.IExecutePlugin")->extension<IExecutePlugin>();
0070     Q_ASSERT(iface);
0071 
0072     QList<KJob*> jobList;
0073     if (KJob* depJob = iface->dependencyJob(launchConfig)) {
0074         jobList += depJob;
0075     }
0076 
0077     auto valgrindJob = m_tool->createJob(launchConfig);
0078     jobList += valgrindJob;
0079 
0080     auto ecJob = new KDevelop::ExecuteCompositeJob(KDevelop::ICore::self()->runController(), jobList);
0081     ecJob->setObjectName(valgrindJob->statusName());
0082 
0083     return ecJob;
0084 }
0085 
0086 QStringList Launcher::supportedModes() const
0087 {
0088     return { Plugin::self()->launchMode()->id() };
0089 }
0090 
0091 QList<KDevelop::LaunchConfigurationPageFactory*> Launcher::configPages() const
0092 {
0093     return m_configPageFactories;
0094 }
0095 
0096 QString Launcher::name() const
0097 {
0098     return m_tool->name();
0099 }
0100 
0101 QString Launcher::description() const
0102 {
0103     return m_tool->fullName();
0104 }
0105 
0106 QString Launcher::id()
0107 {
0108     return m_tool->id();
0109 }
0110 
0111 }