You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by an...@apache.org on 2016/07/19 06:25:47 UTC
cordova-windows git commit: CB-11582 Remove duplicate capabilities
when writing the AppxManifest
Repository: cordova-windows
Updated Branches:
refs/heads/master 2c3bf8b76 -> aef95b000
CB-11582 Remove duplicate capabilities when writing the AppxManifest
This closes #186
Project: http://git-wip-us.apache.org/repos/asf/cordova-windows/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-windows/commit/aef95b00
Tree: http://git-wip-us.apache.org/repos/asf/cordova-windows/tree/aef95b00
Diff: http://git-wip-us.apache.org/repos/asf/cordova-windows/diff/aef95b00
Branch: refs/heads/master
Commit: aef95b000764d8df9177ad808b6e45d7a59f4de6
Parents: 2c3bf8b
Author: Robert Schmid <r....@outlook.com>
Authored: Thu Jul 14 14:50:56 2016 -0700
Committer: Vladimir Kotikov <v-...@microsoft.com>
Committed: Tue Jul 19 09:24:30 2016 +0300
----------------------------------------------------------------------
spec/unit/AppxManifest.spec.js | 14 ++++++++++++++
template/cordova/lib/AppxManifest.js | 24 +++++++++++++++++++++++-
2 files changed, 37 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/aef95b00/spec/unit/AppxManifest.spec.js
----------------------------------------------------------------------
diff --git a/spec/unit/AppxManifest.spec.js b/spec/unit/AppxManifest.spec.js
index 691252a..0da7afa 100644
--- a/spec/unit/AppxManifest.spec.js
+++ b/spec/unit/AppxManifest.spec.js
@@ -25,6 +25,7 @@ var Win10AppxManifest = AppxManifest.__get__('Win10AppxManifest');
var refineColor = AppxManifest.__get__('refineColor');
var WINDOWS_MANIFEST = 'template/package.windows.appxmanifest';
+var WINDOWS_10_MANIFEST = 'template/package.windows10.appxmanifest';
var WINDOWS_PHONE_MANIFEST = 'template/package.phone.appxmanifest';
var CSS_COLOR_NAME = 'turquoise';
@@ -169,6 +170,19 @@ describe('AppxManifest', function () {
});
});
+ describe('instance write method', function () {
+ it('should not write duplicate UAP capability declarations', function () {
+ var manifest = AppxManifest.get(WINDOWS_10_MANIFEST);
+ var capabilities = manifest.doc.find('.//Capabilities');
+ capabilities.append(new et.Element('uap:Capability', { 'Name': 'enterpriseAuthentication' }));
+ capabilities.append(new et.Element('uap:Capability', { 'Name': 'enterpriseAuthentication' }));
+
+ var xml = manifest.writeToString();
+
+ expect((xml.match(/enterpriseAuthentication/g) || []).length).toBe(1);
+ });
+ });
+
describe('getVisualElements methods', function () {
it('refineColor should leave CSS color name as is', function () {
expect(refineColor(CSS_COLOR_NAME)).toEqual(CSS_COLOR_NAME);
http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/aef95b00/template/cordova/lib/AppxManifest.js
----------------------------------------------------------------------
diff --git a/template/cordova/lib/AppxManifest.js b/template/cordova/lib/AppxManifest.js
index 68cbf1c..db59cf1 100644
--- a/template/cordova/lib/AppxManifest.js
+++ b/template/cordova/lib/AppxManifest.js
@@ -654,10 +654,15 @@ Win10AppxManifest.prototype.setDependencies = function (dependencies) {
* manifest will be written to file it has been read from.
*/
Win10AppxManifest.prototype.write = function(destPath) {
+ fs.writeFileSync(destPath || this.path, this.writeToString(), 'utf-8');
+};
+
+Win10AppxManifest.prototype.writeToString = function() {
ensureUapPrefixedCapabilities(this.doc.find('.//Capabilities'));
+ ensureUniqueCapabilities(this.doc.find('.//Capabilities'));
// sort Capability elements as per CB-5350 Windows8 build fails due to invalid 'Capabilities' definition
sortCapabilities(this.doc);
- fs.writeFileSync(destPath || this.path, this.doc.write({indent: 4}), 'utf-8');
+ return this.doc.write({indent: 4});
};
/**
@@ -673,4 +678,21 @@ function ensureUapPrefixedCapabilities(capabilities) {
});
}
+/**
+ * Cleans up duplicate capability declarations that were generated during the prepare process
+ * @param capabilities {ElementTree.Element} The appx manifest element for <capabilities>
+ */
+function ensureUniqueCapabilities(capabilities) {
+ var uniqueCapabilities = [];
+ capabilities.getchildren()
+ .forEach(function(el) {
+ var name = el.attrib.Name;
+ if (uniqueCapabilities.indexOf(name) !== -1) {
+ capabilities.remove(el);
+ } else {
+ uniqueCapabilities.push(name);
+ }
+ });
+}
+
module.exports = AppxManifest;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org