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

AddParentPom recipe #4289

Merged
merged 21 commits into from
Jul 3, 2024
Merged

AddParentPom recipe #4289

merged 21 commits into from
Jul 3, 2024

Conversation

rcsilva83
Copy link
Contributor

Tests fail with "Recipe was expected to make a change but made no changes."

What's changed?

A new AddParentPom recipe is added.

What's your motivation?

I need to add a parent POM to my projects.

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

Discover why is the recipe making no changes (as stated by the tests) and how to better share code with ChangeParentPom recipe.

Anyone you would like to review specifically?

@timtebeek (as he invited me to make a draft PR on #4239)

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 timtebeek self-requested a review June 26, 2024 19:42
@timtebeek timtebeek added the recipe Requested Recipe label Jun 26, 2024
@timtebeek
Copy link
Contributor

Great start @rcsilva83 ! Thanks for kicking this off. I've pushed a change to your PR to get the tests running. You had overridden isAcceptable, but for the precondition check to work you'd need to instead override a visit method, and return a changed instance to trigger the guarded visitor. SearchResult.found does exactly that. Hope that helps you explore what the recipe actually should do, as it seemed you got stuck at this point.

@timtebeek timtebeek marked this pull request as draft June 26, 2024 21:00
@timtebeek timtebeek changed the title [WIP] Adding AddParentPom recipe AddParentPom recipe Jun 26, 2024
rcsilva83 and others added 7 commits June 27, 2024 17:53
Tests fail with "Recipe was expected to make a change but made no changes."
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
<parent> should come right after <modelVersion>
@rcsilva83
Copy link
Contributor Author

Hi @timtebeek !

Thank you very much for your help. The recipe is almost done: it's working but I still need to handle new parent's properties and dependency management.

However, I have some doubts:

  1. What to do when no versions are found when using wildcard version? (see line 152)
  2. Should I always search for version on Maven repository or should I bypass this when the version is fixed? From what I saw on other recipes this kind of optimization isn't done.

Regards!

@rcsilva83
Copy link
Contributor Author

I still need to handle new parent's properties and dependency management.

Actually, do you think is there anything to do on this regard? I though I needed to remove properties and dependency management declarations from the pom.xml if they exist on the new parent pom but I don't think that's the case. The ChangeParentPom recipe just add properties and dependency management declarations from the old parent pom, right?

If you can confirm this to me, I'll remove some unused code from the recipe and, after you feedback on the 2 questions I made before, it will be done.

@timtebeek
Copy link
Contributor

Thanks a lot @rcsilva83 ! To answer your questions I'll reply to each in a separate paragraph below.

In ChangeParentPom we seem to skip with no changes when no acceptable version is found. Probably best to be consistent then, even if it could make for a frustrating debugging experience when there are misconfigurations.

I wouldn't skip over validating the parent; we'd like to be sure the parent exists, since we'll use it to update the model of the code, and might otherwise lead to invalid configuration.

As for updating properties: I'd maybe only go as far as doing a doAfterVisit(new org.openrewrite.maven.RemoveRedundantDependencyVersions().getVisitor()); that clears out one of the major reasons to add a parent pom.xml; if there's more clean ups to be done then I suggest to similarly move those to separate recipes, such that there's less complexity in each, with the opportunity for reuse.

Is there anything else you'd then still like to push before a review and merge?

@rcsilva83
Copy link
Contributor Author

In ChangeParentPom we seem to skip with no changes when no acceptable version is found. Probably best to be consistent then, even if it could make for a frustrating debugging experience when there are misconfigurations.

I'll adjust this and make a new push. Then I think it'll be ready for merge :)

@rcsilva83
Copy link
Contributor Author

@timtebeek I need your help on a new problem. After changing the change to make no changes when no suitable version is found, I still got an empty <parent/> in the and, because it was added in the visitDocument method. I couldn't find a way to remove it, so I moved all the code to visitDocument method and removed visitTag method.

Everything is fine but apparently the doAfterVisit(new org.openrewrite.maven.RemoveRedundantDependencyVersions().getVisitor()) isn't working anymore and the versions matching with parent aren't being removed anymore.

How can I solve this? I couldn't find any situation like this in other recipes.

@timtebeek
Copy link
Contributor

All tests seem to pass; are we missing anything? Wondering because of your question above and the draft status. Ideally we have a failing test if there's anything to add still.

We're planning a new release tomorrow; let me know if this should make it in in the current form, or with small changes.

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.

Some initial feedback already, with a few questions that might lead to stripping out some functionality still.

@rcsilva83
Copy link
Contributor Author

Hi @timtebeek ! I'll take a look on you feedback and make the code changes needed. But I committed the failing tests I told before so you can understand the problem. I just solve them moving the code to visitDocument method but the RemoveRedundantDependencyVersions stopped working.

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.

Nice work here @rcsilva83 ! The reason RemoveRedundantDependencyVersions stopped working is because you had removed the call to maybeUpdateModel(). That ensures our model is aware of the Maven parent before we make subsequent changes.

I've applied a few more polishing commits, and with those I think we're ready to merge. Thanks again!

@timtebeek timtebeek marked this pull request as ready for review July 3, 2024 09:03
@timtebeek timtebeek merged commit 477d3df into openrewrite:main Jul 3, 2024
2 checks passed
@rcsilva83
Copy link
Contributor Author

@timtebeek, and I thank you for the guidance and patience! Now I know why OpenRewrite is improving so fast and have such a vibrant community :)

Regards!

@rcsilva83 rcsilva83 deleted the add-maven-parent branch July 3, 2024 16:38
@timtebeek
Copy link
Contributor

Thank you! Couldn't do it without so many folks pitching in. You're changes have already landed in
https://github.com/openrewrite/rewrite/releases/tag/v8.29.0
I'll follow up with downstream releases of recipe modules and the OpenRewrite plugins, culminating in our rewrite-recipe-bom over the next couple hours: https://github.com/openrewrite/rewrite-recipe-bom/releases

@timtebeek timtebeek linked an issue Jul 28, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
recipe Requested Recipe
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

"Add Maven Parent" recipe
2 participants