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/11/28 19:16:24 UTC

[34/50] git commit: modifying package name (bundle id) for ios projects.

modifying package name (bundle id) for ios projects.


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

Branch: refs/heads/master
Commit: 501c2d8baec8a4a9f2f2c6a78b6c3350f5c3fb44
Parents: 3b42d94
Author: Fil Maj <ma...@gmail.com>
Authored: Wed Oct 10 11:55:25 2012 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Wed Oct 10 11:55:25 2012 -0700

----------------------------------------------------------------------
 package.json                     |    1 +
 spec/metadata/ios_parser.spec.js |   23 ++++++++++++++++++++++-
 src/metadata/ios_parser.js       |   13 ++++++++++++-
 3 files changed, 35 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/501c2d8b/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 8e59e1e..dd0ca11 100644
--- a/package.json
+++ b/package.json
@@ -24,6 +24,7 @@
     "elementtree":"0.1.3",
     "pluginstall":"git://github.com/imhotep/pluginstall.git",
     "node-xcode":"git://github.com/imhotep/node-xcode.git",
+    "plist":"0.4.0",
     "express":"3.0",
     "shelljs":"0.0.7",
     "ncallbacks":"1.0.0",

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/501c2d8b/spec/metadata/ios_parser.spec.js
----------------------------------------------------------------------
diff --git a/spec/metadata/ios_parser.spec.js b/spec/metadata/ios_parser.spec.js
index f7c7fbf..1388586 100644
--- a/spec/metadata/ios_parser.spec.js
+++ b/spec/metadata/ios_parser.spec.js
@@ -7,11 +7,14 @@ var ios_parser = require('../../src/metadata/ios_parser'),
     cfg_path = path.join(__dirname, '..', 'fixtures', 'projects', 'test', 'www', 'config.xml'),
     ios_path = path.join(__dirname, '..', 'fixtures', 'projects', 'native', 'ios'),
     tempDir = path.join(__dirname, '..', '..', 'temp'),
+    ios_plist = path.join(ios_path, 'balls', 'balls-Info.plist'),
     ios_pbx = path.join(ios_path, 'balls.xcodeproj', 'project.pbxproj');
 
 var cwd = process.cwd();
 
 var original_pbx = fs.readFileSync(ios_pbx, 'utf-8');
+var original_plist = fs.readFileSync(ios_plist, 'utf-8');
+var original_config = fs.readFileSync(cfg_path, 'utf-8');
 
 describe('ios project parser', function() {
     it('should throw an exception with a path that is not a native ios project', function() {
@@ -60,7 +63,25 @@ describe('ios project parser', function() {
                 expect(pbx_contents.match(/PRODUCT_NAME\s*=\s*"bond. james bond."/)[0]).toBe('PRODUCT_NAME = "bond. james bond."');
             });
         });
-        it('should update the application package name properly');
+        it('should update the application package name (bundle identifier) properly', function() {
+            var cb = jasmine.createSpy();
+            this.after(function() {
+                fs.writeFileSync(ios_plist, original_plist, 'utf-8');
+                fs.writeFileSync(cfg_path, original_config, 'utf-8');
+            });
+
+            runs(function() {
+                config.packageName('ca.filmaj.dewd');
+                project.update_from_config(config, cb);
+            });
+
+            waitsFor(function() { return cb.wasCalled; }, "update_from_config callback");
+
+            runs(function() {
+                var plist_contents = fs.readFileSync(ios_plist, 'utf-8');
+                expect(plist_contents.match(/<string>ca.filmaj.dewd/));
+            });
+        });
     });
 
     describe('update_www method', function() {

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/501c2d8b/src/metadata/ios_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/ios_parser.js b/src/metadata/ios_parser.js
index aa9ed31..1e826df 100644
--- a/src/metadata/ios_parser.js
+++ b/src/metadata/ios_parser.js
@@ -1,6 +1,7 @@
 var fs   = require('fs'),
     path = require('path'),
     xcode = require('xcode'),
+    plist = require('plist'),
     util = require('../util'),
     shell = require('shelljs'),
     config_parser = require('../config_parser');
@@ -10,6 +11,8 @@ module.exports = function ios_parser(project) {
         var xcodeproj_dir = fs.readdirSync(project).filter(function(e) { return e.match(/\.xcodeproj$/i); })[0];
         if (!xcodeproj_dir) throw 'The provided path is not a Cordova iOS project.';
         this.xcodeproj = path.join(project, xcodeproj_dir);
+        this.originalName = this.xcodeproj.substring(this.xcodeproj.lastIndexOf('/'), this.xcodeproj.indexOf('.xcodeproj'));
+        this.cordovaproj = path.join(project, this.originalName);
     } catch(e) {
         throw 'The provided path is not a Cordova iOS project.';
     }
@@ -22,8 +25,16 @@ module.exports.prototype = {
         } else throw 'update_from_config requires a config_parser object';
 
         var name = config.name();
-        var proj = new xcode.project(this.pbxproj);
+        var pkg = config.packageName();
+
+        // Update package id (bundle id)
+        var plistFile = path.join(this.cordovaproj, this.originalName + '-Info.plist');
+        var plistObj = plist.parseFileSync(plistFile);
+        plistObj.CFBundleIdentifier = pkg;
+        fs.writeFileSync(plistFile, plist.build(plistObj));
 
+        // Update product name
+        var proj = new xcode.project(this.pbxproj);
         var parser = this;
         proj.parse(function(err,hash) {
             if (err) throw 'An error occured during parsing of project.pbxproj. Start weeping.';