blackberry platform support added.

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/8bb37809
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/tree/8bb37809
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/diff/8bb37809

Branch: refs/heads/cordova-client
Commit: 8bb3780908fd949b85c26075f43b28867f482c2c
Parents: a533afb
Author: Fil Maj <maj....@gmail.com>
Authored: Tue Sep 25 23:33:47 2012 -0700
Committer: Fil Maj <maj....@gmail.com>
Committed: Tue Sep 25 23:33:47 2012 -0700

----------------------------------------------------------------------
 platforms.js          |    2 +-
 spec/platform.spec.js |   49 ++++++++++++++++++++++++++++++++++++++++++-
 src/platform.js       |    9 +++++++-
 src/util.js           |    3 +-
 4 files changed, 58 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/8bb37809/platforms.js
----------------------------------------------------------------------
diff --git a/platforms.js b/platforms.js
index c6c5601..4acc953 100644
--- a/platforms.js
+++ b/platforms.js
@@ -1 +1 @@
-module.exports = ['ios','android'];
+module.exports = ['ios', 'android', 'blackberry'];

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/8bb37809/spec/platform.spec.js
----------------------------------------------------------------------
diff --git a/spec/platform.spec.js b/spec/platform.spec.js
index 2e05a5a..56bc6d5 100644
--- a/spec/platform.spec.js
+++ b/spec/platform.spec.js
@@ -5,6 +5,7 @@ var cordova = require('../cordova'),
     et = require('elementtree'),
     config_parser = require('../src/config_parser'),
     helper = require('./helper'),
+    platforms = require('../platforms'),
     tempDir = path.join(__dirname, '..', 'temp');
 
 var cwd = process.cwd();
@@ -87,14 +88,14 @@ describe('platform command', function() {
             var lib = path.join(__dirname, '..', 'lib');
             
             beforeEach(function() {
-                ['ios','android'].forEach(function(p) {
+                platforms.forEach(function(p) {
                     var s = path.join(lib, p);
                     var d = path.join(lib, p + '-bkup');
                     shell.mv(s, d);
                 });
             });
             afterEach(function() {
-                ['ios','android'].forEach(function(p) {
+                platforms.forEach(function(p) {
                     var s = path.join(lib, p + '-bkup');
                     var d = path.join(lib, p);
                     shell.mv(s, d);
@@ -121,8 +122,20 @@ describe('platform command', function() {
                 expect(s.calls[0].args[0].match(/^git 
clone.*cordova-ios/)).not.toBeNull();
                 expect(s.calls[1].args[0].match(/git checkout 
2.1.0/)).not.toBeNull();
             });
+            it('should clone down the blackberry library and checkout 
appropriate tag', function() {
+                var s = spyOn(shell, 'exec').andReturn({code:0});
+
+                try {
+                    cordova.platform('add', 'blackberry', function() {});
+                } catch(e) {}
+
+                expect(s).toHaveBeenCalled();
+                expect(s.calls[0].args[0].match(/^git 
clone.*cordova-blackberry/)).not.toBeNull();
+                expect(s.calls[1].args[0].match(/git checkout 
2.1.0/)).not.toBeNull();
+            });
             it('should add a basic android project');
             it('should add a basic ios project');
+            it('should add a basic blackberry project');
         });
 
         describe('android', function() {
@@ -190,6 +203,38 @@ describe('platform command', function() {
                 });
             });
         });
+        describe('blackberry', function() {
+            it('should add a basic blackberry project', function() {
+                var cb = jasmine.createSpy();
+
+                runs(function() {
+                    cordova.platform('add', 'blackberry', cb);
+                });
+                waitsFor(function() { return cb.wasCalled; }, "platform add 
blackberry callback");
+                runs(function() {
+                    expect(fs.existsSync(path.join(tempDir, 'platforms', 
'blackberry', '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', cb);
+                });
+                waitsFor(function() { return cb.wasCalled; }, "platform add 
blackberry callback");
+                runs(function() {
+                    var bb_cfg = new config_parser(path.join(tempDir, 
'platforms', 'blackberry', 'www', 'config.xml'));
+                    expect(bb_cfg.name()).toBe(cfg.name());
+                });
+            });
+        });
     });
     describe('remove', function() {
         beforeEach(function() {

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/8bb37809/src/platform.js
----------------------------------------------------------------------
diff --git a/src/platform.js b/src/platform.js
index db32dd1..4f73917 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -5,6 +5,7 @@ var config_parser = require('./config_parser'),
     path          = require('path'),
     shell         = require('shelljs'),
     android_parser= require('./metadata/android_parser'),
+    blackberry_parser= require('./metadata/blackberry_parser'),
     ios_parser    = require('./metadata/ios_parser'),
     shell         = require('shelljs');
 
@@ -46,12 +47,13 @@ module.exports = function platform(command, target, 
callback) {
             var bin = path.join(__dirname, '..', 'lib', 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, pkg, 
name);
+            var command = util.format('"%s" "%s" "%s" "%s"', bin, output, 
(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(target) {
                 case 'android':
                     var android = new android_parser(output);
@@ -62,6 +64,11 @@ module.exports = function platform(command, target, 
callback) {
                     var ios = new ios_parser(output);
                     ios.update_from_config(cfg, callback);
                     break;
+                case 'blackberry':
+                    var bb = new blackberry_parser(output);
+                    bb.update_from_config(cfg);
+                    if (callback) callback();
+                    break;
             }
             break;
         case 'remove':

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/8bb37809/src/util.js
----------------------------------------------------------------------
diff --git a/src/util.js b/src/util.js
index f37c04c..fa0a77f 100644
--- a/src/util.js
+++ b/src/util.js
@@ -5,7 +5,8 @@ var fs         = require('fs'),
 
 var repos = {
     ios:'https://git-wip-us.apache.org/repos/asf/incubator-cordova-ios.git',
-    
android:'https://git-wip-us.apache.org/repos/asf/incubator-cordova-android.git'
+    
android:'https://git-wip-us.apache.org/repos/asf/incubator-cordova-android.git',
+    
blackberry:'https://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks.git'
 };
 
 module.exports = {

Reply via email to