Repository: cordova-windows
Updated Branches:
  refs/heads/master 57de5e0cf -> 1a65ff45d


CB-11933: Remove capabilities from manifest

Windows has special logic for appxmanifest's capabilities removal, therefore we 
should override this behaviour

 This closes #202


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

Branch: refs/heads/master
Commit: 1a65ff45d24e7d6e33fb16ef556b41896822e685
Parents: 57de5e0
Author: Nikita Matrosov <matrosov.nikit...@gmail.com>
Authored: Mon Oct 17 13:28:09 2016 +0300
Committer: Vladimir Kotikov <v-vlk...@microsoft.com>
Committed: Mon Oct 17 14:17:51 2016 +0300

----------------------------------------------------------------------
 spec/unit/ConfigChanges.spec.js                 | 61 ++++++++++++++++++++
 .../plugin.xml                                  | 12 ++++
 .../www/org.test.plugins.capabilityplugin.js    |  0
 template/cordova/Api.js                         | 10 +++-
 4 files changed, 82 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/1a65ff45/spec/unit/ConfigChanges.spec.js
----------------------------------------------------------------------
diff --git a/spec/unit/ConfigChanges.spec.js b/spec/unit/ConfigChanges.spec.js
index 3733fe8..44ad4cd 100644
--- a/spec/unit/ConfigChanges.spec.js
+++ b/spec/unit/ConfigChanges.spec.js
@@ -19,6 +19,9 @@
 
 var BaseMunger = require('cordova-common').ConfigChanges.PlatformMunger;
 var PlatformMunger = 
require('../../template/cordova/lib/ConfigChanges').PlatformMunger;
+var PluginInfo = require('cordova-common').PluginInfo;
+var Api = require('../../template/cordova/Api');
+var AppxManifest = require('../../template/cordova/lib/AppxManifest');
 
 var os = require('os');
 var path = require('path');
@@ -27,6 +30,12 @@ var shell = require('shelljs');
 var tempDir = path.join(os.tmpdir(), 'windows');
 var WINDOWS_MANIFEST = 'package.windows.appxmanifest';
 var WINDOWS10_MANIFEST = 'package.windows10.appxmanifest';
+var FIXTURES = path.join(__dirname, 'fixtures');
+var DUMMY_PLUGIN = 'org.test.plugins.capabilityplugin';
+
+var dummyPlugin = path.join(FIXTURES, DUMMY_PLUGIN);
+var dummyProjName = 'testProj';
+var windowsProject = path.join(FIXTURES, dummyProjName);
 
 describe('PlatformMunger', function () {
     var munge, munger;
@@ -75,3 +84,55 @@ describe('PlatformMunger', function () {
     });
 });
 
