incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject [3/7] git commit: platforms related to a project are no longer added to config.xml. instead tool looks at dir tree under ./platforms. simpler.
Date Mon, 01 Oct 2012 06:46:30 GMT
platforms related to a project are no longer added to config.xml. instead tool looks at dir
tree under ./platforms. simpler.


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

Branch: refs/heads/cordova-client
Commit: 57552608a687bcbfcb80012d362ab07c8a8b0e08
Parents: 31ac868
Author: Fil Maj <maj.fil@gmail.com>
Authored: Sun Sep 30 23:35:55 2012 -0700
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Sun Sep 30 23:35:55 2012 -0700

----------------------------------------------------------------------
 spec/config_parser.spec.js |   58 ------------------------
 spec/platform.spec.js      |   94 +++++++++++----------------------------
 src/config_parser.js       |   24 ----------
 src/platform.js            |   30 ++++---------
 4 files changed, 35 insertions(+), 171 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/57552608/spec/config_parser.spec.js
----------------------------------------------------------------------
diff --git a/spec/config_parser.spec.js b/spec/config_parser.spec.js
index f5e9fa4..4fa28a7 100644
--- a/spec/config_parser.spec.js
+++ b/spec/config_parser.spec.js
@@ -63,62 +63,4 @@ describe('config.xml parser', function () {
             expect(fs.readFileSync(xml, 'utf-8')).toMatch(/<name>one toke over the
line<\/name>/);
         });
     });
-
-    describe('platforms', function() {
-        describe('ls command', function() {
-            it('should return an empty array if there are no platforms specified in the document',
function() {
-                var cfg = new config_parser(xml);
-
-                expect(cfg.ls_platforms().length).toBe(0);
-            });
-            it('should return a populated array if there are platforms specified in the document',
function() {
-                var doc = new et.ElementTree(et.XML(fs.readFileSync(xml, 'utf-8')));
-                var p = new et.Element('platform');
-                p.attrib.name = 'android';
-                doc.find('platforms').append(p);
-                fs.writeFileSync(xml, doc.write(), 'utf-8');
-
-                var cfg = new config_parser(xml);
-                expect(cfg.ls_platforms().length).toBe(1);
-                expect(cfg.ls_platforms()[0]).toEqual('android');
-            });
-        });
-
-        describe('add command', function() {
-            it('should add a platform element to the platforms element', function() {
-                var cfg = new config_parser(xml);
-                cfg.add_platform('android');
-                
-                var doc = new et.ElementTree(et.XML(fs.readFileSync(xml, 'utf-8')));
-                expect(doc.find('platforms').getchildren()[0].attrib.name).toEqual('android');
-            });
-            it('should ignore existing platforms', function() {
-                var cfg = new config_parser(xml);
-                cfg.add_platform('android');
-                cfg.add_platform('android');
-                
-                var doc = new et.ElementTree(et.XML(fs.readFileSync(xml, 'utf-8')));
-                expect(doc.find('platforms').getchildren().length).toEqual(1);
-            });
-            it('should ignore garbage platforms', function() {
-                var cfg = new config_parser(xml);
-                cfg.add_platform('bat country');
-                
-                var doc = new et.ElementTree(et.XML(fs.readFileSync(xml, 'utf-8')));
-                expect(doc.find('platforms').getchildren().length).toEqual(0);
-            });
-        });
-
-        describe('remove command', function() {
-            it('should remove a platform element from the platforms element', function()
{
-                var cfg = new config_parser(xml);
-                cfg.add_platform('ios');
-
-                cfg.remove_platform('ios');
-
-                var doc = new et.ElementTree(et.XML(fs.readFileSync(xml, 'utf-8')));
-                expect(doc.find('platforms').getchildren().length).toEqual(0);
-            });
-        });
-    });
 });

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/57552608/spec/platform.spec.js
----------------------------------------------------------------------
diff --git a/spec/platform.spec.js b/spec/platform.spec.js
index 4dc8c6b..a6fa8be 100644
--- a/spec/platform.spec.js
+++ b/spec/platform.spec.js
@@ -9,6 +9,11 @@ var cordova = require('../cordova'),
     platforms = require('../platforms'),
     tempDir = path.join(__dirname, '..', 'temp');
 
