cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [5/8] cordova-lib git commit: CB-8123 Fix path handling so tests work on any platform.
Date Thu, 12 Feb 2015 00:50:56 GMT
CB-8123 Fix path handling so tests work on any platform.


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

Branch: refs/heads/master
Commit: f1c5d8fb409233f775a2fff4aea449670acce59a
Parents: 22a214f
Author: Tim Barham <tbarham@TB-MAC.local>
Authored: Wed Feb 4 18:30:25 2015 +1000
Committer: Tim Barham <tbarham@TB-MAC.local>
Committed: Wed Feb 4 18:30:25 2015 +1000

----------------------------------------------------------------------
 .../spec-plugman/platforms/windows.spec.js      | 31 ++++++++++++--------
 cordova-lib/src/util/windows/jsprojManager.js   | 23 +++++++++++----
 2 files changed, 35 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/f1c5d8fb/cordova-lib/spec-plugman/platforms/windows.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-plugman/platforms/windows.spec.js b/cordova-lib/spec-plugman/platforms/windows.spec.js
index 444c987..f64bc3b 100644
--- a/cordova-lib/spec-plugman/platforms/windows.spec.js
+++ b/cordova-lib/spec-plugman/platforms/windows.spec.js
@@ -243,16 +243,16 @@ beforeEach(function () {
                 var frameworks = copyArray(valid_frameworks);
 
                 it('should write to correct project files when conditions are specified',
function () {
-                    var xpath = 'ProjectReference[@Include="' + dummyplugin + '\\src\\windows\\dummy1.vcxproj"][@Condition="\'$(Platform)\'==\'x64\'"]';
+                    var xpath = 'ProjectReference[@Include="' + windowsJoin(dummyplugin,
'src', 'windows', 'dummy1.vcxproj') + '"][@Condition="\'$(Platform)\'==\'x64\'"]';
                     validateInstalledProjects('framework', frameworks[4], xpath, ['all']);
 
-                    xpath = 'ProjectReference[@Include="' + dummyplugin + '\\src\\windows\\dummy2.vcxproj"]';
+                    xpath = 'ProjectReference[@Include="' + windowsJoin(dummyplugin, 'src',
'windows', 'dummy2.vcxproj') + '"]';
                     validateInstalledProjects('framework', frameworks[5], xpath, ['windows8']);
 
-                    xpath = 'ProjectReference[@Include="' + dummyplugin + '\\src\\windows\\dummy3.vcxproj"]';
+                    xpath = 'ProjectReference[@Include="' + windowsJoin(dummyplugin, 'src',
'windows', 'dummy3.vcxproj') + '"]';
                     validateInstalledProjects('framework', frameworks[6], xpath, ['windows',
'windows8']);
 
-                    xpath = 'ProjectReference[@Include="' + dummyplugin + '\\src\\windows\\dummy4.vcxproj"][@Condition="\'$(Platform)\'==\'x86\'"]';
+                    xpath = 'ProjectReference[@Include="' + windowsJoin(dummyplugin, 'src',
'windows', 'dummy4.vcxproj') + '"][@Condition="\'$(Platform)\'==\'x86\'"]';
                     validateInstalledProjects('framework', frameworks[7], xpath, ['windows',
'phone']);
                 });
             });
@@ -389,22 +389,22 @@ beforeEach(function () {
 
                     install('windows', cordovaProjectWindowsPlatformDir, dummyplugin, cordovaProjectPluginsDir,
{})
                         .then(function () {
-                            var path = 'ItemGroup/ProjectReference';
-                            var incText = cordovaProjectPluginsDir + "\\" + dummy_id + '\\src\\windows\\dummy1.vcxproj';
+                            var xmlPath = 'ItemGroup/ProjectReference';
+                            var incText = windowsJoin(cordovaProjectPluginsDir , dummy_id,
'src', 'windows', 'dummy1.vcxproj');
                             var targetConditions = {versions: undefined, target: undefined,
arch: 'x64'};
-                            validateUninstalledProjects('framework', frameworks[4], path,
incText, targetConditions, ['all']);
+                            validateUninstalledProjects('framework', frameworks[4], xmlPath,
incText, targetConditions, ['all']);
 
-                            incText = cordovaProjectPluginsDir + "\\" + dummy_id + '\\src\\windows\\dummy2.vcxproj';
+                            incText = windowsJoin(cordovaProjectPluginsDir , dummy_id, 'src',
'windows', 'dummy2.vcxproj');
                             targetConditions = {versions: '<8.1', target: undefined, arch:
undefined};
-                            validateUninstalledProjects('framework', frameworks[5], path,
incText, targetConditions, ['windows8']);
+                            validateUninstalledProjects('framework', frameworks[5], xmlPath,
incText, targetConditions, ['windows8']);
 
-                            incText = cordovaProjectPluginsDir + "\\" + dummy_id + '\\src\\windows\\dummy3.vcxproj';
+                            incText = windowsJoin(cordovaProjectPluginsDir , dummy_id, 'src',
'windows', 'dummy3.vcxproj');
                             targetConditions = {versions: undefined, target: 'win', arch:
undefined};
-                            validateUninstalledProjects('framework', frameworks[6], path,
incText, targetConditions, ['windows', 'windows8']);
+                            validateUninstalledProjects('framework', frameworks[6], xmlPath,
incText, targetConditions, ['windows', 'windows8']);
 
-                            incText = cordovaProjectPluginsDir + "\\" + dummy_id + '\\src\\windows\\dummy4.vcxproj';
+                            incText = windowsJoin(cordovaProjectPluginsDir , dummy_id, 'src',
'windows', 'dummy4.vcxproj');
                             targetConditions = {versions: '8.1', target: 'all', arch: 'x86'};
-                            validateUninstalledProjects('framework', frameworks[7], path,
incText, targetConditions, ['windows', 'phone']);
+                            validateUninstalledProjects('framework', frameworks[7], xmlPath,
incText, targetConditions, ['windows', 'phone']);
 
                             done();
                         });
@@ -413,3 +413,8 @@ beforeEach(function () {
         });
     });
 });
+
+function windowsJoin() {
+    // Paths that are written to project files will be in Windows format, regardless of the
current OS.
+    return path.join.apply(path, arguments).split('/').join('\\');
+}

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/f1c5d8fb/cordova-lib/src/util/windows/jsprojManager.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/util/windows/jsprojManager.js b/cordova-lib/src/util/windows/jsprojManager.js
index 57642ba..1b2671e 100644
--- a/cordova-lib/src/util/windows/jsprojManager.js
+++ b/cordova-lib/src/util/windows/jsprojManager.js
@@ -129,7 +129,10 @@ jsprojManager.prototype = {
     addProjectReference: function (relative_path, targetConditions) {
         events.emit('verbose', 'jsprojManager.addProjectReference(incText: ' + relative_path
+ ', targetConditions: ' + JSON.stringify(targetConditions) + ')');
 
-        relative_path = relative_path.split('/').join('\\');
+        // relative_path is the actual path to the file in the current OS, where-as inserted_path
is what we write in
+        // the project file, and is always in Windows format.
+        relative_path = path.normalize(relative_path);
+        var inserted_path = relative_path.split('/').join('\\');
 
         var pluginProjectXML = xml_helpers.parseElementtreeSync(relative_path);
 
@@ -147,7 +150,7 @@ jsprojManager.prototype = {
             "\t\t" + projectGuid + "=" + projectGuid + "\r\n" +
             "\tEndProjectSection\r\n";
         var postInsertText = '\r\nProject("' + projectTypeGuid + '") = "' +
-            projName + '", "' + relative_path + '", ' +
+            projName + '", "' + inserted_path + '", ' +
             '"' + projectGuid + '"\r\nEndProject';
 
         var matchingProjects = this._getMatchingProjects(targetConditions);
@@ -197,7 +200,7 @@ jsprojManager.prototype = {
 
         // Add the ItemGroup/ProjectReference to each matching cordova project :
         // <ItemGroup><ProjectReference Include="blahblah.csproj"/></ItemGroup>
-        var item = createReferenceElement('ItemGroup/ProjectReference', relative_path, targetConditions);
+        var item = createReferenceElement('ItemGroup/ProjectReference', inserted_path, targetConditions);
         matchingProjects.forEach(function (project) {
             project.appendToRoot(item);
         });
@@ -206,6 +209,11 @@ jsprojManager.prototype = {
     removeProjectReference: function (relative_path, targetConditions) {
         events.emit('verbose', 'jsprojManager.removeProjectReference(incText: ' + relative_path
+ ', targetConditions: ' + JSON.stringify(targetConditions) + ')');
 
+        // relative_path is the actual path to the file in the current OS, where-as inserted_path
is what we write in
+        // the project file, and is always in Windows format.
+        relative_path = path.normalize(relative_path);
+        var inserted_path = relative_path.split('/').join('\\');
+
         // find the guid + name of the referenced project
         var pluginProjectXML = xml_helpers.parseElementtreeSync(relative_path);
         var projectGuid = pluginProjectXML.find("PropertyGroup/ProjectGuid").text;
@@ -218,7 +226,7 @@ jsprojManager.prototype = {
         }
 
         var preInsertTextRegExp = getProjectReferencePreInsertRegExp(projectGuid);
-        var postInsertTextRegExp = getProjectReferencePostInsertRegExp(projName, projectGuid,
relative_path, projectTypeGuid);
+        var postInsertTextRegExp = getProjectReferencePostInsertRegExp(projName, projectGuid,
inserted_path, projectTypeGuid);
 
         // There may be multiple solutions (for different VS versions) - process them all
         getSolutionPaths(this.projectFolder).forEach(function (solutionPath) {
@@ -239,7 +247,7 @@ jsprojManager.prototype = {
         });
 
         this._getMatchingProjects(targetConditions).forEach(function (project) {
-            project.removeReferenceElementItemGroup('ItemGroup/ProjectReference', relative_path,
targetConditions);
+            project.removeReferenceElementItemGroup('ItemGroup/ProjectReference', inserted_path,
targetConditions);
         });
     },
 
@@ -423,6 +431,8 @@ proj.prototype = {
         var item = new et.Element('ItemGroup');
 
         relative_path.forEach(function (filePath) {
+            // filePath is never used to find the actual file - it determines what we write
to the project file, and so
+            // should always be in Windows format.
             filePath = filePath.split('/').join('\\');
 
             var content = new et.Element('Content');
@@ -436,7 +446,8 @@ proj.prototype = {
     removeSourceFile: function (relative_path) {
         var isRegexp = relative_path instanceof RegExp;
         if (!isRegexp) {
-            // path.normalize(relative_path);// ??
+            // relative_path is never used to find the actual file - it determines what we
write to the project file,
+            // and so should always be in Windows format.
             relative_path = relative_path.split('/').join('\\');
         }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message