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 build files parsing issues #4045

Merged
merged 1 commit into from
Mar 3, 2024
Merged

Conversation

thewolt
Copy link
Contributor

@thewolt thewolt commented Feb 24, 2024

What's changed?

Improved the groovy parser to support:

  • reference to FQNC like in the ProcessBuilder.Redirect.to(..) call
  • groovy xml node attribute manipulation like n.@conf = 'runtime->default;docs->docs;sources->sources'

What's your motivation?

I tried to use the ChangeDependency recipe on an old gradle build with lots of custom code

Anything in particular you'd like reviewers to focus on?

  • in GroovyTypeMapping#classType, in production i've encountered some ClassCastException where JavaType.Unknown cannot be casted to JavaType.Class but i was not able to reproduce in unit tests. I found that downcasting to JavaType.FullyQualified avoids the CCE and does not seem to break something else

Anyone you would like to review specifically?

Have you considered any alternatives or workarounds?

Any additional context

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@timtebeek
Copy link
Contributor

Thanks for diving in for a fix! Let us know when you'd consider this ready for review.

@thewolt thewolt force-pushed the main branch 2 times, most recently from 241ac97 to 05eb162 Compare February 26, 2024 16:09
@thewolt thewolt marked this pull request as ready for review February 26, 2024 16:09
@thewolt
Copy link
Contributor Author

thewolt commented Feb 26, 2024

I've got one question though... it seems that the issue i'm trying to fix is not related to the ChangeDependency recipe specifically but rather the gradle parser in general.

Is there a better place to put the test?

@timtebeek
Copy link
Contributor

Indeed looks like you're fixing a parser bug instead; that should help even more folks & cases, thanks! Might be easier to reproduce in a smaller test as seen in these tree test examples. Does that help?

@thewolt
Copy link
Contributor Author

thewolt commented Feb 27, 2024

Yes it absolutely helped. The tests have been successfully moved there and I may have found another bug when an inner class is imported.

The last thing is about the FIXME that i left in GroovyTypeMapping... it is a private method and the signature change does not seem to bother the two usages. Unfortunately I was not able to reproduce it in unit test. Does this change require a unit test ?

@timtebeek timtebeek requested a review from shanman190 February 27, 2024 11:02
@timtebeek
Copy link
Contributor

Glad to hear that helped! The new smaller tests look much cleaner indeed. I'm tagging Knut or Shannon for a review here, as they have more experience with the Groovy/Gradle parsers, and are more likely to spot any possible impact I might overlook. I'd think it's fine not to add the explicit test you mentioned if it's very awkward to trigger or test for, but perhaps they feel differently.

@thewolt
Copy link
Contributor Author

thewolt commented Feb 27, 2024

Build failed because:

Caused by:
                    org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not find org.openrewrite:rewrite-gradle:8.19.0-SNAPSHOT.
                    Searched in the following locations:
                      - file:/home/runner/.m2/repository/org/openrewrite/rewrite-gradle/8.19.0-SNAPSHOT/maven-metadata.xml
                      - file:/home/runner/.m2/repository/org/openrewrite/rewrite-gradle/8.19.0-SNAPSHOT/rewrite-gradle-8.19.0-SNAPSHOT.pom
                      - https://oss.sonatype.org/content/repositories/snapshots/org/openrewrite/rewrite-gradle/8.19.0-SNAPSHOT/maven-metadata.xml
                      - https://oss.sonatype.org/content/repositories/snapshots/org/openrewrite/rewrite-gradle/8.19.0-SNAPSHOT/rewrite-gradle-8.19.0-20240227.124952-11.pom
                      - https://repo.maven.apache.org/maven2/org/openrewrite/rewrite-gradle/8.19.0-SNAPSHOT/maven-metadata.xml
                      - https://repo.maven.apache.org/maven2/org/openrewrite/rewrite-gradle/8.19.0-SNAPSHOT/rewrite-gradle-8.19.0-SNAPSHOT.pom
                    Required by:
                        unspecified:unspecified:unspecified > org.openrewrite.gradle.tooling:plugin:2.1.0-SNAPSHOT:20240226.180904-8

It does not seem related to my change ...

@jkschneider jkschneider merged commit 8de6df1 into openrewrite:main Mar 3, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants