You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2012/09/26 08:13:22 UTC

[7/8] added blackberry project parser + specs in prep for bb support

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/a533afb6/spec/fixtures/projects/native/blackberry/www/spec.html
----------------------------------------------------------------------
diff --git a/spec/fixtures/projects/native/blackberry/www/spec.html b/spec/fixtures/projects/native/blackberry/www/spec.html
new file mode 100644
index 0000000..71f00de
--- /dev/null
+++ b/spec/fixtures/projects/native/blackberry/www/spec.html
@@ -0,0 +1,68 @@
+<!DOCTYPE html>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+     KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+<html>
+    <head>
+        <title>Jasmine Spec Runner</title>
+
+        <!-- jasmine source -->
+        <link rel="shortcut icon" type="image/png" href="spec/lib/jasmine-1.2.0/jasmine_favicon.png">
+        <link rel="stylesheet" type="text/css" href="spec/lib/jasmine-1.2.0/jasmine.css">
+        <script type="text/javascript" src="spec/lib/jasmine-1.2.0/jasmine.js"></script>
+        <script type="text/javascript" src="spec/lib/jasmine-1.2.0/jasmine-html.js"></script>
+
+        <!-- include source files here... -->
+        <script type="text/javascript" src="js/index.js"></script>
+
+        <!-- include spec files here... -->
+        <script type="text/javascript" src="spec/helper.js"></script>
+        <script type="text/javascript" src="spec/index.js"></script>
+
+        <script type="text/javascript">
+            (function() {
+                var jasmineEnv = jasmine.getEnv();
+                jasmineEnv.updateInterval = 1000;
+
+                var htmlReporter = new jasmine.HtmlReporter();
+
+                jasmineEnv.addReporter(htmlReporter);
+
+                jasmineEnv.specFilter = function(spec) {
+                    return htmlReporter.specFilter(spec);
+                };
+
+                var currentWindowOnload = window.onload;
+
+                window.onload = function() {
+                    if (currentWindowOnload) {
+                        currentWindowOnload();
+                    }
+                    execJasmine();
+                };
+
+                function execJasmine() {
+                    jasmineEnv.execute();
+                }
+            })();
+        </script>
+    </head>
+    <body>
+        <div id="stage" style="display:none;"></div>
+    </body>
+</html>

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/a533afb6/spec/metadata/blackberry_parser.spec.js
----------------------------------------------------------------------
diff --git a/spec/metadata/blackberry_parser.spec.js b/spec/metadata/blackberry_parser.spec.js
new file mode 100644
index 0000000..c0e7995
--- /dev/null
+++ b/spec/metadata/blackberry_parser.spec.js
@@ -0,0 +1,52 @@
+var blackberry_parser = require('../../src/metadata/blackberry_parser'),
+    config_parser = require('../../src/config_parser'),
+    path = require('path'),
+    fs = require('fs'),
+    cfg_path = path.join(__dirname, '..', 'fixtures', 'projects', 'test', 'www', 'config.xml'),
+    blackberry_path = path.join(__dirname, '..', 'fixtures', 'projects', 'native', 'blackberry'),
+    blackberry_config = path.join(blackberry_path, 'www', 'config.xml');
+
+var cwd = process.cwd();
+
+var original_config = fs.readFileSync(blackberry_config, 'utf-8');
+
+describe('blackberry project parser', function() {
+    it('should throw an exception with a path that is not a native blackberry project', function() {
+        expect(function() {
+            var project = new blackberry_parser(cwd);
+        }).toThrow();
+    });
+    it('should accept a proper native blackberry project path as construction parameter', function() {
+        var project;
+        expect(function() {
+            project = new blackberry_parser(blackberry_path);
+        }).not.toThrow();
+        expect(project).toBeDefined();
+    });
+
+    describe('update_from_config method', function() {
+        var project, config;
+
+        beforeEach(function() {
+            project = new blackberry_parser(blackberry_path);
+            config = new config_parser(cfg_path);
+        });
+        afterEach(function() {
+            fs.writeFileSync(blackberry_config, original_config, 'utf-8');
+        });
+        it('should throw an exception if a non config_parser object is passed into it', function() {
+            expect(function() {
+                project.update_from_config({});
+            }).toThrow();
+        });
+        it('should update the application name properly', function() {
+            config.name('bond. james bond.');
+            project.update_from_config(config);
+
+            var bb_cfg = new config_parser(blackberry_config);
+
+            expect(bb_cfg.name()).toBe('bond. james bond.');
+        });
+        it('should update the application package name properly');
+    });
+});

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/a533afb6/src/metadata/blackberry_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/blackberry_parser.js b/src/metadata/blackberry_parser.js
new file mode 100644
index 0000000..32bb266
--- /dev/null
+++ b/src/metadata/blackberry_parser.js
@@ -0,0 +1,21 @@
+var fs   = require('fs'),
+    path = require('path'),
+    et = require('elementtree'),
+    config_parser = require('../config_parser');
+
+module.exports = function blackberry_parser(project) {
+    if (!fs.existsSync(path.join(project, 'project.properties')) || !fs.existsSync(path.join(project, 'build.xml'))) {
+        throw 'The provided path is not a Cordova BlackBerry WebWorks project.';
+    }
+    this.path = project;
+    this.xml = new config_parser(path.join(this.path, 'www', 'config.xml'));
+};
+
+module.exports.prototype = {
+    update_from_config:function(config) {
+        if (config instanceof config_parser) {
+        } else throw 'update_from_config requires a config_parser object';
+
+        this.xml.name(config.name());
+    }
+};