Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8765F195E5 for ; Tue, 29 Mar 2016 06:33:06 +0000 (UTC) Received: (qmail 4884 invoked by uid 500); 29 Mar 2016 06:33:06 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 4855 invoked by uid 500); 29 Mar 2016 06:33:06 -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 4839 invoked by uid 99); 29 Mar 2016 06:33:06 -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; Tue, 29 Mar 2016 06:33:06 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D9457DFE04; Tue, 29 Mar 2016 06:33:05 +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 Message-Id: <8e57c63554454ff595ca870e50696232@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: cordova-windows git commit: CB-10845 Invalidate manifest cache in prepare Date: Tue, 29 Mar 2016 06:33:05 +0000 (UTC) Repository: cordova-windows Updated Branches: refs/heads/master b796bd75c -> a4c673e30 CB-10845 Invalidate manifest cache in prepare This closes #164 Project: http://git-wip-us.apache.org/repos/asf/cordova-windows/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-windows/commit/a4c673e3 Tree: http://git-wip-us.apache.org/repos/asf/cordova-windows/tree/a4c673e3 Diff: http://git-wip-us.apache.org/repos/asf/cordova-windows/diff/a4c673e3 Branch: refs/heads/master Commit: a4c673e3028f8b2cb28e2a9cc395ebb9620c2fce Parents: b796bd7 Author: Vladimir Kotikov Authored: Thu Mar 24 16:04:13 2016 +0300 Committer: Vladimir Kotikov Committed: Tue Mar 29 09:29:14 2016 +0300 ---------------------------------------------------------------------- spec/unit/AppxManifest.spec.js | 36 +++++++++++++++++++++++++++++++ template/cordova/lib/AppxManifest.js | 19 ++++++++++++++++ template/cordova/lib/prepare.js | 5 +++++ 3 files changed, 60 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/a4c673e3/spec/unit/AppxManifest.spec.js ---------------------------------------------------------------------- diff --git a/spec/unit/AppxManifest.spec.js b/spec/unit/AppxManifest.spec.js index 48fb514..691252a 100644 --- a/spec/unit/AppxManifest.spec.js +++ b/spec/unit/AppxManifest.spec.js @@ -65,6 +65,42 @@ describe('AppxManifest', function () { }); }); + describe('purgeCache method', function () { + beforeEach(function () { + AppxManifest.__set__('manifestCache', { a: 'foo/a', b: 'foo/b', c: 'foo/c' }); + }); + + it('should remove all entries when no parameter is specified', function () { + AppxManifest.purgeCache(); + var cache = AppxManifest.__get__('manifestCache'); + expect(Object.keys(cache).length).toBe(0); + }); + + it('should remove an entry when parameter is a string key', function () { + AppxManifest.purgeCache('a'); + var cache = AppxManifest.__get__('manifestCache'); + expect(Object.keys(cache).length).toBe(2); + expect(cache.a).not.toBeDefined(); + }); + + it('should remove multiple entries when parameter is an array of keys', function () { + AppxManifest.purgeCache(['a', 'b']); + var cache = AppxManifest.__get__('manifestCache'); + expect(Object.keys(cache).length).toBe(1); + expect(cache.a).not.toBeDefined(); + expect(cache.b).not.toBeDefined(); + }); + + it('should not remove anything if there is no such key', function () { + AppxManifest.purgeCache(['bar']); + var cache = AppxManifest.__get__('manifestCache'); + expect(Object.keys(cache).length).toBe(3); + expect(cache.a).toBeDefined(); + expect(cache.b).toBeDefined(); + expect(cache.c).toBeDefined(); + }); + }); + describe('static get() method', function () { it('should return an AppxManifest instance', function () { http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/a4c673e3/template/cordova/lib/AppxManifest.js ---------------------------------------------------------------------- diff --git a/template/cordova/lib/AppxManifest.js b/template/cordova/lib/AppxManifest.js index 465f698..5688ce1 100644 --- a/template/cordova/lib/AppxManifest.js +++ b/template/cordova/lib/AppxManifest.js @@ -112,6 +112,25 @@ AppxManifest.get = function (fileName, ignoreCache) { return result; }; +/** + * Removes manifests from cache to prevent using stale entries + * + * @param {String|String[]} [cacheKeys] The keys to delete from cache. If not + * specified, the whole cache will be purged + */ +AppxManifest.purgeCache = function (cacheKeys) { + if (!cacheKeys) { + // if no arguments passed, remove all entries + manifestCache = {}; + return; + } + + var keys = Array.isArray(cacheKeys) ? cacheKeys : [cacheKeys]; + keys.forEach(function (key) { + delete manifestCache[key]; + }); +}; + AppxManifest.prototype.getPhoneIdentity = function () { var phoneIdentity = this.doc.getroot().find('./mp:PhoneIdentity'); if (!phoneIdentity) http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/a4c673e3/template/cordova/lib/prepare.js ---------------------------------------------------------------------- diff --git a/template/cordova/lib/prepare.js b/template/cordova/lib/prepare.js index ca90fab..e8e04fc 100644 --- a/template/cordova/lib/prepare.js +++ b/template/cordova/lib/prepare.js @@ -420,6 +420,11 @@ module.exports.prepare = function (cordovaProject) { this._config = updateConfigFilesFrom(cordovaProject.projectConfig, this._munger, this.locations); + // CB-10845 avoid using cached appxmanifests since they could be + // previously modififed outside of AppxManifest class + // TODO: invalidate only entries that were affected by config munge + AppxManifest.purgeCache(); + // Update own www dir with project's www assets and plugins' assets and js-files return Q.when(updateWwwFrom(cordovaProject, this.locations)) .then(function () { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org For additional commands, e-mail: commits-help@cordova.apache.org