[rkward-cvs] SF.net SVN: rkward-code:[4519] trunk/rkward

tfry at users.sf.net tfry at users.sf.net
Thu Jan 31 12:16:59 UTC 2013


Revision: 4519
          http://sourceforge.net/p/rkward/code/4519
Author:   tfry
Date:     2013-01-31 12:16:58 +0000 (Thu, 31 Jan 2013)
Log Message:
-----------
Add means for including pluginmap by id rather than relative filename.
Undocumented, untested. The point is to support inclusion across packages.

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/plugin/rkcomponentmap.cpp
    trunk/rkward/rkward/plugin/rkcomponentmap.h
    trunk/rkward/rkward/plugins/all.pluginmap
    trunk/rkward/rkward/plugins/analysis.pluginmap
    trunk/rkward/rkward/plugins/data.pluginmap
    trunk/rkward/rkward/plugins/distributions.pluginmap
    trunk/rkward/rkward/plugins/embedded.pluginmap
    trunk/rkward/rkward/plugins/import_export.pluginmap
    trunk/rkward/rkward/plugins/irt.pluginmap
    trunk/rkward/rkward/plugins/plots.pluginmap
    trunk/rkward/rkward/plugins/x11device.pluginmap
    trunk/rkward/rkward/settings/rksettingsmoduleplugins.cpp
    trunk/rkward/rkward/settings/rksettingsmoduleplugins.h

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2013-01-29 18:39:47 UTC (rev 4518)
+++ trunk/rkward/ChangeLog	2013-01-31 12:16:58 UTC (rev 4519)
@@ -1,5 +1,7 @@
+- Pluginmaps can <require> other pluginmaps based on their id (for cross-package inclusion)
+	- TODO: document, test
 - Added new element <dependency_check> for dynamic version checks within a plugin (R and RKWard versions, only, so far)
-	- TODO: document, test
+	- TODO: document
 - Add guard against accidental usage of the standard distributed pluginmaps in a later version of RKWard (installed in parallel)
 - Easier (de-)activation of RKWard plugin maps using checkboxes (Settings->Configure RKWard->Plugins)
 - Broken or quirky .pluginmap files are reported to the user, and disables completely broken maps, automatically
@@ -8,7 +10,7 @@
 	- TODO:
 		- Also provide "about" info and dependencies on plugin help pages
 		- Explicitly document the fact that <include>s can be used for <about> and <dependencies>
-		- Think about means for cross-package pluginmap includes
+		- Provide "priority" argument for pluginmaps (hidden,low,mid,high; where only mid and high will be activated by default)
 - Added support for the upcoming R 3.0.0			TODO: Check for any more regressions, before release
 - Added <switch> logic element to switch between several target properties (or fixed values) based on the value of a condition property
 - Sort plugin gains option to sort data.frames by more than one column at a time, and options for type conversion	TODO: adjust test(s)

Modified: trunk/rkward/rkward/plugin/rkcomponentmap.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentmap.cpp	2013-01-29 18:39:47 UTC (rev 4518)
+++ trunk/rkward/rkward/plugin/rkcomponentmap.cpp	2013-01-31 12:16:58 UTC (rev 4519)
@@ -30,14 +30,24 @@
 #include "rkcomponentcontext.h"
 #include "rkstandardcomponent.h"
 #include "../misc/xmlhelper.h"
+#include "../misc/rkcommonfunctions.h"
 #include "../debug.h"
 #include "../rkglobals.h"
 #include "../rkward.h"
+#include "../settings/rksettingsmoduleplugins.h"
 
 QString RKPluginMapFile::makeFileName (const QString &filename) {
 	return QDir::cleanPath (QDir (basedir).filePath (filename));
 }
 
