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

Improve UpgradeDependencyVersion to update dependency version whose value is defined via a property from the parent POM. #4214

Merged

Conversation

nguyenhoan
Copy link
Contributor

@nguyenhoan nguyenhoan commented May 24, 2024

What's changed?

Improve UpgradeDependencyVersion to update dependency version whose value is defined via a property from the parent POM.

What's your motivation?

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

Anyone you would like to review specifically?

@timtebeek

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

…alue is defined via a property from the parent POM.
@timtebeek timtebeek self-requested a review May 27, 2024 07:54
Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the quick work here @nguyenhoan ! It might take me some time to get to a review due to travel over the next two weeks, but at first glance it looks good.

I want to look in more detail though, as this is one of our most heavily used recipes, so I want to be sure we cover all cases correctly.

@nguyenhoan
Copy link
Contributor Author

Sure. Thanks!

@nguyenhoan
Copy link
Contributor Author

@timtebeek just wanted to check if you have an ETA for a full review of this PR? Thanks!

@timtebeek
Copy link
Contributor

Apologies @nguyenhoan ! Travel & catching up to what I've missed is taking a little longer than I had hoped; I plan to revisit this Monday. At first glance it's quality work; I just want to make sure there's no regressions given how often this recipe is used, and I'll have to update downstream use in tandem. Appreciate your patience & persistence in seeing this through!

@timtebeek timtebeek self-requested a review June 7, 2024 20:34
@nguyenhoan
Copy link
Contributor Author

Thanks @timtebeek! Please let me know if you need anything from me. Look forward to the release of this enhancement.

@nguyenhoan
Copy link
Contributor Author

@timtebeek just a gentle ping on when this can be merged. Thanks!

Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Finally found a moment to go over your PR in more detail. Two questions arose as I went through the code. Would you be able to look into those?

And thanks for your patience in all of the above; Really do appreciate the work; just a bit harder to wrap my head around a review with the changes that have gone in.

nguyenhoan and others added 2 commits June 20, 2024 22:34
… newer version and use it to update the property instead of using the version in the argument which could contain a dependency version selector pattern.
Comment on lines 148 to 154
ResolvedDependency d = findDependency(tag);
if (d != null && d.getRepository() != null) {
// if the resolved dependency exists AND it does not represent an artifact that was parsed
// as a source file, attempt to find a new version.
try {
String newerVersion = findNewerVersion(d.getVersion(),
() -> downloadMetadata(d.getGroupId(), d.getArtifactId(), ctx), versionComparator, ctx);
Copy link
Contributor

@timtebeek timtebeek Jun 24, 2024

Choose a reason for hiding this comment

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

Something I don't quite understand from looking over the code is that we appear to be looking at any dependency, not just dependencies whose groupId & artifactId match the one we're looking to upgrade. Am I reading that correctly?

Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Thanks so much for getting this started @nguyenhoan , and your patience as I had to wrap my head around the changes. I've added a few smaller changes, mostly to familiarize myself with the code, and to better accommodate changes I expect to work in next. Great addition, and neat to better support such minimal property bumps from now on.

@timtebeek timtebeek merged commit 26feaab into openrewrite:main Jun 24, 2024
2 checks passed
@nguyenhoan
Copy link
Contributor Author

Thank you for helping with this important enhancement and bringing it to the destination!

Could you please let me know when the relevant changes to other modules such as org.openrewrite.java.dependencies.UpgradeDependencyVersion in rewrite-java-dependencies are also merged and the new releases in tandem happen? Thanks!

@timtebeek
Copy link
Contributor

I've just opened a PR for rewrite-java-dependencies

We release snapshot versions every day, and new releases of all openrewrite recipe modules typically every two weeks. We previous release was last week; so then likely by next week there should be a release containing this improvement.

@nguyenhoan
Copy link
Contributor Author

Awesome! Thanks!

@nguyenhoan nguyenhoan deleted the UpgradeDependencyVersion-issue-4193 branch June 27, 2024 20:34
@timtebeek
Copy link
Contributor

Your change has just been released; thanks again!
https://github.com/openrewrite/rewrite/releases/tag/v8.29.0

@nguyenhoan
Copy link
Contributor Author

Yay! Thank you!

crankydillo pushed a commit to crankydillo/rewrite that referenced this pull request Jul 11, 2024
…alue is defined via a property from the parent POM. (openrewrite#4214)

* Improve UpgradeDependencyVersion to update dependency version whose value is defined via a property from the parent POM.

* Make `VersionComparator versionComparator` field to reduce the number of instantiations.

* Remove debugging code.

* Avoid using Java stream.

* Add tests to verify behavior with remote parent property

* Rename variable as suggested

* Inline single use of private method delegate

* Filter out `null` value instead of throwing exception. Store resolved newer version and use it to update the property instead of using the version in the argument which could contain a dependency version selector pattern.

* Update test to show we support version patterns too

* Limit property accumulation to matching dependencies

* Restore check that ResolvedDependency.getRepository() != null

* Do not look at managed or plugin dependency version properties yet

* Compare actual new version, not version pattern

* Break after finding the matching property

* Pull up `getPomDeclaringProperty` closer to usage

* Inline & document parent pom handling into `storeParentPomProperty`

---------

Co-authored-by: Hoan Nguyen <hoanamzn@amazon.com>
Co-authored-by: Tim te Beek <tim@moderne.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
3 participants