Github user TimBarham commented on a diff in the pull request:

    https://github.com/apache/cordova-lib/pull/294#discussion_r46228904
  
    --- Diff: cordova-lib/src/plugman/platforms/ubuntu.js ---
    @@ -29,6 +29,51 @@ function toCamelCase(str) {
         }).join('');
     }
     
    +function getPluginXml(plugin_dir) {
    +    var et = require('elementtree'),
    +    fs = require('fs'),
    +    path = require('path');
    +
    +    var pluginxml;
    +    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;
    +
    +    // 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 = plugin_id.match(/\.[^.]+$/)[0].substr(1);
    +        class_name = toCamelCase(class_name);
    +    } else {
    +        class_name = 
plugin_id.match(/cordova\-plugin\-([\w\-]+)$/)[0].substr(15);
    --- End diff --
    
    This will fail with a JavaScript error if `plugin_id` does not start with 
`cordova-plugin`, since `match()` will return `null`. Instead, should do the 
`match()` call separately, then only try to get the first array element if the 
return value is not `null`. If the return value *is* `null`, then should use 
some fallback (like camel-case the entire `plugin_id`, for example).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@cordova.apache.org
For additional commands, e-mail: dev-h...@cordova.apache.org

Reply via email to