+QString RKPluginMapFile::parseId (const QDomElement& e) {
+	RK_TRACE (PLUGIN);
+
+	XMLHelper *xml = XMLHelper::getStaticHelper ();
+	return (xml->getStringAttribute (e, "namespace", "rkward", DL_WARNING) + "::" + xml->getStringAttribute (e, "id", QString (), DL_INFO));
+}
+
+
 RKComponentGUIXML::RKComponentGUIXML () {
 	RK_TRACE (PLUGIN);
 
@@ -353,6 +363,7 @@
 	QString cnamespace = xml->getStringAttribute (document_element, "namespace", "rkward", DL_INFO) + "::";
 
 	RKPluginMapFile *pluginmap_file_desc = new RKPluginMapFile (prefix);
+	pluginmap_file_desc->id = RKPluginMapFile::parseId (document_element);
 	pluginmapfiles.insert (QFileInfo (plugin_map_file).absoluteFilePath (), pluginmap_file_desc);
 
 	// step 0: check dependencies, parse about, and initialize
@@ -369,11 +380,31 @@
 	QStringList includelist;
 	list = xml->getChildElements (document_element, "require", DL_INFO);
 	for (XMLChildList::const_iterator it=list.constBegin (); it != list.constEnd (); ++it) {
-		QString file = pluginmap_file_desc->makeFileName (xml->getStringAttribute (*it, "file", QString::null, DL_ERROR));
-		if (QFileInfo (file).isReadable ()) {
-			includelist.append (file);
+		if ((*it).hasAttribute ("file")) {
+			QString file = pluginmap_file_desc->makeFileName (xml->getStringAttribute (*it, "file", QString (), DL_ERROR));
+			if (QFileInfo (file).isReadable ()) {
+				includelist.append (file);
+			} else {
+				ret.addAndPrintError (DL_ERROR, i18n ("Specified required file '%1' does not exist or is not readable. Ignoring.", file));
+			}
 		} else {
-			ret.addAndPrintError (DL_ERROR, i18n ("Specified required file '%1' does not exist or is not readable. Ignoring.", file));
+			QString map_id = xml->getStringAttribute (*it, "map", QString (), DL_ERROR);
+			// Try to locate the map among the already loaded files, first
+			QString file;
+			for (PluginMapFileMap::const_iterator pmit = pluginmapfiles.constBegin (); pmit != pluginmapfiles.constEnd (); ++pmit) {
+				if (pmit.value ()->id == map_id) {
+					file = pmit.key ();
+					break;
+				}
+			}
+			// If the map is not among the loaded files, try to look it up among all known pluginmaps
+			if (file.isEmpty ()) file = RKSettingsModulePlugins::findPluginMapById (map_id);
+			if (!file.isEmpty ()) {
+				RK_DEBUG (PLUGIN, DL_INFO, "Resolving plugin map specification %s to filename %s", qPrintable (map_id), qPrintable (file));
+				includelist.append (file);
+			} else {
+				ret.addAndPrintError (DL_ERROR, i18n ("Could not resolve specified required pluginmap '%1'. You may have to install additional packages.", map_id));
+			}
 		}
 	}
 	for (QStringList::const_iterator it = includelist.constBegin (); it != includelist.constEnd (); ++it) {

Modified: trunk/rkward/rkward/plugin/rkcomponentmap.h
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentmap.h	2013-01-29 18:39:47 UTC (rev 4518)
+++ trunk/rkward/rkward/plugin/rkcomponentmap.h	2013-01-31 12:16:58 UTC (rev 4519)
@@ -31,9 +31,11 @@
 	QString getBaseDir () { return basedir; };
 	QString makeFileName (const QString &filename);
 	QList<RKComponentDependency> getDependencies () { return dependencies; };
+	static QString parseId (const QDomElement &e);
 private:
 friend class RKComponentMap;
 	QString basedir;
+	QString id;
 	QList<RKComponentDependency> dependencies;
 };
 

Modified: trunk/rkward/rkward/plugins/all.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/all.pluginmap	2013-01-29 18:39:47 UTC (rev 4518)
+++ trunk/rkward/rkward/plugins/all.pluginmap	2013-01-31 12:16:58 UTC (rev 4519)
@@ -1,6 +1,6 @@
 <!DOCTYPE rkpluginmap>
 
-<document base_prefix="" namespace="rkward">
+<document base_prefix="" namespace="rkward"  id="all_rkward_plugins">
 	<include file="pluginmap_meta.inc"/>
 
 	<require file="import_export.pluginmap"/>

Modified: trunk/rkward/rkward/plugins/analysis.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/analysis.pluginmap	2013-01-29 18:39:47 UTC (rev 4518)
+++ trunk/rkward/rkward/plugins/analysis.pluginmap	2013-01-31 12:16:58 UTC (rev 4519)
@@ -1,6 +1,6 @@
 <!DOCTYPE rkpluginmap>
 
-<document base_prefix="" namespace="rkward">
+<document base_prefix="" namespace="rkward" id="analysis">
 	<include file="pluginmap_meta.inc"/>
 
 	<components>

Modified: trunk/rkward/rkward/plugins/data.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/data.pluginmap	2013-01-29 18:39:47 UTC (rev 4518)
+++ trunk/rkward/rkward/plugins/data.pluginmap	2013-01-31 12:16:58 UTC (rev 4519)
@@ -1,6 +1,6 @@
 <!DOCTYPE rkpluginmap>
 
-<document base_prefix="" namespace="rkward">
+<document base_prefix="" namespace="rkward" id="data">
 	<include file="pluginmap_meta.inc"/>
 
 	<components>

Modified: trunk/rkward/rkward/plugins/distributions.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/distributions.pluginmap	2013-01-29 18:39:47 UTC (rev 4518)
+++ trunk/rkward/rkward/plugins/distributions.pluginmap	2013-01-31 12:16:58 UTC (rev 4519)
@@ -1,6 +1,6 @@
 <!DOCTYPE rkpluginmap>
 
-<document base_prefix="distributions/" namespace="rkward">
+<document base_prefix="distributions/" namespace="rkward" id="distributions">
 	<include file="pluginmap_meta.inc"/>
 
 	<components>

Modified: trunk/rkward/rkward/plugins/embedded.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/embedded.pluginmap	2013-01-29 18:39:47 UTC (rev 4518)
+++ trunk/rkward/rkward/plugins/embedded.pluginmap	2013-01-31 12:16:58 UTC (rev 4519)
@@ -1,6 +1,6 @@
 <!DOCTYPE rkpluginmap>
 
-<document base_prefix="" namespace="rkward">
+<document base_prefix="" namespace="rkward" id="embedded">
 	<include file="pluginmap_meta.inc"/>
 
 	<components>

Modified: trunk/rkward/rkward/plugins/import_export.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/import_export.pluginmap	2013-01-29 18:39:47 UTC (rev 4518)
+++ trunk/rkward/rkward/plugins/import_export.pluginmap	2013-01-31 12:16:58 UTC (rev 4519)
@@ -1,6 +1,6 @@
 <!DOCTYPE rkpluginmap>
 
-<document base_prefix="00saveload/" namespace="rkward">
+<document base_prefix="00saveload/" namespace="rkward" id="import_export">
 	<include file="pluginmap_meta.inc"/>
 
 	<components>

Modified: trunk/rkward/rkward/plugins/irt.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/irt.pluginmap	2013-01-29 18:39:47 UTC (rev 4518)
+++ trunk/rkward/rkward/plugins/irt.pluginmap	2013-01-31 12:16:58 UTC (rev 4519)
@@ -1,6 +1,6 @@
 <!DOCTYPE rkpluginmap>
 
-<document base_prefix="" namespace="rkward">
+<document base_prefix="" namespace="rkward" id="irt">
 	<include file="pluginmap_meta.inc"/>
 
 	<components>

Modified: trunk/rkward/rkward/plugins/plots.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/plots.pluginmap	2013-01-29 18:39:47 UTC (rev 4518)
+++ trunk/rkward/rkward/plugins/plots.pluginmap	2013-01-31 12:16:58 UTC (rev 4519)
@@ -1,6 +1,6 @@
 <!DOCTYPE rkpluginmap>
 
-<document base_prefix="plots/" namespace="rkward">
+<document base_prefix="plots/" namespace="rkward" id="plots">
 	<include file="pluginmap_meta.inc"/>
 
 	<components>

Modified: trunk/rkward/rkward/plugins/x11device.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/x11device.pluginmap	2013-01-29 18:39:47 UTC (rev 4518)
+++ trunk/rkward/rkward/plugins/x11device.pluginmap	2013-01-31 12:16:58 UTC (rev 4519)
@@ -1,6 +1,6 @@
 <!DOCTYPE rkpluginmap>
 
-<document base_prefix="x11device/" namespace="rkward">
+<document base_prefix="x11device/" namespace="rkward" id="x11device">
 	<include file="pluginmap_meta.inc"/>
 
 	<components>

Modified: trunk/rkward/rkward/settings/rksettingsmoduleplugins.cpp
===================================================================
--- trunk/rkward/rkward/settings/rksettingsmoduleplugins.cpp	2013-01-29 18:39:47 UTC (rev 4518)
+++ trunk/rkward/rkward/settings/rksettingsmoduleplugins.cpp	2013-01-31 12:16:58 UTC (rev 4519)
@@ -166,6 +166,7 @@
 		ppmg.writeEntry ("Broken", inf.broken_in_this_version);
 		ppmg.writeEntry ("Quirky", inf.quirky_in_this_version);
 		ppmg.writeEntry ("timestamp", inf.last_modified);
+		ppmg.writeEntry ("id", inf.id);
 		all_known_maps.append (inf.filename);
 	}
 	// NOTE: The group list is always sorted alphabetically, which is why we need a separate list setting for saving info on order.
@@ -200,6 +201,7 @@
 			inf.broken_in_this_version = ppmg.readEntry ("Broken", false) && !RKSettingsModuleGeneral::rkwardVersionChanged ();
 			inf.quirky_in_this_version = ppmg.readEntry ("Quirky", false) && !RKSettingsModuleGeneral::rkwardVersionChanged ();
 			inf.last_modified = ppmg.readEntry ("timestamp", QDateTime ());
+			inf.id = ppmg.readEntry ("id");
 			known_plugin_maps.append (inf);
 		}
 	}
