apache / cordova-android

Apache Cordova Android
https://cordova.apache.org/
Apache License 2.0
3.59k stars 1.52k forks source link

fix: Gradle Args parsing #1606

Closed breautek closed 1 year ago

breautek commented 1 year ago

Platforms affected

Android / Gradle Argument pass through

Motivation and Context

gradle expects a specific usage which Cordova doesn't conform to.

$ gradle --help

USAGE: gradle [option...] [task...]

Currently we append the gradle arguments at the end of the gradle argument list, but option arguments are suppose to appear before the task(s).

Closes https://github.com/apache/cordova-android/issues/1604

Additionally, while testing I also discovered that arguments that requires multiple values (e.g. --warning-mode all) doesn't get passed through properly, yielding an argument array that looks like:

[ "--warning-mode all" ]

when the expect array should look like:

[ "--warning-mode", "all" ]

Description

Testing

Ran npm test and manually tested in hello world app using commands such as:

cordova build android --minSdkVersion 30 -- --gradleArg="--stacktrace"

cordova build android --minSdkVersion 30 -- --gradleArg="--stacktrace --warning-mode all"

Checklist

codecov-commenter commented 1 year ago

Codecov Report

Merging #1606 (1421eff) into master (a62f699) will increase coverage by 0.78%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1606      +/-   ##
==========================================
+ Coverage   71.82%   72.61%   +0.78%     
==========================================
  Files          23       23              
  Lines        1796     1800       +4     
==========================================
+ Hits         1290     1307      +17     
+ Misses        506      493      -13     
Impacted Files Coverage Δ
lib/build.js 51.45% <100.00%> (+10.86%) :arrow_up:
lib/builders/ProjectBuilder.js 71.87% <100.00%> (+2.25%) :arrow_up:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

breautek commented 1 year ago

This looks okay to me.

It would maybe be good to have a test case that covered the splitting of gradleArgs into multiple extraArgs tokens.

I added a new build.spec.js unit test file since gradle argument parsing happens earlier than what ProjectBuilder.spec.js tests. I only added testing that was relevant in the PR but could probably be expanded further to match more closely to what run.spec.js does.

Added series of different test cases regarding using the --gradleArg flag and testing the parsed argv array, which would include the usage of nopt + string-argv third-party dependencies.