Changeset View
Changeset View
Standalone View
Standalone View
plugins/heaptrack/plugin.cpp
Show All 27 Lines | |||||
28 | #include <config-kdevelop.h> | 28 | #include <config-kdevelop.h> | ||
29 | #if KF5SysGuard_FOUND | 29 | #if KF5SysGuard_FOUND | ||
30 | #include "dialogs/processselection.h" | 30 | #include "dialogs/processselection.h" | ||
31 | #include <QPointer> | 31 | #include <QPointer> | ||
32 | #endif | 32 | #endif | ||
33 | 33 | | |||
34 | #include <execute/iexecuteplugin.h> | 34 | #include <execute/iexecuteplugin.h> | ||
35 | #include <interfaces/iplugincontroller.h> | 35 | #include <interfaces/iplugincontroller.h> | ||
36 | #include <interfaces/launchconfigurationtype.h> | ||||
36 | #include <shell/core.h> | 37 | #include <shell/core.h> | ||
37 | #include <shell/launchconfiguration.h> | 38 | #include <shell/launchconfiguration.h> | ||
38 | #include <shell/runcontroller.h> | 39 | #include <shell/runcontroller.h> | ||
39 | #include <util/executecompositejob.h> | 40 | #include <util/executecompositejob.h> | ||
40 | 41 | | |||
41 | #include <KActionCollection> | 42 | #include <KActionCollection> | ||
43 | #include <KMessageBox> | ||||
42 | #include <KPluginFactory> | 44 | #include <KPluginFactory> | ||
43 | 45 | | |||
44 | #include <QAction> | 46 | #include <QAction> | ||
47 | #include <QApplication> | ||||
45 | #include <QFile> | 48 | #include <QFile> | ||
46 | 49 | | |||
47 | K_PLUGIN_FACTORY_WITH_JSON(HeaptrackFactory, "kdevheaptrack.json", registerPlugin<Heaptrack::Plugin>();) | 50 | K_PLUGIN_FACTORY_WITH_JSON(HeaptrackFactory, "kdevheaptrack.json", registerPlugin<Heaptrack::Plugin>();) | ||
48 | 51 | | |||
49 | namespace Heaptrack | 52 | namespace Heaptrack | ||
50 | { | 53 | { | ||
51 | 54 | | |||
52 | Plugin::Plugin(QObject* parent, const QVariantList&) | 55 | Plugin::Plugin(QObject* parent, const QVariantList&) | ||
Show All 21 Lines | |||||
74 | } | 77 | } | ||
75 | 78 | | |||
76 | Plugin::~Plugin() | 79 | Plugin::~Plugin() | ||
77 | { | 80 | { | ||
78 | } | 81 | } | ||
79 | 82 | | |||
80 | void Plugin::launchHeaptrack() | 83 | void Plugin::launchHeaptrack() | ||
81 | { | 84 | { | ||
82 | auto runController = KDevelop::Core::self()->runControllerInternal(); | 85 | IExecutePlugin* executePlugin = nullptr; | ||
83 | if (runController->launchConfigurations().isEmpty()) { | 86 | | ||
84 | runController->showConfigurationDialog(); | 87 | // First we should check that our "kdevexecute" plugin is loaded. This is needed since | ||
88 | // current plugin controller logic allows us to unload this plugin with keeping dependent | ||||
89 | // plugins like Heaptrack in "loaded" state. This seems to be wrong behaviour but now we have | ||||
90 | // to do additional checks. | ||||
91 | // TODO fix plugin controller to avoid such inconsistent states. | ||||
92 | auto pluginController = core()->pluginController(); | ||||
93 | if (auto plugin = pluginController->pluginForExtension( | ||||
94 | QStringLiteral("org.kdevelop.IExecutePlugin"), QStringLiteral("kdevexecute"))) { | ||||
95 | executePlugin = plugin->extension<IExecutePlugin>(); | ||||
96 | } else { | ||||
97 | auto pluginInfo = pluginController->infoForPluginId(QStringLiteral("kdevexecute")); | ||||
98 | KMessageBox::error( | ||||
99 | qApp->activeWindow(), | ||||
100 | i18n("Unable to start Heaptrack analysis - \"%1\" plugin is not loaded.", pluginInfo.name())); | ||||
101 | return; | ||||
85 | } | 102 | } | ||
86 | 103 | | |||
104 | auto runController = KDevelop::Core::self()->runControllerInternal(); | ||||
87 | auto defaultLaunch = runController->defaultLaunch(); | 105 | auto defaultLaunch = runController->defaultLaunch(); | ||
88 | if (!defaultLaunch) { | 106 | if (!defaultLaunch) { | ||
89 | return; | 107 | runController->showConfigurationDialog(); | ||
90 | } | 108 | } | ||
91 | 109 | | |||
92 | auto pluginController = core()->self()->pluginController(); | 110 | if (!defaultLaunch->type()->launcherForId(QStringLiteral("nativeAppLauncher"))) { | ||
93 | auto iface = pluginController->pluginForExtension(QStringLiteral("org.kdevelop.IExecutePlugin"))->extension<IExecutePlugin>(); | 111 | KMessageBox::error( | ||
94 | Q_ASSERT(iface); | 112 | qApp->activeWindow(), | ||
113 | i18n("Heaptrack analysis can be started only for native applications.")); | ||||
114 | return; | ||||
115 | } | ||||
95 | 116 | | |||
96 | auto heaptrackJob = new Job(defaultLaunch); | 117 | auto heaptrackJob = new Job(defaultLaunch, executePlugin); | ||
97 | connect(heaptrackJob, &Job::finished, this, &Plugin::jobFinished); | 118 | connect(heaptrackJob, &Job::finished, this, &Plugin::jobFinished); | ||
98 | 119 | | |||
99 | QList<KJob*> jobList; | 120 | QList<KJob*> jobList; | ||
100 | if (KJob* depJob = iface->dependencyJob(defaultLaunch)) { | 121 | if (KJob* depJob = executePlugin->dependencyJob(defaultLaunch)) { | ||
101 | jobList += depJob; | 122 | jobList += depJob; | ||
102 | } | 123 | } | ||
103 | jobList += heaptrackJob; | 124 | jobList += heaptrackJob; | ||
104 | 125 | | |||
105 | auto ecJob = new KDevelop::ExecuteCompositeJob(runController, jobList); | 126 | auto ecJob = new KDevelop::ExecuteCompositeJob(runController, jobList); | ||
106 | ecJob->setObjectName(heaptrackJob->statusName()); | 127 | ecJob->setObjectName(heaptrackJob->statusName()); | ||
107 | runController->registerJob(ecJob); | 128 | runController->registerJob(ecJob); | ||
108 | 129 | | |||
▲ Show 20 Lines • Show All 55 Lines • Show Last 20 Lines |