Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B5D9719E2C for ; Mon, 18 Apr 2016 09:13:21 +0000 (UTC) Received: (qmail 71764 invoked by uid 500); 18 Apr 2016 09:13:21 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 71746 invoked by uid 500); 18 Apr 2016 09:13:21 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 71737 invoked by uid 99); 18 Apr 2016 09:13:21 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Apr 2016 09:13:21 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 212D5DFB95; Mon, 18 Apr 2016 09:13:21 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: an-selm@apache.org To: commits@cordova.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: ios commit: CB-11022 Duplicate www files on plugin installtion/removal Date: Mon, 18 Apr 2016 09:13:21 +0000 (UTC) Repository: cordova-ios Updated Branches: refs/heads/master 787bce0f8 -> 1d177aae2 CB-11022 Duplicate www files on plugin installtion/removal This closes #218 Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/1d177aae Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/1d177aae Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/1d177aae Branch: refs/heads/master Commit: 1d177aae2b89b44558c00aa42d1adfb776f50af9 Parents: 787bce0 Author: Vladimir Kotikov Authored: Thu Apr 14 14:57:26 2016 +0300 Committer: Vladimir Kotikov Committed: Mon Apr 18 12:12:53 2016 +0300 ---------------------------------------------------------------------- .../scripts/cordova/lib/plugman/Plugman.js | 40 ++++--- .../cordova/lib/plugman/pluginHandlers.js | 27 +++-- tests/spec/unit/Plugman/pluginHandler.spec.js | 110 +++++++++++++++++++ 3 files changed, 148 insertions(+), 29 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/1d177aae/bin/templates/scripts/cordova/lib/plugman/Plugman.js ---------------------------------------------------------------------- diff --git a/bin/templates/scripts/cordova/lib/plugman/Plugman.js b/bin/templates/scripts/cordova/lib/plugman/Plugman.js index 5855e9e..4414413 100644 --- a/bin/templates/scripts/cordova/lib/plugman/Plugman.js +++ b/bin/templates/scripts/cordova/lib/plugman/Plugman.js @@ -95,11 +95,12 @@ Plugman.prototype.addPlugin = function (plugin, installOptions) { .add_plugin_changes(plugin, installOptions.variables, /*is_top_level=*/true, /*should_increment=*/true) .save_all(); - var targetDir = installOptions.usePlatformWww ? - self.locations.platformWww : - self.locations.www; + var targetDirs = [self.locations.www]; + if (installOptions.usePlatformWww) targetDirs.push(self.locations.platformWww); + self._addModulesInfo(plugin, targetDirs); - self._addModulesInfo(plugin, targetDir); + // CB-11022 Return true to indicate that prepare is not necessary + return true; }); }; @@ -134,11 +135,12 @@ Plugman.prototype.removePlugin = function (plugin, uninstallOptions) { .remove_plugin_changes(plugin, /*is_top_level=*/true) .save_all(); - var targetDir = uninstallOptions.usePlatformWww ? - self.locations.platformWww : - self.locations.www; + var targetDirs = [self.locations.www]; + if (uninstallOptions.usePlatformWww) targetDirs.push(self.locations.platformWww); + self._removeModulesInfo(plugin, targetDirs); - self._removeModulesInfo(plugin, targetDir); + // CB-11022 Return true to indicate that prepare is not necessary + return true; }); }; @@ -148,10 +150,10 @@ Plugman.prototype.removePlugin = function (plugin, uninstallOptions) { * * @param {PluginInfo} plugin PluginInfo instance for plugin, which modules * needs to be added. - * @param {String} targetDir The directory, where updated cordova_plugins.js + * @param {String[]} targetDirs The directories, where updated cordova_plugins.js * should be written to. */ -Plugman.prototype._addModulesInfo = function(plugin, targetDir) { +Plugman.prototype._addModulesInfo = function(plugin, targetDirs) { var installedModules = this._platformJson.root.modules || []; var installedPaths = installedModules.map(function (installedModule) { @@ -186,7 +188,7 @@ Plugman.prototype._addModulesInfo = function(plugin, targetDir) { this._platformJson.root.plugin_metadata = {}; } this._platformJson.root.plugin_metadata[plugin.id] = plugin.version; - this._writePluginModules(targetDir); + this._writePluginModules(targetDirs); this._platformJson.save(); }; @@ -194,11 +196,11 @@ Plugman.prototype._addModulesInfo = function(plugin, targetDir) { * Fetches all installed modules, generates cordova_plugins contents and writes * it to file. * - * @param {String} targetDir Directory, where write cordova_plugins.js to. + * @param {String[]} targetDirs Directories, where write cordova_plugins.js to. * Ususally it is either /www or /platform_www * directories. */ -Plugman.prototype._writePluginModules = function (targetDir) { +Plugman.prototype._writePluginModules = function (targetDirs) { // Write out moduleObjects as JSON wrapped in a cordova module to cordova_plugins.js var final_contents = 'cordova.define(\'cordova/plugin_list\', function(require, exports, module) {\n'; final_contents += 'module.exports = ' + JSON.stringify(this._platformJson.root.modules, null, ' ') + ';\n'; @@ -209,8 +211,10 @@ Plugman.prototype._writePluginModules = function (targetDir) { final_contents += '// BOTTOM OF METADATA\n'; final_contents += '});'; // Close cordova.define. - shell.mkdir('-p', targetDir); - fs.writeFileSync(path.join(targetDir, 'cordova_plugins.js'), final_contents, 'utf-8'); + targetDirs.forEach(function (targetDir) { + shell.mkdir('-p', targetDir); + fs.writeFileSync(path.join(targetDir, 'cordova_plugins.js'), final_contents, 'utf-8'); + }); }; /** @@ -219,10 +223,10 @@ Plugman.prototype._writePluginModules = function (targetDir) { * * @param {PluginInfo} plugin PluginInfo instance for plugin, which modules * needs to be removed. - * @param {String} targetDir The directory, where updated cordova_plugins.js + * @param {String[]} targetDirs The directories, where updated cordova_plugins.js * should be written to. */ -Plugman.prototype._removeModulesInfo = function(plugin, targetDir) { +Plugman.prototype._removeModulesInfo = function(plugin, targetDirs) { var installedModules = this._platformJson.root.modules || []; var modulesToRemove = plugin.getJsModules(this.platform) .map(function (jsModule) { @@ -238,6 +242,6 @@ Plugman.prototype._removeModulesInfo = function(plugin, targetDir) { if (this._platformJson.root.plugin_metadata) { delete this._platformJson.root.plugin_metadata[plugin.id]; } - this._writePluginModules(targetDir); + this._writePluginModules(targetDirs); this._platformJson.save(); }; http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/1d177aae/bin/templates/scripts/cordova/lib/plugman/pluginHandlers.js ---------------------------------------------------------------------- diff --git a/bin/templates/scripts/cordova/lib/plugman/pluginHandlers.js b/bin/templates/scripts/cordova/lib/plugman/pluginHandlers.js index e5b2330..239883b 100644 --- a/bin/templates/scripts/cordova/lib/plugman/pluginHandlers.js +++ b/bin/templates/scripts/cordova/lib/plugman/pluginHandlers.js @@ -133,9 +133,8 @@ 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, project.www, obj.target); + if (options && options.usePlatformWww) copyFile(plugin.dir, obj.src, project.platformWww, obj.target); }, uninstall:function(obj, plugin, project, options) { var target = obj.target; @@ -144,17 +143,19 @@ var handlers = { throw new Error(' tag without required "target" attribute'); } - var www = options.usePlatformWww ? project.platformWww : project.www; - - removeFile(www, target); + removeFile(project.www, target); removeFileF(path.resolve(project.www, 'plugins', plugin.id)); + if (options && options.usePlatformWww) { + removeFile(project.platformWww, target); + removeFileF(path.resolve(project.platformWww, 'plugins', plugin.id)); + } } }, 'js-module': { install: function (obj, plugin, project, options) { // Copy the plugin's files into the www directory. var moduleSource = path.resolve(plugin.dir, obj.src); - var moduleName = plugin.id + '.' + (obj.name || path.parse(obj.src).name); + var moduleName = plugin.id + '.' + (obj.name || path.basename(obj.src, path.extname (obj.src))); // Read in the file, prepend the cordova.define, and write it back out. var scriptContent = fs.readFileSync(moduleSource, 'utf-8').replace(/^\ufeff/, ''); // Window BOM @@ -163,15 +164,19 @@ 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(project.www, 'plugins', plugin.id, obj.src); shell.mkdir('-p', path.dirname(moduleDestination)); fs.writeFileSync(moduleDestination, scriptContent, 'utf-8'); + if (options && options.usePlatformWww) { + var platformWwwDestination = path.resolve(project.platformWww, 'plugins', plugin.id, obj.src); + shell.mkdir('-p', path.dirname(platformWwwDestination)); + fs.writeFileSync(platformWwwDestination, 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(project.www, pluginRelativePath); + if (options && options.usePlatformWww) removeFileAndParents(project.platformWww, pluginRelativePath); } } }; http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/1d177aae/tests/spec/unit/Plugman/pluginHandler.spec.js ---------------------------------------------------------------------- diff --git a/tests/spec/unit/Plugman/pluginHandler.spec.js b/tests/spec/unit/Plugman/pluginHandler.spec.js index d5b30d4..3ac7393 100644 --- a/tests/spec/unit/Plugman/pluginHandler.spec.js +++ b/tests/spec/unit/Plugman/pluginHandler.spec.js @@ -262,6 +262,54 @@ describe('ios plugin handler', function() { }); }); + describe('of elements', function() { + var jsModule = {src: 'www/dummyPlugin.js'}; + var install = pluginHandlers.getInstaller('js-module'); + var wwwDest, platformWwwDest; + + beforeEach(function () { + spyOn(fs, 'writeFileSync'); + wwwDest = path.resolve(dummyProject.www, 'plugins', dummyPluginInfo.id, jsModule.src); + platformWwwDest = path.resolve(dummyProject.platformWww, 'plugins', dummyPluginInfo.id, jsModule.src); + }); + + it('should put module to both www and platform_www when options.usePlatformWww flag is specified', function () { + install(jsModule, dummyPluginInfo, dummyProject, {usePlatformWww: true}); + expect(fs.writeFileSync).toHaveBeenCalledWith(wwwDest, jasmine.any(String), 'utf-8'); + expect(fs.writeFileSync).toHaveBeenCalledWith(platformWwwDest, jasmine.any(String), 'utf-8'); + }); + + it('should put module to www only when options.usePlatformWww flag is not specified', function () { + install(jsModule, dummyPluginInfo, dummyProject); + expect(fs.writeFileSync).toHaveBeenCalledWith(wwwDest, jasmine.any(String), 'utf-8'); + expect(fs.writeFileSync).not.toHaveBeenCalledWith(platformWwwDest, jasmine.any(String), 'utf-8'); + }); + }); + + describe('of elements', function() { + var asset = {src: 'www/dummyPlugin.js', target: 'foo/dummy.js'}; + var install = pluginHandlers.getInstaller('asset'); + var wwwDest, platformWwwDest; + + beforeEach(function () { + spyOn(shell, 'cp'); + wwwDest = path.resolve(dummyProject.www, asset.target); + platformWwwDest = path.resolve(dummyProject.platformWww, asset.target); + }); + + it('should put asset to both www and platform_www when options.usePlatformWww flag is specified', function () { + install(asset, dummyPluginInfo, dummyProject, {usePlatformWww: true}); + expect(shell.cp).toHaveBeenCalledWith('-f', path.resolve(dummyPluginInfo.dir, asset.src), path.resolve(dummyProject.www, asset.target)); + expect(shell.cp).toHaveBeenCalledWith('-f', path.resolve(dummyPluginInfo.dir, asset.src), path.resolve(dummyProject.platformWww, asset.target)); + }); + + it('should put asset to www only when options.usePlatformWww flag is not specified', function () { + install(asset, dummyPluginInfo, dummyProject); + expect(shell.cp).toHaveBeenCalledWith('-f', path.resolve(dummyPluginInfo.dir, asset.src), path.resolve(dummyProject.www, asset.target)); + expect(shell.cp).not.toHaveBeenCalledWith(path.resolve(dummyPluginInfo.dir, asset.src), path.resolve(dummyProject.platformWww, asset.target)); + }); + }); + it('of two plugins should apply xcode file changes from both', function(done){ var api = new Api('ios', temp); var fail = jasmine.createSpy('fail'); @@ -405,5 +453,67 @@ describe('ios plugin handler', function() { }); }); }); + + describe('of elements', function() { + var jsModule = {src: 'www/dummyPlugin.js'}; + var uninstall = pluginHandlers.getUninstaller('js-module'); + var wwwDest, platformWwwDest; + + beforeEach(function () { + wwwDest = path.resolve(dummyProject.www, 'plugins', dummyPluginInfo.id, jsModule.src); + platformWwwDest = path.resolve(dummyProject.platformWww, 'plugins', dummyPluginInfo.id, jsModule.src); + + spyOn(shell, 'rm'); + + var existsSyncOrig = fs.existsSync; + spyOn(fs, 'existsSync').andCallFake(function (file) { + if ([wwwDest, platformWwwDest].indexOf(file) >= 0 ) return true; + return existsSyncOrig.call(fs, file); + }); + }); + + it('should put module to both www and platform_www when options.usePlatformWww flag is specified', function () { + uninstall(jsModule, dummyPluginInfo, dummyProject, {usePlatformWww: true}); + expect(shell.rm).toHaveBeenCalledWith(jasmine.any(String), wwwDest); + expect(shell.rm).toHaveBeenCalledWith(jasmine.any(String), platformWwwDest); + }); + + it('should put module to www only when options.usePlatformWww flag is not specified', function () { + uninstall(jsModule, dummyPluginInfo, dummyProject); + expect(shell.rm).toHaveBeenCalledWith(jasmine.any(String), wwwDest); + expect(shell.rm).not.toHaveBeenCalledWith(jasmine.any(String), platformWwwDest); + }); + }); + + describe('of elements', function() { + var asset = {src: 'www/dummyPlugin.js', target: 'foo/dummy.js'}; + var uninstall = pluginHandlers.getUninstaller('asset'); + var wwwDest, platformWwwDest; + + beforeEach(function () { + wwwDest = path.resolve(dummyProject.www, asset.target); + platformWwwDest = path.resolve(dummyProject.platformWww, asset.target); + + spyOn(shell, 'rm'); + + var existsSyncOrig = fs.existsSync; + spyOn(fs, 'existsSync').andCallFake(function (file) { + if ([wwwDest, platformWwwDest].indexOf(file) >= 0 ) return true; + return existsSyncOrig.call(fs, file); + }); + }); + + it('should put module to both www and platform_www when options.usePlatformWww flag is specified', function () { + uninstall(asset, dummyPluginInfo, dummyProject, {usePlatformWww: true}); + expect(shell.rm).toHaveBeenCalledWith(jasmine.any(String), wwwDest); + expect(shell.rm).toHaveBeenCalledWith(jasmine.any(String), platformWwwDest); + }); + + it('should put module to www only when options.usePlatformWww flag is not specified', function () { + uninstall(asset, dummyPluginInfo, dummyProject); + expect(shell.rm).toHaveBeenCalledWith(jasmine.any(String), wwwDest); + expect(shell.rm).not.toHaveBeenCalledWith(jasmine.any(String), platformWwwDest); + }); + }); }); }); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org For additional commands, e-mail: commits-help@cordova.apache.org