+// globals for crazy spy hax
+android_parser = require('../src/metadata/android_parser');
+ios_parser = require('../src/metadata/ios_parser');
+blackberry_parser = require('../src/metadata/blackberry_parser');
+
 var cwd = process.cwd();
 
 describe('platform command', function() {
@@ -53,7 +58,7 @@ describe('platform command', function() {
         });
 
         it('should list out no platforms for a fresh project', function() {
-            expect(cordova.platform('ls')).toEqual('No platforms added. Use `cordova platform
add <platform>`.');
+            expect(cordova.platform('ls').length).toEqual(0);
         });
 
         it('should list out added platforms in a project', function() {
@@ -65,12 +70,12 @@ describe('platform command', function() {
             });
             waitsFor(function() { return cb.wasCalled; }, "create callback");
             runs(function() {
-                expect(cordova.platform('ls')).toEqual('android');
+                expect(cordova.platform('ls')[0]).toEqual('android');
                 cordova.platform('add', 'ios', cbtwo);
             });
             waitsFor(function() { return cbtwo.wasCalled; }, "create callback number two");
             runs(function() {
-                expect(cordova.platform('ls')).toEqual('android\nios');
+                expect(cordova.platform('ls')[1]).toEqual('ios');
             });
         });
     });
@@ -142,35 +147,13 @@ describe('platform command', function() {
 
         describe('android', function() {
             it('should add a basic android project', function() {
-                var cb = jasmine.createSpy();
-
-                runs(function() {
-                    cordova.platform('add', 'android', cb);
-                });
-                waitsFor(function() { return cb.wasCalled; }, "platform add android callback");
-                runs(function() {
-                    expect(fs.existsSync(path.join(tempDir, 'platforms', 'android', 'AndroidManifest.xml'))).toBe(true);
-                });
+                cordova.platform('add', 'android');
+                expect(fs.existsSync(path.join(tempDir, 'platforms', 'android', 'AndroidManifest.xml'))).toBe(true);
             });
-            it('should use the correct application name based on what is in config.xml',
function() {
-                var cfg_path = path.join(tempDir, 'www', 'config.xml');
-                var orig_cfg_contents = fs.readFileSync(cfg_path, 'utf-8');
-                this.after(function() {
-                    fs.writeFileSync(cfg_path, orig_cfg_contents, 'utf-8');
-                });
-                var cfg = new config_parser(cfg_path);
-                var cb = jasmine.createSpy();
-
-                runs(function() {
-                    cfg.name('chim chim');
-                    cordova.platform('add', 'android', cb);
-                });
-                waitsFor(function() { return cb.wasCalled; }, "platform add android callback");
-                runs(function() {
-                    var strings = new et.ElementTree(et.XML(fs.readFileSync(path.join(tempDir,
'platforms', 'android', 'res', 'values', 'strings.xml'), 'utf-8')));
-                    var app_name = strings.find('string[@name="app_name"]').text;
-                    expect(app_name).toBe('chim chim');
-                });
+            it('should call android_parser\'s update_project', function() {
+                var s = spyOn(android_parser.prototype, 'update_project');
+                cordova.platform('add', 'android');
+                expect(s).toHaveBeenCalled();
             });
         });
         describe('ios', function() {
@@ -185,56 +168,30 @@ describe('platform command', function() {
                     expect(fs.existsSync(path.join(tempDir, 'platforms', 'ios', 'www'))).toBe(true);
                 });
             });
-            it('should use the correct application name based on what is in config.xml',
function() {
-                var cfg_path = path.join(tempDir, 'www', 'config.xml');
-                var orig_cfg_contents = fs.readFileSync(cfg_path, 'utf-8');
-                this.after(function() {
-                    fs.writeFileSync(cfg_path, orig_cfg_contents, 'utf-8');
-                });
-                var cfg = new config_parser(cfg_path);
-                var cb = jasmine.createSpy();
-
-                runs(function() {
-                    cfg.name('upon closer inspection they appear to be loafers');
-                    cordova.platform('add', 'ios', cb);
-                });
-                waitsFor(function() { return cb.wasCalled; }, "platform add ios callback");
-                runs(function() {
-                    var pbxproj = fs.readFileSync(path.join(tempDir, 'platforms', 'ios',
'upon_closer_inspection_they_appear_to_be_loafers.xcodeproj', 'project.pbxproj'), 'utf-8');
-                    expect(pbxproj.match(/PRODUCT_NAME\s*=\s*"upon closer inspection they
appear to be loafers"/)[0]).toBe('PRODUCT_NAME = "upon closer inspection they appear to be
loafers"');
-                });
+            it('should call ios_parser\'s update_project', function() {
+                var s = spyOn(ios_parser.prototype, 'update_project');
+                cordova.platform('add', 'ios');
+                expect(s).toHaveBeenCalled();
             });
         });
         describe('blackberry-10', function() {
             it('should add a basic blackberry project', function() {
                 var cb = jasmine.createSpy();
+                var s = spyOn(require('prompt'), 'get').andReturn(true);
 
                 runs(function() {
                     cordova.platform('add', 'blackberry-10', cb);
+                    s.mostRecentCall.args[1](null, {}); // fake out prompt
                 });
                 waitsFor(function() { return cb.wasCalled; }, "platform add blackberry");
                 runs(function() {
                     expect(fs.existsSync(path.join(tempDir, 'platforms', 'blackberry-10',
'www'))).toBe(true);
                 });
             });
-            it('should use the correct application name based on what is in config.xml',
function() {
-                var cfg_path = path.join(tempDir, 'www', 'config.xml');
-                var orig_cfg_contents = fs.readFileSync(cfg_path, 'utf-8');
-                this.after(function() {
-                    fs.writeFileSync(cfg_path, orig_cfg_contents, 'utf-8');
-                });
-                var cfg = new config_parser(cfg_path);
-                var cb = jasmine.createSpy();
-
-                runs(function() {
-                    cfg.name('upon closer inspection they appear to be loafers');
-                    cordova.platform('add', 'blackberry-10', cb);
-                });
-                waitsFor(function() { return cb.wasCalled; }, "platform add blackberry callback");
-                runs(function() {
-                    var bb_cfg = new config_parser(path.join(tempDir, 'platforms', 'blackberry-10',
'www', 'config.xml'));
-                    expect(bb_cfg.name()).toBe(cfg.name());
-                });
+            it('should call blackberry_parser\'s update_project', function() {
+                var s = spyOn(blackberry_parser.prototype, 'update_project');
+                cordova.platform('add', 'blackberry-10');
+                expect(s).toHaveBeenCalled();
             });
         });
     });
@@ -262,7 +219,8 @@ describe('platform command', function() {
             waitsFor(function() { return cb.wasCalled; }, "android create callback");
             runs(function() {
                 cordova.platform('remove', 'android');
-                expect(cordova.platform('ls')).toEqual('ios');
+                expect(cordova.platform('ls').length).toEqual(1);
+                expect(cordova.platform('ls')[0]).toEqual('ios');
             });
         });
     });

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/57552608/src/config_parser.js
----------------------------------------------------------------------
diff --git a/src/config_parser.js b/src/config_parser.js
index aa743dc..59ddce0 100644
--- a/src/config_parser.js
+++ b/src/config_parser.js
@@ -1,5 +1,4 @@
 var et = require('elementtree'),
-    platforms = require('./../platforms'),
     fs = require('fs');
 
 function config_parser(path) {
@@ -8,29 +7,6 @@ function config_parser(path) {
 }
 
 config_parser.prototype = {
-    ls_platforms:function() {
-        return this.doc.find('platforms').getchildren().map(function(p) {
-            return p.attrib.name;
-        });
-    },
-    add_platform:function(platform) {
-        if ((platforms.indexOf(platform) == -1) || this.doc.find('platforms/platform[@name="'
+ platform + '"]')) return;
-        else {
-            var p = new et.Element('platform');
-            p.attrib.name = platform;
-            this.doc.find('platforms').append(p);
-            this.update();
-        }
-    },
-    remove_platform:function(platform) {
-        if ((platforms.indexOf(platform) == -1) || !(this.doc.find('platforms/platform[@name="'
+ platform + '"]'))) return;
-        else {
-            var psEl = this.doc.find('platforms');
-            var pEl = psEl.find('platform[@name="' + platform + '"]');
-            psEl.remove(null, pEl);
-            this.update();
-        }
-    },
     packageName:function(id) {
         if (id) {
             this.doc.getroot().attrib.id = id;

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/57552608/src/platform.js
----------------------------------------------------------------------
diff --git a/src/platform.js b/src/platform.js
index 2d349ee..652a2ba 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -3,7 +3,6 @@ var config_parser = require('./config_parser'),
     util          = require('util'),
     fs            = require('fs'),
     path          = require('path'),
-    shell         = require('shelljs'),
     android_parser= require('./metadata/android_parser'),
     blackberry_parser= require('./metadata/blackberry_parser'),
     ios_parser    = require('./metadata/ios_parser'),
@@ -22,12 +21,7 @@ module.exports = function platform(command, target, callback) {
 
     switch(command) {
         case 'ls':
-            var platforms = cfg.ls_platforms();
-            if (platforms.length) {
-                return platforms.join('\n');
-            } else {
-                return 'No platforms added. Use `cordova platform add <platform>`.';
-            }
+            return fs.readdirSync(path.join(projectRoot, 'platforms'));
             break;
         case 'add':
             var output = path.join(projectRoot, 'platforms', target);
@@ -43,42 +37,36 @@ module.exports = function platform(command, target, callback) {
             if (fs.existsSync(output)) {
                 throw new Error('Platform "' + target + '" already exists' );
             }
-            // directory doesn't exist, run platform's create script
+
+            // Run platform's create script
             var bin = path.join(__dirname, '..', 'lib', cordova_util.underlyingLib(target),
'bin', 'create');
             var pkg = cfg.packageName().replace(/[^\w.]/g,'_');
             var name = cfg.name().replace(/\W/g,'_');
             var command = util.format('"%s" "%s" "%s" "%s"', bin, output, (cordova_util.underlyingLib(target)=='blackberry'?name:pkg),
name);
+
             var create = shell.exec(command, {silent:true});
             if (create.code > 0) {
                 throw new Error('An error occured during creation of ' + target + ' sub-project.
' + create.output);
             }
-            cfg.add_platform(target);
-            // TODO: this is fugly
+
             switch(cordova_util.underlyingLib(target)) {
                 case 'android':
                     var android = new android_parser(output);
-                    android.update_from_config(cfg);
+                    android.update_project(cfg);
                     if (callback) callback();
                     break;
                 case 'ios':
                     var ios = new ios_parser(output);
-                    ios.update_from_config(cfg, callback);
+                    ios.update_project(cfg, callback);
                     break;
                 case 'blackberry':
                     var bb = new blackberry_parser(output);
-                    bb.update_from_config(cfg);
-                    if (callback) callback();
+                    bb.update_project(cfg, callback);
                     break;
             }
             break;
         case 'remove':
-            // Remove the platform from the config.xml
-            cfg.remove_platform(target);
-
-            // Remove the Cordova project for the platform.
-            try {
-                shell.rm('-rf', path.join(projectRoot, 'platforms', target));
-            } catch(e) {}
+            shell.rm('-rf', path.join(projectRoot, 'platforms', target));
             break;
         default:
             throw ('Unrecognized command "' + command + '". Use either `add`, `remove`, or
`ls`.');


Mime
View raw message