You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by an...@apache.org on 2013/03/04 20:32:51 UTC
[62/91] [abbrv] git commit: Issue #17 Adding collision detection for
iOS/Android
Issue #17 Adding collision detection for iOS/Android
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/b11e3538
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/b11e3538
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/b11e3538
Branch: refs/heads/master
Commit: b11e35389bae0300c9686695b937a594617c39b8
Parents: 6a8d07b
Author: Anis Kadri <an...@gmail.com>
Authored: Mon Jan 14 15:59:19 2013 -0800
Committer: Anis Kadri <an...@gmail.com>
Committed: Mon Jan 14 15:59:19 2013 -0800
----------------------------------------------------------------------
platforms/android.js | 14 ++++++++++++++
platforms/ios.js | 13 +++++++++++++
test/android-two-install.js | 10 ++++++++++
test/android-two-uninstall.js | 10 ++++++++++
test/ios-install.js | 9 +++++++++
test/ios-uninstall.js | 7 +++++++
6 files changed, 63 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/b11e3538/platforms/android.js
----------------------------------------------------------------------
diff --git a/platforms/android.js b/platforms/android.js
index 46cc5e7..0a25da9 100644
--- a/platforms/android.js
+++ b/platforms/android.js
@@ -28,6 +28,13 @@ exports.handlePlugin = function (action, project_dir, plugin_dir, plugin_et) {
delete configChanges[configFile];
}
});
+
+ // collision detection
+ if(action == "install" && pluginInstalled(plugin_et, project_dir)) {
+ throw "Plugin "+plugin_id+" already installed"
+ } else if(action == "uninstall" && !pluginInstalled(plugin_et, project_dir)) {
+ throw "Plugin "+plugin_id+" not installed"
+ }
// move asset files
assets.forEach(function (asset) {
@@ -154,3 +161,10 @@ function androidPackageName(project_dir) {
return mDoc._root.attrib['package'];
}
+
+function pluginInstalled(plugin_et, project_dir) {
+ var config_tag = plugin_et.find('./platform[@name="android"]/config-file[@target="res/xml/config.xml"]/plugin')
+ var plugin_name = config_tag.attrib.name;
+ return (fs.readFileSync(path.resolve(project_dir, 'res/xml/config.xml'), 'utf8')
+ .match(new RegExp(plugin_name, "g")) != null);
+}
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/b11e3538/platforms/ios.js
----------------------------------------------------------------------
diff --git a/platforms/ios.js b/platforms/ios.js
index 88e2da8..63e3eaf 100644
--- a/platforms/ios.js
+++ b/platforms/ios.js
@@ -42,6 +42,12 @@ exports.handlePlugin = function (action, project_dir, plugin_dir, plugin_et) {
var pluginsDir = path.resolve(config_files[0], '..', 'Plugins');
var resourcesDir = path.resolve(config_files[0], '..', 'Resources');
+ // collision detection
+ if(action == "install" && pluginInstalled(plugin_et, config_files[0])) {
+ throw "Plugin "+plugin_id+" already installed"
+ } else if(action == "uninstall" && !pluginInstalled(plugin_et, config_files[0])) {
+ throw "Plugin "+plugin_id+" not installed"
+ }
var assets = plugin_et.findall('./asset'),
platformTag = plugin_et.find('./platform[@name="ios"]'),
sourceFiles = platformTag.findall('./source-file'),
@@ -208,6 +214,13 @@ function updatePlistFile(action, config_path, plugin_et) {
fs.writeFileSync(config_path, plist.build(plistObj));
}
+function pluginInstalled(plugin_et, config_path) {
+ var config_tag = plugin_et.find('./platform[@name="ios"]/config-file[@target="config.xml"]/plugin') ||
+ plugin_et.find('./platform[@name="ios"]/plugins-plist');
+ var plugin_name = config_tag.attrib.name || config_tag.attrib.key;
+ return (fs.readFileSync(config_path, 'utf8').match(new RegExp(plugin_name, "g")) != null);
+}
+
function updateConfigXml(action, config_path, plugin_et) {
var hosts = plugin_et.findall('./access'),
platformTag = plugin_et.find('./platform[@name="ios"]'), // FIXME: can probably do better than this
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/b11e3538/test/android-two-install.js
----------------------------------------------------------------------
diff --git a/test/android-two-install.js b/test/android-two-install.js
index 1a22817..ba6c1ac 100644
--- a/test/android-two-install.js
+++ b/test/android-two-install.js
@@ -113,3 +113,13 @@ exports['should add ChildBrowser to AndroidManifest.xml'] = function (test) {
test.ok(found);
test.done();
}
+
+exports['should not install a plugin that is already installed'] = function (test) {
+ var jsPath = path.join(test_dir, 'projects', 'android_two', 'assets', 'www', 'childbrowser.js');
+
+ android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et);
+
+ test.throws(function() {android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et);}, /already installed/);
+
+ test.done();
+}
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/b11e3538/test/android-two-uninstall.js
----------------------------------------------------------------------
diff --git a/test/android-two-uninstall.js b/test/android-two-uninstall.js
index 1dde569..86ce80f 100644
--- a/test/android-two-uninstall.js
+++ b/test/android-two-uninstall.js
@@ -130,3 +130,13 @@ exports['should remove ChildBrowser from AndroidManifest.xml'] = function (test)
test.ok(!found);
test.done();
}
+
+exports['should not uninstall a plugin that is not installed'] = function (test) {
+ var jsPath = path.join(test_dir, 'projects', 'android_two', 'assets', 'www', 'childbrowser.js');
+
+ test.throws(function() {android.handlePlugin('uninstall', test_project_dir, test_plugin_dir, plugin_et);},
+ /not installed/
+ );
+
+ test.done();
+}
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/b11e3538/test/ios-install.js
----------------------------------------------------------------------
diff --git a/test/ios-install.js b/test/ios-install.js
index 84f045e..25e5075 100644
--- a/test/ios-install.js
+++ b/test/ios-install.js
@@ -176,3 +176,12 @@ exports['should add the framework references to the pbxproj file'] = function (t
test.equal(references.length, 4);
test.done();
}
+
+exports['should not install a plugin that is already installed'] = function (test) {
+ ios.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et);
+
+ test.throws(function(){ios.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et); },
+ /already installed/
+ );
+ test.done();
+}
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/b11e3538/test/ios-uninstall.js
----------------------------------------------------------------------
diff --git a/test/ios-uninstall.js b/test/ios-uninstall.js
index e6a3e38..7ec46ce 100644
--- a/test/ios-uninstall.js
+++ b/test/ios-uninstall.js
@@ -183,3 +183,10 @@ exports['should remove the framework references from the pbxproj file'] = functi
test.equal(references.length, 0);
test.done();
}
+
+exports['should not uninstall a plugin that is not installed'] = function (test) {
+ test.throws(function(){ios.handlePlugin('uninstall', test_project_dir, test_plugin_dir, plugin_et); },
+ /not installed/
+ );
+ test.done();
+}