@@ -223,6 +225,21 @@
 	return i;
 }
 
+QString RKSettingsModulePlugins::findPluginMapById (const QString &id) {
+	RK_TRACE (SETTINGS);
+
+	for (int i = 0; i < known_plugin_maps.size (); ++i) {
+		if (known_plugin_maps[i].id == id) return known_plugin_maps[i].filename;
+	}
+	// for "rkward::" namespace, try a little harded:
+	if (id.startsWith ("rkward::")) {
+		QFileInfo info (RKCommonFunctions::getRKWardDataDir () + "/" + id.mid (8));
+		if (info.isReadable ()) return info.absoluteFilePath ();
+	}
+
+	return QString ();
+}
+
 bool RKSettingsModulePlugins::markPluginMapAsBroken (const QString& map) {
 	RK_TRACE (SETTINGS);
 
@@ -320,8 +337,13 @@
 				inf.broken_in_this_version = false;
 				inf.quirky_in_this_version = false;
 				inf.last_modified = info.lastModified ();
+				inf.id.clear ();
 			}
 		}
+
+		if (inf.id.isEmpty ()) {
+			inf.id = RKPluginMapFile::parseId (XMLHelper::getStaticHelper ()->openXMLFile (inf.filename, DL_WARNING));
+		}
 	}
 
 	// make sure the default plugin map is in the list (unless it is non-readable)

