cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [1/5] git commit: Fix plugin check error, when plugin dependency with specific version is given
Date Fri, 20 Jun 2014 22:31:25 GMT
Repository: cordova-lib
Updated Branches:
  refs/heads/master aa2a04be7 -> 67d9679c0


Fix plugin check error, when plugin dependency with specific version is given


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

Branch: refs/heads/master
Commit: cc3117afbc63068fc8a9168798e11bbc00f270ea
Parents: b9347ee
Author: Vladimir Kotikov <v-vlkoti@microsoft.com>
Authored: Fri May 16 17:19:56 2014 +0400
Committer: Vladimir Kotikov <v-vlkoti@microsoft.com>
Committed: Fri May 16 17:21:01 2014 +0400

----------------------------------------------------------------------
 cordova-lib/spec-plugman/fetch.spec.js | 45 +++++++++++++++++++++++++++--
 cordova-lib/src/plugman/fetch.js       | 14 ++++++++-
 2 files changed, 55 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/cc3117af/cordova-lib/spec-plugman/fetch.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-plugman/fetch.spec.js b/cordova-lib/spec-plugman/fetch.spec.js
index 3d43863..c85c950 100644
--- a/cordova-lib/spec-plugman/fetch.spec.js
+++ b/cordova-lib/spec-plugman/fetch.spec.js
@@ -23,7 +23,7 @@ describe('fetch', function() {
         var xml, rm, sym, mkdir, cp, save_metadata;
         beforeEach(function() {
             xml = spyOn(xml_helpers, 'parseElementtreeSync').andReturn({
-                getroot:function() { return {attrib:{id:'id'}};}
+                getroot:function() { return {attrib:{id:'id', version:'version'}};}
             });
             rm = spyOn(shell, 'rm');
             sym = spyOn(fs, 'symlinkSync');
@@ -62,6 +62,19 @@ describe('fetch', function() {
                 expect(1).toBe(1);
             });
         });
+        it('should fail when the expected ID with version specified doesn\'t match', function(done)
{
+            fetch(test_plugin, temp, { expected_id: 'id@wrongVersion' })
+            .then(function() {
+                expect('this call').toBe('fail');
+            }, function(err) {
+                expect(''+err).toContain('Expected fetched plugin to have ID "id@wrongVersion"
but got "id@version".');
+            }).fin(done);
+        });
+        it('should succeed when the plugin version specified is correct', function(done)
{
+            wrapper(fetch(test_plugin, temp, { expected_id: 'id@version' }), done, function()
{
+                expect(1).toBe(1);
+            });
+        });
     });
     describe('git plugins', function() {
         var clone, save_metadata, done, xml;
@@ -75,7 +88,7 @@ describe('fetch', function() {
             save_metadata = spyOn(metadata, 'save_fetch_metadata');
             done = false;
             xml = spyOn(xml_helpers, 'parseElementtreeSync').andReturn({
-                getroot:function() { return {attrib:{id:'id'}};}
+                getroot:function() { return {attrib:{id:'id', version:'version'}};}
             });
         });
         it('should call clonePluginGitRepo for https:// and git:// based urls', function()
{
@@ -168,18 +181,31 @@ describe('fetch', function() {
                 expect(''+err).toContain('Expected fetched plugin to have ID "wrongID" but
got "id".');
             }).fin(done);
         });
+        it('should fail when the expected ID with version specified doesn\'t match', function(done)
{
+            fetch('https://github.com/bobeast/GAPlugin.git', temp, { expected_id: 'id@wrongVersion'
})
+            .then(function() {
+                expect('this call').toBe('fail');
+            }, function(err) {
+                expect(''+err).toContain('Expected fetched plugin to have ID "id@wrongVersion"
but got "id@version".');
+            }).fin(done);
+        });
         it('should succeed when the expected ID is correct', function(done) {
             wrapper(fetch('https://github.com/bobeast/GAPlugin.git', temp, { expected_id:
'id' }), done, function() {
                 expect(1).toBe(1);
             });
         });
+        it('should succeed when the plugin version specified is correct', function(done)
{
+            wrapper(fetch('https://github.com/bobeast/GAPlugin.git', temp, { expected_id:
'id@version' }), done, function() {
+                expect(1).toBe(1);
+            });
+        });
     });
     describe('registry plugins', function() {
         var pluginId = 'dummyplugin', sFetch;
         var xml, rm, sym, mkdir, cp, save_metadata;
         beforeEach(function() {
             xml = spyOn(xml_helpers, 'parseElementtreeSync').andReturn({
-                getroot:function() { return {attrib:{id:'id'}};}
+                getroot:function() { return {attrib:{id:'id', version:'version'}};}
             });
             rm = spyOn(shell, 'rm');
             sym = spyOn(fs, 'symlinkSync');
@@ -202,10 +228,23 @@ describe('fetch', function() {
                 expect(''+err).toContain('Expected fetched plugin to have ID "wrongID" but
got "id".');
             }).fin(done);
         });
+        it('should fail when the expected ID with version specified doesn\'t match', function(done)
{
+            fetch(pluginId, temp, { expected_id: 'id@wrongVersion' })
+            .then(function() {
+                expect('this call').toBe('fail');
+            }, function(err) {
+                expect(''+err).toContain('Expected fetched plugin to have ID "id@wrongVersion"
but got "id@version".');
+            }).fin(done);
+        });
         it('should succeed when the expected ID is correct', function(done) {
             wrapper(fetch(pluginId, temp, { expected_id: 'id' }), done, function() {
                 expect(1).toBe(1);
             });
         });
+        it('should succeed when the plugin version specified is correct', function(done)
{
+            wrapper(fetch(pluginId, temp, { expected_id: 'id@version' }), done, function()
{
+                expect(1).toBe(1);
+            });
+        });
     });
 });

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/cc3117af/cordova-lib/src/plugman/fetch.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/fetch.js b/cordova-lib/src/plugman/fetch.js
index c0a6d7a..6518ea3 100644
--- a/cordova-lib/src/plugman/fetch.js
+++ b/cordova-lib/src/plugman/fetch.js
@@ -114,10 +114,22 @@ function readId(dir) {
     return plugin_id;
 }
 
+function readVersion(dir) {
+    var xml_path = path.join(dir, 'plugin.xml');
+    var et = xml_helpers.parseElementtreeSync(path.join(dir, 'plugin.xml'));
+    var plugin_id = et.getroot().attrib.version;
+    return plugin_id;
+}
+
 // Helper function for checking expected plugin IDs against reality.
 function checkID(expected_id, dir) {
     if ( expected_id ) {
-        var id = readId(dir);
+        // check for plugin version specified (like some.plugin@0.2.3)
+        var id = expected_id.split('@').length == 1 ?
+            readId(dir) :
+            // if id with specific version provided (via '@' symbol), append version to id
+            readId(dir) + "@" + readVersion(dir);
+
         if (expected_id != id) {
             throw new Error('Expected fetched plugin to have ID "' + expected_id + '" but
got "' + id + '".');
         }


Mime
View raw message