Repository: cordova-lib
Updated Branches:
  refs/heads/master 8030d2af3 -> 193bdf3d4


CB-12683: improved error messaging for when a plugin doesn't have package.json


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

Branch: refs/heads/master
Commit: 193bdf3d4e7e3878c51ed02a876a868304bf638b
Parents: 8030d2a
Author: Steve Gill <[email protected]>
Authored: Fri Apr 21 12:08:06 2017 -0700
Committer: Steve Gill <[email protected]>
Committed: Fri Apr 21 14:07:18 2017 -0700

----------------------------------------------------------------------
 cordova-lib/spec-plugman/fetch.spec.js          | 31 ++++++++++++++++++--
 .../plugins/pkgjson-test-plugin/package.json    | 28 ++++++++++++++++++
 .../plugins/pkgjson-test-plugin/plugin.xml      |  4 +++
 cordova-lib/src/plugman/fetch.js                | 11 +++++--
 4 files changed, 70 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/193bdf3d/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 f22832f..f772822 100644
--- a/cordova-lib/spec-plugman/fetch.spec.js
+++ b/cordova-lib/spec-plugman/fetch.spec.js
@@ -28,6 +28,7 @@ var rewire  = require('rewire'),
     metadata = require('../src/plugman/util/metadata'),
     temp    = path.join(os.tmpdir(), 'plugman', 'fetch'),
     test_plugin = path.join(__dirname, 'plugins', 
'org.test.plugins.childbrowser'),
+    test_pkgjson_plugin = path.join(__dirname, 'plugins', 
'pkgjson-test-plugin'),
     test_plugin_searchpath = path.join(test_plugin, '..'),
     //test_plugin_with_space = path.join(__dirname, 'folder with space', 
'plugins', 'org.test.plugins.childbrowser'),
     //test_plugin_xml = 
xml_helpers.parseElementtreeSync(path.join(test_plugin, 'plugin.xml')),
@@ -61,14 +62,24 @@ describe('fetch', function() {
     });
 */
     describe('local plugins', function() {
-        var rm, sym, cp, save_metadata;
+        var rm, sym, cp, save_metadata, revertLocal, revertFetch, fetchCalls = 
0;
         beforeEach(function() {
             rm = spyOn(shell, 'rm');
             sym = spyOn(fs, 'symlinkSync');
             cp = spyOn(shell, 'cp').and.callThrough();
             save_metadata = spyOn(metadata, 'save_fetch_metadata');
             realrm('-rf', temp);
-            fetch.__set__('localPlugins', null);
+            revertLocal = fetch.__set__('localPlugins', null);
+            revertFetch = fetch.__set__('fetch', function(pluginDir) {
+                fetchCalls ++;
+                return Q(pluginDir);
+            });
+        });
+
+        afterEach(function(){
+            revertLocal();
+            revertFetch();
+            fetchCalls = 0;
         });
 
         it('Test 001 : should copy locally-available plugin to plugins 
directory', function(done) {
@@ -115,6 +126,22 @@ describe('fetch', function() {
                 expect(1).toBe(1);
             });
         });
+        it('Test 027 : should copy locally-available plugin to plugins 
directory', function(done) {
+            wrapper(fetch(test_pkgjson_plugin, temp, {fetch:true}), done, 
function() {
+                expect(cp).toHaveBeenCalledWith('-R', 
path.join(test_pkgjson_plugin, '*'), path.join(temp, 'pkgjson-test-plugin'));
+                expect(fetchCalls).toBe(1);
+            });
+        });
+        it('Test 028 : should fail when locally-available plugin is missing 
pacakge.json', function(done) {
+            fetch(test_plugin, temp, {fetch:true})
+            .then(function() {
+                expect(false).toBe(true);
+            }).fail(function(err) { 
+                expect(err).toBeDefined();
+                expect(err.message).toContain('needs a valid package.json');
+                done();
+            });
+        });
     });
     describe('git plugins', function() {
         var clone, save_metadata, done;

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/193bdf3d/cordova-lib/spec-plugman/plugins/pkgjson-test-plugin/package.json
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-plugman/plugins/pkgjson-test-plugin/package.json 
b/cordova-lib/spec-plugman/plugins/pkgjson-test-plugin/package.json
new file mode 100644
index 0000000..e3bc48b
--- /dev/null
+++ b/cordova-lib/spec-plugman/plugins/pkgjson-test-plugin/package.json
@@ -0,0 +1,28 @@
+{
+  "name": "pkgjson-test-plugin",
+  "version": "1.3.0",
+  "description": "Empty plugin used as part of the tests",
+  "cordova": {
+    "id": "pkgjson-test-plugin",
+    "platforms": []
+  },
+  "repository": {
+    "type": "git",
+    "url": "git://git-wip-us.apache.org/repos/asf/cordova-lib.git"
+  },
+  "author": "Apache Software Foundation",
+  "license": "Apache-2.0",
+  "engines": {
+    "cordovaDependencies": {
+      "0.0.0": {
+        "cordova-android": "<2.1.0"
+      },
+      "1.1.2": {
+        "cordova-android": ">=2.1.0 <4.0.0"
+      },
+      "1.3.0": {
+        "cordova-android": "4.0.0"
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/193bdf3d/cordova-lib/spec-plugman/plugins/pkgjson-test-plugin/plugin.xml
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-plugman/plugins/pkgjson-test-plugin/plugin.xml 
b/cordova-lib/spec-plugman/plugins/pkgjson-test-plugin/plugin.xml
new file mode 100644
index 0000000..11ba6b9
--- /dev/null
+++ b/cordova-lib/spec-plugman/plugins/pkgjson-test-plugin/plugin.xml
@@ -0,0 +1,4 @@
+<?xml version='1.0' encoding='utf-8'?>
+<plugin id="pkgjson-test-plugin" version="0.0.0" 
xmlns="http://apache.org/cordova/ns/plugins/1.0"; 
xmlns:android="http://schemas.android.com/apk/res/android";>
+    <name>cordova-lib-test-plugin</name>
+</plugin>

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/193bdf3d/cordova-lib/src/plugman/fetch.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/fetch.js b/cordova-lib/src/plugman/fetch.js
index 0489583..d06502f 100644
--- a/cordova-lib/src/plugman/fetch.js
+++ b/cordova-lib/src/plugman/fetch.js
@@ -117,10 +117,13 @@ function fetchPlugin(plugin_src, plugins_dir, options) {
         // If it's not a network URL, it's either a local path or a plugin ID.
         var plugin_dir = cordovaUtil.fixRelativePath(path.join(plugin_src, 
options.subdir));
         return Q.when().then(function() {
-
+            // check if it is a local path
             if (fs.existsSync(plugin_dir)) {
-
                 if (options.fetch) {
+                    if (!fs.existsSync(path.join(plugin_dir, 'package.json'))) 
{
+                        return Q.reject(new CordovaError('Invalid Plugin! '+ 
plugin_dir + ' needs a valid package.json'));
+                    }
+
                     projectRoot = path.join(plugins_dir, '..');
                     //Plugman projects need to go up two directories to reach 
project root. 
                     //Plugman projects have an options.projectRoot variable
@@ -136,8 +139,12 @@ function fetchPlugin(plugin_src, plugins_dir, options) {
                                 path: directory
                             }
                         };
+                    }).fail(function(error) {
+                        //something went wrong with cordova-fetch
+                        return Q.reject(new CordovaError(error.message));
                     });
                 } else {
+                    //nofetch
                     return {
                         pinfo: pluginInfoProvider.get(plugin_dir),
                         fetchJsonSource: {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to