Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-8123

Enable version, device, and chip arch specific library / dll / winmd references in plugins for the Windows platform

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: cordova-windows
    • Labels:
      None

      Description

      Because Cordova's windows platform can target multiple target platforms, projects and frameworks referenced by the plugin may need to target only a subset of those platforms. To enable this, support the following attributes on the <lib-file> and <framework> elements:

      1. device - indicates the reference is specific to a target device. Supported values are "phone", "windows" or "all" (default is "all").
      2. versions - specify platform versions the reference supports (node semantic version ranges supported). Default is to support all versions.
      3. arch - indicates the reference is specific to a particular chip architecture (x86 or x64).

      The "arch" attribute should result in a Condition="'$(Platform)'=='XXX" attribute on the reference. The other attributes will impact which generated jsproj files the reference is actually added to.

        Issue Links

          Activity

          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user TimBarham closed the pull request at:

          https://github.com/apache/cordova-lib/pull/164

          Show
          githubbot ASF GitHub Bot added a comment - Github user TimBarham closed the pull request at: https://github.com/apache/cordova-lib/pull/164
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user TimBarham commented on the pull request:

          https://github.com/apache/cordova-docs/pull/263#issuecomment-74470571

          Thanks Sergey!

          Show
          githubbot ASF GitHub Bot added a comment - Github user TimBarham commented on the pull request: https://github.com/apache/cordova-docs/pull/263#issuecomment-74470571 Thanks Sergey!
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user sgrebnov commented on the pull request:

          https://github.com/apache/cordova-docs/pull/263#issuecomment-74470463

          reviewed and merged docs update

          Show
          githubbot ASF GitHub Bot added a comment - Github user sgrebnov commented on the pull request: https://github.com/apache/cordova-docs/pull/263#issuecomment-74470463 reviewed and merged docs update
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user asfgit closed the pull request at:

          https://github.com/apache/cordova-docs/pull/263

          Show
          githubbot ASF GitHub Bot added a comment - Github user asfgit closed the pull request at: https://github.com/apache/cordova-docs/pull/263
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit fa3fc7a44ae56b1640c54e62d69f6a67a553794b in cordova-docs's branch refs/heads/master from Tim Barham
          [ https://git-wip-us.apache.org/repos/asf?p=cordova-docs.git;h=fa3fc7a ]

          CB-8123 Plugin references can target specific windows platforms.

          Adds documentation for the new "target", "versions" and "arch" attributes on <lib-file> and <framework> elements in the windows platform of plugin.xml.

          github close #263

          Show
          jira-bot ASF subversion and git services added a comment - Commit fa3fc7a44ae56b1640c54e62d69f6a67a553794b in cordova-docs's branch refs/heads/master from Tim Barham [ https://git-wip-us.apache.org/repos/asf?p=cordova-docs.git;h=fa3fc7a ] CB-8123 Plugin references can target specific windows platforms. Adds documentation for the new "target", "versions" and "arch" attributes on <lib-file> and <framework> elements in the windows platform of plugin.xml. github close #263
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user TimBarham commented on the pull request:

          https://github.com/apache/cordova-docs/pull/263#issuecomment-74453943

          The code changes that this PR documents have been merged. Could someone merge these doc changes? Thanks!

          Show
          githubbot ASF GitHub Bot added a comment - Github user TimBarham commented on the pull request: https://github.com/apache/cordova-docs/pull/263#issuecomment-74453943 The code changes that this PR documents have been merged. Could someone merge these doc changes? Thanks!
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 37567dab758874b56731e211d32b855e28116d99 in cordova-lib's branch refs/heads/CB-8416 from Jesse MacFadyen
          [ https://git-wip-us.apache.org/repos/asf?p=cordova-lib.git;h=37567da ]

          Merge branch 'CB-8123-final' of https://github.com/MSOpenTech/cordova-lib

          Show
          jira-bot ASF subversion and git services added a comment - Commit 37567dab758874b56731e211d32b855e28116d99 in cordova-lib's branch refs/heads/ CB-8416 from Jesse MacFadyen [ https://git-wip-us.apache.org/repos/asf?p=cordova-lib.git;h=37567da ] Merge branch ' CB-8123 -final' of https://github.com/MSOpenTech/cordova-lib
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 98d17dd7976af2cdd3b7bfa9ce0612728dd5e6d7 in cordova-lib's branch refs/heads/CB-8416 from Tim Barham
          [ https://git-wip-us.apache.org/repos/asf?p=cordova-lib.git;h=98d17dd ]

          CB-8123 Fix JSHINT issue.

          Show
          jira-bot ASF subversion and git services added a comment - Commit 98d17dd7976af2cdd3b7bfa9ce0612728dd5e6d7 in cordova-lib's branch refs/heads/ CB-8416 from Tim Barham [ https://git-wip-us.apache.org/repos/asf?p=cordova-lib.git;h=98d17dd ] CB-8123 Fix JSHINT issue.
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit d98343e34bb70d2262ef212726947e9c511a1808 in cordova-lib's branch refs/heads/CB-8416 from Tim Barham
          [ https://git-wip-us.apache.org/repos/asf?p=cordova-lib.git;h=d98343e ]

          Merge branch 'master' into CB-8123-temp

          Conflicts:
          cordova-lib/spec-plugman/platforms/windows8.spec.js

          Show
          jira-bot ASF subversion and git services added a comment - Commit d98343e34bb70d2262ef212726947e9c511a1808 in cordova-lib's branch refs/heads/ CB-8416 from Tim Barham [ https://git-wip-us.apache.org/repos/asf?p=cordova-lib.git;h=d98343e ] Merge branch 'master' into CB-8123 -temp Conflicts: cordova-lib/spec-plugman/platforms/windows8.spec.js
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user stefangordon commented on the pull request:

          https://github.com/apache/cordova-lib/pull/164#issuecomment-74116684

          Great stuff! Any pointers on how users can easily install this via NPM now? I've only had success manually cloning the lib and cli repos and copying correct binaries.

          Show
          githubbot ASF GitHub Bot added a comment - Github user stefangordon commented on the pull request: https://github.com/apache/cordova-lib/pull/164#issuecomment-74116684 Great stuff! Any pointers on how users can easily install this via NPM now? I've only had success manually cloning the lib and cli repos and copying correct binaries.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user TimBarham commented on the pull request:

          https://github.com/apache/cordova-lib/pull/164#issuecomment-73999167

          Thanks Jesse!

          Show
          githubbot ASF GitHub Bot added a comment - Github user TimBarham commented on the pull request: https://github.com/apache/cordova-lib/pull/164#issuecomment-73999167 Thanks Jesse!
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user purplecabbage commented on the pull request:

          https://github.com/apache/cordova-lib/pull/164#issuecomment-73998473

          Thanks Tim! This is now merged, the mirror is just slow to update. This should close in a few minutes.

          Show
          githubbot ASF GitHub Bot added a comment - Github user purplecabbage commented on the pull request: https://github.com/apache/cordova-lib/pull/164#issuecomment-73998473 Thanks Tim! This is now merged, the mirror is just slow to update. This should close in a few minutes.
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 37567dab758874b56731e211d32b855e28116d99 in cordova-lib's branch refs/heads/master from Jesse MacFadyen
          [ https://git-wip-us.apache.org/repos/asf?p=cordova-lib.git;h=37567da ]

          Merge branch 'CB-8123-final' of https://github.com/MSOpenTech/cordova-lib

          Show
          jira-bot ASF subversion and git services added a comment - Commit 37567dab758874b56731e211d32b855e28116d99 in cordova-lib's branch refs/heads/master from Jesse MacFadyen [ https://git-wip-us.apache.org/repos/asf?p=cordova-lib.git;h=37567da ] Merge branch ' CB-8123 -final' of https://github.com/MSOpenTech/cordova-lib
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 98d17dd7976af2cdd3b7bfa9ce0612728dd5e6d7 in cordova-lib's branch refs/heads/master from Tim Barham
          [ https://git-wip-us.apache.org/repos/asf?p=cordova-lib.git;h=98d17dd ]

          CB-8123 Fix JSHINT issue.

          Show
          jira-bot ASF subversion and git services added a comment - Commit 98d17dd7976af2cdd3b7bfa9ce0612728dd5e6d7 in cordova-lib's branch refs/heads/master from Tim Barham [ https://git-wip-us.apache.org/repos/asf?p=cordova-lib.git;h=98d17dd ] CB-8123 Fix JSHINT issue.
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit d98343e34bb70d2262ef212726947e9c511a1808 in cordova-lib's branch refs/heads/master from Tim Barham
          [ https://git-wip-us.apache.org/repos/asf?p=cordova-lib.git;h=d98343e ]

          Merge branch 'master' into CB-8123-temp

          Conflicts:
          cordova-lib/spec-plugman/platforms/windows8.spec.js

          Show
          jira-bot ASF subversion and git services added a comment - Commit d98343e34bb70d2262ef212726947e9c511a1808 in cordova-lib's branch refs/heads/master from Tim Barham [ https://git-wip-us.apache.org/repos/asf?p=cordova-lib.git;h=d98343e ] Merge branch 'master' into CB-8123 -temp Conflicts: cordova-lib/spec-plugman/platforms/windows8.spec.js
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit f1c5d8fb409233f775a2fff4aea449670acce59a in cordova-lib's branch refs/heads/master from Tim Barham
          [ https://git-wip-us.apache.org/repos/asf?p=cordova-lib.git;h=f1c5d8f ]

          CB-8123 Fix path handling so tests work on any platform.

          Show
          jira-bot ASF subversion and git services added a comment - Commit f1c5d8fb409233f775a2fff4aea449670acce59a in cordova-lib's branch refs/heads/master from Tim Barham [ https://git-wip-us.apache.org/repos/asf?p=cordova-lib.git;h=f1c5d8f ] CB-8123 Fix path handling so tests work on any platform.
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 22a214f217014b8c2df0348025d734cdf03580a7 in cordova-lib's branch refs/heads/master from Tim Barham
          [ https://git-wip-us.apache.org/repos/asf?p=cordova-lib.git;h=22a214f ]

          CB-8123 Rename further windows platform related files.

          Renames `windows8.spec.js` to `windows.spec.js`.

          Show
          jira-bot ASF subversion and git services added a comment - Commit 22a214f217014b8c2df0348025d734cdf03580a7 in cordova-lib's branch refs/heads/master from Tim Barham [ https://git-wip-us.apache.org/repos/asf?p=cordova-lib.git;h=22a214f ] CB-8123 Rename further windows platform related files. Renames `windows8.spec.js` to `windows.spec.js`.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user sgrebnov commented on the pull request:

          https://github.com/apache/cordova-lib/pull/164#issuecomment-73859774

          Reviewed and tested, LGTM :+1:

          Show
          githubbot ASF GitHub Bot added a comment - Github user sgrebnov commented on the pull request: https://github.com/apache/cordova-lib/pull/164#issuecomment-73859774 Reviewed and tested, LGTM :+1:
          Hide
          githubbot ASF GitHub Bot added a comment -

          GitHub user TimBarham opened a pull request:

          https://github.com/apache/cordova-lib/pull/164

          CB-8123 Plugin references can target specific windows platforms.

          Adds support for `target`, `versions` and `arch` attributes on `<lib-file>` and `<framework>` elements in the windows platform of plugin.xml. This allows plugin authors to target different references to different target platforms.

          Also adds support for `src` attribute as an alias for the `Include` attribute on the `
          <lib-file>` element (since `src` is documented, but `Include` is used by existing plugins).

          Adds some tests to cover the new attributes. Updates existing plugin tests for windows8 platform to also test windows platform (left in windows8 tests to help verify backward compatibility with old windows8 platform).

          As part of this change, refactored `jsproj` to `jsprojManager` to reflect the fact that, with the windows platform, this class now manages multiple jsproj files.

          Broken into three commits to separate file renames from changes, so that git can successfully track the changes.

          You can merge this pull request into a Git repository by running:

          $ git pull https://github.com/MSOpenTech/cordova-lib CB-8123

          Alternatively you can review and apply these changes as the patch at:

          https://github.com/apache/cordova-lib/pull/164.patch

          To close this pull request, make a commit to your master/trunk branch
          with (at least) the following in the commit message:

          This closes #164


          commit 94efb46eccbe0438dbede35b90c4c2255dac0b77
          Author: Tim Barham <tim.barham@microsoft.com>
          Date: 2015-02-11T00:53:36Z

          CB-8123 Plugin references can target specific windows platforms.

          Adds support for `target`, `versions` and `arch` attributes on `<lib-file>` and `<framework>` elements in the windows platform of plugin.xml. This allows plugin authors to target different references to different target platforms.

          Also adds support for `src` attribute as an alias for the `Include` attribute on the `
          <lib-file>` element (since `src` is documented, but `Include` is used by existing plugins).

          Adds some tests to cover the new attributes. Updates existing plugin tests for windows8 platform to also test windows platform (left in windows8 tests to help verify backward compatibility with old windows8 platform).

          As part of this change, refactored `jsproj` to `jsprojManager` to reflect the fact that, with the windows platform, this class now manages multiple jsproj files.

          I will rename some windows8 files and folders to windows, and jsproj.js to jsprojManager.js in a subsequent commit.

          commit d7a09785bde58d11136653685c08ad148c1ae189
          Author: Tim Barham <tim.barham@microsoft.com>
          Date: 2015-02-11T01:11:40Z

          CB-8123 Rename windows platform related files.

          Renames `windows8` plugin platform folders in tests to `windows`. Renames `jsproj.js` to `jsprojManager.js`.

          commit 5b31cecf7677a53279ded52158dd3a6ea57d379c
          Author: Tim Barham <tim.barham@microsoft.com>
          Date: 2015-02-11T01:12:53Z

          CB-8123 Rename further windows platform related files.

          Renames `windows8.spec.js` to `windows.spec.js`.


          Show
          githubbot ASF GitHub Bot added a comment - GitHub user TimBarham opened a pull request: https://github.com/apache/cordova-lib/pull/164 CB-8123 Plugin references can target specific windows platforms. Adds support for `target`, `versions` and `arch` attributes on `<lib-file>` and `<framework>` elements in the windows platform of plugin.xml. This allows plugin authors to target different references to different target platforms. Also adds support for `src` attribute as an alias for the `Include` attribute on the ` <lib-file>` element (since `src` is documented, but `Include` is used by existing plugins). Adds some tests to cover the new attributes. Updates existing plugin tests for windows8 platform to also test windows platform (left in windows8 tests to help verify backward compatibility with old windows8 platform). As part of this change, refactored `jsproj` to `jsprojManager` to reflect the fact that, with the windows platform, this class now manages multiple jsproj files. Broken into three commits to separate file renames from changes, so that git can successfully track the changes. You can merge this pull request into a Git repository by running: $ git pull https://github.com/MSOpenTech/cordova-lib CB-8123 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/cordova-lib/pull/164.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #164 commit 94efb46eccbe0438dbede35b90c4c2255dac0b77 Author: Tim Barham <tim.barham@microsoft.com> Date: 2015-02-11T00:53:36Z CB-8123 Plugin references can target specific windows platforms. Adds support for `target`, `versions` and `arch` attributes on `<lib-file>` and `<framework>` elements in the windows platform of plugin.xml. This allows plugin authors to target different references to different target platforms. Also adds support for `src` attribute as an alias for the `Include` attribute on the ` <lib-file>` element (since `src` is documented, but `Include` is used by existing plugins). Adds some tests to cover the new attributes. Updates existing plugin tests for windows8 platform to also test windows platform (left in windows8 tests to help verify backward compatibility with old windows8 platform). As part of this change, refactored `jsproj` to `jsprojManager` to reflect the fact that, with the windows platform, this class now manages multiple jsproj files. I will rename some windows8 files and folders to windows, and jsproj.js to jsprojManager.js in a subsequent commit. commit d7a09785bde58d11136653685c08ad148c1ae189 Author: Tim Barham <tim.barham@microsoft.com> Date: 2015-02-11T01:11:40Z CB-8123 Rename windows platform related files. Renames `windows8` plugin platform folders in tests to `windows`. Renames `jsproj.js` to `jsprojManager.js`. commit 5b31cecf7677a53279ded52158dd3a6ea57d379c Author: Tim Barham <tim.barham@microsoft.com> Date: 2015-02-11T01:12:53Z CB-8123 Rename further windows platform related files. Renames `windows8.spec.js` to `windows.spec.js`.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user TimBarham closed the pull request at:

          https://github.com/apache/cordova-lib/pull/155

          Show
          githubbot ASF GitHub Bot added a comment - Github user TimBarham closed the pull request at: https://github.com/apache/cordova-lib/pull/155
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user TimBarham commented on the pull request:

          https://github.com/apache/cordova-lib/pull/155#issuecomment-73799000

          I'll close this PR, and open a new, cleaned up PR.

          Show
          githubbot ASF GitHub Bot added a comment - Github user TimBarham commented on the pull request: https://github.com/apache/cordova-lib/pull/155#issuecomment-73799000 I'll close this PR, and open a new, cleaned up PR.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user purplecabbage commented on the pull request:

          https://github.com/apache/cordova-lib/pull/155#issuecomment-72117279

          yeah, whichever approach is easier. Ultimately the test in this case is invalid, but we don't want it appearing to break the build.

          Show
          githubbot ASF GitHub Bot added a comment - Github user purplecabbage commented on the pull request: https://github.com/apache/cordova-lib/pull/155#issuecomment-72117279 yeah, whichever approach is easier. Ultimately the test in this case is invalid, but we don't want it appearing to break the build.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user TimBarham commented on the pull request:

          https://github.com/apache/cordova-lib/pull/155#issuecomment-72114968

          The tests use path.join(), but jsproj uses hard-coded backslashes (which is reasonable, because normally it would only run on Windows). This problem is showing up now because previously this code wasn’t exercised by tests.

          I’m looking to see if it is feasible/reasonable to update jsproj to be platform agnostic, to the extent it needs to be for tests to pass. I’d prefer that to skipping the tests, so we get consistent coverage (the tests don’t build projects – just verify that files are modified as expected).

          From: Jesse MacFadyen notifications@github.com
          Sent: Thursday, January 29, 2015 12:12 PM
          To: apache/cordova-lib
          Cc: Tim Barham
          Subject: Re: [cordova-lib] CB-8123 Plugin references can target specific windows platforms. (#155)

          You should use path.join( ) in your tests when creating paths so the tests will still pass on MacOS, or check the environment and skip running your tests altogether.


          Reply to this email directly or view it on GitHub<https://github.com/apache/cordova-lib/pull/155#issuecomment-72095389>.

          Show
          githubbot ASF GitHub Bot added a comment - Github user TimBarham commented on the pull request: https://github.com/apache/cordova-lib/pull/155#issuecomment-72114968 The tests use path.join(), but jsproj uses hard-coded backslashes (which is reasonable, because normally it would only run on Windows). This problem is showing up now because previously this code wasn’t exercised by tests. I’m looking to see if it is feasible/reasonable to update jsproj to be platform agnostic, to the extent it needs to be for tests to pass. I’d prefer that to skipping the tests, so we get consistent coverage (the tests don’t build projects – just verify that files are modified as expected). From: Jesse MacFadyen notifications@github.com Sent: Thursday, January 29, 2015 12:12 PM To: apache/cordova-lib Cc: Tim Barham Subject: Re: [cordova-lib] CB-8123 Plugin references can target specific windows platforms. (#155) You should use path.join( ) in your tests when creating paths so the tests will still pass on MacOS, or check the environment and skip running your tests altogether. — Reply to this email directly or view it on GitHub< https://github.com/apache/cordova-lib/pull/155#issuecomment-72095389 >.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user purplecabbage commented on a diff in the pull request:

          https://github.com/apache/cordova-lib/pull/155#discussion_r23798529

          — Diff: cordova-lib/spec-plugman/platforms/windows.spec.js —
          @@ -0,0 +1,415 @@
          +/**
          + Licensed to the Apache Software Foundation (ASF) under one
          + or more contributor license agreements. See the NOTICE file
          + distributed with this work for additional information
          + regarding copyright ownership. The ASF licenses this file
          + to you 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.
          + */
          +var windows = require('../../src/plugman/platforms/windows'),
          + common = require('../../src/plugman/platforms/common'),
          + install = require('../../src/plugman/install'),
          + path = require('path'),
          + fs = require('fs'),
          + shell = require('shelljs'),
          + et = require('elementtree'),
          + os = require('osenv'),
          + cordovaProjectDir = path.join(os.tmpdir(), 'plugman'),
          + cordovaProjectWindowsPlatformDir = path.join(cordovaProjectDir, 'platforms', 'windows'),
          + cordovaProjectPluginsDir = path.join(cordovaProjectDir, 'plugins'),
          + xml_helpers = require('../../src/util/xml-helpers'),
          + dummyplugin = path.join(__dirname, '..', 'plugins', 'org.test.plugins.dummyplugin'),
          + faultyplugin = path.join(__dirname, '..', 'plugins', 'org.test.plugins.faultyplugin');
          +
          +var PluginInfo = require('../../src/PluginInfo');
          +
          +var dummyPluginInfo = new PluginInfo(dummyplugin);
          +var dummy_id = dummyPluginInfo.id;
          +var valid_source = dummyPluginInfo.getSourceFiles('windows');
          +var valid_libfiles = dummyPluginInfo.getLibFiles('windows');
          +var valid_frameworks = dummyPluginInfo.getFrameworks('windows');
          +
          +var faultyPluginInfo = new PluginInfo(faultyplugin);
          +var faulty_id = faultyPluginInfo.id;
          +var invalid_source = faultyPluginInfo.getSourceFiles('windows');
          +var invalid_libfiles = faultyPluginInfo.getLibFiles('windows');
          +
          +function copyArray(arr)

          { + return Array.prototype.slice.call(arr, 0); +}

          +
          +beforeEach(function () {
          + this.addMatchers({
          + toContainXmlPath: function (xpath) {
          + var xml = this.actual;
          + var notText = this.isNot ? 'not ' : '';
          + this.message = function ()

          { + return 'Expected xml \'' + et.tostring(xml) + '\' ' + notText + 'to contain elements matching \'' + xpath + '\'.'; + }

          ;
          +
          + return xml.find(xpath) != null;
          + } });
          +});
          +
          +['windows', 'windows8'].forEach(function (platform) {
          + var windows_project = path.join(__dirname, '..', 'projects', platform);
          +
          + shell.mkdir('-p', cordovaProjectWindowsPlatformDir);
          + shell.cp('-rf', path.join(windows_project, '*'), cordovaProjectWindowsPlatformDir);
          + var proj_files = windows.parseProjectFile(cordovaProjectWindowsPlatformDir);
          + shell.rm('-rf', cordovaProjectDir);
          +
          + var platformProjects = {
          + windows:

          { + all: 'CordovaApp.projitems', + phone: 'CordovaApp.Phone.jsproj', + windows: 'CordovaApp.Windows.jsproj', + windows8: 'CordovaApp.Windows80.jsproj' + }

          , windows8:

          { + all: 'TestApp.jsproj', + windows8: 'TestApp.jsproj' + }

          + }[platform];
          +
          + describe(platform + ' project handler', function () {
          + beforeEach(function ()

          { + shell.mkdir('-p', cordovaProjectWindowsPlatformDir); + shell.mkdir('-p', cordovaProjectPluginsDir); + }

          );
          + afterEach(function ()

          { + shell.rm('-rf', cordovaProjectDir); + }

          );
          +
          + describe('www_dir method', function () {
          + it('should return cordova-windows project www location using www_dir', function ()

          { + expect(windows.www_dir(path.sep)).toEqual(path.sep + 'www'); + }

          );
          + });
          + describe('package_name method', function () {
          + it('should return a windows project\'s proper package name', function ()

          { + expect(windows.package_name(windows_project)).toEqual("CordovaApp"); + }

          );
          + });
          +
          + describe('parseProjectFile method', function () {
          + it('should throw if project is not an windows project', function () {
          + expect(function ()

          { + windows.parseProjectFile(cordovaProjectWindowsPlatformDir); + }

          ).toThrow(windows.InvalidProjectPathError);
          + });
          + });
          +
          + describe('installation', function () {
          + beforeEach(function ()

          { + shell.mkdir('-p', cordovaProjectWindowsPlatformDir); + shell.cp('-rf', path.join(windows_project, '*'), cordovaProjectWindowsPlatformDir); + }

          );
          + afterEach(function ()

          { + shell.rm('-rf', cordovaProjectDir); + }

          );
          +
          + function validateInstalledProjects(tag, elementToInstall, xpath, supportedPlatforms) {
          + jasmine.getEnv().currentSpec.removeAllSpies();
          +
          + var projects = copyArray(proj_files.projects);
          + if (platform === 'windows')

          { + projects.push(proj_files.master); + }

          +
          + var appendToRootFake = function (itemGroup)

          { + expect(itemGroup).toContainXmlPath(xpath); + }

          ;
          +
          + var projectsAddedToSpies = [];
          + var projectsNotAddedToSpies = [];
          +
          + var projectsAddedTo = [];
          + supportedPlatforms.forEach(function (platform) {
          + var platformProject = platformProjects[platform];
          + if (platformProject)

          { + projectsAddedTo.push(platformProjects[platform]); + }

          + });
          +
          + projects.forEach(function (project) {
          + if (projectsAddedTo.indexOf(path.basename(project.location)) > -1)

          { + projectsAddedToSpies.push(spyOn(project, 'appendToRoot').andCallFake(appendToRootFake)); + }

          else

          { + projectsNotAddedToSpies.push(spyOn(project, 'appendToRoot')); + }

          + });
          +
          + windows[tag].install(elementToInstall, dummyplugin, cordovaProjectWindowsPlatformDir, dummy_id, null, proj_files);
          +
          + projectsAddedToSpies.forEach(function (spy)

          { + expect(spy).toHaveBeenCalled(); + }

          );
          +
          + projectsNotAddedToSpies.forEach(function (spy)

          { + expect(spy).not.toHaveBeenCalled(); + }

          );
          + }
          +
          + describe('of <source-file> elements', function () {
          + it('should copy stuff from one location to another by calling common.copyFile', function ()

          { + var source = copyArray(valid_source); + var s = spyOn(common, 'copyFile'); + windows['source-file'].install(source[0], dummyplugin, cordovaProjectWindowsPlatformDir, dummy_id, null, proj_files); + expect(s).toHaveBeenCalledWith(dummyplugin, 'src/windows/dummer.js', cordovaProjectWindowsPlatformDir, path.join('plugins', 'org.test.plugins.dummyplugin', 'dummer.js'), false); + }

          );
          + it('should throw if source-file src cannot be found', function () {
          + var source = copyArray(invalid_source);
          + expect(function ()

          { + windows['source-file'].install(source[1], faultyplugin, cordovaProjectWindowsPlatformDir, faulty_id, null, proj_files); + }

          ).toThrow('"' + path.resolve(faultyplugin, 'src/windows/NotHere.js') + '" not found!');
          + });
          + it('should throw if source-file target already exists', function () {
          + var source = copyArray(valid_source);
          + var target = path.join(cordovaProjectWindowsPlatformDir, 'plugins', dummy_id, 'dummer.js');
          + shell.mkdir('-p', path.dirname(target));
          + fs.writeFileSync(target, 'some bs', 'utf-8');
          + expect(function ()

          { + windows['source-file'].install(source[0], dummyplugin, cordovaProjectWindowsPlatformDir, dummy_id, null, proj_files); + }

          ).toThrow('"' + target + '" already exists!');
          + });
          + });
          +
          + describe('of <lib-file> elements', function () {
          + var libfiles = copyArray(valid_libfiles);
          + var invalidLibFiles = copyArray(invalid_libfiles);
          +
          + // This could be separated into individual specs, but that results in a lot of copying and deleting the
          + // project files, which is not needed.
          + it('should write to correct project files when conditions are specified', function ()

          { + var xpath = 'SDKReference[@Include="TestSDK1, Version=1.0"][@Condition="\'$(Platform)\'==\'x86\'"]'; + validateInstalledProjects('lib-file', libfiles[0], xpath, ['all']); + + xpath = 'SDKReference[@Include="TestSDK2, Version=1.0"]'; + validateInstalledProjects('lib-file', libfiles[1], xpath, ['windows', 'phone']); + + xpath = 'SDKReference[@Include="TestSDK3, Version=1.0"]'; + validateInstalledProjects('lib-file', libfiles[2], xpath, ['phone']); + + xpath = 'SDKReference[@Include="TestSDK4, Version=1.0"]'; + validateInstalledProjects('lib-file', libfiles[3], xpath, ['windows8']); + }

          );
          +
          + it('should throw if conditions are invalid', function () {
          + expect(function ()

          { + windows['lib-file'].install(invalidLibFiles[0], faultyplugin, cordovaProjectWindowsPlatformDir, faulty_id, null, proj_files); + }

          ).toThrow('Invalid lib-file arch attribute (must be "x86", "x64" or "ARM"): x85');
          +
          + expect(function ()

          { + windows['lib-file'].install(invalidLibFiles[1], faultyplugin, cordovaProjectWindowsPlatformDir, faulty_id, null, proj_files); + }

          ).toThrow('Invalid lib-file versions attribute (must be a valid a valid node semantic version range): 8.0a');
          +
          + expect(function ()

          { + windows['lib-file'].install(invalidLibFiles[2], faultyplugin, cordovaProjectWindowsPlatformDir, faulty_id, null, proj_files); + }

          ).toThrow('Invalid lib-file target attribute (must be "all", "phone", "windows" or "win"): daphne');
          + });
          + });
          +
          + describe('of <framework> elements', function () {
          + var frameworks = copyArray(valid_frameworks);
          +
          + // This could be separated into individual specs, but that results in a lot of copying and deleting the
          + // project files, which is not needed.
          + it('should write to correct project files when conditions are specified', function ()

          { + var xpath = 'Reference[@Include="dummy1"][@Condition="\'$(Platform)\'==\'x64\'"]/HintPath'; + validateInstalledProjects('framework', frameworks[0], xpath, ['all']); + + xpath = 'Reference[@Include="dummy2"]/HintPath'; + validateInstalledProjects('framework', frameworks[1], xpath, ['all']); + + xpath = 'Reference[@Include="dummy3"]/HintPath'; + validateInstalledProjects('framework', frameworks[2], xpath, ['windows', 'windows8']); + + xpath = 'Reference[@Include="dummy4"][@Condition="\'$(Platform)\'==\'ARM\'"]/HintPath'; + validateInstalledProjects('framework', frameworks[3], xpath, ['phone']); + }

          );
          + });
          +
          + describe('of <framework> elements of type \'projectReference\'', function () {
          + var frameworks = copyArray(valid_frameworks);
          +
          + it('should write to correct project files when conditions are specified', function () {
          + var xpath = 'ProjectReference[@Include="' + dummyplugin + '\\src\\windows\\dummy1.vcxproj"][@Condition="\'$(Platform)\'==\'x64\'"]';
          — End diff –

          First failing test in Travis.

          Show
          githubbot ASF GitHub Bot added a comment - Github user purplecabbage commented on a diff in the pull request: https://github.com/apache/cordova-lib/pull/155#discussion_r23798529 — Diff: cordova-lib/spec-plugman/platforms/windows.spec.js — @@ -0,0 +1,415 @@ +/** + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you 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. + */ +var windows = require('../../src/plugman/platforms/windows'), + common = require('../../src/plugman/platforms/common'), + install = require('../../src/plugman/install'), + path = require('path'), + fs = require('fs'), + shell = require('shelljs'), + et = require('elementtree'), + os = require('osenv'), + cordovaProjectDir = path.join(os.tmpdir(), 'plugman'), + cordovaProjectWindowsPlatformDir = path.join(cordovaProjectDir, 'platforms', 'windows'), + cordovaProjectPluginsDir = path.join(cordovaProjectDir, 'plugins'), + xml_helpers = require('../../src/util/xml-helpers'), + dummyplugin = path.join(__dirname, '..', 'plugins', 'org.test.plugins.dummyplugin'), + faultyplugin = path.join(__dirname, '..', 'plugins', 'org.test.plugins.faultyplugin'); + +var PluginInfo = require('../../src/PluginInfo'); + +var dummyPluginInfo = new PluginInfo(dummyplugin); +var dummy_id = dummyPluginInfo.id; +var valid_source = dummyPluginInfo.getSourceFiles('windows'); +var valid_libfiles = dummyPluginInfo.getLibFiles('windows'); +var valid_frameworks = dummyPluginInfo.getFrameworks('windows'); + +var faultyPluginInfo = new PluginInfo(faultyplugin); +var faulty_id = faultyPluginInfo.id; +var invalid_source = faultyPluginInfo.getSourceFiles('windows'); +var invalid_libfiles = faultyPluginInfo.getLibFiles('windows'); + +function copyArray(arr) { + return Array.prototype.slice.call(arr, 0); +} + +beforeEach(function () { + this.addMatchers({ + toContainXmlPath: function (xpath) { + var xml = this.actual; + var notText = this.isNot ? 'not ' : ''; + this.message = function () { + return 'Expected xml \'' + et.tostring(xml) + '\' ' + notText + 'to contain elements matching \'' + xpath + '\'.'; + } ; + + return xml.find(xpath) != null; + } }); +}); + + ['windows', 'windows8'] .forEach(function (platform) { + var windows_project = path.join(__dirname, '..', 'projects', platform); + + shell.mkdir('-p', cordovaProjectWindowsPlatformDir); + shell.cp('-rf', path.join(windows_project, '*'), cordovaProjectWindowsPlatformDir); + var proj_files = windows.parseProjectFile(cordovaProjectWindowsPlatformDir); + shell.rm('-rf', cordovaProjectDir); + + var platformProjects = { + windows: { + all: 'CordovaApp.projitems', + phone: 'CordovaApp.Phone.jsproj', + windows: 'CordovaApp.Windows.jsproj', + windows8: 'CordovaApp.Windows80.jsproj' + } , windows8: { + all: 'TestApp.jsproj', + windows8: 'TestApp.jsproj' + } + } [platform] ; + + describe(platform + ' project handler', function () { + beforeEach(function () { + shell.mkdir('-p', cordovaProjectWindowsPlatformDir); + shell.mkdir('-p', cordovaProjectPluginsDir); + } ); + afterEach(function () { + shell.rm('-rf', cordovaProjectDir); + } ); + + describe('www_dir method', function () { + it('should return cordova-windows project www location using www_dir', function () { + expect(windows.www_dir(path.sep)).toEqual(path.sep + 'www'); + } ); + }); + describe('package_name method', function () { + it('should return a windows project\'s proper package name', function () { + expect(windows.package_name(windows_project)).toEqual("CordovaApp"); + } ); + }); + + describe('parseProjectFile method', function () { + it('should throw if project is not an windows project', function () { + expect(function () { + windows.parseProjectFile(cordovaProjectWindowsPlatformDir); + } ).toThrow(windows.InvalidProjectPathError); + }); + }); + + describe('installation', function () { + beforeEach(function () { + shell.mkdir('-p', cordovaProjectWindowsPlatformDir); + shell.cp('-rf', path.join(windows_project, '*'), cordovaProjectWindowsPlatformDir); + } ); + afterEach(function () { + shell.rm('-rf', cordovaProjectDir); + } ); + + function validateInstalledProjects(tag, elementToInstall, xpath, supportedPlatforms) { + jasmine.getEnv().currentSpec.removeAllSpies(); + + var projects = copyArray(proj_files.projects); + if (platform === 'windows') { + projects.push(proj_files.master); + } + + var appendToRootFake = function (itemGroup) { + expect(itemGroup).toContainXmlPath(xpath); + } ; + + var projectsAddedToSpies = []; + var projectsNotAddedToSpies = []; + + var projectsAddedTo = []; + supportedPlatforms.forEach(function (platform) { + var platformProject = platformProjects [platform] ; + if (platformProject) { + projectsAddedTo.push(platformProjects[platform]); + } + }); + + projects.forEach(function (project) { + if (projectsAddedTo.indexOf(path.basename(project.location)) > -1) { + projectsAddedToSpies.push(spyOn(project, 'appendToRoot').andCallFake(appendToRootFake)); + } else { + projectsNotAddedToSpies.push(spyOn(project, 'appendToRoot')); + } + }); + + windows [tag] .install(elementToInstall, dummyplugin, cordovaProjectWindowsPlatformDir, dummy_id, null, proj_files); + + projectsAddedToSpies.forEach(function (spy) { + expect(spy).toHaveBeenCalled(); + } ); + + projectsNotAddedToSpies.forEach(function (spy) { + expect(spy).not.toHaveBeenCalled(); + } ); + } + + describe('of <source-file> elements', function () { + it('should copy stuff from one location to another by calling common.copyFile', function () { + var source = copyArray(valid_source); + var s = spyOn(common, 'copyFile'); + windows['source-file'].install(source[0], dummyplugin, cordovaProjectWindowsPlatformDir, dummy_id, null, proj_files); + expect(s).toHaveBeenCalledWith(dummyplugin, 'src/windows/dummer.js', cordovaProjectWindowsPlatformDir, path.join('plugins', 'org.test.plugins.dummyplugin', 'dummer.js'), false); + } ); + it('should throw if source-file src cannot be found', function () { + var source = copyArray(invalid_source); + expect(function () { + windows['source-file'].install(source[1], faultyplugin, cordovaProjectWindowsPlatformDir, faulty_id, null, proj_files); + } ).toThrow('"' + path.resolve(faultyplugin, 'src/windows/NotHere.js') + '" not found!'); + }); + it('should throw if source-file target already exists', function () { + var source = copyArray(valid_source); + var target = path.join(cordovaProjectWindowsPlatformDir, 'plugins', dummy_id, 'dummer.js'); + shell.mkdir('-p', path.dirname(target)); + fs.writeFileSync(target, 'some bs', 'utf-8'); + expect(function () { + windows['source-file'].install(source[0], dummyplugin, cordovaProjectWindowsPlatformDir, dummy_id, null, proj_files); + } ).toThrow('"' + target + '" already exists!'); + }); + }); + + describe('of <lib-file> elements', function () { + var libfiles = copyArray(valid_libfiles); + var invalidLibFiles = copyArray(invalid_libfiles); + + // This could be separated into individual specs, but that results in a lot of copying and deleting the + // project files, which is not needed. + it('should write to correct project files when conditions are specified', function () { + var xpath = 'SDKReference[@Include="TestSDK1, Version=1.0"][@Condition="\'$(Platform)\'==\'x86\'"]'; + validateInstalledProjects('lib-file', libfiles[0], xpath, ['all']); + + xpath = 'SDKReference[@Include="TestSDK2, Version=1.0"]'; + validateInstalledProjects('lib-file', libfiles[1], xpath, ['windows', 'phone']); + + xpath = 'SDKReference[@Include="TestSDK3, Version=1.0"]'; + validateInstalledProjects('lib-file', libfiles[2], xpath, ['phone']); + + xpath = 'SDKReference[@Include="TestSDK4, Version=1.0"]'; + validateInstalledProjects('lib-file', libfiles[3], xpath, ['windows8']); + } ); + + it('should throw if conditions are invalid', function () { + expect(function () { + windows['lib-file'].install(invalidLibFiles[0], faultyplugin, cordovaProjectWindowsPlatformDir, faulty_id, null, proj_files); + } ).toThrow('Invalid lib-file arch attribute (must be "x86", "x64" or "ARM"): x85'); + + expect(function () { + windows['lib-file'].install(invalidLibFiles[1], faultyplugin, cordovaProjectWindowsPlatformDir, faulty_id, null, proj_files); + } ).toThrow('Invalid lib-file versions attribute (must be a valid a valid node semantic version range): 8.0a'); + + expect(function () { + windows['lib-file'].install(invalidLibFiles[2], faultyplugin, cordovaProjectWindowsPlatformDir, faulty_id, null, proj_files); + } ).toThrow('Invalid lib-file target attribute (must be "all", "phone", "windows" or "win"): daphne'); + }); + }); + + describe('of <framework> elements', function () { + var frameworks = copyArray(valid_frameworks); + + // This could be separated into individual specs, but that results in a lot of copying and deleting the + // project files, which is not needed. + it('should write to correct project files when conditions are specified', function () { + var xpath = 'Reference[@Include="dummy1"][@Condition="\'$(Platform)\'==\'x64\'"]/HintPath'; + validateInstalledProjects('framework', frameworks[0], xpath, ['all']); + + xpath = 'Reference[@Include="dummy2"]/HintPath'; + validateInstalledProjects('framework', frameworks[1], xpath, ['all']); + + xpath = 'Reference[@Include="dummy3"]/HintPath'; + validateInstalledProjects('framework', frameworks[2], xpath, ['windows', 'windows8']); + + xpath = 'Reference[@Include="dummy4"][@Condition="\'$(Platform)\'==\'ARM\'"]/HintPath'; + validateInstalledProjects('framework', frameworks[3], xpath, ['phone']); + } ); + }); + + describe('of <framework> elements of type \'projectReference\'', function () { + var frameworks = copyArray(valid_frameworks); + + it('should write to correct project files when conditions are specified', function () { + var xpath = 'ProjectReference [@Include="' + dummyplugin + '\\src\\windows\\dummy1.vcxproj"] [@Condition="\'$(Platform)\'==\'x64\'"] '; — End diff – First failing test in Travis.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user purplecabbage commented on a diff in the pull request:

          https://github.com/apache/cordova-lib/pull/155#discussion_r23798388

          — Diff: cordova-lib/spec-plugman/platforms/windows.spec.js —
          @@ -0,0 +1,415 @@
          +/**
          + Licensed to the Apache Software Foundation (ASF) under one
          + or more contributor license agreements. See the NOTICE file
          + distributed with this work for additional information
          + regarding copyright ownership. The ASF licenses this file
          + to you 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.
          + */
          +var windows = require('../../src/plugman/platforms/windows'),
          + common = require('../../src/plugman/platforms/common'),
          + install = require('../../src/plugman/install'),
          + path = require('path'),
          + fs = require('fs'),
          + shell = require('shelljs'),
          + et = require('elementtree'),
          + os = require('osenv'),
          + cordovaProjectDir = path.join(os.tmpdir(), 'plugman'),
          + cordovaProjectWindowsPlatformDir = path.join(cordovaProjectDir, 'platforms', 'windows'),
          + cordovaProjectPluginsDir = path.join(cordovaProjectDir, 'plugins'),
          + xml_helpers = require('../../src/util/xml-helpers'),
          + dummyplugin = path.join(__dirname, '..', 'plugins', 'org.test.plugins.dummyplugin'),
          + faultyplugin = path.join(__dirname, '..', 'plugins', 'org.test.plugins.faultyplugin');
          +
          +var PluginInfo = require('../../src/PluginInfo');
          +
          +var dummyPluginInfo = new PluginInfo(dummyplugin);
          +var dummy_id = dummyPluginInfo.id;
          +var valid_source = dummyPluginInfo.getSourceFiles('windows');
          +var valid_libfiles = dummyPluginInfo.getLibFiles('windows');
          +var valid_frameworks = dummyPluginInfo.getFrameworks('windows');
          +
          +var faultyPluginInfo = new PluginInfo(faultyplugin);
          +var faulty_id = faultyPluginInfo.id;
          +var invalid_source = faultyPluginInfo.getSourceFiles('windows');
          +var invalid_libfiles = faultyPluginInfo.getLibFiles('windows');
          +
          +function copyArray(arr)

          { + return Array.prototype.slice.call(arr, 0); +}

          +
          +beforeEach(function () {
          + this.addMatchers({
          + toContainXmlPath: function (xpath) {
          + var xml = this.actual;
          + var notText = this.isNot ? 'not ' : '';
          + this.message = function ()

          { + return 'Expected xml \'' + et.tostring(xml) + '\' ' + notText + 'to contain elements matching \'' + xpath + '\'.'; + }

          ;
          +
          + return xml.find(xpath) != null;
          + } });
          +});
          +
          +['windows', 'windows8'].forEach(function (platform) {
          + var windows_project = path.join(__dirname, '..', 'projects', platform);
          +
          + shell.mkdir('-p', cordovaProjectWindowsPlatformDir);
          + shell.cp('-rf', path.join(windows_project, '*'), cordovaProjectWindowsPlatformDir);
          + var proj_files = windows.parseProjectFile(cordovaProjectWindowsPlatformDir);
          + shell.rm('-rf', cordovaProjectDir);
          +
          + var platformProjects = {
          + windows:

          { + all: 'CordovaApp.projitems', + phone: 'CordovaApp.Phone.jsproj', + windows: 'CordovaApp.Windows.jsproj', + windows8: 'CordovaApp.Windows80.jsproj' + }

          , windows8:

          { + all: 'TestApp.jsproj', + windows8: 'TestApp.jsproj' + }

          + }[platform];
          +
          + describe(platform + ' project handler', function () {
          + beforeEach(function ()

          { + shell.mkdir('-p', cordovaProjectWindowsPlatformDir); + shell.mkdir('-p', cordovaProjectPluginsDir); + }

          );
          + afterEach(function ()

          { + shell.rm('-rf', cordovaProjectDir); + }

          );
          +
          + describe('www_dir method', function () {
          + it('should return cordova-windows project www location using www_dir', function ()

          { + expect(windows.www_dir(path.sep)).toEqual(path.sep + 'www'); + }

          );
          + });
          + describe('package_name method', function () {
          + it('should return a windows project\'s proper package name', function ()

          { + expect(windows.package_name(windows_project)).toEqual("CordovaApp"); + }

          );
          + });
          +
          + describe('parseProjectFile method', function () {
          + it('should throw if project is not an windows project', function () {
          + expect(function ()

          { + windows.parseProjectFile(cordovaProjectWindowsPlatformDir); + }

          ).toThrow(windows.InvalidProjectPathError);
          + });
          + });
          +
          + describe('installation', function () {
          + beforeEach(function ()

          { + shell.mkdir('-p', cordovaProjectWindowsPlatformDir); + shell.cp('-rf', path.join(windows_project, '*'), cordovaProjectWindowsPlatformDir); + }

          );
          + afterEach(function ()

          { + shell.rm('-rf', cordovaProjectDir); + }

          );
          +
          + function validateInstalledProjects(tag, elementToInstall, xpath, supportedPlatforms) {
          + jasmine.getEnv().currentSpec.removeAllSpies();
          +
          + var projects = copyArray(proj_files.projects);
          + if (platform === 'windows')

          { + projects.push(proj_files.master); + }

          +
          + var appendToRootFake = function (itemGroup)

          { + expect(itemGroup).toContainXmlPath(xpath); + }

          ;
          +
          + var projectsAddedToSpies = [];
          + var projectsNotAddedToSpies = [];
          +
          + var projectsAddedTo = [];
          + supportedPlatforms.forEach(function (platform) {
          + var platformProject = platformProjects[platform];
          + if (platformProject)

          { + projectsAddedTo.push(platformProjects[platform]); + }

          + });
          +
          + projects.forEach(function (project) {
          + if (projectsAddedTo.indexOf(path.basename(project.location)) > -1)

          { + projectsAddedToSpies.push(spyOn(project, 'appendToRoot').andCallFake(appendToRootFake)); + }

          else

          { + projectsNotAddedToSpies.push(spyOn(project, 'appendToRoot')); + }

          + });
          +
          + windows[tag].install(elementToInstall, dummyplugin, cordovaProjectWindowsPlatformDir, dummy_id, null, proj_files);
          +
          + projectsAddedToSpies.forEach(function (spy)

          { + expect(spy).toHaveBeenCalled(); + }

          );
          +
          + projectsNotAddedToSpies.forEach(function (spy)

          { + expect(spy).not.toHaveBeenCalled(); + }

          );
          + }
          +
          + describe('of <source-file> elements', function () {
          + it('should copy stuff from one location to another by calling common.copyFile', function ()

          { + var source = copyArray(valid_source); + var s = spyOn(common, 'copyFile'); + windows['source-file'].install(source[0], dummyplugin, cordovaProjectWindowsPlatformDir, dummy_id, null, proj_files); + expect(s).toHaveBeenCalledWith(dummyplugin, 'src/windows/dummer.js', cordovaProjectWindowsPlatformDir, path.join('plugins', 'org.test.plugins.dummyplugin', 'dummer.js'), false); + }

          );
          + it('should throw if source-file src cannot be found', function () {
          + var source = copyArray(invalid_source);
          + expect(function ()

          { + windows['source-file'].install(source[1], faultyplugin, cordovaProjectWindowsPlatformDir, faulty_id, null, proj_files); + }

          ).toThrow('"' + path.resolve(faultyplugin, 'src/windows/NotHere.js') + '" not found!');
          + });
          + it('should throw if source-file target already exists', function () {
          + var source = copyArray(valid_source);
          + var target = path.join(cordovaProjectWindowsPlatformDir, 'plugins', dummy_id, 'dummer.js');
          + shell.mkdir('-p', path.dirname(target));
          + fs.writeFileSync(target, 'some bs', 'utf-8');
          + expect(function ()

          { + windows['source-file'].install(source[0], dummyplugin, cordovaProjectWindowsPlatformDir, dummy_id, null, proj_files); + }

          ).toThrow('"' + target + '" already exists!');
          + });
          + });
          +
          + describe('of <lib-file> elements', function () {
          + var libfiles = copyArray(valid_libfiles);
          + var invalidLibFiles = copyArray(invalid_libfiles);
          +
          + // This could be separated into individual specs, but that results in a lot of copying and deleting the
          + // project files, which is not needed.
          + it('should write to correct project files when conditions are specified', function ()

          { + var xpath = 'SDKReference[@Include="TestSDK1, Version=1.0"][@Condition="\'$(Platform)\'==\'x86\'"]'; + validateInstalledProjects('lib-file', libfiles[0], xpath, ['all']); + + xpath = 'SDKReference[@Include="TestSDK2, Version=1.0"]'; + validateInstalledProjects('lib-file', libfiles[1], xpath, ['windows', 'phone']); + + xpath = 'SDKReference[@Include="TestSDK3, Version=1.0"]'; + validateInstalledProjects('lib-file', libfiles[2], xpath, ['phone']); + + xpath = 'SDKReference[@Include="TestSDK4, Version=1.0"]'; + validateInstalledProjects('lib-file', libfiles[3], xpath, ['windows8']); + }

          );
          +
          + it('should throw if conditions are invalid', function () {
          + expect(function ()

          { + windows['lib-file'].install(invalidLibFiles[0], faultyplugin, cordovaProjectWindowsPlatformDir, faulty_id, null, proj_files); + }

          ).toThrow('Invalid lib-file arch attribute (must be "x86", "x64" or "ARM"): x85');
          +
          + expect(function ()

          { + windows['lib-file'].install(invalidLibFiles[1], faultyplugin, cordovaProjectWindowsPlatformDir, faulty_id, null, proj_files); + }

          ).toThrow('Invalid lib-file versions attribute (must be a valid a valid node semantic version range): 8.0a');
          +
          + expect(function ()

          { + windows['lib-file'].install(invalidLibFiles[2], faultyplugin, cordovaProjectWindowsPlatformDir, faulty_id, null, proj_files); + }

          ).toThrow('Invalid lib-file target attribute (must be "all", "phone", "windows" or "win"): daphne');
          + });
          + });
          +
          + describe('of <framework> elements', function () {
          — End diff –

          First failing test in Travis

          Show
          githubbot ASF GitHub Bot added a comment - Github user purplecabbage commented on a diff in the pull request: https://github.com/apache/cordova-lib/pull/155#discussion_r23798388 — Diff: cordova-lib/spec-plugman/platforms/windows.spec.js — @@ -0,0 +1,415 @@ +/** + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you 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. + */ +var windows = require('../../src/plugman/platforms/windows'), + common = require('../../src/plugman/platforms/common'), + install = require('../../src/plugman/install'), + path = require('path'), + fs = require('fs'), + shell = require('shelljs'), + et = require('elementtree'), + os = require('osenv'), + cordovaProjectDir = path.join(os.tmpdir(), 'plugman'), + cordovaProjectWindowsPlatformDir = path.join(cordovaProjectDir, 'platforms', 'windows'), + cordovaProjectPluginsDir = path.join(cordovaProjectDir, 'plugins'), + xml_helpers = require('../../src/util/xml-helpers'), + dummyplugin = path.join(__dirname, '..', 'plugins', 'org.test.plugins.dummyplugin'), + faultyplugin = path.join(__dirname, '..', 'plugins', 'org.test.plugins.faultyplugin'); + +var PluginInfo = require('../../src/PluginInfo'); + +var dummyPluginInfo = new PluginInfo(dummyplugin); +var dummy_id = dummyPluginInfo.id; +var valid_source = dummyPluginInfo.getSourceFiles('windows'); +var valid_libfiles = dummyPluginInfo.getLibFiles('windows'); +var valid_frameworks = dummyPluginInfo.getFrameworks('windows'); + +var faultyPluginInfo = new PluginInfo(faultyplugin); +var faulty_id = faultyPluginInfo.id; +var invalid_source = faultyPluginInfo.getSourceFiles('windows'); +var invalid_libfiles = faultyPluginInfo.getLibFiles('windows'); + +function copyArray(arr) { + return Array.prototype.slice.call(arr, 0); +} + +beforeEach(function () { + this.addMatchers({ + toContainXmlPath: function (xpath) { + var xml = this.actual; + var notText = this.isNot ? 'not ' : ''; + this.message = function () { + return 'Expected xml \'' + et.tostring(xml) + '\' ' + notText + 'to contain elements matching \'' + xpath + '\'.'; + } ; + + return xml.find(xpath) != null; + } }); +}); + + ['windows', 'windows8'] .forEach(function (platform) { + var windows_project = path.join(__dirname, '..', 'projects', platform); + + shell.mkdir('-p', cordovaProjectWindowsPlatformDir); + shell.cp('-rf', path.join(windows_project, '*'), cordovaProjectWindowsPlatformDir); + var proj_files = windows.parseProjectFile(cordovaProjectWindowsPlatformDir); + shell.rm('-rf', cordovaProjectDir); + + var platformProjects = { + windows: { + all: 'CordovaApp.projitems', + phone: 'CordovaApp.Phone.jsproj', + windows: 'CordovaApp.Windows.jsproj', + windows8: 'CordovaApp.Windows80.jsproj' + } , windows8: { + all: 'TestApp.jsproj', + windows8: 'TestApp.jsproj' + } + } [platform] ; + + describe(platform + ' project handler', function () { + beforeEach(function () { + shell.mkdir('-p', cordovaProjectWindowsPlatformDir); + shell.mkdir('-p', cordovaProjectPluginsDir); + } ); + afterEach(function () { + shell.rm('-rf', cordovaProjectDir); + } ); + + describe('www_dir method', function () { + it('should return cordova-windows project www location using www_dir', function () { + expect(windows.www_dir(path.sep)).toEqual(path.sep + 'www'); + } ); + }); + describe('package_name method', function () { + it('should return a windows project\'s proper package name', function () { + expect(windows.package_name(windows_project)).toEqual("CordovaApp"); + } ); + }); + + describe('parseProjectFile method', function () { + it('should throw if project is not an windows project', function () { + expect(function () { + windows.parseProjectFile(cordovaProjectWindowsPlatformDir); + } ).toThrow(windows.InvalidProjectPathError); + }); + }); + + describe('installation', function () { + beforeEach(function () { + shell.mkdir('-p', cordovaProjectWindowsPlatformDir); + shell.cp('-rf', path.join(windows_project, '*'), cordovaProjectWindowsPlatformDir); + } ); + afterEach(function () { + shell.rm('-rf', cordovaProjectDir); + } ); + + function validateInstalledProjects(tag, elementToInstall, xpath, supportedPlatforms) { + jasmine.getEnv().currentSpec.removeAllSpies(); + + var projects = copyArray(proj_files.projects); + if (platform === 'windows') { + projects.push(proj_files.master); + } + + var appendToRootFake = function (itemGroup) { + expect(itemGroup).toContainXmlPath(xpath); + } ; + + var projectsAddedToSpies = []; + var projectsNotAddedToSpies = []; + + var projectsAddedTo = []; + supportedPlatforms.forEach(function (platform) { + var platformProject = platformProjects [platform] ; + if (platformProject) { + projectsAddedTo.push(platformProjects[platform]); + } + }); + + projects.forEach(function (project) { + if (projectsAddedTo.indexOf(path.basename(project.location)) > -1) { + projectsAddedToSpies.push(spyOn(project, 'appendToRoot').andCallFake(appendToRootFake)); + } else { + projectsNotAddedToSpies.push(spyOn(project, 'appendToRoot')); + } + }); + + windows [tag] .install(elementToInstall, dummyplugin, cordovaProjectWindowsPlatformDir, dummy_id, null, proj_files); + + projectsAddedToSpies.forEach(function (spy) { + expect(spy).toHaveBeenCalled(); + } ); + + projectsNotAddedToSpies.forEach(function (spy) { + expect(spy).not.toHaveBeenCalled(); + } ); + } + + describe('of <source-file> elements', function () { + it('should copy stuff from one location to another by calling common.copyFile', function () { + var source = copyArray(valid_source); + var s = spyOn(common, 'copyFile'); + windows['source-file'].install(source[0], dummyplugin, cordovaProjectWindowsPlatformDir, dummy_id, null, proj_files); + expect(s).toHaveBeenCalledWith(dummyplugin, 'src/windows/dummer.js', cordovaProjectWindowsPlatformDir, path.join('plugins', 'org.test.plugins.dummyplugin', 'dummer.js'), false); + } ); + it('should throw if source-file src cannot be found', function () { + var source = copyArray(invalid_source); + expect(function () { + windows['source-file'].install(source[1], faultyplugin, cordovaProjectWindowsPlatformDir, faulty_id, null, proj_files); + } ).toThrow('"' + path.resolve(faultyplugin, 'src/windows/NotHere.js') + '" not found!'); + }); + it('should throw if source-file target already exists', function () { + var source = copyArray(valid_source); + var target = path.join(cordovaProjectWindowsPlatformDir, 'plugins', dummy_id, 'dummer.js'); + shell.mkdir('-p', path.dirname(target)); + fs.writeFileSync(target, 'some bs', 'utf-8'); + expect(function () { + windows['source-file'].install(source[0], dummyplugin, cordovaProjectWindowsPlatformDir, dummy_id, null, proj_files); + } ).toThrow('"' + target + '" already exists!'); + }); + }); + + describe('of <lib-file> elements', function () { + var libfiles = copyArray(valid_libfiles); + var invalidLibFiles = copyArray(invalid_libfiles); + + // This could be separated into individual specs, but that results in a lot of copying and deleting the + // project files, which is not needed. + it('should write to correct project files when conditions are specified', function () { + var xpath = 'SDKReference[@Include="TestSDK1, Version=1.0"][@Condition="\'$(Platform)\'==\'x86\'"]'; + validateInstalledProjects('lib-file', libfiles[0], xpath, ['all']); + + xpath = 'SDKReference[@Include="TestSDK2, Version=1.0"]'; + validateInstalledProjects('lib-file', libfiles[1], xpath, ['windows', 'phone']); + + xpath = 'SDKReference[@Include="TestSDK3, Version=1.0"]'; + validateInstalledProjects('lib-file', libfiles[2], xpath, ['phone']); + + xpath = 'SDKReference[@Include="TestSDK4, Version=1.0"]'; + validateInstalledProjects('lib-file', libfiles[3], xpath, ['windows8']); + } ); + + it('should throw if conditions are invalid', function () { + expect(function () { + windows['lib-file'].install(invalidLibFiles[0], faultyplugin, cordovaProjectWindowsPlatformDir, faulty_id, null, proj_files); + } ).toThrow('Invalid lib-file arch attribute (must be "x86", "x64" or "ARM"): x85'); + + expect(function () { + windows['lib-file'].install(invalidLibFiles[1], faultyplugin, cordovaProjectWindowsPlatformDir, faulty_id, null, proj_files); + } ).toThrow('Invalid lib-file versions attribute (must be a valid a valid node semantic version range): 8.0a'); + + expect(function () { + windows['lib-file'].install(invalidLibFiles[2], faultyplugin, cordovaProjectWindowsPlatformDir, faulty_id, null, proj_files); + } ).toThrow('Invalid lib-file target attribute (must be "all", "phone", "windows" or "win"): daphne'); + }); + }); + + describe('of <framework> elements', function () { — End diff – First failing test in Travis
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user purplecabbage commented on the pull request:

          https://github.com/apache/cordova-lib/pull/155#issuecomment-71907847

          Very cool Tim!

          Show
          githubbot ASF GitHub Bot added a comment - Github user purplecabbage commented on the pull request: https://github.com/apache/cordova-lib/pull/155#issuecomment-71907847 Very cool Tim!
          Hide
          githubbot ASF GitHub Bot added a comment -

          GitHub user TimBarham opened a pull request:

          https://github.com/apache/cordova-docs/pull/263

          CB-8123 Plugin references can target specific windows platforms.

          Adds documentation for the new `target`, `versions` and `arch` attributes on `<lib-file>` and `<framework>` elements in the `windows` platform of `plugin.xml`.

          You can merge this pull request into a Git repository by running:

          $ git pull https://github.com/MSOpenTech/cordova-docs CB-8123

          Alternatively you can review and apply these changes as the patch at:

          https://github.com/apache/cordova-docs/pull/263.patch

          To close this pull request, make a commit to your master/trunk branch
          with (at least) the following in the commit message:

          This closes #263


          commit 85ca7c92b18c59f1071c9a5d588c0744343b1a50
          Author: Tim Barham <tim.barham@microsoft.com>
          Date: 2015-01-20T00:55:04Z

          CB-8123 Plugin references can target specific windows platforms.

          Adds documentation for the new "target", "versions" and "arch" attributes on <lib-file> and <framework> elements in the windows platform of plugin.xml.


          Show
          githubbot ASF GitHub Bot added a comment - GitHub user TimBarham opened a pull request: https://github.com/apache/cordova-docs/pull/263 CB-8123 Plugin references can target specific windows platforms. Adds documentation for the new `target`, `versions` and `arch` attributes on `<lib-file>` and `<framework>` elements in the `windows` platform of `plugin.xml`. You can merge this pull request into a Git repository by running: $ git pull https://github.com/MSOpenTech/cordova-docs CB-8123 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/cordova-docs/pull/263.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #263 commit 85ca7c92b18c59f1071c9a5d588c0744343b1a50 Author: Tim Barham <tim.barham@microsoft.com> Date: 2015-01-20T00:55:04Z CB-8123 Plugin references can target specific windows platforms. Adds documentation for the new "target", "versions" and "arch" attributes on <lib-file> and <framework> elements in the windows platform of plugin.xml.
          Hide
          githubbot ASF GitHub Bot added a comment -

          GitHub user TimBarham opened a pull request:

          https://github.com/apache/cordova-lib/pull/155

          CB-8123 Plugin references can target specific windows platforms.

          Adds support for `target`, `versions` and `arch` attributes on `<lib-file>` and `<framework>` elements in the windows platform of plugin.xml. This allows plugin authors to target different references to different target platforms.

          Also adds support for `src` attribute as an alias for the `Include` attribute on the `<lib-file>` element (since `src` is documented, but `Include` is used by existing plugins).

          Adds some tests to cover the new attributes. Updates existing plugin tests for windows8 platform to also test windows platform (left in windows8 tests to help verify backward compatibility with old windows8 platform).

          As part of this change, refactored `jsproj` to `jsprojManager` to reflect the fact that, with the windows platform, this class now manages multiple jsproj files.

          You can merge this pull request into a Git repository by running:

          $ git pull https://github.com/MSOpenTech/cordova-lib CB-8123-final

          Alternatively you can review and apply these changes as the patch at:

          https://github.com/apache/cordova-lib/pull/155.patch

          To close this pull request, make a commit to your master/trunk branch
          with (at least) the following in the commit message:

          This closes #155


          commit 8b6f7b9b443fe6b35e070bd1ad8ff81df53f559f
          Author: Tim Barham <tim.barham@microsoft.com>
          Date: 2015-01-28T19:15:39Z

          CB-8123 Plugin references can target specific windows platforms.

          Adds support for `target`, `versions` and `arch` attributes on `<lib-file>` and `<framework>` elements in the windows platform of plugin.xml. This allows plugin authors to target different references to different target platforms.

          Also adds support for `src` attribute as an alias for the `Include` attribute on the `<lib-file>` element (since `src` is documented, but `Include` is used by existing plugins).

          Adds some tests to cover the new attributes. Updates existing plugin tests for windows8 platform to also test windows platform (left in windows8 tests to help verify backward compatibility with old windows8 platform).

          As part of this change, refactored `jsproj` to `jsprojManager` to reflect the fact that, with the windows platform, this class now manages multiple jsproj files.

          Note that I plan to rename some windows8 files and folders to windows, and jsproj.js to jsprojManager.js in a subsequent commit.

          commit 48852eefb20840149fa9ada28082e6cb0a2ff208
          Author: Tim Barham <tim.barham@microsoft.com>
          Date: 2015-01-28T19:30:27Z

          CB-8123 Rename windows platform related files.

          Renames `windows8` plugin platform folders in tests to `windows`. Renames `jsproj.js` to `jsprojManager.js`.

          commit 22a214f217014b8c2df0348025d734cdf03580a7
          Author: Tim Barham <tim.barham@microsoft.com>
          Date: 2015-01-28T19:31:48Z

          CB-8123 Rename further windows platform related files.

          Renames `windows8.spec.js` to `windows.spec.js`.


          Show
          githubbot ASF GitHub Bot added a comment - GitHub user TimBarham opened a pull request: https://github.com/apache/cordova-lib/pull/155 CB-8123 Plugin references can target specific windows platforms. Adds support for `target`, `versions` and `arch` attributes on `<lib-file>` and `<framework>` elements in the windows platform of plugin.xml. This allows plugin authors to target different references to different target platforms. Also adds support for `src` attribute as an alias for the `Include` attribute on the `<lib-file>` element (since `src` is documented, but `Include` is used by existing plugins). Adds some tests to cover the new attributes. Updates existing plugin tests for windows8 platform to also test windows platform (left in windows8 tests to help verify backward compatibility with old windows8 platform). As part of this change, refactored `jsproj` to `jsprojManager` to reflect the fact that, with the windows platform, this class now manages multiple jsproj files. You can merge this pull request into a Git repository by running: $ git pull https://github.com/MSOpenTech/cordova-lib CB-8123 -final Alternatively you can review and apply these changes as the patch at: https://github.com/apache/cordova-lib/pull/155.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #155 commit 8b6f7b9b443fe6b35e070bd1ad8ff81df53f559f Author: Tim Barham <tim.barham@microsoft.com> Date: 2015-01-28T19:15:39Z CB-8123 Plugin references can target specific windows platforms. Adds support for `target`, `versions` and `arch` attributes on `<lib-file>` and `<framework>` elements in the windows platform of plugin.xml. This allows plugin authors to target different references to different target platforms. Also adds support for `src` attribute as an alias for the `Include` attribute on the `<lib-file>` element (since `src` is documented, but `Include` is used by existing plugins). Adds some tests to cover the new attributes. Updates existing plugin tests for windows8 platform to also test windows platform (left in windows8 tests to help verify backward compatibility with old windows8 platform). As part of this change, refactored `jsproj` to `jsprojManager` to reflect the fact that, with the windows platform, this class now manages multiple jsproj files. Note that I plan to rename some windows8 files and folders to windows, and jsproj.js to jsprojManager.js in a subsequent commit. commit 48852eefb20840149fa9ada28082e6cb0a2ff208 Author: Tim Barham <tim.barham@microsoft.com> Date: 2015-01-28T19:30:27Z CB-8123 Rename windows platform related files. Renames `windows8` plugin platform folders in tests to `windows`. Renames `jsproj.js` to `jsprojManager.js`. commit 22a214f217014b8c2df0348025d734cdf03580a7 Author: Tim Barham <tim.barham@microsoft.com> Date: 2015-01-28T19:31:48Z CB-8123 Rename further windows platform related files. Renames `windows8.spec.js` to `windows.spec.js`.
          Hide
          TimBarham Tim Barham added a comment -

          I am currently working on this and should have a pull request out shortly.

          Show
          TimBarham Tim Barham added a comment - I am currently working on this and should have a pull request out shortly.

            People

            • Assignee:
              TimBarham Tim Barham
              Reporter:
              TimBarham Tim Barham
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 72h
                72h
                Remaining:
                Remaining Estimate - 72h
                72h
                Logged:
                Time Spent - Not Specified
                Not Specified

                  Development