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 2013/06/14 22:24:37 UTC
[1/4] git commit: use symlink instead of copying. Partial fix for
[CB-3812]
Updated Branches:
refs/heads/master2 f829e6320 -> 9d28a67d6
use symlink instead of copying. Partial fix for [CB-3812]
Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/d2392da2
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/d2392da2
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/d2392da2
Branch: refs/heads/master2
Commit: d2392da27aeae5bead4c1d089d9f16d541f73026
Parents: f829e63
Author: Fil Maj <ma...@gmail.com>
Authored: Fri Jun 14 10:30:04 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Fri Jun 14 10:30:04 2013 -0700
----------------------------------------------------------------------
src/lazy_load.js | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/d2392da2/src/lazy_load.js
----------------------------------------------------------------------
diff --git a/src/lazy_load.js b/src/lazy_load.js
index 4919ab8..c90b0aa 100644
--- a/src/lazy_load.js
+++ b/src/lazy_load.js
@@ -47,13 +47,14 @@ module.exports = {
});
},
custom:function(url, id, platform, version, callback) {
- var download_dir = path.join(util.libDirectory, platform, id, version);
+ var id_dir = path.join(util.libDirectory, platform, id);
+ shell.mkdir('-p', id_dir);
+ var download_dir = path.join(id_dir, version);
if (fs.existsSync(download_dir)) {
events.emit('log', 'Platform library for "' + platform + '" already exists. No need to download. Continuing.');
if (callback) callback();
return;
}
- shell.mkdir('-p', download_dir);
hooker.fire('before_library_download', {
platform:platform,
url:url,
@@ -62,6 +63,7 @@ module.exports = {
}, function() {
var uri = URL.parse(url);
if (uri.protocol) {
+ shell.mkdir(download_dir);
// assuming its remote
var filename = path.join(download_dir, id+'-'+platform+'-'+version+'.tar.gz');
if (fs.existsSync(filename)) {
@@ -136,7 +138,8 @@ module.exports = {
req.end();
} else {
// local path
- shell.cp('-rf', path.join(uri.path, '*'), download_dir);
+ // symlink instead of copying
+ fs.symlinkSync(uri.path, download_dir, 'dir');
hooker.fire('after_library_download', {
platform:platform,
url:url,
[4/4] git commit: npm version 2.8.18. Fixes [CB-3812].
Posted by fi...@apache.org.
npm version 2.8.18. Fixes [CB-3812].
Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/9d28a67d
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/9d28a67d
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/9d28a67d
Branch: refs/heads/master2
Commit: 9d28a67d68d2cba3a8ce3b8088883e3db38f6f86
Parents: 1bfd00c
Author: Fil Maj <ma...@gmail.com>
Authored: Fri Jun 14 13:24:29 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Fri Jun 14 13:24:29 2013 -0700
----------------------------------------------------------------------
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9d28a67d/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index f8af922..e3f27a9 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "cordova",
- "version": "2.8.17",
+ "version": "2.8.18",
"preferGlobal": "true",
"description": "Cordova command line interface tool",
"main": "cordova",
[2/4] git commit: [CB-3812] Platform parsers nwo support custom
directory locations. Added helper "has_custom_path" to config module.
Posted by fi...@apache.org.
[CB-3812] Platform parsers nwo support custom directory locations. Added helper "has_custom_path" to config module.
Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/9758d9fe
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/9758d9fe
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/9758d9fe
Branch: refs/heads/master2
Commit: 9758d9fe1c3630c345f5aac6385501b26c3ee034
Parents: d2392da
Author: Fil Maj <ma...@gmail.com>
Authored: Fri Jun 14 11:27:29 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Fri Jun 14 11:27:29 2013 -0700
----------------------------------------------------------------------
spec/platform.spec.js | 18 +++++++++---------
src/config.js | 10 ++++++++++
src/metadata/android_parser.js | 21 +++++++++++++++++----
src/metadata/blackberry_parser.js | 16 ++++++++++------
src/metadata/ios_parser.js | 10 +++++++---
src/metadata/wp7_parser.js | 16 +++++++++++-----
src/metadata/wp8_parser.js | 20 +++++++++++++-------
src/platform.js | 6 +++---
8 files changed, 80 insertions(+), 37 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9758d9fe/spec/platform.spec.js
----------------------------------------------------------------------
diff --git a/spec/platform.spec.js b/spec/platform.spec.js
index 3ea285a..3205811 100644
--- a/spec/platform.spec.js
+++ b/spec/platform.spec.js
@@ -30,10 +30,10 @@ var cordova = require('../cordova'),
var cwd = process.cwd();
var supported_platforms = Object.keys(platforms).filter(function(p) { return p != 'www'; });
+var project_dir = '/some/path';
describe('platform command', function() {
var is_cordova, list_platforms, fire, config_parser, find_plugins, config_read, load_custom, load_cordova, rm, mkdir, existsSync, supports, pkg, name, exec, prep_spy, plugman_install;
- var project_dir = '/some/path';
beforeEach(function() {
is_cordova = spyOn(util, 'isCordova').andReturn(project_dir);
fire = spyOn(hooker.prototype, 'fire').andCallFake(function(e, opts, cb) {
@@ -58,7 +58,7 @@ describe('platform command', function() {
rm = spyOn(shell, 'rm');
mkdir = spyOn(shell, 'mkdir');
existsSync = spyOn(fs, 'existsSync').andReturn(false);
- supports = spyOn(platform, 'supports').andCallFake(function(name, cb) {
+ supports = spyOn(platform, 'supports').andCallFake(function(project_root, name, cb) {
cb();
});
exec = spyOn(shell, 'exec').andCallFake(function(cmd, opts, cb) {
@@ -190,24 +190,24 @@ describe('platform.supports(name, callback)', function() {
var supports = {};
beforeEach(function() {
supported_platforms.forEach(function(p) {
- supports[p] = spyOn(platforms[p].parser, 'check_requirements').andCallFake(function(cb) { cb(); });
+ supports[p] = spyOn(platforms[p].parser, 'check_requirements').andCallFake(function(project, cb) { cb(); });
});
});
it('should require a platform name', function() {
expect(function() {
- cordova.platform.supports(undefined, function(e){});
+ cordova.platform.supports(project_dir, undefined, function(e){});
}).toThrow();
});
it('should require a callback function', function() {
expect(function() {
- cordova.platform.supports('android', undefined);
+ cordova.platform.supports(project_dir, 'android', undefined);
}).toThrow();
});
describe('when platform is unknown', function() {
it('should trigger callback with false', function(done) {
- cordova.platform.supports('windows-3.1', function(e) {
+ cordova.platform.supports(project_dir, 'windows-3.1', function(e) {
expect(e).toEqual(jasmine.any(Error));
done();
});
@@ -216,7 +216,7 @@ describe('platform.supports(name, callback)', function() {
describe('when platform is supported', function() {
it('should trigger callback without error', function(done) {
- cordova.platform.supports('android', function(e) {
+ cordova.platform.supports(project_dir, 'android', function(e) {
expect(e).toBeNull();
done();
});
@@ -226,9 +226,9 @@ describe('platform.supports(name, callback)', function() {
describe('when platform is unsupported', function() {
it('should trigger callback with error', function(done) {
supported_platforms.forEach(function(p) {
- supports[p].andCallFake(function(cb) { cb(new Error('no sdk')); });
+ supports[p].andCallFake(function(project, cb) { cb(new Error('no sdk')); });
});
- cordova.platform.supports('android', function(e) {
+ cordova.platform.supports(project_dir, 'android', function(e) {
expect(e).toEqual(jasmine.any(Error));
done();
});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9758d9fe/src/config.js
----------------------------------------------------------------------
diff --git a/src/config.js b/src/config.js
index fb0a59b..ca41ee6 100644
--- a/src/config.js
+++ b/src/config.js
@@ -19,6 +19,7 @@
var path = require('path'),
fs = require('fs'),
+ url = require('url'),
shell = require('shelljs'),
events = require('./events'),
util = require('./util');
@@ -52,3 +53,12 @@ module.exports.write = function set_config(project_root, json) {
fs.writeFileSync(config_json, JSON.stringify(json), 'utf-8');
return json;
};
+
+module.exports.has_custom_path = function(project_root, platform) {
+ var json = module.exports.read(project_root);
+ if (json.lib && json.lib[platform]) {
+ var uri = url.parse(json.lib[platform].uri);
+ if (!(uri.protocol)) return uri.path;
+ }
+ return false;
+};
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9758d9fe/src/metadata/android_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/android_parser.js b/src/metadata/android_parser.js
index d71473e..f03ee8f 100644
--- a/src/metadata/android_parser.js
+++ b/src/metadata/android_parser.js
@@ -22,6 +22,7 @@ var fs = require('fs'),
util = require('../util'),
events = require('../events'),
shell = require('shelljs'),
+ project_config= require('../config'),
config_parser = require('../config_parser');
var default_prefs = {
@@ -39,7 +40,7 @@ module.exports = function android_parser(project) {
this.android_config = path.join(this.path, 'res', 'xml', 'config.xml');
};
-module.exports.check_requirements = function(callback) {
+module.exports.check_requirements = function(project_root, callback) {
events.emit('log', 'Checking Android requirements...');
var command = 'android list target';
events.emit('log', 'Running "' + command + '" (output to follow)');
@@ -51,7 +52,14 @@ module.exports.check_requirements = function(callback) {
if (output.indexOf('android-17') == -1) {
callback('Please install Android target 17 (the Android 4.2 SDK). Make sure you have the latest Android tools installed as well. Run `android` from your command-line to install/update any missing SDKs or tools.');
} else {
- var cmd = 'android update project -p ' + path.join(util.libDirectory, 'android', 'cordova', util.cordovaTag, 'framework') + ' -t android-17';
+ var custom_path = project_config.has_custom_path(project_root, 'android');
+ var framework_path;
+ if (custom_path) {
+ framework_path = path.resolve(path.join(custom_path, 'framework'));
+ } else {
+ framework_path = path.join(util.libDirectory, 'android', 'cordova', util.cordovaTag, 'framework');
+ }
+ var cmd = 'android update project -p "' + framework_path + '" -t android-17';
events.emit('log', 'Running "' + cmd + '" (output to follow)...');
shell.exec(cmd, {silent:true, async:true}, function(code, output) {
events.emit('log', output);
@@ -160,9 +168,14 @@ module.exports.prototype = {
shell.cp('-rf', www, platformWww);
// write out android lib's cordova.js
- var jsPath = path.join(util.libDirectory, 'android', 'cordova', util.cordovaTag, 'framework', 'assets', 'www', 'cordova.js');
+ var custom_path = project_config.has_custom_path(projectRoot, 'android');
+ var jsPath;
+ if (custom_path) {
+ jsPath = path.resolve(path.join(custom_path, 'framework', 'assets', 'www', 'cordova.js'));
+ } else {
+ jsPath = path.join(util.libDirectory, 'android', 'cordova', util.cordovaTag, 'framework', 'assets', 'www', 'cordova.js');
+ }
fs.writeFileSync(path.join(this.www_dir(), 'cordova.js'), fs.readFileSync(jsPath, 'utf-8'), 'utf-8');
-
},
// update the overrides folder into the www folder
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9758d9fe/src/metadata/blackberry_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/blackberry_parser.js b/src/metadata/blackberry_parser.js
index 6cb39a0..b348d9e 100644
--- a/src/metadata/blackberry_parser.js
+++ b/src/metadata/blackberry_parser.js
@@ -23,7 +23,8 @@ var fs = require('fs'),
shell = require('shelljs'),
util = require('../util'),
events = require('../events'),
- config_parser = require('../config_parser');
+ config_parser = require('../config_parser'),
+ config = require('../config');
module.exports = function blackberry_parser(project) {
if (!fs.existsSync(path.join(project, 'project.json')) || !fs.existsSync(path.join(project, 'www'))) {
@@ -34,7 +35,7 @@ module.exports = function blackberry_parser(project) {
this.xml = new config_parser(this.config_path);
};
-module.exports.check_requirements = function(callback) {
+module.exports.check_requirements = function(project_root, callback) {
if (process.env && process.env.QNX_HOST) {
callback(false);
} else {
@@ -121,19 +122,22 @@ module.exports.prototype = {
// copy over project www assets
shell.cp('-rf', www, this.path);
+ var custom_path = config.has_custom_path(projectRoot, 'blackberry');
+ var lib_path = path.join(util.libDirectory, 'blackberry', 'cordova', util.cordovaTag);
+ if (custom_path) lib_path = custom_path;
// add cordova.js
- shell.cp('-f', path.join(util.libDirectory, 'blackberry', 'cordova', util.cordovaTag, 'javascript', 'cordova.blackberry10.js'), path.join(this.www_dir(), 'cordova.js'));
+ shell.cp('-f', path.join(lib_path, 'javascript', 'cordova.blackberry10.js'), path.join(this.www_dir(), 'cordova.js'));
// add webworks ext directories
- shell.cp('-rf', path.join(util.libDirectory, 'blackberry', 'cordova', util.cordovaTag, 'framework', 'ext*'), this.www_dir());
+ shell.cp('-rf', path.join(lib_path, 'framework', 'ext*'), this.www_dir());
// add config.xml
// @TODO should use project www/config.xml but it must use BBWP elements
- shell.cp('-f', path.join(util.libDirectory, 'blackberry', 'cordova', util.cordovaTag, 'bin', 'templates', 'project', 'www', 'config.xml'), this.www_dir());
+ shell.cp('-f', path.join(lib_path, 'bin', 'templates', 'project', 'www', 'config.xml'), this.www_dir());
// add res/
// @TODO remove this when config.xml is generalized
- shell.cp('-rf', path.join(util.libDirectory, 'blackberry', 'cordova', util.cordovaTag, 'bin', 'templates', 'project', 'www', 'res'), this.www_dir());
+ shell.cp('-rf', path.join(lib_path, 'bin', 'templates', 'project', 'www', 'res'), this.www_dir());
},
// update the overrides folder into the www folder
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9758d9fe/src/metadata/ios_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/ios_parser.js b/src/metadata/ios_parser.js
index 99e5a5e..bcf7718 100644
--- a/src/metadata/ios_parser.js
+++ b/src/metadata/ios_parser.js
@@ -25,7 +25,8 @@ var fs = require('fs'),
plist = require('plist'),
semver = require('semver'),
et = require('elementtree'),
- config_parser = require('../config_parser');
+ config_parser = require('../config_parser'),
+ config = require('../config');
var MIN_XCODE_VERSION = '4.5.x';
@@ -60,7 +61,7 @@ module.exports = function ios_parser(project) {
this.config = new config_parser(this.config_path);
};
-module.exports.check_requirements = function(callback) {
+module.exports.check_requirements = function(project_root, callback) {
events.emit('log', 'Checking iOS requirements...');
// Check xcode + version.
var command = 'xcodebuild -version';
@@ -177,7 +178,10 @@ module.exports.prototype = {
shell.cp('-rf', www, this.path);
// write out proper cordova.js
- shell.cp('-f', path.join(util.libDirectory, 'ios', 'cordova', util.cordovaTag, 'CordovaLib', 'cordova.js'), path.join(project_www, 'cordova.js'));
+ var custom_path = config.has_custom_path(projectRoot, 'ios');
+ var lib_path = path.join(util.libDirectory, 'ios', 'cordova', util.cordovaTag);
+ if (custom_path) lib_path = custom_path;
+ shell.cp('-f', path.join(lib_path, 'CordovaLib', 'cordova.js'), path.join(project_www, 'cordova.js'));
},
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9758d9fe/src/metadata/wp7_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/wp7_parser.js b/src/metadata/wp7_parser.js
index d5aeb51..f786025 100644
--- a/src/metadata/wp7_parser.js
+++ b/src/metadata/wp7_parser.js
@@ -23,7 +23,8 @@ var fs = require('fs'),
events = require('../events'),
shell = require('shelljs'),
events = require('../events'),
- config_parser = require('../config_parser');
+ config_parser = require('../config_parser'),
+ config = require('../config');
module.exports = function wp7_parser(project) {
try {
@@ -39,10 +40,12 @@ module.exports = function wp7_parser(project) {
this.manifest_path = path.join(this.wp7_proj_dir, 'Properties', 'WMAppManifest.xml');
};
-module.exports.check_requirements = function(callback) {
- // TODO: requires the libraries to be available.
+module.exports.check_requirements = function(project_root, callback) {
events.emit('log', 'Checking WP7 requirements...');
- var command = '"' + path.join(util.libDirectory, 'wp7', 'cordova', util.cordovaTag, 'bin', 'check_reqs') + '"';
+ var lib_path = path.join(util.libDirectory, 'wp7', 'cordova', util.cordovaTag);
+ var custom_path = config.has_custom_path(project_root, 'wp7');
+ if (custom_path) lib_path = custom_path;
+ var command = '"' + path.join(lib_path, 'bin', 'check_reqs') + '"';
events.emit('log', 'Running "' + command + '" (output to follow)');
shell.exec(command, {silent:true, async:true}, function(code, output) {
events.emit('log', output);
@@ -145,7 +148,10 @@ module.exports.prototype = {
shell.cp('-rf', project_www, this.wp7_proj_dir);
// copy over wp7 lib's cordova.js
- var cordovajs_path = path.join(util.libDirectory, 'wp7', 'cordova', util.cordovaTag, 'templates', 'standalone', 'www', 'cordova.js');
+ var lib_path = path.join(util.libDirectory, 'wp7', 'cordova', util.cordovaTag);
+ var custom_path = config.has_custom_path(project_root, 'wp7');
+ if (custom_path) lib_path = custom_path;
+ var cordovajs_path = path.join(lib_path, 'templates', 'standalone', 'www', 'cordova.js');
fs.writeFileSync(path.join(this.www_dir(), 'cordova.js'), fs.readFileSync(cordovajs_path, 'utf-8'), 'utf-8');
this.update_csproj();
},
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9758d9fe/src/metadata/wp8_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/wp8_parser.js b/src/metadata/wp8_parser.js
index 14d5fb4..ee7bcd0 100644
--- a/src/metadata/wp8_parser.js
+++ b/src/metadata/wp8_parser.js
@@ -39,10 +39,13 @@ module.exports = function wp8_parser(project) {
this.manifest_path = path.join(this.wp8_proj_dir, 'Properties', 'WMAppManifest.xml');
};
-module.exports.check_requirements = function(callback) {
+module.exports.check_requirements = function(project_root, callback) {
events.emit('log', 'Checking WP8 requirements...');
- // TODO: requires the libraries to be available.
- var command = '"' + path.join(util.libDirectory, 'wp8', 'cordova', util.cordovaTag, 'bin', 'check_reqs') + '"';
+ var custom_path = config.has_custom_path(project_root, 'wp8');
+ var lib_path = path.join(util.libDirectory, 'wp8', 'cordova', util.cordovaTag);
+ if (custom_path) lib_path = custom_path;
+
+ var command = '"' + path.join(lib_path, 'bin', 'check_reqs') + '"';
events.emit('log', 'Running "' + command + '" (output to follow)');
shell.exec(command, {silent:true, async:true}, function(code, output) {
events.emit('log', output);
@@ -101,8 +104,7 @@ module.exports.prototype = {
var cleanedPage = raw.replace(/^\uFEFF/i, '');
var csproj = new et.ElementTree(et.XML(cleanedPage));
prev_name = csproj.find('.//RootNamespace').text;
- if(prev_name != pkg)
- {
+ if (prev_name != pkg) {
//console.log("Updating package name from " + prev_name + " to " + pkg);
//CordovaAppProj.csproj
csproj.find('.//RootNamespace').text = pkg;
@@ -138,14 +140,18 @@ module.exports.prototype = {
},
// copies the app www folder into the wp8 project's www folder and updates the csproj file.
update_www:function() {
- var project_www = util.projectWww(path.join(this.wp8_proj_dir, '..', '..'));
+ var projectRoot = util.isCordova(this.wp8_proj_dir);
+ var project_www = util.projectWww(projectRoot);
// remove stock platform assets
shell.rm('-rf', this.www_dir());
// copy over all app www assets
shell.cp('-rf', project_www, this.wp8_proj_dir);
+ var custom_path = config.has_custom_path(projectRoot, 'wp8');
+ var lib_path = path.join(util.libDirectory, 'wp8', 'cordova', util.cordovaTag);
+ if (custom_path) lib_path = custom_path;
// copy over wp8 lib's cordova.js
- var cordovajs_path = path.join(util.libDirectory, 'wp8', 'cordova', util.cordovaTag, 'templates', 'standalone', 'www', 'cordova.js');
+ var cordovajs_path = path.join(lib_path, 'templates', 'standalone', 'www', 'cordova.js');
fs.writeFileSync(path.join(this.www_dir(), 'cordova.js'), fs.readFileSync(cordovajs_path, 'utf-8'), 'utf-8');
this.update_csproj();
},
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9758d9fe/src/platform.js
----------------------------------------------------------------------
diff --git a/src/platform.js b/src/platform.js
index 62bf05e..1149f23 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -168,7 +168,7 @@ module.exports = function platform(command, targets, callback) {
* - {Error} `e` null when a platform is supported otherwise describes error.
*/
-module.exports.supports = function(name, callback) {
+module.exports.supports = function(project_root, name, callback) {
// required parameters
if (!name) throw new Error('requires a platform name parameter');
if (!callback) throw new Error('requires a callback parameter');
@@ -188,7 +188,7 @@ module.exports.supports = function(name, callback) {
}
// check for platform support
- platformParser.check_requirements(function(e) {
+ platformParser.check_requirements(project_root, function(e) {
// typecast String to Error
e = (e instanceof String) ? new Error(e) : e;
// typecast false Boolean to null
@@ -217,7 +217,7 @@ function call_into_create(target, projectRoot, cfg, id, version, callback, end)
} else {
// Make sure we have minimum requirements to work with specified platform
events.emit('log', 'Checking if platform "' + target + '" passes minimum requirements...');
- module.exports.supports(target, function(err) {
+ module.exports.supports(projectRoot, target, function(err) {
if (err) {
if (callback) callback(err);
else throw err;
[3/4] git commit: finished up android parser specs
Posted by fi...@apache.org.
finished up android parser specs
Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/1bfd00cf
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/1bfd00cf
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/1bfd00cf
Branch: refs/heads/master2
Commit: 1bfd00cf828dd492192fc66e94df96dd4be25dbc
Parents: 9758d9f
Author: Fil Maj <ma...@gmail.com>
Authored: Fri Jun 14 13:21:10 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Fri Jun 14 13:21:10 2013 -0700
----------------------------------------------------------------------
spec/metadata/android_parser.spec.js | 129 ++++++++++++++++++++++++++----
src/metadata/android_parser.js | 9 ++-
2 files changed, 120 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/1bfd00cf/spec/metadata/android_parser.spec.js
----------------------------------------------------------------------
diff --git a/spec/metadata/android_parser.spec.js b/spec/metadata/android_parser.spec.js
index f2fd28d..6a890aa 100644
--- a/spec/metadata/android_parser.spec.js
+++ b/spec/metadata/android_parser.spec.js
@@ -21,17 +21,20 @@ var platforms = require('../../platforms'),
path = require('path'),
shell = require('shelljs'),
fs = require('fs'),
- et = require('elementtree'),
+ ET = require('elementtree'),
+ config = require('../../src/config'),
+ config_parser = require('../../src/config_parser'),
cordova = require('../../cordova');
describe('android project parser', function() {
var proj = '/some/path';
- var exists, exec;
+ var exists, exec, custom;
beforeEach(function() {
exists = spyOn(fs, 'existsSync').andReturn(true);
exec = spyOn(shell, 'exec').andCallFake(function(cmd, opts, cb) {
cb(0, 'android-17');
});
+ custom = spyOn(config, 'has_custom_path').andReturn(false);
});
describe('constructions', function() {
@@ -57,7 +60,7 @@ describe('android project parser', function() {
exec.andCallFake(function(cmd, opts, cb) {
cb(50, 'there was an errorz!');
});
- platforms.android.parser.check_requirements(function(err) {
+ platforms.android.parser.check_requirements(proj, function(err) {
expect(err).toContain('there was an errorz!');
done();
});
@@ -66,29 +69,40 @@ describe('android project parser', function() {
exec.andCallFake(function(cmd, opts, cb) {
cb(0, 'android-15');
});
- platforms.android.parser.check_requirements(function(err) {
+ platforms.android.parser.check_requirements(proj, function(err) {
expect(err).toEqual('Please install Android target 17 (the Android 4.2 SDK). Make sure you have the latest Android tools installed as well. Run `android` from your command-line to install/update any missing SDKs or tools.');
done();
});
});
it('should check that `android` is on the path by calling `android list target`', function(done) {
- platforms.android.parser.check_requirements(function(err) {
+ platforms.android.parser.check_requirements(proj, function(err) {
expect(err).toEqual(false);
expect(exec).toHaveBeenCalledWith('android list target', jasmine.any(Object), jasmine.any(Function));
done();
});
});
it('should check that we can update an android project by calling `android update project`', function(done) {
- platforms.android.parser.check_requirements(function(err) {
+ platforms.android.parser.check_requirements(proj, function(err) {
expect(err).toEqual(false);
- expect(exec.mostRecentCall.args[0]).toMatch(/^android update project -p .*framework -t android-17$/gi);
+ expect(exec.mostRecentCall.args[0]).toMatch(/^android update project -p .* -t android-17$/gi);
+ expect(exec.mostRecentCall.args[0]).toContain(util.libDirectory);
+ done();
+ });
+ });
+ it('should check that we can update an android project by calling `android update project` on a custom path if it is so defined', function(done) {
+ var custom_path = '/some/custom/path/to/android/lib'
+ custom.andReturn(custom_path);
+ platforms.android.parser.check_requirements(proj, function(err) {
+ expect(err).toEqual(false);
+ expect(exec.mostRecentCall.args[0]).toMatch(/^android update project -p .* -t android-17$/gi);
+ expect(exec.mostRecentCall.args[0]).toContain(custom_path);
done();
});
});
});
describe('instance', function() {
- var p, cp, rm, is_cordova, write;
+ var p, cp, rm, is_cordova, write, read;
var android_proj = path.join(proj, 'platforms', 'android');
beforeEach(function() {
p = new platforms.android.parser(android_proj);
@@ -96,14 +110,93 @@ describe('android project parser', function() {
rm = spyOn(shell, 'rm');
is_cordova = spyOn(util, 'isCordova').andReturn(proj);
write = spyOn(fs, 'writeFileSync');
+ read = spyOn(fs, 'readFileSync');
});
describe('update_from_config method', function() {
- it('should write out the app name to strings.xml');
- it('should write out the app id to androidmanifest.xml and update the cordova-android entry Java class');
- it('should write out the app version to androidmanifest.xml');
- it('should update the whitelist');
- it('should update preferences');
+ var et, xml, find, write_xml, root, cfg, readdir, cfg_parser, find_obj, root_obj, cfg_access_add, cfg_access_rm, cfg_pref_add, cfg_pref_rm;
+ beforeEach(function() {
+ find_obj = {
+ text:'hi'
+ };
+ root_obj = {
+ attrib:{
+ package:'android_pkg'
+ }
+ };
+ find = jasmine.createSpy('ElementTree find').andReturn(find_obj);
+ write_xml = jasmine.createSpy('ElementTree write');
+ root = jasmine.createSpy('ElementTree getroot').andReturn(root_obj);
+ et = spyOn(ET, 'ElementTree').andReturn({
+ find:find,
+ write:write_xml,
+ getroot:root
+ });
+ xml = spyOn(ET, 'XML');
+ readdir = spyOn(fs, 'readdirSync').andReturn([path.join(proj, 'src', 'android_pkg')]);
+ cfg = new config_parser();
+ cfg.name = function() { return 'testname' };
+ cfg.packageName = function() { return 'testpkg' };
+ cfg.version = function() { return 'one point oh' };
+ cfg.access.get = function() { return [] };
+ cfg.preference.get = function() { return [] };
+ read.andReturn('some java package');
+ cfg_access_add = jasmine.createSpy('config_parser access add');
+ cfg_access_rm = jasmine.createSpy('config_parser access rm');
+ cfg_pref_rm = jasmine.createSpy('config_parser pref rm');
+ cfg_pref_add = jasmine.createSpy('config_parser pref add');
+ cfg_parser = spyOn(util, 'config_parser').andReturn({
+ access:{
+ remove:cfg_access_rm,
+ get:function(){},
+ add:cfg_access_add
+ },
+ preference:{
+ remove:cfg_pref_rm,
+ get:function(){},
+ add:cfg_pref_add
+ }
+ });
+ });
+
+ it('should write out the app name to strings.xml', function() {
+ p.update_from_config(cfg);
+ expect(find_obj.text).toEqual('testname');
+ });
+ it('should write out the app id to androidmanifest.xml and update the cordova-android entry Java class', function() {
+ p.update_from_config(cfg);
+ expect(root_obj.attrib.package).toEqual('testpkg');
+ });
+ it('should write out the app version to androidmanifest.xml', function() {
+ p.update_from_config(cfg);
+ expect(root_obj.attrib['android:versionName']).toEqual('one point oh');
+ });
+ it('should wipe out the android whitelist every time', function() {
+ p.update_from_config(cfg);
+ expect(cfg_access_rm).toHaveBeenCalled();
+ });
+ it('should update the whitelist', function() {
+ cfg.access.get = function() { return ['one'] };
+ p.update_from_config(cfg);
+ expect(cfg_access_add).toHaveBeenCalledWith('one');
+ });
+ it('should update preferences', function() {
+ var sample_pref = {name:'pref',value:'yes'};
+ cfg.preference.get = function() { return [sample_pref] };
+ p.update_from_config(cfg);
+ expect(cfg_pref_add).toHaveBeenCalledWith(sample_pref);
+ });
+ it('should wipe out the android preferences every time', function() {
+ p.update_from_config(cfg);
+ expect(cfg_pref_rm).toHaveBeenCalled();
+ });
+ it('should write out default preferences every time', function() {
+ var sample_pref = {name:'preftwo',value:'false'};
+ cfg.preference.get = function() { return [sample_pref] };
+ p.update_from_config(cfg);
+ expect(cfg_pref_add).toHaveBeenCalledWith({name:"useBrowserHistory",value:"true"});
+ expect(cfg_pref_add).toHaveBeenCalledWith({name:"exit-on-suspend",value:"false"});
+ });
});
describe('www_dir method', function() {
it('should return assets/www', function() {
@@ -126,9 +219,17 @@ describe('android project parser', function() {
expect(rm).toHaveBeenCalled();
expect(cp).toHaveBeenCalled();
});
- it('should copy in a fresh cordova.js', function() {
+ it('should copy in a fresh cordova.js from stock cordova lib if no custom lib is specified', function() {
+ p.update_www();
+ expect(write).toHaveBeenCalled();
+ expect(read.mostRecentCall.args[0]).toContain(util.libDirectory);
+ });
+ it('should copy in a fresh cordova.js from custom cordova lib if custom lib is specified', function() {
+ var custom_path = '/custom/path';
+ custom.andReturn(custom_path);
p.update_www();
expect(write).toHaveBeenCalled();
+ expect(read.mostRecentCall.args[0]).toContain(custom_path);
});
});
describe('update_overrides method', function() {
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/1bfd00cf/src/metadata/android_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/android_parser.js b/src/metadata/android_parser.js
index f03ee8f..8fcd574 100644
--- a/src/metadata/android_parser.js
+++ b/src/metadata/android_parser.js
@@ -86,19 +86,20 @@ module.exports.prototype = {
fs.writeFileSync(this.strings, strings.write({indent: 4}), 'utf-8');
events.emit('log', 'Wrote out Android application name to "' + name + '"');
- // Update the version by changing the AndroidManifest android:versionName
var manifest = new et.ElementTree(et.XML(fs.readFileSync(this.manifest, 'utf-8')));
+ // Update the version by changing the AndroidManifest android:versionName
var version = config.version();
manifest.getroot().attrib["android:versionName"] = version;
- fs.writeFileSync(this.manifest, manifest.write({indent: 4}), 'utf-8');
// Update package name by changing the AndroidManifest id and moving the entry class around to the proper package directory
- var manifest = new et.ElementTree(et.XML(fs.readFileSync(this.manifest, 'utf-8')));
var pkg = config.packageName();
pkg = pkg.replace(/-/g, '_'); // Java packages cannot support dashes
var orig_pkg = manifest.getroot().attrib.package;
manifest.getroot().attrib.package = pkg;
+
+ // Write out AndroidManifest.xml
fs.writeFileSync(this.manifest, manifest.write({indent: 4}), 'utf-8');
+
var orig_pkgDir = path.join(this.path, 'src', path.join.apply(null, orig_pkg.split('.')));
var orig_java_class = fs.readdirSync(orig_pkgDir).filter(function(f) {return f.indexOf('.svn') == -1;})[0];
var pkgDir = path.join(this.path, 'src', path.join.apply(null, pkg.split('.')));
@@ -111,7 +112,7 @@ module.exports.prototype = {
fs.writeFileSync(new_javs, javs_contents, 'utf-8');
// Update whitelist by changing res/xml/config.xml
- var android_cfg_xml = new config_parser(this.android_config);
+ var android_cfg_xml = new util.config_parser(this.android_config);
// clean out all existing access elements first
android_cfg_xml.access.remove();
// add only the ones specified in the app/config.xml file