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

Expose AddOrUpdateChild as a recipe using XPath + child XML #4533

Merged

Conversation

DidierLoiseau
Copy link
Contributor

@DidierLoiseau DidierLoiseau commented Sep 28, 2024

What's changed?

Simple XML recipe that can add or update a child below the element(s) selected by XPath.

What's your motivation?

Provide more flexible ways of updating XML/pom files. In our specific case we need to configure openapi-generator-maven-plugin with <useJakartaEe>true</useJakartaEe> when it matches <generatorName>spring</generatorName>, following JavaxMigrationToJakarta (once this PR is merged, maybe it could be included there).

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

I had considered offering the option to add the child even when it already exists, but that wouldn’t be idempotent. I implemented an option to not replace the child in such a case, disabled by default.

I based this branch on top of #4532 so the former should be merged first and it’s not needed to review the changes on XPath implementation. I just wanted to use the XPath fixes in the tests of this new recipe.

Have you considered any alternatives or workarounds?

I don’t think any other equivalent recipe exists. ChangePluginConfiguration only allows to override the whole configuration.

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

@DidierLoiseau DidierLoiseau force-pushed the feat/add-or-update-child-tag-recipe branch 3 times, most recently from 94afcd4 to 00bba0a Compare September 28, 2024 21:20
@DidierLoiseau DidierLoiseau force-pushed the feat/add-or-update-child-tag-recipe branch from 00bba0a to 1ab9aab Compare September 28, 2024 21:48
@DidierLoiseau DidierLoiseau force-pushed the feat/add-or-update-child-tag-recipe branch from 325e2b8 to 11279d7 Compare September 30, 2024 07:57
@DidierLoiseau DidierLoiseau force-pushed the feat/add-or-update-child-tag-recipe branch from 11279d7 to ba2bbb4 Compare September 30, 2024 11:23
@sambsnyd sambsnyd merged commit c307b31 into openrewrite:main Oct 4, 2024
2 checks passed
@sambsnyd
Copy link
Member

sambsnyd commented Oct 4, 2024

Thanks @DidierLoiseau !

@DidierLoiseau
Copy link
Contributor Author

Thanks for merging @sambsnyd

I based this branch on top of #4532 so the former should be merged first

Sorry it seems I wrote former instead of latter there, so when you merged #4532 afterwards it created an empty commit, and c307b31 includes the changes of both 😕

@DidierLoiseau DidierLoiseau deleted the feat/add-or-update-child-tag-recipe branch October 16, 2024 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants