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-9556 Don't uninstall dependent plugin if it was installed as a top-level after
Date Mon, 31 Aug 2015 09:17:24 GMT
Repository: cordova-lib
Updated Branches:
  refs/heads/master 18ae81ccc -> 41765f1fd


CB-9556 Don't uninstall dependent plugin if it was installed as a top-level after


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

Branch: refs/heads/master
Commit: 41765f1fd7393be1fff2b39ba7cf00b5bf6f1ef1
Parents: 18ae81c
Author: Vladimir Kotikov <v-vlkoti@microsoft.com>
Authored: Wed Aug 26 12:58:33 2015 +0300
Committer: Vladimir Kotikov <v-vlkoti@microsoft.com>
Committed: Mon Aug 31 12:07:55 2015 +0300

----------------------------------------------------------------------
 cordova-lib/spec-plugman/uninstall.spec.js   | 28 ++++++++--
 cordova-lib/src/plugman/install.js           |  7 ++-
 cordova-lib/src/plugman/util/PlatformJson.js | 65 ++++++++++++++++++-----
 3 files changed, 81 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/41765f1f/cordova-lib/spec-plugman/uninstall.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-plugman/uninstall.spec.js b/cordova-lib/spec-plugman/uninstall.spec.js
index 552ee00..264d8b9 100644
--- a/cordova-lib/spec-plugman/uninstall.spec.js
+++ b/cordova-lib/spec-plugman/uninstall.spec.js
@@ -35,10 +35,12 @@ var uninstall = require('../src/plugman/uninstall'),
     srcProject = path.join(spec, 'projects', 'android_uninstall'),
     project = path.join(spec, 'projects', 'android_uninstall.test'),
     project2 = path.join(spec, 'projects', 'android_uninstall.test2'),
+    project3 = path.join(spec, 'projects', 'android_uninstall.test3'),
 
     plugins_dir = path.join(spec, 'plugins'),
     plugins_install_dir = path.join(project, 'cordova', 'plugins'),
     plugins_install_dir2 = path.join(project2, 'cordova', 'plugins'),
+    plugins_install_dir3 = path.join(project3, 'cordova', 'plugins'),
 
     plugins = {
         'org.test.plugins.dummyplugin' : path.join(plugins_dir, 'org.test.plugins.dummyplugin'),
@@ -55,10 +57,10 @@ function uninstallPromise(f) {
 describe('start', function() {
 
     it('start', function() {
-        shell.rm('-rf', project);
-        shell.rm('-rf', project2);
+        shell.rm('-rf', project, project2, project3);
         shell.cp('-R', path.join(srcProject, '*'), project);
         shell.cp('-R', path.join(srcProject, '*'), project2);
+        shell.cp('-R', path.join(srcProject, '*'), project3);
 
         done = false;
         promise = Q()
@@ -71,6 +73,10 @@ describe('start', function() {
         }).then(function(){
             return install('android', project2, plugins['A']);
         }).then(function(){
+            return install('android', project3, plugins['A']);
+        }).then(function(){
+            return install('android', project3, plugins['C']);
+        }).then(function(){
             done = true;
         }, function(err) {
             done = err.stack;
@@ -230,6 +236,21 @@ describe('uninstallPlugin', function() {
                 ]);
             });
         });
+
+        it('should not remove dependent plugin if it was installed after as top-level', function()
{
+            runs(function() {
+                uninstallPromise( uninstall.uninstallPlugin('A', plugins_install_dir3) );
+            });
+            waitsFor(function() { return done; }, 'promise never resolved', 200);
+            runs(function() {
+                var del = common.spy.getDeleted(emit);
+
+                expect(del).toEqual([
+                    'Deleted "D"',
+                    'Deleted "A"'
+                ]);
+            });
+        });
     });
 });
 
@@ -303,8 +324,7 @@ describe('end', function() {
             if(err)
                 plugman.emit('error', err);
 
-            shell.rm('-rf', project);
-            shell.rm('-rf', project2);
+            shell.rm('-rf', project, project2, project3);
             done = true;
         });
 

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/41765f1f/cordova-lib/src/plugman/install.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/install.js b/cordova-lib/src/plugman/install.js
index d8c1997..b99d155 100644
--- a/cordova-lib/src/plugman/install.js
+++ b/cordova-lib/src/plugman/install.js
@@ -274,7 +274,12 @@ function runInstall(actions, platform, project_dir, plugin_dir, plugins_dir,
opt
 
     if (platformJson.isPluginInstalled(pluginInfo.id)) {
         if (options.is_top_level) {
-            events.emit('results', 'Plugin "' + pluginInfo.id + '" already installed on '
+ platform + '.');
+            var msg = 'Plugin "' + pluginInfo.id + '" already installed on ' + platform +
'.';
+            if (platformJson.isPluginDependent(pluginInfo.id)) {
+                msg += ' Making it top-level.';
+                platformJson.makeTopLevel(pluginInfo.id).save();
+            }
+            events.emit('verbose', msg);
         } else {
             events.emit('verbose', 'Dependent plugin "' + pluginInfo.id + '" already installed
on ' + platform + '.');
         }

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/41765f1f/cordova-lib/src/plugman/util/PlatformJson.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/util/PlatformJson.js b/cordova-lib/src/plugman/util/PlatformJson.js
index fda1d0d..1b9f05b 100644
--- a/cordova-lib/src/plugman/util/PlatformJson.js
+++ b/cordova-lib/src/plugman/util/PlatformJson.js
@@ -42,21 +42,43 @@ PlatformJson.prototype.save = function() {
     fs.writeFileSync(this.filePath, JSON.stringify(this.root, null, 4), 'utf-8');
 };
 
-PlatformJson.prototype.isPluginInstalled = function(pluginId) {
-    var installed_plugin_id;
-    var json = this.root;
+/**
+ * Indicates whether the specified plugin is installed as a top-level (not as
+ *  dependency to others)
+ * @method function
+ * @param  {String} pluginId A plugin id to check for.
+ * @return {Boolean} true if plugin installed as top-level, otherwise false.
+ */
+PlatformJson.prototype.isPluginTopLevel = function(pluginId) {
+    var installedPlugins = this.root.installed_plugins;
+    return installedPlugins[pluginId] ||
+        installedPlugins[pluginMappernto[pluginId]] ||
+        installedPlugins[pluginMapperotn[pluginId]];
+};
 
-    for (installed_plugin_id in json.installed_plugins) {
-        if ((installed_plugin_id == pluginId)||(installed_plugin_id == pluginMappernto[pluginId])
|| (installed_plugin_id == pluginMapperotn[pluginId])) {
-            return true;
-        }
-    }
-    for (installed_plugin_id in json.dependent_plugins) {
-        if ((installed_plugin_id == pluginId)||(installed_plugin_id == pluginMappernto[pluginId])
|| (installed_plugin_id == pluginMapperotn[pluginId])) {
-            return true;
-        }
-    }
-    return false;
+/**
+ * Indicates whether the specified plugin is installed as a dependency to other
+ *  plugin.
+ * @method function
+ * @param  {String} pluginId A plugin id to check for.
+ * @return {Boolean} true if plugin installed as a dependency, otherwise false.
+ */
+PlatformJson.prototype.isPluginDependent = function(pluginId) {
+    var dependentPlugins = this.root.dependent_plugins;
+    return dependentPlugins[pluginId] ||
+        dependentPlugins[pluginMappernto[pluginId]] ||
+        dependentPlugins[pluginMapperotn[pluginId]];
+};
+
+/**
+ * Indicates whether plugin is installed either as top-level or as dependency.
+ * @method function
+ * @param  {String} pluginId A plugin id to check for.
+ * @return {Boolean} true if plugin installed, otherwise false.
+ */
+PlatformJson.prototype.isPluginInstalled = function(pluginId) {
+    return this.isPluginTopLevel(pluginId) ||
+        this.isPluginDependent(pluginId);
 };
 
 PlatformJson.prototype.addInstalledPluginToPrepareQueue = function(pluginDirName, vars, is_top_level)
{
@@ -67,6 +89,21 @@ PlatformJson.prototype.addUninstalledPluginToPrepareQueue = function(pluginId,
i
     this.root.prepare_queue.uninstalled.push({'plugin':pluginId, 'id':pluginId, 'topLevel':is_top_level});
 };
 
+/**
+ * Moves plugin, specified by id to top-level plugins. If plugin is top-level
+ *  already, then does nothing.
+ * @method function
+ * @param  {String} pluginId A plugin id to make top-level.
+ * @return {PlatformJson} PlatformJson instance.
+ */
+PlatformJson.prototype.makeTopLevel = function(pluginId) {
+    var plugin = this.root.dependent_plugins[pluginId];
+    if (plugin) {
+        delete this.root.dependent_plugins[pluginId];
+        this.root.installed_plugins[pluginId] = plugin;
+    }
+    return this;
+};
 
 // convert a munge from the old format ([file][parent][xml] = count) to the current one
 function fix_munge(root) {


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


Mime
View raw message