Repository: cordova-windows
Updated Branches:
  refs/heads/master 92a298a31 -> 1410f3c3d


CB-10326 Don't copy `resource-file` files at plugin install time

Instead, reference the file in the plugin directory. This allows to have 
multiple
source files map to the same destination file inside the build directory and
choose the appropriate file based on the build configuration, e.g. architecture.

Github close #139


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

Branch: refs/heads/master
Commit: 1410f3c3d97425369ea32ec6c05c72ac02b39b75
Parents: 92a298a
Author: Marco Biasini <[email protected]>
Authored: Wed Feb 10 09:11:55 2016 +0100
Committer: sgrebnov <[email protected]>
Committed: Sat Feb 13 12:32:12 2016 +0300

----------------------------------------------------------------------
 template/cordova/lib/JsprojManager.js |  9 ++++-----
 template/cordova/lib/PluginHandler.js | 22 +++++++++++++++++-----
 2 files changed, 21 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/1410f3c3/template/cordova/lib/JsprojManager.js
----------------------------------------------------------------------
diff --git a/template/cordova/lib/JsprojManager.js 
b/template/cordova/lib/JsprojManager.js
index 941e4f8..d92b629 100644
--- a/template/cordova/lib/JsprojManager.js
+++ b/template/cordova/lib/JsprojManager.js
@@ -108,19 +108,19 @@ jsprojManager.prototype = {
         });
     },
 
-    addResourceFileToProject: function (relPath, targetConditions) {
-        events.emit('verbose', 'jsprojManager.addResourceFile(relPath: ' + 
relPath + ', targetConditions: ' + JSON.stringify(targetConditions) + ')');
+    addResourceFileToProject: function (sourcePath, destPath, 
targetConditions) {
+        events.emit('verbose', 'jsprojManager.addResourceFile(sourcePath: ' + 
sourcePath + ', destPath: ' + destPath + ', targetConditions: ' + 
JSON.stringify(targetConditions) + ')');
 
         // add hint path with full path
         var link = new et.Element('Link');
-        link.text = relPath;
+        link.text = destPath;
         var children = [link];
 
         var copyToOutputDirectory = new et.Element('CopyToOutputDirectory');
         copyToOutputDirectory.text = 'Always';
         children.push(copyToOutputDirectory);
 
-        var item = createItemGroupElement('ItemGroup/Content', relPath, 
targetConditions, children);
+        var item = createItemGroupElement('ItemGroup/Content', sourcePath, 
targetConditions, children);
         this._getMatchingProjects(targetConditions).forEach(function (project) 
{
             project.appendToRoot(item);
         });
@@ -128,7 +128,6 @@ jsprojManager.prototype = {
 
     removeResourceFileFromProject: function (relPath, targetConditions) {
         events.emit('verbose', 'jsprojManager.removeResourceFile(relPath: ' + 
relPath + ', targetConditions: ' + JSON.stringify(targetConditions) + ')');
-
         this._getMatchingProjects(targetConditions).forEach(function (project) 
{
             project.removeItemGroupElement('ItemGroup/Content', relPath, 
targetConditions);
         });

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/1410f3c3/template/cordova/lib/PluginHandler.js
----------------------------------------------------------------------
diff --git a/template/cordova/lib/PluginHandler.js 
b/template/cordova/lib/PluginHandler.js
index 98ea02a..27726ea 100644
--- a/template/cordova/lib/PluginHandler.js
+++ b/template/cordova/lib/PluginHandler.js
@@ -25,6 +25,13 @@ 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) {
@@ -42,13 +49,18 @@ var handlers = {
     },
     'resource-file':{
         install:function(obj, plugin, project, options) {
-            // 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, 
getTargetConditions(obj));
+            // 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));
         },
         uninstall:function(obj, plugin, project, options) {
-            removeFile(project.root, obj.target);
-            project.removeResourceFileFromProject(obj.target, 
getTargetConditions(obj));
+            var relativeSrcPath = getPluginFilePath(plugin, obj.src, 
project.projectFolder);
+            project.removeResourceFileFromProject(relativeSrcPath, 
getTargetConditions(obj));
         }
     },
     'lib-file': {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to