cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an-s...@apache.org
Subject [4/4] cordova-windows git commit: CB-12163 Make resource-file copy files again
Date Wed, 25 Jan 2017 15:50:11 GMT
CB-12163 Make resource-file copy files again

Fix destPath check in copyFile


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

Branch: refs/heads/master
Commit: c71379a8e78542854597544fc97f756e2eae5b44
Parents: 15a54f0
Author: ktop <ktop500@gmail.com>
Authored: Tue Dec 6 15:58:42 2016 -0500
Committer: Vladimir Kotikov <kotikov.vladimir@gmail.com>
Committed: Wed Jan 25 18:49:56 2017 +0300

----------------------------------------------------------------------
 spec/unit/pluginHandler/windows.spec.js | 23 +++++++++--------------
 template/cordova/lib/JsprojManager.js   |  2 +-
 template/cordova/lib/PluginHandler.js   | 24 ++++++------------------
 3 files changed, 16 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/c71379a8/spec/unit/pluginHandler/windows.spec.js
----------------------------------------------------------------------
diff --git a/spec/unit/pluginHandler/windows.spec.js b/spec/unit/pluginHandler/windows.spec.js
index 8793c3c..6aea7a4 100644
--- a/spec/unit/pluginHandler/windows.spec.js
+++ b/spec/unit/pluginHandler/windows.spec.js
@@ -74,11 +74,6 @@ beforeEach(function () {
     });
 });
 
-var getPluginFilePath = PluginHandler.__get__('getPluginFilePath');
-var computeResourcePath = function(resourceFile) {
-    return getPluginFilePath(dummyPluginInfo, resourceFile.src, cordovaProjectWindowsPlatformDir);
-};
-
 var PLATFORM_PROJECTS = {
     all: 'CordovaApp.projitems',
     phone: 'CordovaApp.Phone.jsproj',
@@ -95,7 +90,7 @@ describe('windows project handler', function () {
         dummyProject = JsprojManager.getProject(cordovaProjectWindowsPlatformDir);
         shell.mkdir('-p', cordovaProjectPluginsDir);
         shell.cp('-rf', dummyplugin, cordovaProjectPluginsDir);
-        // CB-11558 Reinitialize plugin.dir to become project_root/plugins/plugin.id to avoid

+        // CB-11558 Reinitialize plugin.dir to become project_root/plugins/plugin.id to avoid
         // different drives issue resulting in absolute path in projectReferences.
         dummyPluginInfo = new PluginInfo(path.join(cordovaProjectPluginsDir, dummyPluginInfo.id));
     });
@@ -221,16 +216,16 @@ describe('windows project handler', function () {
             // project files, which is not needed.
             it('should write to correct project files when conditions are specified', function
() {
 
-                var xpath = 'Content[@Include="' + computeResourcePath(resourceFiles[0])
+ '"][@Condition="\'$(Platform)\'==\'x86\'"]';
+                var xpath = 'Content[@Include="' + resourceFiles[0].target + '"][@Condition="\'$(Platform)\'==\'x86\'"]';
                 validateInstalledProjects('resource-file', resourceFiles[0], xpath, ['all']);
 
-                xpath = 'Content[@Include="' + computeResourcePath(resourceFiles[1]) + '"]';
+                xpath = 'Content[@Include="' + resourceFiles[1].target + '"]';
                 validateInstalledProjects('resource-file', resourceFiles[1], xpath, ['windows',
'phone', 'windows10']);
 
-                xpath = 'Content[@Include="' + computeResourcePath(resourceFiles[2]) + '"]';
+                xpath = 'Content[@Include="' + resourceFiles[2].target + '"]';
                 validateInstalledProjects('resource-file', resourceFiles[2], xpath, ['phone']);
 
-                xpath = 'Content[@Include="' + computeResourcePath(resourceFiles[3]) + '"][@Condition="\'$(Platform)\'==\'x64\'"]';
+                xpath = 'Content[@Include="' + resourceFiles[3].target + '"][@Condition="\'$(Platform)\'==\'x64\'"]';
                 validateInstalledProjects('resource-file', resourceFiles[3], xpath, ['windows8']);
             });
 
@@ -505,19 +500,19 @@ describe('windows project handler', function () {
                     install(resourceFile, dummyPluginInfo, dummyProject);
                 });
                 var path = 'ItemGroup/Content';
-                var incText = computeResourcePath(resourcefiles[0]);
+                var incText = resourcefiles[0].target;
                 var targetConditions = {versions: undefined, deviceTarget: undefined, arch:
'x86'};
                 validateUninstalledProjects('resource-file', resourcefiles[0], path, incText,
targetConditions, ['all']);
 
-                incText = computeResourcePath(resourcefiles[1]);
+                incText = resourcefiles[1].target;
                 targetConditions = {versions: '>=8.1', deviceTarget: undefined, arch:
undefined};
                 validateUninstalledProjects('resource-file', resourcefiles[1], path, incText,
targetConditions, ['windows', 'phone', 'windows10']);
 
-                incText = computeResourcePath(resourcefiles[2]);
+                incText = resourcefiles[2].target;
                 targetConditions = {versions: undefined, deviceTarget: 'phone', arch: undefined};
                 validateUninstalledProjects('resource-file', resourcefiles[2], path, incText,
targetConditions, ['phone']);
 
-                incText = computeResourcePath(resourcefiles[3]);
+                incText = resourcefiles[3].target;
                 targetConditions = {versions: '8.0', deviceTarget: 'windows', arch: 'x64'};
                 validateUninstalledProjects('resource-file', resourcefiles[3], path, incText,
targetConditions, ['windows8']);
             });

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/c71379a8/template/cordova/lib/JsprojManager.js
----------------------------------------------------------------------
diff --git a/template/cordova/lib/JsprojManager.js b/template/cordova/lib/JsprojManager.js
index 2a93fc1..549288c 100644
--- a/template/cordova/lib/JsprojManager.js
+++ b/template/cordova/lib/JsprojManager.js
@@ -121,7 +121,7 @@ jsprojManager.prototype = {
         copyToOutputDirectory.text = 'Always';
         children.push(copyToOutputDirectory);
 
-        var item = createItemGroupElement('ItemGroup/Content', sourcePath, targetConditions,
children);
+        var item = createItemGroupElement('ItemGroup/Content', destPath, targetConditions,
children);
         this._getMatchingProjects(targetConditions).forEach(function (project) {
             project.appendToRoot(item);
         });

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/c71379a8/template/cordova/lib/PluginHandler.js
----------------------------------------------------------------------
diff --git a/template/cordova/lib/PluginHandler.js b/template/cordova/lib/PluginHandler.js
index 0ba69cf..b39dade 100644
--- a/template/cordova/lib/PluginHandler.js
+++ b/template/cordova/lib/PluginHandler.js
@@ -25,13 +25,6 @@ var shell = require('shelljs');
 var events = require('cordova-common').events;
 var CordovaError = require('cordova-common').CordovaError;
 
-// returns relative file path for a file in the plugin's folder that can be referenced
-// from a project file.
-function getPluginFilePath(plugin, pluginFile, targetDir) {
-    var src = path.resolve(plugin.dir, pluginFile);
-    return '$(ProjectDir)' + path.relative(targetDir, src);
-}
-
 var handlers = {
     'source-file': {
         install:function(obj, plugin, project, options) {
@@ -53,18 +46,13 @@ var handlers = {
     },
     'resource-file':{
         install:function(obj, plugin, project, options) {
-            // do not copy, but reference the file in the plugin folder. This allows to
-            // have multiple source files map to the same target and select the appropriate
-            // one based on the current build settings, e.g. architecture.
-            // also, we don't check for existence. This allows to insert build variables
-            // into the source file name, e.g.
-            // <resource-file src="$(Platform)/My.dll" target="My.dll" />
-            var relativeSrcPath = getPluginFilePath(plugin, obj.src, project.projectFolder);
-            project.addResourceFileToProject(relativeSrcPath, obj.target, getTargetConditions(obj));
+            // as per specification resource-file target is specified relative to platform
root
+            copyFile(plugin.dir, obj.src, project.root, obj.target);
+            project.addResourceFileToProject(obj.target, obj.target, getTargetConditions(obj));
         },
         uninstall:function(obj, plugin, project, options) {
-            var relativeSrcPath = getPluginFilePath(plugin, obj.src, project.projectFolder);
-            project.removeResourceFileFromProject(relativeSrcPath, getTargetConditions(obj));
+            removeFile(project.root, obj.target);
+            project.removeResourceFileFromProject(obj.target, getTargetConditions(obj));
         }
     },
     'lib-file': {
@@ -208,7 +196,7 @@ function copyFile (plugin_dir, src, project_dir, dest, link) {
     dest = path.resolve(project_dir, dest);
 
     // check that dest path is located in project directory
-    if (dest.indexOf(project_dir) !== 0)
+    if (dest.indexOf(path.resolve(project_dir)) !== 0)
         throw new CordovaError('Destination "' + dest + '" for source file "' + src + '"
is located outside the project');
 
     shell.mkdir('-p', path.dirname(dest));


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


Mime
View raw message