Files
qt-creator/src/libs/extensionsystem/pluginmanager_p.h

159 lines
5.0 KiB
C
Raw Normal View History

/****************************************************************************
2008-12-02 12:01:29 +01:00
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
2008-12-02 12:01:29 +01:00
**
** This file is part of Qt Creator.
2008-12-02 12:01:29 +01:00
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
2010-12-17 16:01:08 +01:00
**
****************************************************************************/
2008-12-02 14:09:21 +01:00
#pragma once
2008-12-02 12:01:29 +01:00
#include "pluginspec.h"
#include <utils/algorithm.h>
#include <QSet>
#include <QStringList>
#include <QObject>
#include <QScopedPointer>
#include <QReadWriteLock>
#include <queue>
QT_BEGIN_NAMESPACE
class QTime;
class QTimer;
class QSettings;
2011-01-20 14:03:07 +01:00
class QEventLoop;
QT_END_NAMESPACE
2008-12-02 12:01:29 +01:00
namespace ExtensionSystem {
class PluginManager;
namespace Internal {
class PluginSpecPrivate;
class EXTENSIONSYSTEM_EXPORT PluginManagerPrivate : public QObject
2008-12-02 12:01:29 +01:00
{
Q_OBJECT
2008-12-02 12:01:29 +01:00
public:
PluginManagerPrivate(PluginManager *pluginManager);
~PluginManagerPrivate() override;
2008-12-02 12:01:29 +01:00
// Object pool operations
void addObject(QObject *obj);
void removeObject(QObject *obj);
// Plugin operations
void loadPlugins();
void shutdown();
2008-12-02 12:01:29 +01:00
void setPluginPaths(const QStringList &paths);
QVector<ExtensionSystem::PluginSpec *> loadQueue();
2008-12-02 12:01:29 +01:00
void loadPlugin(PluginSpec *spec, PluginSpec::State destState);
void resolveDependencies();
void enableDependenciesIndirectly();
void initProfiling();
void profilingSummary() const;
void profilingReport(const char *what, const PluginSpec *spec = nullptr);
void setSettings(QSettings *settings);
void setGlobalSettings(QSettings *settings);
void readSettings();
void writeSettings();
2008-12-02 12:01:29 +01:00
class TestSpec {
public:
Plugin Tests: Support additional test objects/classes So far tests running within Qt Creator could be implemented with a private slot in the plugin class starting with "test". Binding the test functions to the plugin object/class is fine for test functions without side effects. But as soon as side effects come into play we need proper initialization and cleanup as it's provided by init(), cleanup(), initTestCase() and cleanupTestCase(). However, implementing these functions in the plugin class is not appropriate since they would affect (potentially quite diverse) test functions. This patch enables us to provide 'ordinary' test classes in which we can handle initialization and clean up the usual way. In addition to the current test invocations, e.g.: # (1) Run all test functions of the plugin ./qtcreator -test CppTools # (2) Run selected test functions of the plugin by stating them ./qtcreator -test CppTools,test_completion,test_builtinsymbolsearcher # (3) Run selected test functions of the plugin by a wild card # expression ./qtcreator -test "CppTools,*pointerdeclaration*" # (4) Run a test function of the plugin with certain test data ./qtcreator -test CppTools,test_completion:template_1 it's now also possible to state the test class in order to execute all test functions of that class: # Run all test functions of a certain class: ./qtcreator -test CppTools,SomeClassWithTests As long as the test class does not start with "test", there should not be any problems. Further, an invocation like (1) now additionally execute all test functions of all test classes. For invocations of type (2), (3) and (4) all test functions of all test classes are considered, too. Change-Id: Ief08a6e9e451c599fd0109b8b8e57f92e3ee19f2 Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com> Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
2015-01-15 13:14:35 +01:00
TestSpec(PluginSpec *pluginSpec, const QStringList &testFunctionsOrObjects = QStringList())
: pluginSpec(pluginSpec)
, testFunctionsOrObjects(testFunctionsOrObjects)
{}
PluginSpec *pluginSpec = nullptr;
Plugin Tests: Support additional test objects/classes So far tests running within Qt Creator could be implemented with a private slot in the plugin class starting with "test". Binding the test functions to the plugin object/class is fine for test functions without side effects. But as soon as side effects come into play we need proper initialization and cleanup as it's provided by init(), cleanup(), initTestCase() and cleanupTestCase(). However, implementing these functions in the plugin class is not appropriate since they would affect (potentially quite diverse) test functions. This patch enables us to provide 'ordinary' test classes in which we can handle initialization and clean up the usual way. In addition to the current test invocations, e.g.: # (1) Run all test functions of the plugin ./qtcreator -test CppTools # (2) Run selected test functions of the plugin by stating them ./qtcreator -test CppTools,test_completion,test_builtinsymbolsearcher # (3) Run selected test functions of the plugin by a wild card # expression ./qtcreator -test "CppTools,*pointerdeclaration*" # (4) Run a test function of the plugin with certain test data ./qtcreator -test CppTools,test_completion:template_1 it's now also possible to state the test class in order to execute all test functions of that class: # Run all test functions of a certain class: ./qtcreator -test CppTools,SomeClassWithTests As long as the test class does not start with "test", there should not be any problems. Further, an invocation like (1) now additionally execute all test functions of all test classes. For invocations of type (2), (3) and (4) all test functions of all test classes are considered, too. Change-Id: Ief08a6e9e451c599fd0109b8b8e57f92e3ee19f2 Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com> Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
2015-01-15 13:14:35 +01:00
QStringList testFunctionsOrObjects;
};
bool containsTestSpec(PluginSpec *pluginSpec) const
{
return Utils::contains(testSpecs, [pluginSpec](const TestSpec &s) { return s.pluginSpec == pluginSpec; });
}
void removeTestSpec(PluginSpec *pluginSpec)
{
testSpecs = Utils::filtered(testSpecs, [pluginSpec](const TestSpec &s) { return s.pluginSpec != pluginSpec; });
}
QHash<QString, QVector<PluginSpec *>> pluginCategories;
QVector<PluginSpec *> pluginSpecs;
std::vector<TestSpec> testSpecs;
2008-12-02 12:01:29 +01:00
QStringList pluginPaths;
QString pluginIID;
QVector<QObject *> allObjects; // ### make this a QVector<QPointer<QObject> > > ?
QStringList defaultDisabledPlugins; // Plugins/Ignored from install settings
QStringList defaultEnabledPlugins; // Plugins/ForceEnabled from install settings
2010-03-30 14:18:15 +02:00
QStringList disabledPlugins;
QStringList forceEnabledPlugins;
// delayed initialization
QTimer *delayedInitializeTimer = nullptr;
std::queue<PluginSpec *> delayedInitializeQueue;
// ansynchronous shutdown
QSet<PluginSpec *> asynchronousPlugins; // plugins that have requested async shutdown
QEventLoop *shutdownEventLoop = nullptr; // used for async shutdown
2008-12-02 12:01:29 +01:00
QStringList arguments;
QScopedPointer<QTime> m_profileTimer;
QHash<const PluginSpec *, int> m_profileTotal;
int m_profileElapsedMS = 0;
unsigned m_profilingVerbosity = 0;
QSettings *settings = nullptr;
QSettings *globalSettings = nullptr;
2008-12-02 12:01:29 +01:00
// Look in argument descriptions of the specs for the option.
PluginSpec *pluginForOption(const QString &option, bool *requiresArgument) const;
PluginSpec *pluginByName(const QString &name) const;
// used by tests
static PluginSpec *createSpec();
static PluginSpecPrivate *privateSpec(PluginSpec *spec);
mutable QReadWriteLock m_lock;
bool m_isInitializationDone = false;
2008-12-02 12:01:29 +01:00
private:
PluginManager *q;
void nextDelayedInitialize();
void asyncShutdownFinished();
2008-12-02 12:01:29 +01:00
void readPluginPaths();
bool loadQueue(PluginSpec *spec,
QVector<ExtensionSystem::PluginSpec *> &queue,
QVector<ExtensionSystem::PluginSpec *> &circularityCheckQueue);
2008-12-02 12:01:29 +01:00
void stopAll();
void deleteAll();
#ifdef WITH_TESTS
void startTests();
#endif
2008-12-02 12:01:29 +01:00
};
} // namespace Internal
} // namespace ExtensionSystem