Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

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

Closed

Conversation

matrosov-nikita
Copy link
Contributor

What does this PR do?

This PR moves windows-specific logic from cordova-common to cordova-windows. This logic is associated with demuxing 'package.appxmanifest' into relevant platform-specific appx manifests. Also auto-test was moved and edited according changes.

What testing has been done on this change?

Auto test

Checklist

  • Reported an issue in the JIRA database
  • Commit message follows the format: "CB-3232: (android) Fix bug with resolving file paths", where CB-xxxx is the JIRA ID & "android" is the platform affected.
  • Added automated test coverage as appropriate for this change.

Copy link
Contributor

@daserge daserge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM apart the comments and assuming the tests will pass.
Do I get it right that it will require us to release cordova-common before platform release?

// Demux 'package.appxmanifest' into relevant platform-specific appx manifests.
// Only spend the cycles if there are version-specific plugin settings
if (changes.some(function(change) {
return change.target === 'package.appxmanifest';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matrosov-nikita could you explain the code change here from

            changes.some(function(change) {
                return ((typeof change.versions !== 'undefined') ||
                    (typeof change.deviceTarget !== 'undefined'));
            }))

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes w/ target 'package.appxmanifest' and w/o versions and deviceTarget used to demux into manifests in remove_plugin_changes and munge_helper methods. This logic is moved in PluginInfo.js (see also b101ded?diff=unified#diff-93a26ea6e269125a5b151c4176a3b42bR54).
Once windows-specific logic is completed there aren't any changes with 'package.appxmanifest' target.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In cordova-common we'll get ready changes and push them again. (see also https://github.com/apache/cordova-lib/blob/master/cordova-common/src/ConfigChanges/ConfigChanges.js#L365). So, I suppose, that we needn't release cordova-common before platform release.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thank you!
Could you update the code so that it passes for node@0.x (as we a still supporting it)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daserge, i think this condition has been moved to line 50

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" />');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add checks for capabilities count back - they could prevent situation when we have something extraneous.
expect(windows81AppxManifest.parents['/Parent/Capabilities'][0].count).toBe(3);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daserge, done.

@vladimir-kotikov
Copy link
Member

Do I get it right that it will require us to release cordova-common before platform release?

@matrosov-nikita, I think the idea was to make it so updated cordova-windows will continue to work w/ current cordova-common, right?

@matrosov-nikita
Copy link
Contributor Author

@vladimir-kotikov, yes, you are right. Have you any questions or concerns about this matter?

@@ -187,12 +187,14 @@ describe('generate_plugin_config_munge for windows project', function() {
// 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'][1].count).toBe(2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matrosov-nikita is this a right element to check count?
Should not it be expect(windows81AppxManifest.parents['/Parent/Capabilities'].count).toBe(4);?
I know it was this way in the original code, but it just looks strange.

@daserge
Copy link
Contributor

daserge commented Nov 14, 2016

Also, @matrosov-nikita could you please create a Jira issue for tracking (http://issues.cordova.io), rename the PR title and add the commit prefix?

* @return {[Object]} plugin's munge
*/
PlatformMunger.prototype.generate_plugin_config_munge = function (pluginInfo, vars, edit_config_changes) {
var self = this;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to be requried - calling a prototype is not a closure so you can safely use this

*/
function PluginInfo(dirname) {
CommonPluginInfo.apply(this, arguments);
var parentGetConfigFiles = this.getConfigFiles;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than saving this into a variable i'd propose to call ThisClass.super_.prototype.generate_plugin_config_munge method directly

var parentGetConfigFiles = this.getConfigFiles;
this.getConfigFiles = function(platform) {
var changes = parentGetConfigFiles(platform);
var editChanges = this.getEditConfigs(platform);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that we should do something with <edit-config> tags here. You'd probably need to override parent getEditConfigs method in a same way as getConfigFiles possibly sharing the similar logic between them.

}
// Demux 'package.appxmanifest' into relevant platform-specific appx manifests.
// Only spend the cycles if there are version-specific plugin settings
if (changes.some(function(change) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: could you please invert if condition here? Also it might be more convenient to assign this condition to intermediate variable, something like var hasManifestChanges = changes.some(function(change) { return change.target === 'package.appxmanifest' })

// Demux 'package.appxmanifest' into relevant platform-specific appx manifests.
// Only spend the cycles if there are version-specific plugin settings
if (changes.some(function(change) {
return change.target === 'package.appxmanifest';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daserge, i think this condition has been moved to line 50

changes = changes.concat(substs.map(function(subst) {
return Object.assign({}, change, {target: subst});
}));
return changes;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: you can just return here - result of this function is not used anywhere

In addition it overrides getConfigFiles method to use windows-specific logic
*/
function PluginInfo(dirname) {
CommonPluginInfo.apply(this, arguments);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls add a comment, clarifying why you're not using util.inherit to build a children class

var oldChanges = changes;
changes = [];

oldChanges.forEach(function(change, changeIndex) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A general comment - can you please divide this function into smaller pieces, so it'd be easier to review and test?

@codecov-io
Copy link

codecov-io commented Nov 14, 2016

Current coverage is 75.28% (diff: 100%)

Merging #207 into master will increase coverage by 0.63%

@@             master       #207   diff @@
==========================================
  Files            15         16     +1   
  Lines          2067       2120    +53   
  Methods         390        401    +11   
  Messages          0          0          
  Branches        403        410     +7   
==========================================
+ Hits           1543       1596    +53   
  Misses          524        524          
  Partials          0          0          

Powered by Codecov. Last update 541c451...ba22817

@matrosov-nikita matrosov-nikita changed the title Move windows-specific logic from cordova-common CB-12142: Move windows-specific logic from cordova-common Nov 14, 2016
@matrosov-nikita
Copy link
Contributor Author

@vladimir-kotikov @daserge, I've created a Jira issue: https://issues.apache.org/jira/browse/CB-12142, fixed all your comments. Also I think it would be better to add prefix to commit after squashing. Pls, review.

return processChanges(configFiles);
};

function processChanges(changes) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to move this out of PluginInfo - this way it'd be possible to use this function in tests (using rewire)

return changes;
}

function checkManifestChanges(changes) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're calling this only once - is there a real need to wrap this into function?

return change.target === 'package.appxmanifest';
});
}
function hasChangeVersion(change) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

return (typeof change.versions !== 'undefined');
}

function hasChangeTarget(change) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

}

var targetDeviceSet = getDeviceTargetSetForChange(change);
changes = replaceChangeTarget(targetDeviceSet, change, changes);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming replaceChangeTarget to something more appropriate as it doesn't really replace anything in the original array


// This is a local function that creates the new replacement representing the
// mutation. Used to save code further down.
function createReplacement(manifestFile, originalChange) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very similar to createChangeWithNewTarget function - consider merging into one function

@matrosov-nikita matrosov-nikita force-pushed the remove-windows-logic branch 11 times, most recently from 87d886a to 600ac0b Compare November 16, 2016 11:41
This logic is associated with demuxing 'package.appxmanifest' into relevant platform-specific appx manifests. Also auto-test was moved and edited according changes
@matrosov-nikita matrosov-nikita force-pushed the remove-windows-logic branch 3 times, most recently from 034a6b3 to 519016f Compare November 17, 2016 11:13
@vladimir-kotikov
Copy link
Member

Looks good. Let's wait for tomorrow and merge it.

@asfgit asfgit closed this in dacf70e Nov 18, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants