[kdevplatform/1.7] /: Make it possible to define plugin dependencies by name.

Milian Wolff mail at milianw.de
Fri Jul 18 09:59:56 UTC 2014


Git commit b8745d3d8d7a14a139758394930a9baf1e8a072b by Milian Wolff.
Committed on 18/07/2014 at 09:56.
Pushed by mwolff into branch '1.7'.

Make it possible to define plugin dependencies by name.

To do so, define a X-KDevelop-IRequired entry in the plugin's
.desktop file with the contents "interface at pluginname", e.g.:

X-KDevelop-IRequired=org.kdevelop.IBasicVersionControl at kdevgit

In this case, only the kdevgit plugin is checked for the given
IBasicVersionControl interface.

The advantage here is that this way, the depdendency is also properly
tracked when trying to unload a plugin.

CCMAIL: kdevelop-devel at kde.org
CCBUG: 336948

M  +2    -1    interfaces/iplugin.h
M  +32   -8    shell/plugincontroller.cpp

http://commits.kde.org/kdevplatform/b8745d3d8d7a14a139758394930a9baf1e8a072b

diff --git a/interfaces/iplugin.h b/interfaces/iplugin.h
index f451fac..9b95b6f 100644
--- a/interfaces/iplugin.h
+++ b/interfaces/iplugin.h
@@ -108,7 +108,8 @@ class ContextMenuExtension;
  * - <i>X-KDevelop-Interfaces</i> is a list of extension interfaces that this
  * plugin implements (optional);
  * - <i>X-KDevelop-IRequired</i> is a list of extension interfaces that this
- * plugin depends on (optional);
+ * plugin depends on (optional); A list entry can also be of the form @c interface at pluginname,
+ * in which case a plugin of the given name is required which implements the interface.
  * - <i>X-KDevelop-IOptional</i> is a list of extension interfaces that this
  * plugin will use if they are available (optional);
  * - <i>X-KDevelop-Language</i> is the name of the language the plugin provides 
diff --git a/shell/plugincontroller.cpp b/shell/plugincontroller.cpp
index af32f47..c3196d3 100644
--- a/shell/plugincontroller.cpp
+++ b/shell/plugincontroller.cpp
@@ -119,6 +119,24 @@ bool constraintsMatch( const KPluginInfo& info, const QVariantMap& constraints)
     return true;
 }
 
+struct Dependency
+{
+    Dependency(const QString &dependency)
+        : interface(dependency)
+    {
+        if (dependency.contains('@')) {
+            const auto list = dependency.split('@', QString::SkipEmptyParts);
+            if (list.size() == 2) {
+                interface = list.at(0);
+                pluginName = list.at(1);
+            }
+        }
+    }
+
+    QString interface;
+    QString pluginName;
+};
+
 }
 
 namespace KDevelop {
@@ -161,8 +179,11 @@ public:
                 dependencies += info.property( KEY_Optional ).toStringList();
                 foreach( const QString& dep, dependencies )
                 {
-                    if( interfaces.contains( dep ) && !canUnload( info ) )
-                    {
+                    Dependency dependency(dep);
+                    if (!dependency.pluginName.isEmpty() && dependency.pluginName != plugin.pluginName()) {
+                        continue;
+                    }
+                    if (interfaces.contains(dependency.interface) && !canUnload(info)) {
                         return false;
                     }
                 }
@@ -514,6 +535,7 @@ bool PluginController::checkForDependencies( const KPluginInfo& info, QStringLis
             d->foreachEnabledPlugin([&required] (const KPluginInfo& plugin) -> bool {
                 foreach(const QString& iface, plugin.property( KEY_Interfaces ).toStringList()) {
                     required.remove(iface);
+                    required.remove(iface + '@' + plugin.pluginName());
                 }
                 return !required.isEmpty();
             });
@@ -530,9 +552,10 @@ void PluginController::loadOptionalDependencies( const KPluginInfo& info )
 {
     QVariant prop = info.property( KEY_Optional );
     if( prop.canConvert<QStringList>() ) {
-        foreach( const QString &iface, prop.toStringList() ) {
-            if (!pluginForExtension(iface)) {
-                kDebug() << "Couldn't load optional dependecy:" << iface << info.pluginName();
+        foreach( const QString &dep, prop.toStringList() ) {
+            Dependency dependency(dep);
+            if (!pluginForExtension(dependency.interface, dependency.pluginName)) {
+                kDebug() << "Couldn't load optional dependency:" << dep << info.pluginName();
             }
         }
     }
@@ -542,9 +565,10 @@ bool PluginController::loadDependencies( const KPluginInfo& info, QString& faile
 {
     QVariant prop = info.property( KEY_Required );
     if( prop.canConvert<QStringList>() ) {
-        foreach( const QString &iface, prop.toStringList() ) {
-            if (!pluginForExtension(iface)) {
-                failedDependency = iface;
+        foreach( const QString &value, prop.toStringList() ) {
+            Dependency dependency(value);
+            if (!pluginForExtension(dependency.interface, dependency.pluginName)) {
+                failedDependency = value;
                 return false;
             }
         }


More information about the KDevelop-devel mailing list