-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Allow Tooling API clients to invoke --help and --version
#35987
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
base: master
Are you sure you want to change the base?
Conversation
…rsion Signed-off-by: Ujwal Suresh Vanjare <[email protected]>
Signed-off-by: Ujwal Suresh Vanjare <[email protected]>
Signed-off-by: Ujwal Suresh Vanjare <[email protected]>
1c0baeb to
69eba30
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements support for --help, --version, and --show-version command-line arguments in the Tooling API by introducing a VersionHelpConsumerActionExecutor that intercepts these flags and handles them appropriately before build execution.
Key Changes:
- Introduced
VersionHelpConsumerActionExecutorto handle help and version flags in the Tooling API execution chain - Added
getConnectionParameters()method toConsumerOperationParametersfor parameter access - Updated test preconditions from
GradleBuildJvmSpecAvailabletoJdk17Availablefor consistency
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
platforms/ide/tooling-api/src/main/java/org/gradle/tooling/internal/consumer/connection/VersionHelpConsumerActionExecutor.java |
New executor that intercepts --help, --version, and --show-version arguments and handles them by querying Help or BuildEnvironment models |
platforms/ide/tooling-api/src/main/java/org/gradle/tooling/internal/consumer/ConnectionFactory.java |
Integrates the new VersionHelpConsumerActionExecutor into the connection chain |
platforms/ide/tooling-api/src/main/java/org/gradle/tooling/internal/consumer/parameters/ConsumerOperationParameters.java |
Adds getter method for accessing connection parameters |
platforms/ide/tooling-api/src/test/groovy/org/gradle/tooling/internal/consumer/connection/VersionHelpConsumerActionExecutorTest.groovy |
Unit tests for the new executor covering delegation, help output, version output, and show-version scenarios |
platforms/ide/tooling-api/src/crossVersionTest/groovy/org/gradle/integtests/tooling/r940/VersionHelpConsumerCrossVersionSpec.groovy |
Cross-version integration tests verifying behavior across Gradle versions |
testing/smoke-test/src/smokeTest/groovy/org/gradle/smoketests/GradleBuildToolingApiSmokeTest.groovy |
Smoke tests validating the functionality in real-world scenarios |
testing/smoke-test/src/smokeTest/groovy/org/gradle/smoketests/AbstractGradleceptionSmokeTest.groovy |
Updates test precondition and fixes path separator handling for Windows compatibility |
testing/smoke-test/src/testFixtures/groovy/org/gradle/test/preconditions/SmokeTestPreconditions.groovy |
Adds new Jdk17Available precondition for smoke tests |
testing/internal-testing/src/main/resources/valid-precondition-combinations.csv |
Registers the new precondition combination as valid |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thank you for your proposed contribution! This PR has a valid DCO and tests. The relevant team for this area will confirm the design of the implementation choices. @usv240 Even before the team looks at this, could you make sure that |
Signed-off-by: Ujwal Suresh Vanjare <[email protected]>
|
@bot-gradle test ACT |
This comment has been minimized.
This comment has been minimized.
|
The following builds have passed: |
|
|
||
| @ToolingApiVersion(">=9.4.0") | ||
| @TargetGradleVersion(">=9.4.0") | ||
| class VersionHelpConsumerCrossVersionSpec extends ToolingApiSpecification { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Please separate the coverage for help and version-related coverage intoto two related test classes.
| @TargetGradleVersion(">=9.4.0") | ||
| class VersionHelpConsumerCrossVersionSpec extends ToolingApiSpecification { | ||
|
|
||
| def "prints version info and ignores tasks when --version is present"() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Missing test coverage for old target Gradle versions.
| class VersionHelpConsumerCrossVersionSpec extends ToolingApiSpecification { | ||
|
|
||
| def "prints version info and ignores tasks when --version is present"() { | ||
| def output = new ByteArrayOutputStream() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an existing result.output property available in this class. You can define assertions on that.
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| public class VersionHelpConsumerActionExecutor implements ConsumerActionExecutor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Although this kind of works, I find it quite hack-ish. I've spent quite some time and looked into the details. The main problem is that this ActionExecutor intercepts the TAPI requests at the wrong abstraction level: outside of where the project connection is available.
The main issue is that here we don't know anything about the provider side (ie the target Gradle distribution). Currently it seems sufficient that we simply catch the exception when an unsupported Gradle version is being used. At the same time, the plan is to backport the --help and the --version rendering for older Gradle versions that is impossible here.
I propose the following: move the interception logic into org.gradle.tooling.internal.consumer.connection.AbstractConsumerConnection.
- Maybe extract the interception logic to a subclass between
AbstractConsumerConnectionand it's existing immediate subclass. - There, you have access to
VersionDetailswhich you can use to separate the supported/unsupported cases. - You can do the interceptions only for task execution.
- For model loading, launching tests you could look into how to improve existing functionality
- Don't fail model loading/test execution when
--helpor--versionis listed as arguments - Instead emit a warning that the argument list was cleaned up.
- Don't fail model loading/test execution when
Later (in a separate PR) we can add static content for older Gradle versions in the new ConsumerConnection class.
| IntegTestPreconditions$Java21HomeAvailable,IntegTestPreconditions$Java17HomeAvailable,IntegTestPreconditions$NotEmbeddedExecutor | ||
| UnitTestPreconditions$NotAlpine | ||
| UnitTestPreconditions$NotWindows,UnitTestPreconditions$NotAlpine | ||
| SmokeTestPreconditions$Jdk17Available,UnitTestPreconditions$Jdk9OrLater,IntegTestPreconditions$NotConfigCached |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 Seems unrelated
| ].combinations() | ||
| } | ||
|
|
||
| def "can run with --version"() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ We probably don't need this. The cross-version coverage is quite enough.
|
|
||
| class SmokeTestPreconditions { | ||
|
|
||
| static class Jdk17Available implements TestPrecondition { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
--help and --version
…nection and split tests Signed-off-by: Ujwal Suresh Vanjare <[email protected]>
e4b3487 to
83a7631
Compare
|
Hi @donat , |
donat
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused now. The last commit on this PR removed the behavior that we expect:
If the user runs the build with --help or --version the tasks should be ignored and the corresponding help or version info should be printed on the console.
Please restore that behavior.
- Added handleHelpOrVersion() to intercept flags for task execution - Removed flags with warning for model/test operations - Implemented help precedence over version flags - Fixed entry point requirement in model parameter builder - Updated tests with correct expectations and precedence coverage Addresses review feedback from @donat. Fixes gradle#14116 Signed-off-by: Ujwal Suresh Vanjare <[email protected]>
|
Hi @donat Fixed now with the complete implementation. All your feedback has been addressed. |
Fixes #14116
Context
This PR implements support for
--help,--version, and--show-versioncommand-line arguments in the Tooling API.Previously, providing these arguments via
longRunningOperation.withArguments(...)would often fail (e.g., "Task not found" errors) or be ignored because the Tooling API treated the request as a standard build execution rather than a meta-information request.Implementation Details:
VersionHelpConsumerActionExecutorto the connection chain.--help,--version, or--show-versionare detected.Helpmodel (for--help) orBuildEnvironmentmodel (for--version) to generate the correct output.--show-version, it prints the version information and then proceeds with the original build action.Contributor Checklist
<subproject>/src/integTest) to verify changes from a user perspective.<subproject>/src/test) to verify logic../gradlew sanityCheck../gradlew :tooling-api:quickTest.