diff --git a/kdevplatform/shell/plugincontroller.h b/kdevplatform/shell/plugincontroller.h --- a/kdevplatform/shell/plugincontroller.h +++ b/kdevplatform/shell/plugincontroller.h @@ -132,7 +132,6 @@ void unloadProjectPlugins(); void resetToDefaults(); - bool isEnabled(const KPluginMetaData& info) const; private: /** diff --git a/kdevplatform/shell/plugincontroller.cpp b/kdevplatform/shell/plugincontroller.cpp --- a/kdevplatform/shell/plugincontroller.cpp +++ b/kdevplatform/shell/plugincontroller.cpp @@ -60,6 +60,8 @@ inline QString KEY_Interfaces() { return QStringLiteral("X-KDevelop-Interfaces"); } inline QString KEY_Required() { return QStringLiteral("X-KDevelop-IRequired"); } inline QString KEY_Optional() { return QStringLiteral("X-KDevelop-IOptional"); } +inline QString KEY_KPlugin() { return QStringLiteral("KPlugin"); } +inline QString KEY_EnabledByDefault() { return QStringLiteral("EnabledByDefault"); } inline QString KEY_Global() { return QStringLiteral("Global"); } inline QString KEY_Project() { return QStringLiteral("Project"); } @@ -228,33 +230,22 @@ */ bool isEnabled(const KPluginMetaData& info) const { + // first check black listing from environment static const QStringList disabledPlugins = QString::fromLatin1(qgetenv("KDEV_DISABLE_PLUGINS")).split(';'); if (disabledPlugins.contains(info.pluginId())) { return false; } if (!isUserSelectable( info )) return true; - // in case there's a user preference, prefer that + // read stored user preference const KConfigGroup grp = Core::self()->activeSession()->config()->group( KEY_Plugins() ); const QString pluginEnabledKey = info.pluginId() + KEY_Suffix_Enabled(); if (grp.hasKey(pluginEnabledKey)) { return grp.readEntry(pluginEnabledKey, true); } - // in all other cases: figure out if we want to load that plugin by default - const auto defaultPlugins = ShellExtension::getInstance()->defaultPlugins(); - const bool isDefaultPlugin = defaultPlugins.isEmpty() || defaultPlugins.contains(info.pluginId()); - if (isDefaultPlugin) { - return true; - } - - if (!isGlobalPlugin( info )) { - QJsonValue enabledByDefault = info.rawData()[QStringLiteral("KPlugin")].toObject()[QStringLiteral("EnabledByDefault")]; - return enabledByDefault.isNull() || enabledByDefault.toBool(); //We consider plugins enabled until specified otherwise - } - return false; } @@ -346,11 +337,6 @@ return loadPluginInternal( pluginName ); } -bool PluginController::isEnabled( const KPluginMetaData& info ) const -{ - return d->isEnabled(info); -} - void PluginController::initialize() { QElapsedTimer timer; @@ -361,7 +347,10 @@ { foreach( const KPluginMetaData& pi, d->plugins ) { - pluginMap.insert( pi.pluginId(), true ); + QJsonValue enabledByDefaultValue = pi.rawData()[KEY_KPlugin()].toObject()[KEY_EnabledByDefault()]; + // plugins enabled until explicitly specified otherwise + const bool enabledByDefault = (enabledByDefaultValue.isNull() || enabledByDefaultValue.toBool()); + pluginMap.insert(pi.pluginId(), enabledByDefault); } } else { @@ -387,32 +376,28 @@ } } - foreach( const KPluginMetaData& pi, d->plugins ) - { - if( isGlobalPlugin( pi ) ) - { - QMap::const_iterator it = pluginMap.constFind( pi.pluginId() ); - if( it != pluginMap.constEnd() && ( it.value() || !isUserSelectable( pi ) ) ) - { - // Plugin is mentioned in pluginmap and the value is true, so try to load it - loadPluginInternal( pi.pluginId() ); - if(!grp.hasKey(pi.pluginId() + KEY_Suffix_Enabled())) { - if( isUserSelectable( pi ) ) - { - // If plugin isn't listed yet, add it with true now - grp.writeEntry(pi.pluginId() + KEY_Suffix_Enabled(), true); - } - } else if( grp.hasKey( pi.pluginId() + "Disabled" ) && !isUserSelectable( pi ) ) - { - // Remove now-obsolete entries - grp.deleteEntry( pi.pluginId() + "Disabled" ); - } + // store current known set of enabled plugins + foreach (const KPluginMetaData& pi, d->plugins) { + if (isUserSelectable(pi)) { + auto it = pluginMap.constFind(pi.pluginId()); + if (it != pluginMap.constEnd() && (it.value())) { + grp.writeEntry(pi.pluginId() + KEY_Suffix_Enabled(), true); } + } else { + // Backward compat: Remove any now-obsolete entries + grp.deleteEntry(pi.pluginId() + QLatin1String("Disabled")); } } // Synchronize so we're writing out to the file. grp.sync(); + // load global plugins + foreach (const KPluginMetaData& pi, d->plugins) { + if (isGlobalPlugin(pi)) { + loadPluginInternal(pi.pluginId()); + } + } + qCDebug(SHELL) << "Done loading plugins - took:" << timer.elapsed() << "ms"; } @@ -490,7 +475,7 @@ return plugin; } - if ( !isEnabled( info ) ) { + if (!d->isEnabled(info)) { // Do not load disabled plugins qCWarning(SHELL) << "Not loading plugin named" << pluginId << "because it has been disabled!"; return nullptr; @@ -760,6 +745,7 @@ loadPluginInternal( info.pluginId() ); } } + // TODO: what about project plugins? what about dependency plugins? } } @@ -774,7 +760,15 @@ { foreach( const KPluginMetaData& info, d->plugins ) { - plugins << info.pluginId(); + if (!isUserSelectable(info)) { + continue; + } + + QJsonValue enabledByDefault = info.rawData()[KEY_KPlugin()].toObject()[KEY_EnabledByDefault()]; + // plugins enabled until explicitly specified otherwise + if (enabledByDefault.isNull() || enabledByDefault.toBool()) { + plugins << info.pluginId(); + } } } foreach( const QString& s, plugins ) diff --git a/kdevplatform/shell/settings/pluginpreferences.cpp b/kdevplatform/shell/settings/pluginpreferences.cpp --- a/kdevplatform/shell/settings/pluginpreferences.cpp +++ b/kdevplatform/shell/settings/pluginpreferences.cpp @@ -68,7 +68,6 @@ category = QStringLiteral("Other"); } KPluginInfo kpi(info); - kpi.setPluginEnabled(Core::self()->pluginControllerInternal()->isEnabled(info)); plugins[category] << kpi; } else qCDebug(SHELL) << "skipping..." << info.pluginId() << info.value(QStringLiteral("X-KDevelop-Category")) << loadMode; @@ -82,7 +81,6 @@ Core::self()->activeSession()->config()); } connect(selector, &KPluginSelector::changed, this, &PluginPreferences::changed); - selector->load(); } void PluginPreferences::defaults() diff --git a/kdevplatform/shell/shellextension.h b/kdevplatform/shell/shellextension.h --- a/kdevplatform/shell/shellextension.h +++ b/kdevplatform/shell/shellextension.h @@ -69,7 +69,9 @@ /** * Reimplement to return the list of plugins that should - * automatically be loaded + * loaded by default. + * If an empty list is returned, instead the plugin metadata is fallen back to, + * by reading the bool value KPlugin/EnabledByDefault (default: true). */ virtual QStringList defaultPlugins() = 0; diff --git a/kdevplatform/shell/tests/CMakeLists.txt b/kdevplatform/shell/tests/CMakeLists.txt --- a/kdevplatform/shell/tests/CMakeLists.txt +++ b/kdevplatform/shell/tests/CMakeLists.txt @@ -19,13 +19,25 @@ set(TEST_PLUGIN_DIR "${CMAKE_CURRENT_BINARY_DIR}/testplugindir") configure_file("testfilepaths.h.cmake" "testfilepaths.h" ESCAPE_QUOTES) -kdevplatform_add_plugin(kdevnonguiinterfaceplugin JSON kdevnonguiinterfaceplugin.json SKIP_INSTALL SOURCES nonguiinterfaceplugin.cpp) -target_link_libraries(kdevnonguiinterfaceplugin Qt5::Core KDev::Interfaces) -set_target_properties(kdevnonguiinterfaceplugin PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${TEST_PLUGIN_DIR}/kdevplatform/${KDEV_PLUGIN_VERSION}") + +macro(KDEVSHELL_ADD_TEST_PLUGIN _PLUGIN_NAME) + kdevplatform_add_plugin(${_PLUGIN_NAME} JSON plugins/${_PLUGIN_NAME}.testpluginjson SKIP_INSTALL SOURCES plugins/${_PLUGIN_NAME}.cpp) + target_link_libraries(${_PLUGIN_NAME} Qt5::Core KDev::Interfaces) + set_target_properties(${_PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${TEST_PLUGIN_DIR}/kdevplatform/${KDEV_PLUGIN_VERSION}") +endmacro() + +kdevshell_add_test_plugin(nonguiinterfaceplugin) +kdevshell_add_test_plugin(projectdefaultplugin) +kdevshell_add_test_plugin(projectnondefaultplugin) +kdevshell_add_test_plugin(globaldefaultplugin) +kdevshell_add_test_plugin(globalnondefaultplugin) ecm_add_test(test_plugincontroller.cpp LINK_LIBRARIES Qt5::Test KDev::Tests KDev::Shell KDev::Interfaces KDev::Sublime) +ecm_add_test(test_pluginenabling.cpp + LINK_LIBRARIES Qt5::Test KDev::Tests KDev::Shell KDev::Interfaces KDev::Sublime) + ecm_add_test(test_testcontroller.cpp LINK_LIBRARIES Qt5::Test KDev::Tests) diff --git a/kdevplatform/shell/tests/kdevnonguiinterfaceplugin.json b/kdevplatform/shell/tests/kdevnonguiinterfaceplugin.json deleted file mode 100644 --- a/kdevplatform/shell/tests/kdevnonguiinterfaceplugin.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "KPlugin": { - "Description": "This plugin is purely for unit-test", - "Description[ca@valencia]": "Este connector és exclusivament per a unitats de proves", - "Description[ca]": "Aquest connector és exclusivament per a unitats de proves", - "Description[de]": "Die ist eine Modul nur für Unit-Tests", - "Description[es]": "Este complemento es exclusivamente para pruebas unitarias", - "Description[fi]": "Tämä liitännäinen on puhtaasti yksikkötestausta varten", - "Description[gl]": "Este complemento é soamente para probas unitarias.", - "Description[nl]": "Deze plugin is alleen voor eenheid-testen", - "Description[pl]": "Ta wtyczka służy tylko do testów jednostek", - "Description[pt]": "Este 'plugin' serve apenas para testes unitários", - "Description[pt_BR]": "Este plugin é apenas para testes unitários", - "Description[sk]": "Tento plugin je čisto na unit testy", - "Description[sl]": "Ta vstavek je samo za preizkušanje enot", - "Description[sv]": "Insticksprogrammet är enbart avsett för enhetstest", - "Description[tr]": "Bu eklenti tamamen birim-testleri içindir", - "Description[uk]": "Цей додаток призначено лише для тестування модулів", - "Description[x-test]": "xxThis plugin is purely for unit-testxx", - "Description[zh_CN]": "此插件只用于 unit 测试", - "Id": "kdevnonguiinterface", - "License": "LGPL", - "Name": "KDevNonGuiInterface", - "Name[bs]": "KDevNonGUI sučelje", - "Name[nds]": "KDevKeenBöversiet", - "Name[sv]": "KDevelop icke grafiskt användargränssnitt", - "Name[x-test]": "xxKDevNonGuiInterfacexx", - "ServiceTypes": [ - "KDevelop/Plugin" - ] - }, - "X-KDevelop-Interfaces": [ - "org.kdevelop.ITestNonGuiInterface" - ], - "X-KDevelop-Mode": "NoGUI" -} diff --git a/kdevplatform/shell/tests/nonguiinterfaceplugin.h b/kdevplatform/shell/tests/plugins/globaldefaultplugin.cpp rename from kdevplatform/shell/tests/nonguiinterfaceplugin.h rename to kdevplatform/shell/tests/plugins/globaldefaultplugin.cpp --- a/kdevplatform/shell/tests/nonguiinterfaceplugin.h +++ b/kdevplatform/shell/tests/plugins/globaldefaultplugin.cpp @@ -1,7 +1,7 @@ /* * This file is part of KDevelop * - * Copyright 2007 Hamish Rodda + * Copyright 2017 Friedrich W. H. Kossebau * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -19,29 +19,23 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef NONGUIINTERFACEPLUGIN -#define NONGUIINTERFACEPLUGIN - #include -#include +#include -class ITestNonGuiInterface +class GlobalDefaultPlugin : public KDevelop::IPlugin { + Q_OBJECT public: - virtual ~ITestNonGuiInterface() {} + GlobalDefaultPlugin(QObject* parent, const QVariantList&); }; -Q_DECLARE_INTERFACE( ITestNonGuiInterface, "org.kdevelop.ITestNonGuiInterface" ) - - -class NonGuiInterfacePlugin : public KDevelop::IPlugin, ITestNonGuiInterface +GlobalDefaultPlugin::GlobalDefaultPlugin(QObject* parent, const QVariantList&) + : IPlugin(QStringLiteral("globaldefaultplugin"), parent) { - Q_OBJECT - Q_INTERFACES(ITestNonGuiInterface) -public: - explicit NonGuiInterfacePlugin( QObject* parent, const QVariantList& = QVariantList() ); -}; +} -#endif +K_PLUGIN_FACTORY_WITH_JSON(GlobalDefaultPluginFactory, "globaldefaultplugin.testpluginjson", + registerPlugin();) +#include "globaldefaultplugin.moc" diff --git a/kdevplatform/shell/tests/plugins/globaldefaultplugin.testpluginjson b/kdevplatform/shell/tests/plugins/globaldefaultplugin.testpluginjson new file mode 100644 --- /dev/null +++ b/kdevplatform/shell/tests/plugins/globaldefaultplugin.testpluginjson @@ -0,0 +1,13 @@ +{ + "KPlugin": { + "Description": "This plugin is purely for unit-test", + "Id": "test_globaldefault", + "License": "LGPL", + "Name": "GlobalDefaultPlugin", + "ServiceTypes": [ + "KDevelop/Plugin" + ] + }, + "X-KDevelop-Category": "Global", + "X-KDevelop-Mode": "NoGUI" +} diff --git a/kdevplatform/shell/tests/nonguiinterfaceplugin.h b/kdevplatform/shell/tests/plugins/globalnondefaultplugin.cpp copy from kdevplatform/shell/tests/nonguiinterfaceplugin.h copy to kdevplatform/shell/tests/plugins/globalnondefaultplugin.cpp --- a/kdevplatform/shell/tests/nonguiinterfaceplugin.h +++ b/kdevplatform/shell/tests/plugins/globalnondefaultplugin.cpp @@ -1,7 +1,7 @@ /* * This file is part of KDevelop * - * Copyright 2007 Hamish Rodda + * Copyright 2017 Friedrich W. H. Kossebau * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -19,29 +19,23 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef NONGUIINTERFACEPLUGIN -#define NONGUIINTERFACEPLUGIN - #include -#include +#include -class ITestNonGuiInterface +class GlobalNonDefaultPlugin : public KDevelop::IPlugin { + Q_OBJECT public: - virtual ~ITestNonGuiInterface() {} + GlobalNonDefaultPlugin(QObject* parent, const QVariantList&); }; -Q_DECLARE_INTERFACE( ITestNonGuiInterface, "org.kdevelop.ITestNonGuiInterface" ) - - -class NonGuiInterfacePlugin : public KDevelop::IPlugin, ITestNonGuiInterface +GlobalNonDefaultPlugin::GlobalNonDefaultPlugin(QObject* parent, const QVariantList&) + : IPlugin(QStringLiteral("globalnondefaultplugin"), parent) { - Q_OBJECT - Q_INTERFACES(ITestNonGuiInterface) -public: - explicit NonGuiInterfacePlugin( QObject* parent, const QVariantList& = QVariantList() ); -}; +} -#endif +K_PLUGIN_FACTORY_WITH_JSON(GlobalNonDefaultPluginFactory, "globalnondefaultplugin.testpluginjson", + registerPlugin();) +#include "globalnondefaultplugin.moc" diff --git a/kdevplatform/shell/tests/plugins/globalnondefaultplugin.testpluginjson b/kdevplatform/shell/tests/plugins/globalnondefaultplugin.testpluginjson new file mode 100644 --- /dev/null +++ b/kdevplatform/shell/tests/plugins/globalnondefaultplugin.testpluginjson @@ -0,0 +1,14 @@ +{ + "KPlugin": { + "Description": "This plugin is purely for unit-test", + "Id": "test_globalnondefault", + "License": "LGPL", + "Name": "GlobalNonDefaultPlugin", + "EnabledByDefault": false, + "ServiceTypes": [ + "KDevelop/Plugin" + ] + }, + "X-KDevelop-Category": "Global", + "X-KDevelop-Mode": "NoGUI" +} diff --git a/kdevplatform/shell/tests/nonguiinterfaceplugin.h b/kdevplatform/shell/tests/plugins/nonguiinterface.h copy from kdevplatform/shell/tests/nonguiinterfaceplugin.h copy to kdevplatform/shell/tests/plugins/nonguiinterface.h --- a/kdevplatform/shell/tests/nonguiinterfaceplugin.h +++ b/kdevplatform/shell/tests/plugins/nonguiinterface.h @@ -19,12 +19,10 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef NONGUIINTERFACEPLUGIN -#define NONGUIINTERFACEPLUGIN +#ifndef ITESTNONGUIINTERFACE +#define ITESTNONGUIINTERFACE -#include - -#include +#include class ITestNonGuiInterface { @@ -35,13 +33,5 @@ Q_DECLARE_INTERFACE( ITestNonGuiInterface, "org.kdevelop.ITestNonGuiInterface" ) -class NonGuiInterfacePlugin : public KDevelop::IPlugin, ITestNonGuiInterface -{ - Q_OBJECT - Q_INTERFACES(ITestNonGuiInterface) -public: - explicit NonGuiInterfacePlugin( QObject* parent, const QVariantList& = QVariantList() ); -}; - #endif diff --git a/kdevplatform/shell/tests/nonguiinterfaceplugin.cpp b/kdevplatform/shell/tests/plugins/nonguiinterfaceplugin.cpp rename from kdevplatform/shell/tests/nonguiinterfaceplugin.cpp rename to kdevplatform/shell/tests/plugins/nonguiinterfaceplugin.cpp --- a/kdevplatform/shell/tests/nonguiinterfaceplugin.cpp +++ b/kdevplatform/shell/tests/plugins/nonguiinterfaceplugin.cpp @@ -19,16 +19,27 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "nonguiinterfaceplugin.h" +#include "nonguiinterface.h" -#include +#include -K_PLUGIN_FACTORY_WITH_JSON(KDevProblemReporterFactory, "kdevnonguiinterfaceplugin.json", registerPlugin();) +#include -NonGuiInterfacePlugin::NonGuiInterfacePlugin( QObject* parent, const QVariantList& ) - : IPlugin( QStringLiteral("kdevnonguiinterfaceplugin"), parent ) +class NonGuiInterfacePlugin : public KDevelop::IPlugin, ITestNonGuiInterface +{ + Q_OBJECT + Q_INTERFACES(ITestNonGuiInterface) +public: + NonGuiInterfacePlugin(QObject* parent, const QVariantList&); +}; + +NonGuiInterfacePlugin::NonGuiInterfacePlugin(QObject* parent, const QVariantList&) + : IPlugin(QStringLiteral("nonguiinterfaceplugin"), parent) { } +K_PLUGIN_FACTORY_WITH_JSON(NonGuiInterfacePluginFactory, "nonguiinterfaceplugin.testpluginjson", + registerPlugin();) + #include "nonguiinterfaceplugin.moc" diff --git a/kdevplatform/shell/tests/plugins/nonguiinterfaceplugin.testpluginjson b/kdevplatform/shell/tests/plugins/nonguiinterfaceplugin.testpluginjson new file mode 100644 --- /dev/null +++ b/kdevplatform/shell/tests/plugins/nonguiinterfaceplugin.testpluginjson @@ -0,0 +1,15 @@ +{ + "KPlugin": { + "Description": "This plugin is purely for unit-test", + "Id": "test_nonguiinterface", + "License": "LGPL", + "Name": "NonGuiInterface", + "ServiceTypes": [ + "KDevelop/Plugin" + ] + }, + "X-KDevelop-Interfaces": [ + "org.kdevelop.ITestNonGuiInterface" + ], + "X-KDevelop-Mode": "NoGUI" +} diff --git a/kdevplatform/shell/tests/nonguiinterfaceplugin.h b/kdevplatform/shell/tests/plugins/projectdefaultplugin.cpp copy from kdevplatform/shell/tests/nonguiinterfaceplugin.h copy to kdevplatform/shell/tests/plugins/projectdefaultplugin.cpp --- a/kdevplatform/shell/tests/nonguiinterfaceplugin.h +++ b/kdevplatform/shell/tests/plugins/projectdefaultplugin.cpp @@ -1,7 +1,7 @@ /* * This file is part of KDevelop * - * Copyright 2007 Hamish Rodda + * Copyright 2017 Friedrich W. H. Kossebau * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -19,29 +19,23 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef NONGUIINTERFACEPLUGIN -#define NONGUIINTERFACEPLUGIN - #include -#include +#include -class ITestNonGuiInterface +class ProjectDefaultPlugin : public KDevelop::IPlugin { + Q_OBJECT public: - virtual ~ITestNonGuiInterface() {} + ProjectDefaultPlugin(QObject* parent, const QVariantList&); }; -Q_DECLARE_INTERFACE( ITestNonGuiInterface, "org.kdevelop.ITestNonGuiInterface" ) - - -class NonGuiInterfacePlugin : public KDevelop::IPlugin, ITestNonGuiInterface +ProjectDefaultPlugin::ProjectDefaultPlugin(QObject* parent, const QVariantList&) + : IPlugin(QStringLiteral("projectdefaultplugin"), parent) { - Q_OBJECT - Q_INTERFACES(ITestNonGuiInterface) -public: - explicit NonGuiInterfacePlugin( QObject* parent, const QVariantList& = QVariantList() ); -}; +} -#endif +K_PLUGIN_FACTORY_WITH_JSON(ProjectDefaultPluginFactory, "projectdefaultplugin.testpluginjson", + registerPlugin();) +#include "projectdefaultplugin.moc" diff --git a/kdevplatform/shell/tests/plugins/projectdefaultplugin.testpluginjson b/kdevplatform/shell/tests/plugins/projectdefaultplugin.testpluginjson new file mode 100644 --- /dev/null +++ b/kdevplatform/shell/tests/plugins/projectdefaultplugin.testpluginjson @@ -0,0 +1,13 @@ +{ + "KPlugin": { + "Description": "This plugin is purely for unit-test", + "Id": "test_projectdefault", + "License": "LGPL", + "Name": "ProjectDefaultPlugin", + "ServiceTypes": [ + "KDevelop/Plugin" + ] + }, + "X-KDevelop-Category": "Project", + "X-KDevelop-Mode": "NoGUI" +} diff --git a/kdevplatform/shell/tests/nonguiinterfaceplugin.h b/kdevplatform/shell/tests/plugins/projectnondefaultplugin.cpp copy from kdevplatform/shell/tests/nonguiinterfaceplugin.h copy to kdevplatform/shell/tests/plugins/projectnondefaultplugin.cpp --- a/kdevplatform/shell/tests/nonguiinterfaceplugin.h +++ b/kdevplatform/shell/tests/plugins/projectnondefaultplugin.cpp @@ -1,7 +1,7 @@ /* * This file is part of KDevelop * - * Copyright 2007 Hamish Rodda + * Copyright 2017 Friedrich W. H. Kossebau * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -19,29 +19,23 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef NONGUIINTERFACEPLUGIN -#define NONGUIINTERFACEPLUGIN - #include -#include +#include -class ITestNonGuiInterface +class ProjectNonDefaultPlugin : public KDevelop::IPlugin { + Q_OBJECT public: - virtual ~ITestNonGuiInterface() {} + ProjectNonDefaultPlugin(QObject* parent, const QVariantList&); }; -Q_DECLARE_INTERFACE( ITestNonGuiInterface, "org.kdevelop.ITestNonGuiInterface" ) - - -class NonGuiInterfacePlugin : public KDevelop::IPlugin, ITestNonGuiInterface +ProjectNonDefaultPlugin::ProjectNonDefaultPlugin(QObject* parent, const QVariantList&) + : IPlugin(QStringLiteral("projectnondefaultplugin"), parent) { - Q_OBJECT - Q_INTERFACES(ITestNonGuiInterface) -public: - explicit NonGuiInterfacePlugin( QObject* parent, const QVariantList& = QVariantList() ); -}; +} -#endif +K_PLUGIN_FACTORY_WITH_JSON(ProjectNonDefaultPluginFactory, "projectnondefaultplugin.testpluginjson", + registerPlugin();) +#include "projectnondefaultplugin.moc" diff --git a/kdevplatform/shell/tests/plugins/projectnondefaultplugin.testpluginjson b/kdevplatform/shell/tests/plugins/projectnondefaultplugin.testpluginjson new file mode 100644 --- /dev/null +++ b/kdevplatform/shell/tests/plugins/projectnondefaultplugin.testpluginjson @@ -0,0 +1,14 @@ +{ + "KPlugin": { + "Description": "This plugin is purely for unit-test", + "Id": "test_projectnondefault", + "License": "LGPL", + "Name": "ProjectNonDefaultPlugin", + "EnabledByDefault": false, + "ServiceTypes": [ + "KDevelop/Plugin" + ] + }, + "X-KDevelop-Category": "Project", + "X-KDevelop-Mode": "NoGUI" +} diff --git a/kdevplatform/shell/tests/test_plugincontroller.cpp b/kdevplatform/shell/tests/test_plugincontroller.cpp --- a/kdevplatform/shell/tests/test_plugincontroller.cpp +++ b/kdevplatform/shell/tests/test_plugincontroller.cpp @@ -19,8 +19,8 @@ #include "test_plugincontroller.h" -#include "nonguiinterfaceplugin.h" #include "testfilepaths.h" +#include "plugins/nonguiinterface.h" #include #include @@ -37,7 +37,7 @@ { qApp->addLibraryPath(QStringLiteral(TEST_PLUGIN_DIR)); - AutoTestShell::init({QStringLiteral("kdevnonguiinterface")}); + AutoTestShell::init({QStringLiteral("test_nonguiinterface")}); TestCore::initialize( Core::NoUi ); m_pluginCtrl = Core::self()->pluginControllerInternal(); } @@ -57,33 +57,33 @@ void TestPluginController::pluginInfo() { - IPlugin* plugin = m_pluginCtrl->loadPlugin( QStringLiteral("kdevnonguiinterface") ); + IPlugin* plugin = m_pluginCtrl->loadPlugin(QStringLiteral("test_nonguiinterface")); QVERIFY(plugin); KPluginMetaData pluginInfo = m_pluginCtrl->pluginInfo(plugin); - QCOMPARE(pluginInfo.pluginId(), QStringLiteral("kdevnonguiinterface")); + QCOMPARE(pluginInfo.pluginId(), QStringLiteral("test_nonguiinterface")); } void TestPluginController::loadUnloadPlugin() { QSignalSpy spy(m_pluginCtrl, SIGNAL(pluginLoaded(KDevelop::IPlugin*))); QSignalSpy spyloading(m_pluginCtrl, SIGNAL(loadingPlugin(QString))); QVERIFY(spy.isValid()); QVERIFY(spyloading.isValid()); - m_pluginCtrl->loadPlugin( QStringLiteral( "kdevnonguiinterface" ) ); - QVERIFY( m_pluginCtrl->plugin( QStringLiteral( "kdevnonguiinterface" ) ) ); + m_pluginCtrl->loadPlugin(QStringLiteral("test_nonguiinterface")); + QVERIFY( m_pluginCtrl->plugin(QStringLiteral("test_nonguiinterface")) ); QCOMPARE(spy.size(), 1); QCOMPARE(spyloading.size(), 1); QList args = spyloading.takeFirst(); - QCOMPARE( args.at(0).toString(), QStringLiteral( "kdevnonguiinterface" ) ); + QCOMPARE( args.at(0).toString(), QStringLiteral("test_nonguiinterface") ); QSignalSpy spy2(m_pluginCtrl, SIGNAL(pluginUnloaded(KDevelop::IPlugin*)) ); QSignalSpy spy3(m_pluginCtrl, SIGNAL(unloadingPlugin(KDevelop::IPlugin*)) ); QVERIFY(spy2.isValid()); QVERIFY(spy3.isValid()); - m_pluginCtrl->unloadPlugin( QStringLiteral("kdevnonguiinterface") ); - QVERIFY( !m_pluginCtrl->plugin( QStringLiteral( "kdevnonguiinterface" ) ) ); + m_pluginCtrl->unloadPlugin(QStringLiteral("test_nonguiinterface")); + QVERIFY( !m_pluginCtrl->plugin(QStringLiteral("test_nonguiinterface")) ); QCOMPARE(spy2.size(), 1); QCOMPARE(spy3.size(), 1); diff --git a/kdevplatform/shell/tests/nonguiinterfaceplugin.h b/kdevplatform/shell/tests/test_pluginenabling.h rename from kdevplatform/shell/tests/nonguiinterfaceplugin.h rename to kdevplatform/shell/tests/test_pluginenabling.h --- a/kdevplatform/shell/tests/nonguiinterfaceplugin.h +++ b/kdevplatform/shell/tests/test_pluginenabling.h @@ -1,7 +1,5 @@ /* - * This file is part of KDevelop - * - * Copyright 2007 Hamish Rodda + * Copyright 2017 Friedrich W. H. Kossebau * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -19,29 +17,33 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef NONGUIINTERFACEPLUGIN -#define NONGUIINTERFACEPLUGIN +#ifndef KDEVPLATFORM_TEST_PLUGINENABLING_H +#define KDEVPLATFORM_TEST_PLUGINENABLING_H -#include +#include -#include +namespace KDevelop +{ +class PluginController; +} -class ITestNonGuiInterface +class TestPluginEnabling : public QObject { -public: - virtual ~ITestNonGuiInterface() {} -}; + Q_OBJECT -Q_DECLARE_INTERFACE( ITestNonGuiInterface, "org.kdevelop.ITestNonGuiInterface" ) +private Q_SLOTS: + void initTestCase(); + void loadPluginCustomDefaults_data(); + void loadPluginCustomDefaults(); + void loadPluginNormalDefaults_data(); + void loadPluginNormalDefaults(); -class NonGuiInterfacePlugin : public KDevelop::IPlugin, ITestNonGuiInterface -{ - Q_OBJECT - Q_INTERFACES(ITestNonGuiInterface) -public: - explicit NonGuiInterfacePlugin( QObject* parent, const QVariantList& = QVariantList() ); -}; +private: + void loadPlugin(const QString& pluginId, bool shouldBeEnabled); -#endif +private: + KDevelop::PluginController* m_pluginCtrl; +}; +#endif // KDEVPLATFORM_TEST_PLUGINENABLING_H diff --git a/kdevplatform/shell/tests/test_pluginenabling.cpp b/kdevplatform/shell/tests/test_pluginenabling.cpp new file mode 100644 --- /dev/null +++ b/kdevplatform/shell/tests/test_pluginenabling.cpp @@ -0,0 +1,147 @@ +/* + * Copyright 2017 Friedrich W. H. Kossebau + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "test_pluginenabling.h" + +#include "testfilepaths.h" + +#include +#include + +#include + +#include +#include +#include + +#include "../core.h" +#include "../plugincontroller.h" + +using namespace KDevelop; + +void TestPluginEnabling::initTestCase() +{ + qApp->addLibraryPath(QStringLiteral(TEST_PLUGIN_DIR)); +} + +void TestPluginEnabling::loadPlugin(const QString& pluginId, bool shouldBeEnabled) +{ + // check config storage + KConfigGroup grp = Core::self()->activeSession()->config()->group(QStringLiteral("Plugins")); + + const QString pluginEnabledKey = pluginId + QLatin1String("Enabled"); + // logic in kdevelop + const bool enabled = grp.hasKey(pluginEnabledKey) ? grp.readEntry(pluginEnabledKey, true) : false; + + QCOMPARE(enabled, shouldBeEnabled); + + // check plugin loading + QCOMPARE((m_pluginCtrl->loadPlugin(pluginId) != nullptr), shouldBeEnabled); + QCOMPARE((m_pluginCtrl->plugin(pluginId) != nullptr), shouldBeEnabled); + + if (shouldBeEnabled) { + m_pluginCtrl->unloadPlugin(pluginId); + QVERIFY(!m_pluginCtrl->plugin(pluginId)); + } + + // switch enabled state + const bool shouldNowBeEnabled = !shouldBeEnabled; + grp.writeEntry(pluginEnabledKey, shouldNowBeEnabled); + + // check plugin loading again + QCOMPARE((m_pluginCtrl->loadPlugin(pluginId) != nullptr), shouldNowBeEnabled); + QCOMPARE((m_pluginCtrl->plugin(pluginId) != nullptr), shouldNowBeEnabled); + + if (shouldNowBeEnabled) { + m_pluginCtrl->unloadPlugin(pluginId); + QVERIFY(!m_pluginCtrl->plugin(pluginId)); + } + +} + +void TestPluginEnabling::loadPluginCustomDefaults_data() +{ + QTest::addColumn("pluginId"); + QTest::addColumn("shouldBeEnabled"); + + QTest::newRow("test_globaldefault") << "test_globaldefault" << false; + QTest::newRow("test_globalnondefault") << "test_globalnondefault" << true; + QTest::newRow("test_projectdefault") << "test_projectdefault" << false; + QTest::newRow("test_projectnondefault") << "test_projectnondefault" << true; +} + +void TestPluginEnabling::loadPluginCustomDefaults() +{ + QFETCH(QString, pluginId); + QFETCH(bool, shouldBeEnabled); + + AutoTestShell::init({ + // set those as default which would not be by own metadata + // and do not set those which otherwise would, so both + QStringLiteral("test_globalnondefault"), + QStringLiteral("test_projectnondefault") + }); + // TODO: somehow currently the clean-up of the previous session is not yet done + // on the next data item test run, so the session with the name is still locked + // so we work-around that for now by using a custom session name per session + // TODO: consider adding a new bool temporarySession = true to TestCore::initialize() + TestCore::initialize(Core::NoUi, QStringLiteral("test_pluginenabling_custom_")+pluginId); + TestCore::self()->activeSession()->setTemporary(true); + m_pluginCtrl = Core::self()->pluginControllerInternal(); + + loadPlugin(pluginId, shouldBeEnabled); + + TestCore::shutdown(); +} + +void TestPluginEnabling::loadPluginNormalDefaults_data() +{ + QTest::addColumn("pluginId"); + QTest::addColumn("shouldBeEnabled"); + + QTest::newRow("test_globaldefault") << "test_globaldefault" << true; + QTest::newRow("test_globalnondefault") << "test_globalnondefault" << false; + QTest::newRow("test_projectdefault") << "test_projectdefault" << true; + QTest::newRow("test_projectnondefault") << "test_projectnondefault" << false; +} + +void TestPluginEnabling::loadPluginNormalDefaults() +{ + QFETCH(QString, pluginId); + QFETCH(bool, shouldBeEnabled); + + AutoTestShell::init(); + // see TODO in loadPluginCustomDefaults() + TestCore::initialize(Core::NoUi, QStringLiteral("test_pluginenabling_normal_")+pluginId); + TestCore::self()->activeSession()->setTemporary(true); + m_pluginCtrl = Core::self()->pluginControllerInternal(); + + // check plugin metadata + const auto pluginInfo = m_pluginCtrl->infoForPluginId(pluginId); + // logic in kdevelop different from KPluginMetaData::isEnabledByDefault(), here defaults to true + const auto enabledByDefaultValue = pluginInfo.rawData()["KPlugin"].toObject()["EnabledByDefault"]; + const bool enabledByDefault = (enabledByDefaultValue.isNull() || enabledByDefaultValue.toBool()); + QCOMPARE(enabledByDefault, shouldBeEnabled); + + loadPlugin(pluginId, shouldBeEnabled); + + TestCore::shutdown(); +} + +QTEST_MAIN(TestPluginEnabling) diff --git a/plugins/cmake/tests/test_cmakemanager.cpp b/plugins/cmake/tests/test_cmakemanager.cpp --- a/plugins/cmake/tests/test_cmakemanager.cpp +++ b/plugins/cmake/tests/test_cmakemanager.cpp @@ -44,7 +44,7 @@ { QLoggingCategory::setFilterRules(QStringLiteral("*.debug=false\ndefault.debug=true\n")); - AutoTestShell::init({"kdevcmakemanager"}); + AutoTestShell::init({"KDevCMakeManager", "KDevCMakeBuilder", "KDevMakeBuilder", "KDevStandardOutputView"}); TestCore::initialize(); cleanup(); diff --git a/plugins/cmake/tests/test_ctestfindsuites.cpp b/plugins/cmake/tests/test_ctestfindsuites.cpp --- a/plugins/cmake/tests/test_ctestfindsuites.cpp +++ b/plugins/cmake/tests/test_ctestfindsuites.cpp @@ -53,7 +53,7 @@ void TestCTestFindSuites::initTestCase() { - AutoTestShell::init({"kdevcmakemanager"}); + AutoTestShell::init({"KDevCMakeManager", "KDevCMakeBuilder", "KDevMakeBuilder", "KDevStandardOutputView"}); TestCore::initialize(); cleanup(); diff --git a/plugins/custom-buildsystem/tests/test_custombuildsystemplugin.cpp b/plugins/custom-buildsystem/tests/test_custombuildsystemplugin.cpp --- a/plugins/custom-buildsystem/tests/test_custombuildsystemplugin.cpp +++ b/plugins/custom-buildsystem/tests/test_custombuildsystemplugin.cpp @@ -52,7 +52,7 @@ } void TestCustomBuildSystemPlugin::initTestCase() { - AutoTestShell::init({"kdevcustombuildsystem"}); + AutoTestShell::init({"KDevCustomBuildSystem", "KDevStandardOutputView"}); TestCore::initialize(); } diff --git a/plugins/qmakemanager/tests/test_qmakeproject.cpp b/plugins/qmakemanager/tests/test_qmakeproject.cpp --- a/plugins/qmakemanager/tests/test_qmakeproject.cpp +++ b/plugins/qmakemanager/tests/test_qmakeproject.cpp @@ -55,7 +55,7 @@ void TestQMakeProject::initTestCase() { - AutoTestShell::init({ "kdevqmakemanager" }); + AutoTestShell::init({ "KDevQMakeManager", "KDevQMakeBuilder", "KDevMakeBuilder", "KDevStandardOutputView" }); TestCore::initialize(); } diff --git a/plugins/qmljs/duchain/tests/test_qmljsdeclarations.cpp b/plugins/qmljs/duchain/tests/test_qmljsdeclarations.cpp --- a/plugins/qmljs/duchain/tests/test_qmljsdeclarations.cpp +++ b/plugins/qmljs/duchain/tests/test_qmljsdeclarations.cpp @@ -44,7 +44,7 @@ void TestDeclarations::initTestCase() { - AutoTestShell::init({"kdevqmljslanguagesupport"}); + AutoTestShell::init({"kdevqmljs"}); TestCore::initialize(Core::NoUi); QmlJS::registerDUChainItems(); diff --git a/plugins/qmljs/tests/test_files.cpp b/plugins/qmljs/tests/test_files.cpp --- a/plugins/qmljs/tests/test_files.cpp +++ b/plugins/qmljs/tests/test_files.cpp @@ -46,7 +46,7 @@ void TestFiles::initTestCase() { - AutoTestShell::init({"kdevqmljslanguagesupport"}); + AutoTestShell::init({"kdevqmljs"}); TestCore::initialize(KDevelop::Core::NoUi); DUChain::self()->disablePersistentStorage(); Core::self()->languageController()->backgroundParser()->setDelay(0); diff --git a/plugins/subversion/tests/test_svnimport.cpp b/plugins/subversion/tests/test_svnimport.cpp --- a/plugins/subversion/tests/test_svnimport.cpp +++ b/plugins/subversion/tests/test_svnimport.cpp @@ -73,7 +73,7 @@ void TestSvnImport::initTestCase() { QLoggingCategory::setFilterRules(QStringLiteral("*.debug=false\ndefault.debug=true\nkdevplatform.plugins.svn.debug=true\n")); - AutoTestShell::init({QStringLiteral("kdevsubversion")}); + AutoTestShell::init({QStringLiteral("kdevsubversion"), QStringLiteral("KDevStandardOutputView")}); TestCore::initialize(); QList plugins = Core::self()->pluginController()->allPluginsForExtension(QStringLiteral("org.kdevelop.IBasicVersionControl")); diff --git a/plugins/subversion/tests/test_svnrecursiveadd.cpp b/plugins/subversion/tests/test_svnrecursiveadd.cpp --- a/plugins/subversion/tests/test_svnrecursiveadd.cpp +++ b/plugins/subversion/tests/test_svnrecursiveadd.cpp @@ -110,7 +110,7 @@ void TestSvnRecursiveAdd::initTestCase() { - AutoTestShell::init({"kdevsubversion"}); + AutoTestShell::init({"kdevsubversion", "KDevStandardOutputView"}); TestCore::initialize(); }