Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 60583200B61 for ; Mon, 25 Jul 2016 21:04:33 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 5F178160A8F; Mon, 25 Jul 2016 19:04:33 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id AE438160A91 for ; Mon, 25 Jul 2016 21:04:32 +0200 (CEST) Received: (qmail 50362 invoked by uid 500); 25 Jul 2016 19:04:31 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 50146 invoked by uid 99); 25 Jul 2016 19:04:31 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Jul 2016 19:04:31 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 8B0B3E00A7; Mon, 25 Jul 2016 19:04:31 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: an-selm@apache.org To: commits@cordova.apache.org Date: Mon, 25 Jul 2016 19:04:31 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/7] cordova-windows git commit: CB-11582 Remove duplicate capabilities when writing the AppxManifest archived-at: Mon, 25 Jul 2016 19:04:33 -0000 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 Authored: Thu Jul 14 14:50:56 2016 -0700 Committer: Vladimir Kotikov 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 + */ +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