From bd0c8ce6398be2f3c005787dc383d4c98677b635 Mon Sep 17 00:00:00 2001 From: ebhsgit <48874658+ebhsgit@users.noreply.github.com> Date: Wed, 18 May 2022 14:10:15 +1000 Subject: [PATCH] [Android] Added support for BoM imports (#1311) * Added support for BoM imports https://docs.gradle.org/current/userguide/platforms.html#sub:bom_import Changes * propertiesObj.systemLibs regex - exclude the value contains ( * added propertiesObj.bomPlatforms - any value which matches platform("...") * Fix eslint style issues Co-authored-by: 8bhsolutions <48874658+8bhsolutions@users.noreply.github.com> --- lib/builders/ProjectBuilder.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/builders/ProjectBuilder.js b/lib/builders/ProjectBuilder.js index 98450254..d253e73e 100644 --- a/lib/builders/ProjectBuilder.js +++ b/lib/builders/ProjectBuilder.js @@ -140,7 +140,8 @@ class ProjectBuilder { return { libs: findAllUniq(data, /^\s*android\.library\.reference\.\d+=(.*)(?:\s|$)/mg), gradleIncludes: findAllUniq(data, /^\s*cordova\.gradle\.include\.\d+=(.*)(?:\s|$)/mg), - systemLibs: findAllUniq(data, /^\s*cordova\.system\.library\.\d+=(.*)(?:\s|$)/mg) + systemLibs: findAllUniq(data, /^\s*cordova\.system\.library\.\d+=((?!.*\().*)(?:\s|$)/mg), + bomPlatforms: findAllUniq(data, /^\s*cordova\.system\.library\.\d+=platform\((?:'|")(.*)(?:'|")\)/mg) }; } @@ -234,11 +235,24 @@ class ProjectBuilder { [/^\/?google\/google_play_services\/libproject\/google-play-services_lib\/?$/, 'com.google.android.gms:play-services:+'] ]; + propertiesObj.bomPlatforms.forEach(function (p) { + if (!/:.*:/.exec(p)) { + throw new CordovaError('Malformed BoM platform: ' + p); + } + + // Add bom platform + depsList += ' implementation platform("' + p + '")\n'; + }); + propertiesObj.systemLibs.forEach(function (p) { let mavenRef; // It's already in gradle form if it has two ':'s if (/:.*:/.exec(p)) { mavenRef = p; + } else if (/:.*/.exec(p)) { + // Support BoM imports + mavenRef = p; + events.emit('warn', 'Library expects a BoM package: ' + p); } else { for (let i = 0; i < SYSTEM_LIBRARY_MAPPINGS.length; ++i) { const pair = SYSTEM_LIBRARY_MAPPINGS[i];