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

Question: Is there a way to Use something like Preconditions in getRecipeList-Method? #4711

Closed
Botschap opened this issue Nov 25, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Botschap
Copy link

Botschap commented Nov 25, 2024

I am using

  • OpenRewrite v8.38.2

I am trying to create a Recipe using Java-Code that adds Maven-Dependencies dependent on two conditions.

  1. is a company specific config set in a config-file
  2. is the dependency used in the current pom.xml

My Problem is that its not possible to use Preconditions in the getRecipeList()-Method of a Recipe but in the getVisitors()-Method where its not possible to return e.g. the AddDependency-Recipe but only its Visitor. That means the Scanning-Logic is never applied and the Recipe is not beheaving as expected.

Is there a Solution to this Problem or is our approach just the wrong one?

this is how the getVisitor()-Method works

Preconditions.check(
                        Preconditions.and(
                                
                                Preconditions.not(
                                        new FindKey("$.my_config").getVisitor()),
                                // Prüfung auf Vorhandensein der notw. Dependency
                                new FindDependency(groupId, artifactId, null,"").getVisitor()
                        ),

                        new AddDependency(
                              ....
                        ).getVisitor());

this is how I would like to use it

Preconditions.check(
                        Preconditions.and(
                                
                                Preconditions.not(
                                        new FindKey("$.my_config").getVisitor()),
                                // Prüfung auf Vorhandensein der notw. Dependency
                                new FindDependency(groupId, artifactId, null,"").getVisitor()
                        ),

                        new AddDependency(
                              ....
                        ));

Are you interested in contributing a fix to OpenRewrite?

@Botschap Botschap added the bug Something isn't working label Nov 25, 2024
@timtebeek
Copy link
Contributor

hi @Botschap ; Indeed the *RecipeList methods are not expected to be used with ScanningRecipes; I'll look towards making that explicit.

As for how to still achieve your goals; here's two example of delegating to two other recipes from one scanning recipe:

I hope seeing those examples helps you there; with that I think we can close this issue, but I'll monitor for any replies.

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
Archived in project
Development

No branches or pull requests

2 participants