You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by no...@apache.org on 2020/06/18 12:58:28 UTC
[cordova-android] branch master updated: fix: Plugin install fails
when preview sdk is installed (#985)
This is an automated email from the ASF dual-hosted git repository.
normanbreau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-android.git
The following commit(s) were added to refs/heads/master by this push:
new 8d8600b fix: Plugin install fails when preview sdk is installed (#985)
8d8600b is described below
commit 8d8600b442a5c98959317b665a5b5e157620ccb4
Author: Norman Breau <no...@normanbreau.com>
AuthorDate: Thu Jun 18 09:58:14 2020 -0300
fix: Plugin install fails when preview sdk is installed (#985)
---
bin/templates/cordova/lib/android_sdk.js | 19 ++++++++-----------
spec/unit/android_sdk.spec.js | 17 ++++++++++++-----
2 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/bin/templates/cordova/lib/android_sdk.js b/bin/templates/cordova/lib/android_sdk.js
index 2ab843d..963d7f1 100755
--- a/bin/templates/cordova/lib/android_sdk.js
+++ b/bin/templates/cordova/lib/android_sdk.js
@@ -29,17 +29,14 @@ var suffix_number_regex = /(\d+)$/;
// the number at the end, the more recent the target, the closer to the
// start of the array.
function sort_by_largest_numerical_suffix (a, b) {
- var suffix_a = a.match(suffix_number_regex);
- var suffix_b = b.match(suffix_number_regex);
- if (suffix_a && suffix_b) {
- // If the two targets being compared have suffixes, return less than
- // zero, or greater than zero, based on which suffix is larger.
- return (parseInt(suffix_a[1]) > parseInt(suffix_b[1]) ? -1 : 1);
- } else {
- // If no suffix numbers were detected, leave the order as-is between
- // elements a and b.
- return 0;
- }
+ let suffix_a = a.match(suffix_number_regex);
+ let suffix_b = b.match(suffix_number_regex);
+ // If no number is detected (eg: preview version like android-R),
+ // designate a suffix of 0 so it gets moved to the end
+ suffix_a = suffix_a || ['0', '0'];
+ suffix_b = suffix_b || ['0', '0'];
+ // Return < zero, or > zero, based on which suffix is larger.
+ return (parseInt(suffix_a[1]) > parseInt(suffix_b[1]) ? -1 : 1);
}
module.exports.print_newest_available_sdk_target = function () {
diff --git a/spec/unit/android_sdk.spec.js b/spec/unit/android_sdk.spec.js
index 6cf77c2..346bca9 100644
--- a/spec/unit/android_sdk.spec.js
+++ b/spec/unit/android_sdk.spec.js
@@ -33,14 +33,21 @@ describe('android_sdk', () => {
describe('sort_by_largest_numerical_suffix', () => {
it('should return the newest version first', () => {
- const ids = ['android-24', 'android-19', 'android-27', 'android-23'];
- const sortedIds = ['android-27', 'android-24', 'android-23', 'android-19'];
+ const ids = ['android-P', 'android-24', 'android-19', 'android-27', 'android-23'];
+ const sortedIds = ['android-27', 'android-24', 'android-23', 'android-19', 'android-P'];
expect(ids.sort(android_sdk.__get__('sort_by_largest_numerical_suffix'))).toEqual(sortedIds);
});
- it('should return 0 (no sort) if one of the versions has no number', () => {
- const ids = ['android-27', 'android-P'];
- expect(android_sdk.__get__('sort_by_largest_numerical_suffix')(ids[0], ids[1])).toBe(0);
+ describe('should return release version over preview versions', () => {
+ it('Test #001', () => {
+ const ids = ['android-27', 'android-P'];
+ expect(android_sdk.__get__('sort_by_largest_numerical_suffix')(ids[0], ids[1])).toBe(-1);
+ });
+
+ it('Test #002', () => {
+ const ids = ['android-P', 'android-27'];
+ expect(android_sdk.__get__('sort_by_largest_numerical_suffix')(ids[0], ids[1])).toBe(1);
+ });
});
});
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org