Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CB-12683: improved error messaging for when a plugin doesn't have pac… #548

Merged
merged 1 commit into from
Apr 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions cordova-lib/spec-plugman/fetch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions cordova-lib/spec-plugman/plugins/pkgjson-test-plugin/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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>
11 changes: 9 additions & 2 deletions cordova-lib/src/plugman/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: {
Expand Down