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

Creating "OR" preconditions instead of "AND" (#4003) does not actually work #4505

Conversation

DidierLoiseau
Copy link
Contributor

@DidierLoiseau DidierLoiseau commented Sep 20, 2024

What's changed?

Adds 2 failing tests using declarative recipes as preconditions.

Based on Creating "OR" preconditions instead of "AND", you should be able to use a declarative recipe as a precondition to combine recipes into an “or” clause, but it does not actually work.

Upon debugging, it appears that DeclarativeRecipe does not actually override getVisitor(), so when DeclarativeRecipe.getRecipeList() calls getVisitor() on the declarative recipe used as precondition, it just returns noop().

What's your motivation?

Be able to re-use a configured recipe as precondition for other recipes.

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

Anyone you would like to review specifically?

#4003 involved a discussion mostly between @timtebeek and @nmck257 who might be interested.

Have you considered any alternatives or workarounds?

Currently the only alternative is to repeat the predicate configuration, using only imperative recipes. If you need a disjunction of conditions, you will have to duplicate the whole recipe, but it may not always work.

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

Includes the example from the documentation.
@timtebeek
Copy link
Contributor

Very much appreciated! Had this in the back of my mind still, but didn't quite get to writing the tests and giving them a try. Indeed this ought to work as described, as that's a nice simplification where possible. Did you already explore what might be the cause? I wonder if the getRecipeList() is evaluated at all, or whether it's only looking at getVisitor()... 🤔

@timtebeek timtebeek self-requested a review September 20, 2024 10:10
@timtebeek timtebeek added the bug Something isn't working label Sep 20, 2024
@DidierLoiseau
Copy link
Contributor Author

Did you already explore what might be the cause? I wonder if the getRecipeList() is evaluated at all, or whether it's only looking at getVisitor()... 🤔

I did some debugging which I described in the "what changed" section. I don't know what would be an appropriate solution though. Did it ever work?

@timtebeek
Copy link
Contributor

Thanks a lot @DidierLoiseau ; I've pushed up a change that fixes the tests you've provided. 🙏🏻
Could you let me know if that aligns with what you were thinking?

@timtebeek timtebeek merged commit 7bc2966 into openrewrite:main Sep 20, 2024
2 checks passed
@DidierLoiseau
Copy link
Contributor Author

Amazing! Thanks for your reactivity as well!

I should be able to try it out next week. However, as I am using the Maven plugin from the command-line, and it seems I can’t override the version of the rewrite modules used by the plugin without adding it to the pom (I’m using it with -Drewrite.recipeArtifactCoordinates and my own library, which depends on the newer version). Is there a way to do that? Alternatively: would you mind releasing the plugin as well? 🙏

@timtebeek
Copy link
Contributor

I've just kicked off a build (not yet release) of the rewrite-maven-plugin: That should produce a snapshot version that uses the latest from openrewrite/rewrite. Ideally that's enough to try this out before the scheduled release next Wednesday. 🤞🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants