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/11/18 18:05:57 UTC

[1/3] cordova-windows git commit: CB-12142: Move windows-specific logic from cordova-common

Repository: cordova-windows
Updated Branches:
  refs/heads/master 541c451d4 -> dacf70ec3


CB-12142: Move windows-specific logic from cordova-common

This logic is associated with demuxing 'package.appxmanifest' into relevant platform-specific appx manifests. Also auto-test was moved and edited according changes


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

Branch: refs/heads/master
Commit: 8753c42d14bda1fb0af552f339dcd78720506d5f
Parents: 541c451
Author: Nikita Matrosov <ma...@gmail.com>
Authored: Wed Nov 16 14:40:39 2016 +0300
Committer: Nikita Matrosov <ma...@gmail.com>
Committed: Thu Nov 17 13:11:47 2016 +0300

----------------------------------------------------------------------
 spec/unit/ConfigChanges.spec.js                 |  79 +++++++++++-
 .../fixtures/org.test.configtest/plugin.xml     |  61 ++++++++++
 template/cordova/Api.js                         |  12 +-
 template/cordova/lib/PluginInfo.js              | 120 +++++++++++++++++++
 4 files changed, 269 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/8753c42d/spec/unit/ConfigChanges.spec.js
----------------------------------------------------------------------
diff --git a/spec/unit/ConfigChanges.spec.js b/spec/unit/ConfigChanges.spec.js
index 48755c7..916ba83 100644
--- a/spec/unit/ConfigChanges.spec.js
+++ b/spec/unit/ConfigChanges.spec.js
@@ -19,23 +19,30 @@
 
 var BaseMunger = require('cordova-common').ConfigChanges.PlatformMunger;
 var PlatformMunger = require('../../template/cordova/lib/ConfigChanges').PlatformMunger;
-var PluginInfo = require('cordova-common').PluginInfo;
+var PluginInfoProvider = require('cordova-common').PluginInfoProvider;
+var PluginInfo = require('../../template/cordova/lib/PluginInfo.js').PluginInfo;
 var Api = require('../../template/cordova/Api');
 var AppxManifest = require('../../template/cordova/lib/AppxManifest');
 
 var os = require('os');
 var path = require('path');
 var shell = require('shelljs');
+var rewire = require('rewire');
 
+var configChanges = require('../../template/cordova/lib/ConfigChanges');
+var pluginInfo = rewire('../../template/cordova/lib/PluginInfo.js');
 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 CONFIG_PLUGIN = 'org.test.configtest';
 
 var dummyPlugin = path.join(FIXTURES, DUMMY_PLUGIN);
+var configplugin = path.join(FIXTURES, CONFIG_PLUGIN);
 var dummyProjName = 'testProj';
 var windowsProject = path.join(FIXTURES, dummyProjName);
+var windows_testapp_jsproj = path.join(FIXTURES, 'testProj/platforms/windows/CordovaApp.Windows.jsproj');
 
 describe('PlatformMunger', function () {
     var munge, munger;
@@ -199,3 +206,73 @@ describe('Capabilities within package.windows.appxmanifest', function() {
     });
 });
 
