cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject git commit: CB-6162 Show a better error message when publish fails the whitelist
Date Tue, 04 Mar 2014 21:24:08 GMT
Repository: cordova-plugman
Updated Branches:
  refs/heads/master 62be35690 -> cc51a5f10


CB-6162 Show a better error message when publish fails the whitelist


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

Branch: refs/heads/master
Commit: cc51a5f10aa79532e9fc3c8c4ae1c6301819c430
Parents: 62be356
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Tue Mar 4 16:23:32 2014 -0500
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Tue Mar 4 16:23:32 2014 -0500

----------------------------------------------------------------------
 spec/registry/registry.spec.js |  97 +++++++++++++----------------
 src/registry/manifest.js       | 119 ++++++++++++++++++------------------
 src/registry/whitelist.js      |   2 +-
 3 files changed, 102 insertions(+), 116 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/cc51a5f1/spec/registry/registry.spec.js
----------------------------------------------------------------------
diff --git a/spec/registry/registry.spec.js b/spec/registry/registry.spec.js
index 7990037..7615ee6 100644
--- a/spec/registry/registry.spec.js
+++ b/spec/registry/registry.spec.js
@@ -8,6 +8,21 @@ var registry = require('../../src/registry/registry'),
     npm = require('npm');
 
 describe('registry', function() {
+    var done;
+    beforeEach(function() {
+        done = false;
+    });
+    function registryPromise(shouldSucceed, f) {
+        waitsFor(function() { return done; }, 'promise never resolved', 500);
+        return f.then(function() {
+          done = true;
+          expect(shouldSucceed).toBe(true);
+        }, function(err) {
+          done = err;
+          expect(shouldSucceed).toBe(false);
+        });
+    }
+
     describe('manifest', function() {
         var pluginDir, packageJson, tmp_plugin, tmp_plugin_xml, tmp_package_json;
         beforeEach(function() {
@@ -21,40 +36,35 @@ describe('registry', function() {
             shell.rm('-rf', tmp_plugin);
         });
         it('should generate a package.json from a plugin.xml', function() {
-            manifest.generatePackageJsonFromPluginXml(tmp_plugin);
-            expect(fs.existsSync(tmp_package_json));
-            var packageJson = JSON.parse(fs.readFileSync(tmp_package_json));
-            expect(packageJson.name).toEqual('com.cordova.engine');
-            expect(packageJson.version).toEqual('1.0.0');
-            expect(packageJson.engines).toEqual(
-                [ { name : 'cordova', version : '>=2.3.0' }, { name : 'cordova-plugman',
version : '>=0.10.0' }, { name : 'mega-fun-plugin', version : '>=1.0.0' }, { name :
'mega-boring-plugin', version : '>=3.0.0' } ]
-            );
+            registryPromise(true, manifest.generatePackageJsonFromPluginXml(tmp_plugin).then(function()
{
+                expect(fs.existsSync(tmp_package_json));
+                var packageJson = JSON.parse(fs.readFileSync(tmp_package_json));
+                expect(packageJson.name).toEqual('com.cordova.engine');
+                expect(packageJson.version).toEqual('1.0.0');
+                expect(packageJson.engines).toEqual(
+                    [ { name : 'cordova', version : '>=2.3.0' }, { name : 'cordova-plugman',
version : '>=0.10.0' }, { name : 'mega-fun-plugin', version : '>=1.0.0' }, { name :
'mega-boring-plugin', version : '>=3.0.0' } ]);
+            }));
         });
         it('should raise an error if name does not follow com.domain.* format', function()
{
             var xmlData = fs.readFileSync(tmp_plugin_xml).toString().replace('id="com.cordova.engine"',
'id="engine"');
             fs.writeFileSync(tmp_plugin_xml, xmlData);
-            manifest.generatePackageJsonFromPluginXml(tmp_plugin);
-            expect(!fs.existsSync(tmp_package_json));
+            registryPromise(false, manifest.generatePackageJsonFromPluginXml(tmp_plugin));
         });
-        it('should generate a package.json if name uses org.apache.cordova.* for a whitlisted
plugin', function() {
+        it('should generate a package.json if name uses org.apache.cordova.* for a whitelisted
plugin', function() {
             var xmlData = fs.readFileSync(tmp_plugin_xml).toString().replace('id="com.cordova.engine"',
'id="org.apache.cordova.camera"');
             fs.writeFileSync(tmp_plugin_xml, xmlData);
-            manifest.generatePackageJsonFromPluginXml(tmp_plugin);
-            expect(!fs.existsSync(tmp_package_json));
+            registryPromise(true, manifest.generatePackageJsonFromPluginXml(tmp_plugin).then(function()
{
+                expect(!fs.existsSync(tmp_package_json));
+            }));
         });
-        it('should raise an error if name uses org.apache.cordova.* for a non-whitlisted
plugin', function() {
+        it('should raise an error if name uses org.apache.cordova.* for a non-whitelisted
plugin', function() {
             var xmlData = fs.readFileSync(tmp_plugin_xml).toString().replace('id="com.cordova.engine"',
'id="org.apache.cordova.myinvalidplugin"');
             fs.writeFileSync(tmp_plugin_xml, xmlData);
-            manifest.generatePackageJsonFromPluginXml(tmp_plugin);
-            expect(!fs.existsSync(tmp_package_json));
+            registryPromise(false, manifest.generatePackageJsonFromPluginXml(tmp_plugin));
         });
     });
     describe('actions', function() {
-        var done, fakeLoad, fakeNPMCommands;
-
-        function registryPromise(f) {
-            return f.then(function() { done = true; }, function(err) { done = err; });
-        }
+        var fakeLoad, fakeNPMCommands;
 
         beforeEach(function() {
             done = false;
@@ -83,67 +93,42 @@ describe('registry', function() {
         });
         it('should run config', function() {
             var params = ['set', 'registry', 'http://registry.cordova.io'];
-            runs(function() {
-                registryPromise(registry.config(params));
-            });
-            waitsFor(function() { return done; }, 'promise never resolved', 500);
-            runs(function() {
-                expect(done).toBe(true);
+            registryPromise(true, registry.config(params).then(function() {
                 expect(fakeLoad).toHaveBeenCalledWith(registry.settings, jasmine.any(Function));
                 expect(fakeNPMCommands.config).toHaveBeenCalledWith(params, jasmine.any(Function));
-            });
+            }));
         });
         it('should run adduser', function() {
-            runs(function() {
-                registryPromise(registry.adduser(null));
-            });
-            waitsFor(function() { return done; }, 'promise never resolved', 500);
-            runs(function() {
-                expect(done).toBe(true);
+            registryPromise(true, registry.adduser(null).then(function() {
                 expect(fakeLoad).toHaveBeenCalledWith(registry.settings, jasmine.any(Function));
                 expect(fakeNPMCommands.adduser).toHaveBeenCalledWith(null, jasmine.any(Function));
-            });
+            }));
         });
         it('should run publish', function() {
             var params = [__dirname + '/../plugins/DummyPlugin'];
             var spyGenerate = spyOn(manifest, 'generatePackageJsonFromPluginXml').andReturn(Q());
             var spyUnlink = spyOn(fs, 'unlink');
-            runs(function() {
-                registryPromise(registry.publish(params));
-            });
-            waitsFor(function() { return done; }, 'promise never resolved', 500);
-            runs(function() {
-                expect(done).toBe(true);
+            registryPromise(true, registry.publish(params).then(function() {
                 expect(fakeLoad).toHaveBeenCalledWith(registry.settings, jasmine.any(Function));
                 expect(spyGenerate).toHaveBeenCalledWith(params[0]);
                 expect(fakeNPMCommands.publish).toHaveBeenCalledWith(params, jasmine.any(Function));
                 expect(spyUnlink).toHaveBeenCalledWith(path.resolve(params[0], 'package.json'));
-            });
+            }));
         });
         it('should run unpublish', function() {
             var params = ['dummyplugin@0.6.0'];
-            runs(function() {
-                registryPromise(registry.unpublish(params));
-            });
-            waitsFor(function() { return done; }, 'promise never resolved', 500);
-            runs(function() {
-                expect(done).toBe(true);
+            registryPromise(true, registry.unpublish(params).then(function() {
                 expect(fakeLoad).toHaveBeenCalledWith(registry.settings, jasmine.any(Function));
                 expect(fakeNPMCommands.unpublish).toHaveBeenCalledWith(params, jasmine.any(Function));
                 expect(fakeNPMCommands.cache).toHaveBeenCalledWith(['clean'], jasmine.any(Function));
-            });
+            }));
         });
         it('should run search', function() {
             var params = ['dummyplugin', 'plugin'];
-            runs(function() {
-                registryPromise(registry.search(params));
-            });
-            waitsFor(function() { return done; }, 'promise never resolved', 500);
-            runs(function() {
-                expect(done).toBe(true);
+            registryPromise(true, registry.search(params).then(function() {
                 expect(fakeLoad).toHaveBeenCalledWith(registry.settings, jasmine.any(Function));
                 expect(fakeNPMCommands.search).toHaveBeenCalledWith(params, true, jasmine.any(Function));
-            });
+            }));
         });
     });
 });

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/cc51a5f1/src/registry/manifest.js
----------------------------------------------------------------------
diff --git a/src/registry/manifest.js b/src/registry/manifest.js
index c7bbe36..d7ddc48 100644
--- a/src/registry/manifest.js
+++ b/src/registry/manifest.js
@@ -5,12 +5,12 @@ var xml_helpers = require('../util/xml-helpers'),
     whitelist = require('./whitelist');
 
 function validateName(name) {
-    if(!name.match(/^(\w+\.){2,}.*$/)) {
-      return false;
+    if (!name.match(/^(\w+\.){2,}.*$/)) {
+        throw new Error('Invalid plugin ID. It has to follow the reverse domain `com.domain.plugin`
format');
     }
 
-    if(name.match(/org.apache.cordova\..*/) && whitelist.indexOf(name) === -1) {
-      return false;
+    if (name.match(/org.apache.cordova\..*/) && whitelist.indexOf(name) === -1) {
+        throw new Error('Invalid Plugin ID. The "org.apache.cordova" prefix is reserved for
plugins provided directly by the Cordova project.');
     }
 
     return true;
@@ -19,63 +19,64 @@ function validateName(name) {
 // Java world big-up!
 // Returns a promise.
 function generatePackageJsonFromPluginXml(plugin_path) {
-    var package_json = {};
-    var pluginXml = xml_helpers.parseElementtreeSync(path.join(plugin_path, 'plugin.xml'));
-
-    if(!pluginXml) return Q.reject(new Error('invalid plugin.xml document'));
-
-    var pluginElm = pluginXml.getroot();
-
-    if(!pluginElm) return Q.reject(new Error('invalid plugin.xml document'));
-
-    // REQUIRED: name, version
-    // OPTIONAL: description, license, keywords, engine
-    var name = pluginElm.attrib.id,
-        version = pluginElm.attrib.version,
-        cordova_name = pluginElm.findtext('name'),
-        description = pluginElm.findtext('description'),
-        license = pluginElm.findtext('license'),
-        keywords = pluginElm.findtext('keywords'),
-        repo = pluginElm.findtext('repo'),
-        issue = pluginElm.findtext('issue'),
-        engines = pluginElm.findall('engines/engine'),
-        platformsElm = pluginElm.findall('platform'),
-        platforms = [];
-
-    platformsElm.forEach(function(plat){
-        platforms.push(plat.attrib.name);
-    })
-    if(!version) return Q.reject(new Error('`version` required'));
-
-    package_json.version = version;
-
-    if(!name) return Q.reject(new Error('`name` is required'));
-
-    if(!validateName(name))
-        return Q.reject(new Error('`name` is invalid. It has to follow the reverse domain
`com.domain.plugin` format'));
-    
-    package_json.name = name.toLowerCase();
-
-    if(cordova_name) package_json.cordova_name = cordova_name;
-    if(description)  package_json.description  = description;
-    if(license)      package_json.license      = license;
-    if(repo)         package_json.repo         = repo;
-    if(issue)        package_json.issue        = issue;
-    if(keywords)     package_json.keywords     = keywords.split(',');
-    if(platforms)    package_json.platforms    = platforms;
-
-    // adding engines
-    if(engines) {
-        package_json.engines = [];
-        for(var i = 0, j = engines.length ; i < j ; i++) {
-            package_json.engines.push({name: engines[i].attrib.name, version: engines[i].attrib.version});
+    return Q().then(function() {
+        var package_json = {};
+        var pluginXml = xml_helpers.parseElementtreeSync(path.join(plugin_path, 'plugin.xml'));
+
+        if(!pluginXml) throw new Error('invalid plugin.xml document');
+
+        var pluginElm = pluginXml.getroot();
+
+        if(!pluginElm) throw new Error('invalid plugin.xml document');
+
+        // REQUIRED: name, version
+        // OPTIONAL: description, license, keywords, engine
+        var name = pluginElm.attrib.id,
+            version = pluginElm.attrib.version,
+            cordova_name = pluginElm.findtext('name'),
+            description = pluginElm.findtext('description'),
+            license = pluginElm.findtext('license'),
+            keywords = pluginElm.findtext('keywords'),
+            repo = pluginElm.findtext('repo'),
+            issue = pluginElm.findtext('issue'),
+            engines = pluginElm.findall('engines/engine'),
+            platformsElm = pluginElm.findall('platform'),
+            platforms = [];
+
+        platformsElm.forEach(function(plat){
+            platforms.push(plat.attrib.name);
+        })
+        if(!version) throw new Error('`version` required');
+
+        package_json.version = version;
+
+        if(!name) throw new Error('`id` is required');
+
+        validateName(name);
+
+        package_json.name = name.toLowerCase();
+
+        if(cordova_name) package_json.cordova_name = cordova_name;
+        if(description)  package_json.description  = description;
+        if(license)      package_json.license      = license;
+        if(repo)         package_json.repo         = repo;
+        if(issue)        package_json.issue        = issue;
+        if(keywords)     package_json.keywords     = keywords.split(',');
+        if(platforms)    package_json.platforms    = platforms;
+
+        // adding engines
+        if(engines) {
+            package_json.engines = [];
+            for(var i = 0, j = engines.length ; i < j ; i++) {
+                package_json.engines.push({name: engines[i].attrib.name, version: engines[i].attrib.version});
+            }
         }
-    }
 
-    // write package.json
-    var package_json_path = path.resolve(plugin_path, 'package.json');
-    fs.writeFileSync(package_json_path, JSON.stringify(package_json, null, 4), 'utf8');
-    return Q(package_json);
+        // write package.json
+        var package_json_path = path.resolve(plugin_path, 'package.json');
+        fs.writeFileSync(package_json_path, JSON.stringify(package_json, null, 4), 'utf8');
+        return package_json;
+    });
 }
 
 module.exports.generatePackageJsonFromPluginXml = generatePackageJsonFromPluginXml;

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/cc51a5f1/src/registry/whitelist.js
----------------------------------------------------------------------
diff --git a/src/registry/whitelist.js b/src/registry/whitelist.js
index 7f91ea7..4b17a6c 100644
--- a/src/registry/whitelist.js
+++ b/src/registry/whitelist.js
@@ -6,7 +6,7 @@ module.exports = [
     'org.apache.cordova.media',
     'org.apache.cordova.vibration',
     'org.apache.cordova.media-capture',
-    'org.apache.cordova.inappbrowser', 
+    'org.apache.cordova.inappbrowser',
     'org.apache.cordova.globalization',
     'org.apache.cordova.geolocation',
     'org.apache.cordova.dialogs',


Mime
View raw message