@ammachado provided a very nice pull request to support adding Quarkus properties to config files.
This is awesome and solves part of the problem but one thing that we often have to deal with Quarkus updates is to actually rename a config property.
What problem are you trying to solve?
We would like to be able to rename a configuration property key in Quarkus config files, be they in YAML or .properties.
Currently, we are doing the following:
type: specs.openrewrite.org/v1beta/recipe
name: io.quarkus.updates.core.quarkus33.ApplicationProperties
recipeList:
- org.openrewrite.properties.ChangePropertyKey:
oldPropertyKey: quarkus.hibernate-search-orm.automatic-indexing.synchronization.strategy
newPropertyKey: quarkus.hibernate-search-orm.indexing.plan.synchronization.strategy
- org.openrewrite.properties.ChangePropertyKey:
oldPropertyKey: quarkus\.hibernate-search-orm\.(.+)\.automatic-indexing\.synchronization\.strategy
newPropertyKey: quarkus.hibernate-search-orm.$1.indexing.plan.synchronization.strategy
regex: true
preconditions:
- org.openrewrite.FindSourceFiles:
filePattern: "**/application*.properties"
#####
# Adjust properties in application.yml/yaml
#####
---
type: specs.openrewrite.org/v1beta/recipe
name: io.quarkus.updates.core.quarkus33.ApplicationYml
recipeList:
- org.openrewrite.yaml.ChangePropertyKey:
oldPropertyKey: quarkus.hibernate-search-orm.automatic-indexing.synchronization.strategy
newPropertyKey: quarkus.hibernate-search-orm.indexing.plan.synchronization.strategy
preconditions:
- org.openrewrite.FindSourceFiles:
filePattern: "**/application*.y*ml"
This example is interesting because it shows all the limitations of this approach:
- we have a recipe for .properties and a recipe for YAML. For each configuration property renaming, we need to do both
- renaming a configuration property in YAML actually doesn't work. In Quarkus, each
.
will need to be split in a separate YAML key as done in AddQuarkusProperty
. org.openrewrite.yaml.ChangePropertyKey
is generic and doesn't take into account this specificity
- some properties, such as this one, have a default entry
quarkus.hibernate-search-orm.automatic-indexing.synchronization.strategy
but can also be used as named entries such as quarkus.hibernate-search-orm."name of the persistence unit".indexing.plan.synchronization.strategy
. We handled it for properties but not for YAML. Note that I think it should be a separate recipe as it's impossible to know where the map key
part will be in the configuration property key: we need to pass this knowledge somehow to the recipe. Note that the map key is not always surrounded by quotes. As long as it doesn't contain any special characters, it's perfectly valid.
- we do not handle configuration profiles. Properties can be prefixed with profiles, such as
%dev.<the property>
, %dev,prod.<the property>
. In YAML, you would have a leading %dev:
key.
One other thing we might want to consider would be to also rename entries in .env
but we would need to clarify the rules to get from the configuration property to a matching env variable. I think we could do that in a separate step.
Describe the situation before applying the recipe
quarkus.hibernate-search-orm.automatic-indexing.synchronization.strategy=test
%dev.quarkus.hibernate-search-orm.automatic-indexing.synchronization.strategy=test
%dev,prod.quarkus.hibernate-search-orm.automatic-indexing.synchronization.strategy=test
quarkus.hibernate-search-orm."unitname".automatic-indexing.synchronization.strategy=test
%dev.quarkus.hibernate-search-orm."unitname".automatic-indexing.synchronization.strategy=test
Describe the situation after applying the recipe
quarkus.hibernate-search-orm.indexing.plan.synchronization.strategy=test
%dev.quarkus.hibernate-search-orm.indexing.plan.synchronization.strategy=test
%dev,prod.quarkus.hibernate-search-orm.indexing.plan.synchronization.strategy=test
quarkus.hibernate-search-orm."unitname".indexing.plan.synchronization.strategy=test
%dev.quarkus.hibernate-search-orm."unitname".indexing.plan.synchronization.strategy=test
For YAML, that would be the exact same thing with each part of the key split by .
(but ideally, we would need to be careful as you could have things like "my map key with a . dot"
).