+describe('Capabilities within package.windows.appxmanifest', function() {
+    var testDir;
+
+    beforeEach(function() {
+        testDir = path.join(__dirname, 'testDir');
+        shell.mkdir('-p', testDir);
+        shell.cp('-rf', windowsProject + '/*', testDir);
+    });
+
+    afterEach(function() {
+        shell.rm('-rf', testDir);
+    });
+
+    it('should be removed using overriden PlatformMunger', function(done) {
+        var windowsPlatform = path.join(testDir, 'platforms/windows');
+        var windowsManifest = path.join(windowsPlatform, WINDOWS_MANIFEST);
+        var api = new Api();
+        api.root = windowsPlatform;
+        api.locations.root = windowsPlatform;
+        api.locations.www = path.join(windowsPlatform, 'www');
+        var dummyPluginInfo = new PluginInfo(dummyPlugin);
+
+        var fail = jasmine.createSpy('fail')
+        .andCallFake(function (err) {
+            console.error(err);
+        });
+
+        function getPluginCapabilities() {
+            return dummyPluginInfo.getConfigFiles()[0].xmls;
+        }
+
+        function getManifestCapabilities() {
+            var appxmanifest = AppxManifest.get(windowsManifest, true);
+            return appxmanifest.getCapabilities();
+        }
+        api.addPlugin(dummyPluginInfo)
+        .then(function() {
+            //  There is the one default capability in manifest with 
'internetClient' name
+            
expect(getManifestCapabilities().length).toBe(getPluginCapabilities().length + 
1); 
+            api.removePlugin(dummyPluginInfo);
+        })
+        .then(function() {
+            expect(getManifestCapabilities().length).toBe(1);
+        })
+        .catch(fail)
+        .finally(function() {
+            expect(fail).not.toHaveBeenCalled();
+            done();
+        });
+    });
+});
+

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/1a65ff45/spec/unit/fixtures/org.test.plugins.capabilityplugin/plugin.xml
----------------------------------------------------------------------
diff --git a/spec/unit/fixtures/org.test.plugins.capabilityplugin/plugin.xml 
b/spec/unit/fixtures/org.test.plugins.capabilityplugin/plugin.xml
new file mode 100644
index 0000000..a52d18c
--- /dev/null
+++ b/spec/unit/fixtures/org.test.plugins.capabilityplugin/plugin.xml
@@ -0,0 +1,12 @@
+<?xml version='1.0' encoding='utf-8'?>
+<plugin id="org.test.plugins.capabilityplugin" version="0.0.1" 
xmlns="http://apache.org/cordova/ns/plugins/1.0"; 
xmlns:android="http://schemas.android.com/apk/res/android";>
+    <name>org.test.plugins.capabilityplugin</name>
+    <js-module name="org.test.plugins.capabilityplugin" 
src="www/org.test.plugins.capabilityplugin.js">
+        <clobbers target="cordova.plugins.org.test.plugins.capabilityplugin" />
+    </js-module>
+    <config-file target="package.appxmanifest" parent="/Package/Capabilities" 
device-target="windows">
+        <Capability Name="enterpriseAuthentication" />
+        <Capability Name="privateNetworkClientServer" />
+        <Capability Name="sharedUserCertificates" />
+    </config-file>
+</plugin>

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/1a65ff45/spec/unit/fixtures/org.test.plugins.capabilityplugin/www/org.test.plugins.capabilityplugin.js
----------------------------------------------------------------------
diff --git 
a/spec/unit/fixtures/org.test.plugins.capabilityplugin/www/org.test.plugins.capabilityplugin.js
 
b/spec/unit/fixtures/org.test.plugins.capabilityplugin/www/org.test.plugins.capabilityplugin.js
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/1a65ff45/template/cordova/Api.js
----------------------------------------------------------------------
diff --git a/template/cordova/Api.js b/template/cordova/Api.js
index 70e4797..50a0778 100644
--- a/template/cordova/Api.js
+++ b/template/cordova/Api.js
@@ -22,6 +22,9 @@ var events = require('cordova-common').events;
 var JsprojManager = require('./lib/JsprojManager');
 var PluginManager = require('cordova-common').PluginManager;
 var CordovaLogger = require('cordova-common').CordovaLogger;
+var PlatformMunger = require('./lib/ConfigChanges.js').PlatformMunger;
+var PlatformJson = require('cordova-common').PlatformJson;
+var PluginInfoProvider = require('cordova-common').PluginInfoProvider;
 
 var PLATFORM = 'windows';
 
@@ -233,7 +236,12 @@ Api.prototype.addPlugin = function (plugin, 
installOptions) {
 Api.prototype.removePlugin = function (plugin, uninstallOptions) {
     var self = this;
     var jsProject = JsprojManager.getProject(this.root);
-    return PluginManager.get(this.platform, this.locations, jsProject)
+    var platformJson = PlatformJson.load(this.root, this.platform);
+    var pluginManager = PluginManager.get(this.platform, this.locations, 
jsProject);
+    //  CB-11933 We override this field by windows specific one because 
windows has special logic
+    //  for appxmanifest's capabilities removal (see also 
https://issues.apache.org/jira/browse/CB-11066)
+    pluginManager.munger = new PlatformMunger(this.platform, 
this.locations.root, platformJson, new PluginInfoProvider());
+    return pluginManager
         .removePlugin(plugin, uninstallOptions)
         .then(function () {
             // CB-11657 Add BOM to cordova_plugins, since it is was


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

Reply via email to