+describe('generate_plugin_config_munge for windows project', function() {
+    beforeEach(function() {
+        shell.mkdir('-p', tempDir);
+        shell.cp('-rf', windows_testapp_jsproj, tempDir);
+    });
+
+    afterEach(function() {
+        shell.rm('-rf', tempDir);
+    });
+
+    it('should special case config-file elements for windows', function() {
+        var pluginInfoProvider = new PluginInfoProvider();
+        var munger = new configChanges.PlatformMunger('windows', tempDir, 'unused', null, pluginInfoProvider);
+        var munge = munger.generate_plugin_config_munge(new PluginInfo(configplugin), {});
+        var windows81AppxManifest = munge.files['package.windows.appxmanifest'];
+        var winphone81AppxManifest = munge.files['package.phone.appxmanifest'];
+        var windows10AppxManifest = munge.files['package.windows10.appxmanifest'];
+
+        // 1 comes from versions="=8.1.0" + 1 from versions="=8.1.0" device-target="windows"
+        expect(windows81AppxManifest.parents['/Parent/Capabilities'][0].xml).toBe('<Capability Note="should-exist-for-all-appxmanifest-target-files" />');
+        expect(windows81AppxManifest.parents['/Parent/Capabilities'][1].xml).toBe('<Capability Note="should-exist-for-win81-win-and-phone" />');
+        expect(windows81AppxManifest.parents['/Parent/Capabilities'][2].xml).toBe('<Capability Note="should-exist-for-win81-win-only" />');
+        expect(windows81AppxManifest.parents['/Parent/Capabilities'][3].xml).toBe('<Capability Note="should-exist-for-win10-and-win81-win-and-phone" />');
+        expect(windows81AppxManifest.parents['/Parent/Capabilities'].length).toBe(4);
+
+        // 1 comes from versions="=8.1.0" + 1 from versions="=8.1.0" device-target="phone"
+        expect(winphone81AppxManifest.parents['/Parent/Capabilities'][0].xml).toBe('<Capability Note="should-exist-for-all-appxmanifest-target-files" />');
+        expect(winphone81AppxManifest.parents['/Parent/Capabilities'][1].xml).toBe('<Capability Note="should-exist-for-win81-win-and-phone" />');
+        expect(winphone81AppxManifest.parents['/Parent/Capabilities'][2].xml).toBe('<Capability Note="should-exist-for-win81-phone-only" />');
+        expect(winphone81AppxManifest.parents['/Parent/Capabilities'][3].xml).toBe('<Capability Note="should-exist-for-win10-and-win81-win-and-phone" />');
+        expect(winphone81AppxManifest.parents['/Parent/Capabilities'].length).toBe(4);
+
+        expect(windows10AppxManifest.parents['/Parent/Capabilities'][0].xml).toBe('<Capability Note="should-exist-for-all-appxmanifest-target-files" />');
+        expect(windows10AppxManifest.parents['/Parent/Capabilities'][1].xml).toBe('<Capability Note="should-exist-for-win10-and-win81-win-and-phone" />');
+        expect(windows10AppxManifest.parents['/Parent/Capabilities'][2].xml).toBe('<Capability Note="should-exist-in-win10-only" />');
+        expect(windows10AppxManifest.parents['/Parent/Capabilities'].length).toBe(3);
+    });
+
+    it('should not process change w/o target package.appxmanifest', function() {
+        var processChanges = pluginInfo.__get__('processChanges');
+        var testChanges = [
+            {
+                target: 'package.windows.appxmanifest'
+            },
+            {
+                target: 'package.appxmanifest'
+            }
+        ];
+
+        var changes = processChanges(testChanges);
+        expect(changes.length).toBe(4);
+        expect(changes[0].target).toBe(testChanges[0].target);
+    });
+
+    it('should apply changes to all manifests in case of incorrect "deviceTarget" attribute', function() {
+        var processChanges = pluginInfo.__get__('processChanges');
+
+        var testChanges = [{
+            deviceTarget: 'wrong_device_target',
+            target: 'package.appxmanifest'
+        }];
+
+        var changes = processChanges(testChanges);
+        expect(changes.length).toBe(3);
+        expect(changes[0].target).toBe('package.windows.appxmanifest');
+        expect(changes[1].target).toBe('package.phone.appxmanifest');
+        expect(changes[2].target).toBe('package.windows10.appxmanifest');
+    });
+});
+

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/8753c42d/spec/unit/fixtures/org.test.configtest/plugin.xml
----------------------------------------------------------------------
diff --git a/spec/unit/fixtures/org.test.configtest/plugin.xml b/spec/unit/fixtures/org.test.configtest/plugin.xml
new file mode 100644
index 0000000..d140297
--- /dev/null
+++ b/spec/unit/fixtures/org.test.configtest/plugin.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright 2013 Anis Kadri
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+
+<plugin xmlns="http://cordova.apache.org/ns/plugins/1.0"
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    id="org.test.configtest"
+    version="3.0.0">
+
+    <name>Does Code Fil Write Even Work? Hopefully the Tests Will Tell Us</name>
+
+    <!-- android -->
+    <platform name="android">
+        <config-file target="res/xml/config.xml" parent="/widget">
+            <poop/>
+        </config-file>
+        <config-file target="res/xml/config.xml" parent="/widget">
+            <poop/>
+        </config-file>
+    </platform>
+
+    <platform name="windows">
+        <config-file target="package.appxmanifest" parent="/Parent/Capabilities">
+            <Capability Note="should-exist-for-all-appxmanifest-target-files" />
+        </config-file>
+        <config-file target="package.appxmanifest" parent="/Parent/Capabilities" versions="=8.1.0">
+            <Capability Note="should-exist-for-win81-win-and-phone" />
+        </config-file>
+        <config-file target="package.appxmanifest" parent="/Parent/Capabilities" versions="=8.1.0" device-target="windows">
+            <Capability Note="should-exist-for-win81-win-only" />
+        </config-file>
+        <config-file target="package.appxmanifest" parent="/Parent/Capabilities" versions="=8.1.0" device-target="phone">
+            <Capability Note="should-exist-for-win81-phone-only" />
+        </config-file>
+        <config-file target="package.appxmanifest" parent="/Parent/Capabilities" versions="=8.1.0" device-target="all">
+            <Capability Note="should-exist-for-win81-win-and-phone" />
+        </config-file>
+        <config-file target="package.appxmanifest" parent="/Parent/Capabilities" versions="<=10.0.0" device-target="all">
+            <Capability Note="should-exist-for-win10-and-win81-win-and-phone" />
+        </config-file>
+        <config-file target="package.appxmanifest" parent="/Parent/Capabilities" versions=">=10.0.0">
+            <Capability Note="should-exist-in-win10-only" />
+        </config-file>
+    </platform>
+</plugin>

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/8753c42d/template/cordova/Api.js
----------------------------------------------------------------------
diff --git a/template/cordova/Api.js b/template/cordova/Api.js
index 7637582..125e3c5 100644
--- a/template/cordova/Api.js
+++ b/template/cordova/Api.js
@@ -24,6 +24,7 @@ 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 PluginInfo = require('./lib/PluginInfo').PluginInfo;
 var PluginInfoProvider = require('cordova-common').PluginInfoProvider;
 
 var PLATFORM = 'windows';
