From 13d332d090102724af6e3730cae84fc9d538b536 Mon Sep 17 00:00:00 2001 From: Vladimir Kotikov Date: Wed, 2 Mar 2016 13:26:01 +0300 Subject: [PATCH 1/2] CB-10710 Respect plugman's www option when installing plugins --- bin/templates/cordova/Api.js | 38 ++++++++++++++------- bin/templates/cordova/lib/pluginHandlers.js | 14 +++----- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/bin/templates/cordova/Api.js b/bin/templates/cordova/Api.js index ad6f71c6d7..a6c1b7e068 100644 --- a/bin/templates/cordova/Api.js +++ b/bin/templates/cordova/Api.js @@ -184,8 +184,7 @@ Api.prototype.addPlugin = function (plugin, installOptions) { if (!plugin || plugin.constructor.name !== 'PluginInfo') return Q.reject(new CordovaError('The parameter is incorrect. The first parameter to addPlugin should be a PluginInfo instance')); - installOptions = installOptions || {}; - installOptions.variables = installOptions.variables || {}; + installOptions = this._processPluginOptions(installOptions); var self = this; var actions = new ActionStack(); @@ -224,11 +223,7 @@ Api.prototype.addPlugin = function (plugin, installOptions) { require('./lib/builders/builders').getBuilder('gradle').prepBuildFiles(); } - var targetDir = installOptions.usePlatformWww ? - self.locations.platformWww : - self.locations.www; - - self._addModulesInfo(plugin, targetDir); + self._addModulesInfo(plugin, installOptions.www_dir); }); }; @@ -254,6 +249,8 @@ Api.prototype.removePlugin = function (plugin, uninstallOptions) { var actions = new ActionStack(); var project = AndroidProject.getProjectFile(this.root); + uninstallOptions = this._processPluginOptions(uninstallOptions); + // queue up plugin files plugin.getFilesAndFrameworks(this.platform) .concat(plugin.getAssets(this.platform)) @@ -282,11 +279,7 @@ Api.prototype.removePlugin = function (plugin, uninstallOptions) { require('./lib/builders/builders').getBuilder('gradle').prepBuildFiles(); } - var targetDir = uninstallOptions.usePlatformWww ? - self.locations.platformWww : - self.locations.www; - - self._removeModulesInfo(plugin, targetDir); + self._removeModulesInfo(plugin, uninstallOptions.www_dir); }); }; @@ -502,3 +495,24 @@ Api.prototype._writePluginModules = function (targetDir) { shell.mkdir('-p', targetDir); fs.writeFileSync(path.join(targetDir, 'cordova_plugins.js'), final_contents, 'utf-8'); }; + +/** + * Process options for addPlugin/removePlugin methods. Sets up www directory + * location based on options object. + * + * @param {Object} options Options object for add/removePlugin methods + * @return {Object} Processed options + */ +Api.prototype._processPluginOptions = function (options) { + options = options || {}; + options.variables = options.variables || {}; + + // CB-10710 Use Plugman's CLI www_dir option as www files destination. If + // not specified, choose either "www" or "platform_www" depending on + // "usePlatformWww" option. + if (!options.www_dir) { + options.www_dir = (options.usePlatformWww === true) ? + this.locations.www : + this.locations.platformWww; + } +}; diff --git a/bin/templates/cordova/lib/pluginHandlers.js b/bin/templates/cordova/lib/pluginHandlers.js index 1ee6b1f37c..052fdf6d87 100644 --- a/bin/templates/cordova/lib/pluginHandlers.js +++ b/bin/templates/cordova/lib/pluginHandlers.js @@ -124,17 +124,15 @@ var handlers = { throw new CordovaError(' tag without required "target" attribute'); } - var www = options.usePlatformWww ? project.platformWww : project.www; - copyFile(plugin.dir, obj.src, www, obj.target); + copyFile(plugin.dir, obj.src, options.www_dir, obj.target); }, uninstall:function(obj, plugin, project, options) { var target = obj.target || obj.src; if (!target) throw new CordovaError(' tag without required "target" attribute'); - var www = options.usePlatformWww ? project.platformWww : project.www; - removeFile(www, target); - removeFileF(path.resolve(www, 'plugins', plugin.id)); + removeFile(options.www_dir, target); + removeFileF(path.resolve(options.www_dir, 'plugins', plugin.id)); } }, 'js-module': { @@ -150,15 +148,13 @@ var handlers = { } scriptContent = 'cordova.define("' + moduleName + '", function(require, exports, module) {\n' + scriptContent + '\n});\n'; - var www = options.usePlatformWww ? project.platformWww : project.www; - var moduleDestination = path.resolve(www, 'plugins', plugin.id, obj.src); + var moduleDestination = path.resolve(options.www_dir, 'plugins', plugin.id, obj.src); shell.mkdir('-p', path.dirname(moduleDestination)); fs.writeFileSync(moduleDestination, scriptContent, 'utf-8'); }, uninstall: function (obj, plugin, project, options) { var pluginRelativePath = path.join('plugins', plugin.id, obj.src); - var www = options.usePlatformWww ? project.platformWww : project.www; - removeFileAndParents(www, pluginRelativePath); + removeFileAndParents(options.www_dir, pluginRelativePath); } } }; From e2253c11a637125488e47716fc67d7cf94a651d5 Mon Sep 17 00:00:00 2001 From: Vladimir Kotikov Date: Thu, 3 Mar 2016 10:58:14 +0300 Subject: [PATCH 2/2] Fix plugin failure instalation and trigger CI --- bin/templates/cordova/Api.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/templates/cordova/Api.js b/bin/templates/cordova/Api.js index a6c1b7e068..5562a5c5bc 100644 --- a/bin/templates/cordova/Api.js +++ b/bin/templates/cordova/Api.js @@ -515,4 +515,6 @@ Api.prototype._processPluginOptions = function (options) { this.locations.www : this.locations.platformWww; } + + return options; };