You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2015/12/05 02:26:57 UTC
[3/8] cordova-lib git commit: take plugin class name from the
plugin.xml to avoid class name guess work
take plugin class name from the plugin.xml to avoid class name guess work
Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/1ae6a863
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/1ae6a863
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/1ae6a863
Branch: refs/heads/master
Commit: 1ae6a8631a92f58020c3b0139931d784843c281e
Parents: afde15c
Author: David Barth <da...@canonical.com>
Authored: Tue Nov 3 18:13:49 2015 +0100
Committer: David Barth <da...@canonical.com>
Committed: Tue Nov 3 18:13:49 2015 +0100
----------------------------------------------------------------------
cordova-lib/src/plugman/platforms/ubuntu.js | 49 ++++++++++++++++++++----
1 file changed, 41 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/1ae6a863/cordova-lib/src/plugman/platforms/ubuntu.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/platforms/ubuntu.js b/cordova-lib/src/plugman/platforms/ubuntu.js
index 78a2f04..0f6cee9 100644
--- a/cordova-lib/src/plugman/platforms/ubuntu.js
+++ b/cordova-lib/src/plugman/platforms/ubuntu.js
@@ -29,14 +29,47 @@ function toCamelCase(str) {
}).join('');
}
-function findClassName(str) {
+function getPluginXml(plugin_dir) {
+ var et = require('elementtree'),
+ fs = require('fs'),
+ shell = require('shelljs'),
+ path = require('path');
+
+ var pluginxml = undefined;
+ var config_path = path.join(plugin_dir, 'plugin.xml');
+
+ if (fs.existsSync(config_path)) {
+ // Get the current plugin.xml file
+ pluginxml = et.parse(fs.readFileSync(config_path, 'utf-8'));
+ }
+
+ return pluginxml;
+}
+
+function findClassName(pluginxml, plugin_id) {
var class_name;
- if (str.match(/\.[^.]+$/)) {
+ // first check if we have a class-name parameter in the plugin config
+ if (pluginxml) {
+ var platform = pluginxml.find("./platform/[@name='ubuntu']/");
+ if (platform) {
+ var param = platform.find("./config-file/[@target='config.xml']/feature/param/[@name='ubuntu-package']");
+ if (param && param.attrib) {
+ class_name = param.attrib.value;
+ return class_name;
+ }
+ }
+ }
+
+ // fallback to guess work, based on the plugin package name
+
+ if (plugin_id.match(/\.[^.]+$/)) {
// old-style plugin name
- class_name = str.match(/\.[^.]+$/)[0].substr(1);
+ class_name = plugin_id.match(/\.[^.]+$/)[0].substr(1);
+ class_name = toCamelCase(class_name);
} else {
- class_name = str.match(/cordova\-plugin\-([\w\-]+)$/)[0].substr(15);
+ class_name = plugin_id.match(/cordova\-plugin\-([\w\-]+)$/)[0].substr(15);
+ class_name = toCamelCase(class_name);
}
return class_name;
@@ -84,8 +117,9 @@ module.exports = {
var src = String(fs.readFileSync(plugins));
src = src.replace('INSERT_HEADER_HERE', '#include "plugins/' + plugin_id + '/' + path.basename(obj.src) +'"\nINSERT_HEADER_HERE');
- var class_name = findClassName(plugin_id);
- class_name = toCamelCase(class_name);
+
+ var pluginxml = getPluginXml(plugin_dir);
+ var class_name = findClassName(pluginxml, plugin_id);
src = src.replace('INSERT_PLUGIN_HERE', 'INIT_PLUGIN(' + class_name + ');INSERT_PLUGIN_HERE');
fs.writeFileSync(plugins, src);
@@ -98,8 +132,7 @@ module.exports = {
var src = String(fs.readFileSync(plugins));
src = src.replace('#include "plugins/' + plugin_id + '/' + path.basename(obj.src) +'"', '');
- var class_name = findClassName(plugin_id);
- class_name = toCamelCase(class_name);
+ var class_name = findClassName(undefined, plugin_id);
src = src.replace('INIT_PLUGIN(' + class_name + ');', '');
fs.writeFileSync(plugins, src);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org