Modified: trunk/rkward/rkward/settings/rksettingsmoduleplugins.h
===================================================================
--- trunk/rkward/rkward/settings/rksettingsmoduleplugins.h	2013-01-29 18:39:47 UTC (rev 4518)
+++ trunk/rkward/rkward/settings/rksettingsmoduleplugins.h	2013-01-31 12:16:58 UTC (rev 4519)
@@ -60,6 +60,8 @@
 	 * @param force_reload If true, plugin maps are always reloaded, even if no maps were added
 	 */
 	static void registerPluginMaps (const QStringList &maps, bool force_add, bool force_reload);
+	/** Looks for the given id among known plugin maps */
+	static QString findPluginMapById (const QString &id);
 	/** marks given map as broken (in this version), and deactivates it. @Returns false is the map was already known to be broken, true otherwise. */
 	static bool markPluginMapAsBroken (const QString &map);
 	/** marks given map as quirky (in this version). @Returns false is the map was already known to be quirky, true otherwise. */
@@ -73,6 +75,7 @@
 		bool active;
 		bool broken_in_this_version;
 		bool quirky_in_this_version;
+		QString id;
 		QDateTime last_modified;
 	};
 	typedef QList<PluginMapStoredInfo> PluginMapList;





More information about the rkward-tracker mailing list