Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Gradle Args parsing #1606

Merged
merged 3 commits into from
Apr 22, 2023
Merged

fix: Gradle Args parsing #1606

merged 3 commits into from
Apr 22, 2023

Conversation

breautek
Copy link
Contributor

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 #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

  • Re-ordered the gradle argument array creation so that options appears before the task.
  • Corrected tests who assumed the task will appear at index 0. Tasks will always appear at the end of the array now and have been updated accordingly with that specific expectation.
  • Added a dependency to string-argv. nopt does not fit here because it expects that you know what your CLI arguments are. However since these arguments are gradle arguments, it's better if we can parse them and pass them through. This package handles quotations and such to ensure a proper argv array is created.

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

  • I've run the tests to see all new and existing tests pass
  • I added automated test coverage as appropriate for this change
  • Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • I've updated the documentation if necessary

@breautek breautek added the bug label Apr 21, 2023
@breautek breautek added this to the 12.0.0 milestone Apr 21, 2023
@breautek breautek requested review from dpogue and erisu April 21, 2023 18:59
@codecov-commenter
Copy link

codecov-commenter commented Apr 21, 2023

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%) ⬆️
lib/builders/ProjectBuilder.js 71.87% <100.00%> (+2.25%) ⬆️

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

Copy link
Member

@dpogue dpogue left a comment

Choose a reason for hiding this comment

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

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.

Copy link
Member

@erisu erisu left a comment

Choose a reason for hiding this comment

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

Just a nitpik but, looks good to me.

lib/build.js Outdated Show resolved Hide resolved
lib/build.js Outdated Show resolved Hide resolved
@breautek
Copy link
Contributor Author

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.

@breautek breautek requested a review from dpogue April 22, 2023 17:01
@breautek breautek merged commit 3343c3b into apache:master Apr 22, 2023
breautek added a commit to breautek/cordova-android that referenced this pull request Oct 21, 2023
* fix: Gradle Args parsing

* refactor: Applied ARGVParser.parseArgsStringToArgv -> parseArgsStringToArgv suggestion

* test: Added deeper testing for gradle argument parsing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

--gradleArg=--stacktrace does not appear to work
4 participants