@@ -200,6 +201,9 @@ Api.prototype.addPlugin = function (plugin, installOptions) {
 
     var self = this;
 
+    // We need to use custom PluginInfo to trigger windows-specific processing
+    // of changes in .appxmanifest files. See PluginInfo.js for details
+    var pluginInfo = new PluginInfo(plugin.dir);
     var jsProject = JsprojManager.getProject(this.root);
     installOptions = installOptions || {};
     installOptions.variables = installOptions.variables || {};
@@ -212,7 +216,7 @@ Api.prototype.addPlugin = function (plugin, installOptions) {
     var pluginManager = PluginManager.get(this.platform, this.locations, jsProject);
     pluginManager.munger = new PlatformMunger(this.platform, this.locations.root, platformJson, new PluginInfoProvider());
     return pluginManager
-        .addPlugin(plugin, installOptions)
+        .addPlugin(pluginInfo, installOptions)
         .then(function () {
             // CB-11657 Add BOM to www files here because files added by plugin
             // probably don't have it. Prepare would add BOM but it might not be called
@@ -238,6 +242,10 @@ Api.prototype.addPlugin = function (plugin, installOptions) {
  */
 Api.prototype.removePlugin = function (plugin, uninstallOptions) {
     var self = this;
+
+    // We need to use custom PluginInfo to trigger windows-specific processing
+    // of changes in .appxmanifest files. See PluginInfo.js for details
+    var pluginInfo = new PluginInfo(plugin.dir);
     var jsProject = JsprojManager.getProject(this.root);
     var platformJson = PlatformJson.load(this.root, this.platform);
     var pluginManager = PluginManager.get(this.platform, this.locations, jsProject);
@@ -245,7 +253,7 @@ Api.prototype.removePlugin = function (plugin, uninstallOptions) {
     //  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)
+        .removePlugin(pluginInfo, uninstallOptions)
         .then(function () {
             // CB-11657 Add BOM to cordova_plugins, since it is was
             // regenerated after plugin uninstallation and does not have BOM

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/8753c42d/template/cordova/lib/PluginInfo.js
----------------------------------------------------------------------
diff --git a/template/cordova/lib/PluginInfo.js b/template/cordova/lib/PluginInfo.js
new file mode 100644
index 0000000..a45ee07
--- /dev/null
+++ b/template/cordova/lib/PluginInfo.js
@@ -0,0 +1,120 @@
+var semver = require('semver');
+var CommonPluginInfo = require('cordova-common').PluginInfo;
+
+var MANIFESTS = {
+    'windows': {
+        '8.1.0': 'package.windows.appxmanifest',
+        '10.0.0': 'package.windows10.appxmanifest'
+    },
+    'phone': {
+        '8.1.0': 'package.phone.appxmanifest',
+        '10.0.0': 'package.windows10.appxmanifest'
+    },
+    'all': {
+        '8.1.0': ['package.windows.appxmanifest', 'package.phone.appxmanifest'],
+        '10.0.0': 'package.windows10.appxmanifest'
+    }
+};
+
+var SUBSTS = ['package.phone.appxmanifest', 'package.windows.appxmanifest', 'package.windows10.appxmanifest'];
+var TARGETS = ['windows', 'phone', 'all'];
+
+function processChanges(changes) {
+    var hasManifestChanges  = changes.some(function(change) {
+        return change.target === 'package.appxmanifest';
+    });
+
+    if (!hasManifestChanges) {
+        return changes;
+    }
+
+    // Demux 'package.appxmanifest' into relevant platform-specific appx manifests.
+    // Only spend the cycles if there are version-specific plugin settings
+    var oldChanges = changes;
+    changes = [];
+
+    oldChanges.forEach(function(change) {
+        // Only support semver/device-target demux for package.appxmanifest
+        // Pass through in case something downstream wants to use it
+        if (change.target !== 'package.appxmanifest') {
+            changes.push(change);
+            return;
+        }
+
+        var manifestsForChange = getManifestsForChange(change);
+        changes = changes.concat(demuxChangeWithSubsts(change, manifestsForChange));
+    });
+
+    return changes;
+}
+
+function demuxChangeWithSubsts(change, manifestFiles) {
+    return manifestFiles.map(function(file) {
+         return createReplacement(file, change);
+    });
+}
+
+function getManifestsForChange(change) {
+    var hasTarget = (typeof change.deviceTarget !== 'undefined');
+    var hasVersion = (typeof change.versions !== 'undefined');
+
+    var targetDeviceSet = hasTarget ? change.deviceTarget : 'all';
+
+    if (TARGETS.indexOf(targetDeviceSet) === -1) {
+        // target-device couldn't be resolved, fix it up here to a valid value
+        targetDeviceSet = 'all';
+    }
+
+    // No semver/device-target for this config-file, pass it through
+    if (!(hasTarget || hasVersion)) {
+        return SUBSTS;
+    }
+
+    var knownWindowsVersionsForTargetDeviceSet = Object.keys(MANIFESTS[targetDeviceSet]);
+    return knownWindowsVersionsForTargetDeviceSet.reduce(function(manifestFiles, winver) {
+        if (hasVersion && !semver.satisfies(winver, change.versions)) {
+            return manifestFiles;
+        }
+        return manifestFiles.concat(MANIFESTS[targetDeviceSet][winver]);
+    }, []);
+}
+
+// This is a local function that creates the new replacement representing the
+// mutation.  Used to save code further down.
+function createReplacement(manifestFile, originalChange) {
+    var replacement = {
+        target:         manifestFile,
+        parent:         originalChange.parent,
+        after:          originalChange.after,
+        xmls:           originalChange.xmls,
+        versions:       originalChange.versions,
+        deviceTarget:   originalChange.deviceTarget
+    };
+    return replacement;
+}
+
+
+/*
+A class for holidng the information currently stored in plugin.xml
+It's inherited from cordova-common's PluginInfo class
+In addition it overrides getConfigFiles method to use windows-specific logic
+ */
+function PluginInfo(dirname) {
+    //  We're not using `util.inherit' because original PluginInfo defines
+    //  its' methods inside of constructor
+    CommonPluginInfo.apply(this, arguments);
+    var parentGetConfigFiles = this.getConfigFiles;
+    var parentGetEditConfigs = this.getEditConfigs;
+
+    this.getEditConfigs = function(platform) {
+        var editConfigs = parentGetEditConfigs(platform);
+        return processChanges(editConfigs);
+    };
+
+    this.getConfigFiles = function(platform) {
+        var configFiles = parentGetConfigFiles(platform);
+        return processChanges(configFiles);
+    };
+}
+
+exports.PluginInfo = PluginInfo;


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


[2/3] cordova-windows git commit: Fix pattern for extracting capabilities names

Posted by an...@apache.org.
Fix pattern for extracting capabilities names


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

Branch: refs/heads/master
Commit: 00b6fa74f9279382febe5ad85c46723993a29223
Parents: 8753c42
Author: Nikita Matrosov <ma...@gmail.com>
Authored: Thu Nov 17 16:07:31 2016 +0300
Committer: Nikita Matrosov <ma...@gmail.com>
Committed: Thu Nov 17 16:07:31 2016 +0300

----------------------------------------------------------------------
 template/cordova/lib/ConfigChanges.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/00b6fa74/template/cordova/lib/ConfigChanges.js
----------------------------------------------------------------------
diff --git a/template/cordova/lib/ConfigChanges.js b/template/cordova/lib/ConfigChanges.js
index 1bd620f..ab444c9 100644
--- a/template/cordova/lib/ConfigChanges.js
+++ b/template/cordova/lib/ConfigChanges.js
@@ -82,7 +82,7 @@ function cloneObject(obj) {
  * @return {String} name of capability
  */
 function getCapabilityName(capability) {
-    var reg = /Name="(\w+)"/i;
+    var reg = /Name\s*=\s*"(.*?)"/;
     return capability.xml.match(reg)[1];
 }
 


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


[3/3] cordova-windows git commit: Do not ignore already prefixed capabilities at plugin add/rm

Posted by an...@apache.org.
Do not ignore already prefixed capabilities at plugin add/rm

 This closes #207


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

Branch: refs/heads/master
Commit: dacf70ec33c8a56a063364d5b7447e1fa73da3d8
Parents: 00b6fa7
Author: Nikita Matrosov <ma...@gmail.com>
Authored: Thu Nov 17 16:12:54 2016 +0300
Committer: Vladimir Kotikov <v-...@microsoft.com>
Committed: Fri Nov 18 21:05:42 2016 +0300

----------------------------------------------------------------------
 spec/unit/ConfigChanges.spec.js       | 1 +
 template/cordova/lib/ConfigChanges.js | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/dacf70ec/spec/unit/ConfigChanges.spec.js
----------------------------------------------------------------------
diff --git a/spec/unit/ConfigChanges.spec.js b/spec/unit/ConfigChanges.spec.js
index 916ba83..5f3b990 100644
--- a/spec/unit/ConfigChanges.spec.js
+++ b/spec/unit/ConfigChanges.spec.js
@@ -81,6 +81,7 @@ describe('PlatformMunger', function () {
             ]}};
 
             var capabilitiesMunge = { parents: { '/Package/Capabilities': [
+                { before: undefined, count: 1, xml: '<uap:Capability Name=\"privateNetworkClientServer\">'},
                 { before: undefined, count: 1, xml: '<uap:Capability Name=\"enterpriseAuthentication\">'}
             ]}};
             munger.apply_file_munge(WINDOWS10_MANIFEST, baseMunge, /*remove=*/true);

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/dacf70ec/template/cordova/lib/ConfigChanges.js
----------------------------------------------------------------------
diff --git a/template/cordova/lib/ConfigChanges.js b/template/cordova/lib/ConfigChanges.js
index ab444c9..c07a77a 100644
--- a/template/cordova/lib/ConfigChanges.js
+++ b/template/cordova/lib/ConfigChanges.js
@@ -136,7 +136,7 @@ function compareCapabilities(firstCap, secondCap) {
 function generateUapCapabilities(capabilities) {
 
     function hasCapabilityChange(change) {
-        return /^\s*<(Device)?Capability\s/.test(change.xml);
+        return /^\s*<(\w+:)?(Device)?Capability\s/.test(change.xml);
     }
 
     function createPrefixedCapabilityChange(change) {
@@ -144,8 +144,10 @@ function generateUapCapabilities(capabilities) {
             return change;
         }
 
+        //  If capability is already prefixed, avoid adding another prefix
+        var replaceXML = change.xml.indexOf('uap:') > 0 ? change.xml : change.xml.replace(/Capability/, 'uap:Capability');
         return {
-            xml: change.xml.replace(/Capability/, 'uap:Capability'),
+            xml: replaceXML,
             count: change.count,
             before: change.before
         };


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