cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an-s...@apache.org
Subject cordova-lib git commit: CB-9631 Save plugin to config.xml only if installation succeeds
Date Thu, 10 Sep 2015 06:27:56 GMT
Repository: cordova-lib
Updated Branches:
  refs/heads/master 04310fb70 -> d104e3939


CB-9631 Save plugin to config.xml only if installation succeeds


Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/d104e393
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/d104e393
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/d104e393

Branch: refs/heads/master
Commit: d104e393988f3a71510f99a113236555b3e0f07f
Parents: 04310fb
Author: Vladimir Kotikov <v-vlkoti@microsoft.com>
Authored: Wed Sep 9 17:58:21 2015 +0300
Committer: Vladimir Kotikov <v-vlkoti@microsoft.com>
Committed: Wed Sep 9 19:00:57 2015 +0300

----------------------------------------------------------------------
 cordova-lib/spec-cordova/ConfigParser.spec.js | 26 +++++++-------
 cordova-lib/src/configparser/ConfigParser.js  | 16 ++++++---
 cordova-lib/src/cordova/plugin.js             | 41 ++++++++++------------
 3 files changed, 41 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/d104e393/cordova-lib/spec-cordova/ConfigParser.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/ConfigParser.spec.js b/cordova-lib/spec-cordova/ConfigParser.spec.js
index f3d0b8f..a888cf4 100644
--- a/cordova-lib/spec-cordova/ConfigParser.spec.js
+++ b/cordova-lib/spec-cordova/ConfigParser.spec.js
@@ -170,20 +170,18 @@ describe('config.xml parser', function () {
             });
             it('should allow adding features with params', function(){
                 cfg.addPlugin({name:'aplugin'}, [{name:'paraname',value:'paravalue'}]);
-                var plugins = cfg.doc.findall('plugin');
-                var plugin  = (function(){
-                    var i = plugins.length;
-                    var f;
-                    while (--i >= 0) {
-                        f = plugins[i];
-                        if ('aplugin' === f.attrib.name) return f;
-                    }
-                    return undefined;
-                })();
-                expect(plugin).toBeDefined();
-                var variables = plugin.findall('variable');
-                expect(variables[0].attrib.name).toEqual('paraname');
-                expect(variables[0].attrib.value).toEqual('paravalue');
+                // Additional check for new parameters syntax
+                cfg.addPlugin({name:'bplugin'}, {paraname: 'paravalue'});
+                var plugins = cfg.doc.findall('plugin')
+                .filter(function (plugin) {
+                    return plugin.attrib.name === 'aplugin' || plugin.attrib.name === 'bplugin';
+                });
+                expect(plugins.length).toBe(2);
+                plugins.forEach(function (plugin) {
+                    var variables = plugin.findall('variable');
+                    expect(variables[0].attrib.name).toEqual('paraname');
+                    expect(variables[0].attrib.value).toEqual('paravalue');
+                });
             });
             it('should be able to read legacy feature entries with a version', function(){
                 var plugin = cfg.getPlugin('org.apache.cordova.legacyfeatureversion');

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/d104e393/cordova-lib/src/configparser/ConfigParser.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/configparser/ConfigParser.js b/cordova-lib/src/configparser/ConfigParser.js
index 5d2bb83..9dcccb5 100644
--- a/cordova-lib/src/configparser/ConfigParser.js
+++ b/cordova-lib/src/configparser/ConfigParser.js
@@ -301,7 +301,7 @@ ConfigParser.prototype = {
      * @name addPlugin
      * @function
      * @param {object} attributes name and spec are supported
-     * @param {Array} variables name, value
+     * @param {Array|object} variables name, value or arbitary object
      */
     addPlugin: function (attributes, variables) {
         if (!attributes && !attributes.name) return;
@@ -310,12 +310,18 @@ ConfigParser.prototype = {
         if (attributes.spec) {
             el.attrib.spec = attributes.spec;
         }
+
+        // support arbitrary object as variables source
+        if (variables && typeof variables === 'object' && !Array.isArray(variables))
{
+            variables = Object.keys(variables)
+            .map(function (variableName) {
+                return {name: variableName, value: variables[variableName]};
+            });
+        }
+
         if (variables) {
             variables.forEach(function (variable) {
-                var v = new et.Element('variable');
-                v.attrib.name = variable.name;
-                v.attrib.value = variable.value;
-                el.append(v);
+                el.append(new et.Element('variable', { name: variable.name, value: variable.value
}));
             });
         }
         this.doc.getroot().append(el);

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/d104e393/cordova-lib/src/cordova/plugin.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/plugin.js b/cordova-lib/src/cordova/plugin.js
index 066bf07..d2a44b4 100644
--- a/cordova-lib/src/cordova/plugin.js
+++ b/cordova-lib/src/cordova/plugin.js
@@ -150,28 +150,6 @@ module.exports = function plugin(command, targets, opts) {
                             return pluginInfoProvider.get(directory);
                         });
                     })
-                    .then(function(pluginInfo){
-                        // save to config.xml
-                        if(saveToConfigXmlOn(config_json, opts)){
-
-                            var attributes = {};
-                            attributes.name = pluginInfo.id;
-
-                            var src = parseSource(target, opts);
-                            attributes.spec = src ? src : '~' + pluginInfo.version;
-
-                            var variables = Object.keys(opts.cli_variables || [])
-                            .map(function (variableName) {
-                                return {name: variableName, value: opts.cli_variables[variableName]};
-                            });
-
-                            cfg.removePlugin(pluginInfo.id);
-                            cfg.addPlugin(attributes, variables);
-                            cfg.write();
-                            events.emit('results', 'Saved plugin info for "' + pluginInfo.id
+ '" to config.xml');
-                        }
-                        return pluginInfo;
-                    })
                     .then(function(pluginInfo) {
                         // Validate top-level required variables
                         var pluginVariables = pluginInfo.getPreferences();
@@ -201,7 +179,24 @@ module.exports = function plugin(command, targets, opts) {
 
                             events.emit('verbose', 'Calling plugman.install on plugin "'
+ pluginInfo.dir + '" for platform "' + platform);
                             return plugman.raw.install(platform, platformRoot, path.basename(pluginInfo.dir),
pluginPath, options);
-                        });
+                        })
+                        .thenResolve(pluginInfo);
+                    })
+                    .then(function(pluginInfo){
+                        // save to config.xml
+                        if(saveToConfigXmlOn(config_json, opts)){
+                            var src = parseSource(target, opts);
+                            var attributes = {
+                                name: pluginInfo.id,
+                                spec: src ? src : '~' + pluginInfo.version
+                            };
+
+                            cfg.removePlugin(pluginInfo.id);
+                            cfg.addPlugin(attributes, opts.cli_variables);
+                            cfg.write();
+
+                            events.emit('results', 'Saved plugin info for "' + pluginInfo.id
+ '" to config.xml');
+                        }
                     });
                 }, Q()); // end Q.all
             }).then(function() {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message