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

Pass in single recipe configuration options on the command line #816

Merged
merged 10 commits into from
Jul 24, 2024

Conversation

velo
Copy link
Contributor

@velo velo commented Jul 8, 2024

Use like this:

mvn org.openrewrite.maven:rewrite-maven-plugin:5.36.0-SNAPSHOT:run \
  -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-migrate-java:RELEASE \
  -Drewrite.activeRecipes=org.openrewrite.java.migrate.util.ReplaceStreamCollectWithToList  \
  -Drewrite.options=convertToList=true

@timtebeek timtebeek self-requested a review July 8, 2024 18:14
@timtebeek timtebeek added the enhancement New feature or request label Jul 8, 2024
@timtebeek
Copy link
Contributor

Thanks for getting this started! Would you happen to have an example of how the non-flat Map is assigned from the command line? I'm wondering how to test this properly. We'll likely start with incubating this, and potentially have to limit it to non-composite recipes, as larger composites can contain a single recipe multiple times, and not all recipes might have the same options. Right now it seems like we might set the same argument on all recipes?

@velo
Copy link
Contributor Author

velo commented Jul 9, 2024

From command line it wouldn't be possible, as maven don't parse complex types from command line.

Those can only be set as maven configuration on pom file

<options>
  <convertToList>true</convertToList>
</options>

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 to see this kicked off ; I've added two comments that I think we should address before a merge, but I'm also interested to hear your thoughts. Mostly I want to add this in such a way that we promote good practices, and not enable anti-patterns too much.

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.

I've gone ahead and applied the changes I suggested earlier @velo ; Hope you agree with the final form. I'll likely merge this tomorrow morning unless any blocking feedback comes in.

@timtebeek
Copy link
Contributor

This now works.

mvn org.openrewrite.maven:rewrite-maven-plugin:5.36.0-SNAPSHOT:run -Drewrite.activeRecipes=org.openrewrite.maven.RemovePlugin -Drewrite.options=groupId=org.springframework.boot,artifactId=spring-boot-maven-plugin

When run against the spring-petclinic it correctly removes only the argument plugin;
When a second recipe is activated, or a required option missing, we reject the recipe run.

Thanks to all involved!

@velo
Copy link
Contributor Author

velo commented Jul 23, 2024

This is awesome... I'm still shocked that maven can parse lists but can't maps

@timtebeek timtebeek changed the title Made possible to configure options on recipes Pass in single recipe configuration options on the command line Jul 23, 2024
timtebeek added a commit to openrewrite/rewrite that referenced this pull request Jul 24, 2024
* Do not wrap single active recipe & remove `activateAll()`

As discovered on openrewrite/rewrite-maven-plugin#816

* Add missing recipe descriptions

* Do not expect CompositeRecipe wrapper in data table row

* Return Recipe.noop() when there are no activated recipes

* Add missing test descriptions

* Further test fixes
@timtebeek timtebeek merged commit 7ecc255 into openrewrite:main Jul 24, 2024
1 check passed
@timtebeek
Copy link
Contributor

Thanks again @velo ! Hope this helps folks to do quick one-off configurable recipe runs.

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
Development

Successfully merging this pull request may close these issues.

Pass arguments from the command line into a single configurable recipe
2 participants