Repository: cordova-lib
Updated Branches:
  refs/heads/master 93d4ba683 -> 3e6902209


CB-6711: Use parseProjectFile when working with XCode projects.

Otherwise the changes get overwritten by the cached version of the project file.
This is due to double caching between ConfigKeeper and parseProjectFile.
Add a unit test to guard against similar bugs in the future.

github: close #15


Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/3e690220
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/3e690220
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/3e690220

Branch: refs/heads/master
Commit: 3e6902209b48691f3b3d3b160c9ee923c7b3b3bf
Parents: 93d4ba6
Author: Martin Bektchiev <[email protected]>
Authored: Wed May 14 19:56:35 2014 +0300
Committer: Mark Koudritsky <[email protected]>
Committed: Wed May 28 11:48:22 2014 -0400

----------------------------------------------------------------------
 cordova-lib/spec-plugman/platforms/ios.spec.js | 54 ++++++++++++++-------
 cordova-lib/src/plugman/util/config-changes.js |  4 +-
 2 files changed, 38 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/3e690220/cordova-lib/spec-plugman/platforms/ios.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-plugman/platforms/ios.spec.js 
b/cordova-lib/spec-plugman/platforms/ios.spec.js
index 9243827..7939bc6 100644
--- a/cordova-lib/spec-plugman/platforms/ios.spec.js
+++ b/cordova-lib/spec-plugman/platforms/ios.spec.js
@@ -5,8 +5,6 @@ var ios = require('../../src/plugman/platforms/ios'),
     et = require('elementtree'),
     shell = require('shelljs'),
     os = require('osenv'),
-    common = require('../../src/plugman/platforms/common'),
-    xcode = require('xcode'),
     plist = require('plist-with-patches'),
     bplist = require('bplist-parser'),
     temp = path.join(os.tmpdir(), 'plugman'),
@@ -17,7 +15,9 @@ var ios = require('../../src/plugman/platforms/ios'),
     xml_helpers = require('../../src/util/xml-helpers'),
     variableplugin = path.join(__dirname, '..', 'plugins', 'VariablePlugin'),
     faultyplugin = path.join(__dirname, '..', 'plugins', 'FaultyPlugin'),
-    dummyplugin = path.join(__dirname, '..', 'plugins', 'DummyPlugin');
+    dummyplugin = path.join(__dirname, '..', 'plugins', 'DummyPlugin'),
+    weblessplugin = path.join(__dirname, '..', 'plugins', 'WeblessPlugin'),
+    done = false;
 
 var xml_path = path.join(dummyplugin, 'plugin.xml'),
     xml_test = fs.readFileSync(xml_path, 'utf-8'),
@@ -64,6 +64,10 @@ function copyArray(arr) {
     return Array.prototype.slice.call(arr, 0);
 }
 
