cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an-s...@apache.org
Subject [1/7] cordova-windows git commit: CB-11582 Remove duplicate capabilities when writing the AppxManifest
Date Mon, 25 Jul 2016 19:04:31 GMT
Repository: cordova-windows
Updated Branches:
  refs/heads/4.4.x ac4cb8735 -> f8479e5da


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/4a433498
Tree: http://git-wip-us.apache.org/repos/asf/cordova-windows/tree/4a433498
Diff: http://git-wip-us.apache.org/repos/asf/cordova-windows/diff/4a433498

Branch: refs/heads/4.4.x
Commit: 4a4334982e6ad89711c289291edbf22ad909678e
Parents: ac4cb87
Author: Robert Schmid <r.schmid@outlook.com>
Authored: Thu Jul 14 14:50:56 2016 -0700
Committer: Vladimir Kotikov <v-vlkoti@microsoft.com>
Committed: Mon Jul 25 11:59:19 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/4a433498/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/4a433498/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


Mime
View raw message