forked from qt-creator/qt-creator
ExtensionSystem: Remove the IPlugin back pointer to pluginspec
The price of having to loop in two places seems small compared to cleaner relations between the classes. There's a new hack in the helpmanager to make sure we aren't looping to often. The hack wouldn't be needed if the (odd(?)) check there weren't there. Change-Id: Ifed50213b2de8feedfb45c185808d163c00c19ca Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -5,7 +5,7 @@ add_qtc_library(ExtensionSystem
|
|||||||
extensionsystem_global.h
|
extensionsystem_global.h
|
||||||
extensionsystemtr.h
|
extensionsystemtr.h
|
||||||
invoker.cpp invoker.h
|
invoker.cpp invoker.h
|
||||||
iplugin.cpp iplugin.h iplugin_p.h
|
iplugin.cpp iplugin.h
|
||||||
optionsparser.cpp optionsparser.h
|
optionsparser.cpp optionsparser.h
|
||||||
plugindetailsview.cpp plugindetailsview.h
|
plugindetailsview.cpp plugindetailsview.h
|
||||||
pluginerroroverview.cpp pluginerroroverview.h
|
pluginerroroverview.cpp pluginerroroverview.h
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ Project {
|
|||||||
"invoker.h",
|
"invoker.h",
|
||||||
"iplugin.cpp",
|
"iplugin.cpp",
|
||||||
"iplugin.h",
|
"iplugin.h",
|
||||||
"iplugin_p.h",
|
|
||||||
"optionsparser.cpp",
|
"optionsparser.cpp",
|
||||||
"optionsparser.h",
|
"optionsparser.h",
|
||||||
"plugindetailsview.cpp",
|
"plugindetailsview.cpp",
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
#include "iplugin.h"
|
#include "iplugin.h"
|
||||||
#include "iplugin_p.h"
|
|
||||||
#include "pluginspec.h"
|
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
|
|
||||||
@@ -160,7 +158,16 @@
|
|||||||
\sa aboutToShutdown()
|
\sa aboutToShutdown()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using namespace ExtensionSystem;
|
namespace ExtensionSystem {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
class IPluginPrivate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QList<std::function<QObject *()>> testCreators;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // Internal
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\internal
|
\internal
|
||||||
@@ -218,11 +225,4 @@ QVector<QObject *> IPlugin::createTestObjects() const
|
|||||||
return Utils::transform(d->testCreators, &TestCreator::operator());
|
return Utils::transform(d->testCreators, &TestCreator::operator());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
} // ExtensionSystem
|
||||||
Returns the PluginSpec corresponding to this plugin.
|
|
||||||
This is not available in the constructor.
|
|
||||||
*/
|
|
||||||
PluginSpec *IPlugin::pluginSpec() const
|
|
||||||
{
|
|
||||||
return d->pluginSpec;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -11,13 +11,7 @@
|
|||||||
|
|
||||||
namespace ExtensionSystem {
|
namespace ExtensionSystem {
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal { class IPluginPrivate; }
|
||||||
class IPluginPrivate;
|
|
||||||
class PluginSpecPrivate;
|
|
||||||
}
|
|
||||||
|
|
||||||
class PluginManager;
|
|
||||||
class PluginSpec;
|
|
||||||
|
|
||||||
class EXTENSIONSYSTEM_EXPORT IPlugin : public QObject
|
class EXTENSIONSYSTEM_EXPORT IPlugin : public QObject
|
||||||
{
|
{
|
||||||
@@ -41,8 +35,6 @@ public:
|
|||||||
const QStringList & /* arguments */) { return nullptr; }
|
const QStringList & /* arguments */) { return nullptr; }
|
||||||
virtual QVector<QObject *> createTestObjects() const;
|
virtual QVector<QObject *> createTestObjects() const;
|
||||||
|
|
||||||
PluginSpec *pluginSpec() const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void initialize() {}
|
virtual void initialize() {}
|
||||||
|
|
||||||
@@ -56,8 +48,6 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Internal::IPluginPrivate *d;
|
Internal::IPluginPrivate *d;
|
||||||
|
|
||||||
friend class Internal::PluginSpecPrivate;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ExtensionSystem
|
} // namespace ExtensionSystem
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
// Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "iplugin.h"
|
|
||||||
|
|
||||||
namespace ExtensionSystem {
|
|
||||||
|
|
||||||
class PluginSpec;
|
|
||||||
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
class IPluginPrivate
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
PluginSpec *pluginSpec;
|
|
||||||
QList<std::function<QObject *()>> testCreators;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace ExtensionSystem
|
|
||||||
@@ -1556,6 +1556,15 @@ void PluginManager::checkForProblematicPlugins()
|
|||||||
d->checkForProblematicPlugins();
|
d->checkForProblematicPlugins();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the PluginSpec corresponding to \a plugin.
|
||||||
|
*/
|
||||||
|
|
||||||
|
PluginSpec *PluginManager::specForPlugin(IPlugin *plugin)
|
||||||
|
{
|
||||||
|
return findOrDefault(d->pluginSpecs, equal(&PluginSpec::plugin, plugin));
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\internal
|
\internal
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ public:
|
|||||||
static const QSet<PluginSpec *> pluginsRequiringPlugin(PluginSpec *spec);
|
static const QSet<PluginSpec *> pluginsRequiringPlugin(PluginSpec *spec);
|
||||||
static const QSet<PluginSpec *> pluginsRequiredByPlugin(PluginSpec *spec);
|
static const QSet<PluginSpec *> pluginsRequiredByPlugin(PluginSpec *spec);
|
||||||
static void checkForProblematicPlugins();
|
static void checkForProblematicPlugins();
|
||||||
|
static PluginSpec *specForPlugin(IPlugin *plugin);
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
static void setSettings(Utils::QtcSettings *settings);
|
static void setSettings(Utils::QtcSettings *settings);
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
#include "extensionsystemtr.h"
|
#include "extensionsystemtr.h"
|
||||||
#include "iplugin.h"
|
#include "iplugin.h"
|
||||||
#include "iplugin_p.h"
|
|
||||||
#include "pluginmanager.h"
|
#include "pluginmanager.h"
|
||||||
#include "pluginspec_p.h"
|
#include "pluginspec_p.h"
|
||||||
|
|
||||||
@@ -1090,7 +1089,6 @@ bool PluginSpecPrivate::loadLibrary()
|
|||||||
}
|
}
|
||||||
state = PluginSpec::Loaded;
|
state = PluginSpec::Loaded;
|
||||||
plugin = pluginObject;
|
plugin = pluginObject;
|
||||||
plugin->d->pluginSpec = q;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
namespace ExtensionSystem {
|
namespace ExtensionSystem {
|
||||||
|
|
||||||
class IPlugin;
|
class IPlugin;
|
||||||
class PluginManager;
|
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,9 @@
|
|||||||
|
|
||||||
#include "coreplugin.h"
|
#include "coreplugin.h"
|
||||||
|
|
||||||
|
#include <extensionsystem/pluginmanager.h>
|
||||||
#include <extensionsystem/pluginspec.h>
|
#include <extensionsystem/pluginspec.h>
|
||||||
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
@@ -22,12 +24,17 @@ static Implementation *m_instance = nullptr;
|
|||||||
|
|
||||||
static bool checkInstance()
|
static bool checkInstance()
|
||||||
{
|
{
|
||||||
auto plugin = Internal::CorePlugin::instance();
|
static bool afterPluginCreation = false;
|
||||||
// HelpManager API can only be used after the actual implementation has been created by the
|
if (!afterPluginCreation) {
|
||||||
// Help plugin, so check that the plugins have all been created. That is the case
|
using namespace ExtensionSystem;
|
||||||
// when the Core plugin is initialized.
|
auto plugin = Internal::CorePlugin::instance();
|
||||||
QTC_CHECK(plugin && plugin->pluginSpec()
|
// HelpManager API can only be used after the actual implementation has been created by the
|
||||||
&& plugin->pluginSpec()->state() >= ExtensionSystem::PluginSpec::Initialized);
|
// Help plugin, so check that the plugins have all been created. That is the case
|
||||||
|
// when the Core plugin is initialized.
|
||||||
|
PluginSpec *pluginSpec = PluginManager::specForPlugin(plugin);
|
||||||
|
afterPluginCreation = (plugin && pluginSpec && pluginSpec->state() >= PluginSpec::Initialized);
|
||||||
|
QTC_CHECK(afterPluginCreation);
|
||||||
|
}
|
||||||
return m_instance != nullptr;
|
return m_instance != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "coreplugintr.h"
|
#include "coreplugintr.h"
|
||||||
#include "icore.h"
|
#include "icore.h"
|
||||||
|
|
||||||
|
#include <extensionsystem/pluginmanager.h>
|
||||||
#include <extensionsystem/pluginspec.h>
|
#include <extensionsystem/pluginspec.h>
|
||||||
|
|
||||||
#include <utils/archive.h>
|
#include <utils/archive.h>
|
||||||
@@ -251,7 +252,7 @@ public:
|
|||||||
{
|
{
|
||||||
QTC_ASSERT(m_tempDir.get(), return );
|
QTC_ASSERT(m_tempDir.get(), return );
|
||||||
|
|
||||||
PluginSpec *coreplugin = CorePlugin::instance()->pluginSpec();
|
PluginSpec *coreplugin = PluginManager::specForPlugin(CorePlugin::instance());
|
||||||
|
|
||||||
// look for plugin
|
// look for plugin
|
||||||
QDirIterator it(m_tempDir->path().path(),
|
QDirIterator it(m_tempDir->path().path(),
|
||||||
|
|||||||
@@ -2500,7 +2500,8 @@ void ProjectExplorerPluginPrivate::currentModeChanged(Id mode, Id oldMode)
|
|||||||
void ProjectExplorerPluginPrivate::determineSessionToRestoreAtStartup()
|
void ProjectExplorerPluginPrivate::determineSessionToRestoreAtStartup()
|
||||||
{
|
{
|
||||||
// Process command line arguments first:
|
// Process command line arguments first:
|
||||||
const bool lastSessionArg = m_instance->pluginSpec()->arguments().contains("-lastsession");
|
const bool lastSessionArg =
|
||||||
|
ExtensionSystem::PluginManager::specForPlugin(m_instance)->arguments().contains("-lastsession");
|
||||||
m_sessionToRestoreAtStartup = lastSessionArg ? SessionManager::startupSession() : QString();
|
m_sessionToRestoreAtStartup = lastSessionArg ? SessionManager::startupSession() : QString();
|
||||||
const QStringList arguments = ExtensionSystem::PluginManager::arguments();
|
const QStringList arguments = ExtensionSystem::PluginManager::arguments();
|
||||||
if (!lastSessionArg) {
|
if (!lastSessionArg) {
|
||||||
|
|||||||
@@ -279,7 +279,7 @@ void tst_PluginSpec::loadLibrary()
|
|||||||
QVERIFY(QLatin1String(spec->plugin->metaObject()->className()) == QLatin1String("MyPlugin::MyPluginImpl"));
|
QVERIFY(QLatin1String(spec->plugin->metaObject()->className()) == QLatin1String("MyPlugin::MyPluginImpl"));
|
||||||
QCOMPARE(spec->state, PluginSpec::Loaded);
|
QCOMPARE(spec->state, PluginSpec::Loaded);
|
||||||
QVERIFY(!spec->hasError);
|
QVERIFY(!spec->hasError);
|
||||||
QCOMPARE(spec->plugin->pluginSpec(), ps);
|
QCOMPARE(spec->plugin, ps->plugin());
|
||||||
delete ps;
|
delete ps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user