+function installPromise(f) {
+    f.then(function(res) { done = true; }, function(err) { done = err; });
+}
+
 describe('ios project handler', function() {
     beforeEach(function() {
         shell.mkdir('-p', temp);
@@ -103,11 +107,12 @@ describe('ios project handler', function() {
     });
 
     describe('installation', function() {
-        describe('of <source-file> elements', function() {
-            beforeEach(function() {
-                shell.cp('-rf', ios_config_xml_project, temp);
-            });
+        beforeEach(function() {
+            shell.cp('-rf', ios_config_xml_project, temp);
+            done = false;
+        });
 
+        describe('of <source-file> elements', function() {
             it('should throw if source-file src cannot be found', function() {
                 var source = copyArray(invalid_source);
                 expect(function() {
@@ -157,10 +162,6 @@ describe('ios project handler', function() {
         });
 
         describe('of <header-file> elements', function() {
-            beforeEach(function() {
-                shell.cp('-rf', ios_config_xml_project, temp);
-            });
-
             it('should throw if header-file src cannot be found', function() {
                 var headers = copyArray(invalid_headers);
                 expect(function() {
@@ -203,9 +204,6 @@ describe('ios project handler', function() {
         });
 
         describe('of <resource-file> elements', function() {
-            beforeEach(function() {
-                shell.cp('-rf', ios_config_xml_project, temp);
-            });
             it('should throw if resource-file src cannot be found', function() 
{
                 var resources = copyArray(invalid_resources);
                 expect(function() {
@@ -235,9 +233,6 @@ describe('ios project handler', function() {
             });
         });
         describe('of <framework custom="true"> elements', function() {
-            beforeEach(function() {
-                shell.cp('-rf', ios_config_xml_project, temp);
-            });
             it('should throw if framework src cannot be found', function() {
                 var frameworks = copyArray(invalid_custom_frameworks);
                 expect(function() {
@@ -266,6 +261,31 @@ describe('ios project handler', function() {
                                                  path.join(temp, 
'SampleApp/Plugins/com.phonegap.plugins.dummyplugin'));
             });
         });
+        it('of two plugins should apply xcode file changes from both', 
function(){
+            runs(function() {
+                installPromise(
+                    install('ios', temp, dummyplugin)
+                    .then(function () { install('ios', temp, weblessplugin); })
+                );
+            });
+            waitsFor(function() { return done; }, 'install promise never 
resolved', 200);
+            runs(function() {
+                var xcode = ios.parseProjectFile(temp).xcode;
+                // from DummyPlugin
+                expect(xcode.hasFile(path.join('Resources', 
'DummyPlugin.bundle'))).toBe(true);
+                
expect(xcode.hasFile(path.join('Plugins','com.phonegap.plugins.dummyplugin', 
'DummyPluginCommand.h'))).toBe(true);
+                
expect(xcode.hasFile(path.join('Plugins','com.phonegap.plugins.dummyplugin', 
'DummyPluginCommand.m'))).toBe(true);
+                
expect(xcode.hasFile(path.join('Plugins','com.phonegap.plugins.dummyplugin','targetDir','TargetDirTest.h'))).toBe(true);
+                
expect(xcode.hasFile(path.join('Plugins','com.phonegap.plugins.dummyplugin','targetDir','TargetDirTest.m'))).toBe(true);
+                
expect(xcode.hasFile('usr/lib/src/ios/libsqlite3.dylib')).toBe(true);
+                
expect(xcode.hasFile(path.join('SampleApp','Plugins','com.phonegap.plugins.dummyplugin','Custom.framework'))).toBe(true);
+                // from WeblessPlugin
+                expect(xcode.hasFile(path.join('Resources', 
'WeblessPluginViewController.xib'))).toBe(true);
+                
expect(xcode.hasFile(path.join('Plugins','com.phonegap.plugins.weblessplugin','WeblessPluginCommand.h'))).toBe(true);
+                
expect(xcode.hasFile(path.join('Plugins','com.phonegap.plugins.weblessplugin','WeblessPluginCommand.m'))).toBe(true);
+                expect(xcode.hasFile('usr/lib/libsqlite3.dylib')).toBe(true);
+            });
+        });
     });
 
     describe('uninstallation', function() {

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/3e690220/cordova-lib/src/plugman/util/config-changes.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/util/config-changes.js 
b/cordova-lib/src/plugman/util/config-changes.js
index 9ae767b..bc24a7f 100644
--- a/cordova-lib/src/plugman/util/config-changes.js
+++ b/cordova-lib/src/plugman/util/config-changes.js
@@ -37,7 +37,6 @@ var fs   = require('fs'),
     glob = require('glob'),
     plist = require('plist-with-patches'),
     bplist = require('bplist-parser'),
-    xcode = require('xcode'),
     et   = require('elementtree'),
     _ = require('underscore'),
     xml_helpers = require('../../util/xml-helpers'),
@@ -510,8 +509,7 @@ function ConfigFile_load() {
         self.data = xml_helpers.parseElementtreeSync(filepath);
     } else if (ext == '.pbxproj') {
         self.type = 'pbxproj';
-        self.data = xcode.project(filepath);
-        self.data.parseSync();
+        self.data = platforms.ios.parseProjectFile(self.project_dir).xcode;
     } else {
         // plist file
         self.type = 'plist';

Reply via email to