openrewrite / rewrite-spring

OpenRewrite recipes for Spring projects.
Apache License 2.0
241 stars 68 forks source link

Add relaxed binding support to `ChangeSpringPropertyKey` #552

Open liamjones opened 1 month ago

liamjones commented 1 month ago

What problem are you trying to solve?

Trying to migrate Spring properties set via relaxed binding environment variables during a Spring Boot upgrade migration.

Describe the solution you'd like

ChangeSpringPropertyValue seems to support finding the items via relaxed bindings: https://github.com/openrewrite/rewrite-spring/blob/196dc5f133b61eb56f8ab1c3150fffe68d6f2fd6/src/main/java/org/openrewrite/java/spring/ChangeSpringPropertyValue.java#L69 I'd like to see this support in ChangeSpringPropertyKey as well (which seems to be absent atm).

For example, in the Spring Boot 2.3 upgrade if I have an application.properties containing server.use-forward-headers=true it will currently migrate to server.forward-headers-strategy=true.

However, if I have the environment variable equivalent, SERVER_USEFORWARDHEADERS=true, in a .env file, docker-compose.yml, etc it will not currently be migrated to SERVER_FORWARDHEADERSTRATEGY=true

timtebeek commented 1 month ago

Hi @liamjones ; Yes makes sense, thanks! Would be good to replace those properties no matter if they're in a .properties file, .yml file or indeed referenced by their environment variable equivalent in other files.

We could continue down the path we already have in ChangeSpringPropertyValue, or potentially leverage the traits we're starting to add following https://github.com/openrewrite/rewrite/pull/4309 .

I'd welcome a draft PR that outlines the changes you're after in a unit test, and then from there how you'd map the keys we have now to environment variables following the rules outlined here. Once converted even a FIndAndReplaceText recipe might do the trick to start with.