CB-11951 CB-11967: Respect preference default values when install plugin

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

Branch: refs/heads/master
Commit: afcffc59ad186ae98518ac890fd942d3ca7069d8
Parents: e8d02c2
Author: Nikita Matrosov <matrosov.nikit...@gmail.com>
Authored: Wed Oct 12 13:58:18 2016 +0300
Committer: Steve Gill <stevengil...@gmail.com>
Committed: Fri Oct 14 17:49:33 2016 -0700

----------------------------------------------------------------------
 cordova-lib/spec-cordova/plugin.spec.js | 18 ++++++++++++++++++
 cordova-lib/src/cordova/plugin.js       | 14 ++++++++------
 2 files changed, 26 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/afcffc59/cordova-lib/spec-cordova/plugin.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/plugin.spec.js 
b/cordova-lib/spec-cordova/plugin.spec.js
index ac6f6b9..7de1a0c 100644
--- a/cordova-lib/spec-cordova/plugin.spec.js
+++ b/cordova-lib/spec-cordova/plugin.spec.js
@@ -20,6 +20,7 @@
 var helpers = require('./helpers'),
     path = require('path'),
     Q = require('q'),
+    fs = require('fs'),
     shell = require('shelljs'),
     events = require('cordova-common').events,
     cordova = require('../src/cordova/cordova'),
@@ -203,6 +204,23 @@ describe('plugin end-to-end', function() {
         .fin(done);
     });
 
+    it('should respect preference default values', function (done) {    
+       addPlugin(path.join(pluginsDir, org_test_defaultvariables), 
org_test_defaultvariables, {cli_variables: { REQUIRED:'NO', 
REQUIRED_ANDROID:'NO'}}, done)
+       .then(function() {
+            var platformJsonPath = path.join(project, 'plugins', 
helpers.testPlatform + '.json');
+            var installed_plugins = 
JSON.parse(fs.readFileSync(platformJsonPath)).installed_plugins;
+            var defaultPluginPreferences = 
installed_plugins[org_test_defaultvariables];
+            expect(defaultPluginPreferences).toBeDefined();
+            expect(defaultPluginPreferences.DEFAULT).toBe('yes');
+            expect(defaultPluginPreferences.DEFAULT_ANDROID).toBe('yes');
+            expect(defaultPluginPreferences.REQUIRED_ANDROID).toBe('NO');
+            expect(defaultPluginPreferences.REQUIRED).toBe('NO');
+            return removePlugin(org_test_defaultvariables);
+       })
+       .fail(errorHandler.errorCallback)
+       .fin(done);
+    });
+
     it('should successfully add a plugin when specifying CLI variables', 
function(done) {
         addPlugin(path.join(pluginsDir, org_test_defaultvariables), 
org_test_defaultvariables, {cli_variables: { REQUIRED:'yes', 
REQUIRED_ANDROID:'yes'}}, done)
         .fail(errorHandler.errorCallback)

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/afcffc59/cordova-lib/src/cordova/plugin.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/plugin.js 
b/cordova-lib/src/cordova/plugin.js
index d803425..4ccf40e 100644
--- a/cordova-lib/src/cordova/plugin.js
+++ b/cordova-lib/src/cordova/plugin.js
@@ -155,12 +155,14 @@ module.exports = function plugin(command, targets, opts) {
                         .then(function(pluginInfo) {
                             // Validate top-level required variables
                             var pluginVariables = pluginInfo.getPreferences();
-                            opts.cli_variables = opts.cli_variables || {};     
                     
-                            var pluginEntry = cfg.getPlugin(pluginInfo.id);    
                       
-                            var pluginEntryVariables = pluginEntry ? 
pluginEntry.variables : {};                                                 
-                            
Object.keys(pluginVariables).forEach(function(varName) {
-                                opts.cli_variables[varName] = 
opts.cli_variables[varName] || pluginEntryVariables[varName];
-                            });                
+                            opts.cli_variables = opts.cli_variables || {};
+                            var pluginEntry = cfg.getPlugin(pluginInfo.id);
+                            // Get variables from config.xml
+                            var configVariables = pluginEntry ? 
pluginEntry.variables : {};
+                            // Add config variable if it's missing in 
cli_variables
+                            
Object.keys(configVariables).forEach(function(variable) {
+                                opts.cli_variables[variable] = 
opts.cli_variables[variable] || configVariables[variable];
+                            });
                             var missingVariables = Object.keys(pluginVariables)
                             .filter(function (variableName) {
                                 // discard variables with default value


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

Reply via email to