From fa4e1c9c20d7373ea1d5d3bf1fdf44a29ab6c537 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Mon, 4 Dec 2023 13:24:57 +0100 Subject: [PATCH] Work around PathUtils limitation for now --- .../java/spring/PropertiesToKebabCase.java | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/openrewrite/java/spring/PropertiesToKebabCase.java b/src/main/java/org/openrewrite/java/spring/PropertiesToKebabCase.java index 32ce6b078..ea0e6a23a 100644 --- a/src/main/java/org/openrewrite/java/spring/PropertiesToKebabCase.java +++ b/src/main/java/org/openrewrite/java/spring/PropertiesToKebabCase.java @@ -36,11 +36,11 @@ public String getDisplayName() { @Override public String getDescription() { return "Normalize Spring properties to use lowercase and hyphen-separated syntax. " + - "For example, changing `spring.main.showBanner` to `spring.main.show-banner`. " + - "With [Spring's relaxed binding](https://docs.spring.io/spring-boot/docs/2.5.6/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding), " + - "`kebab-case` may be used in properties files and still be converted to configuration beans. " + - "Note, an exception to this is the case of `@Value`, which is match-sensitive. For example, `@Value(\"${anExampleValue}\")` will not match `an-example-value`. " + - "[The Spring reference documentation recommends using `kebab-case` for properties where possible](https://docs.spring.io/spring-boot/docs/2.5.6/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding)."; + "For example, changing `spring.main.showBanner` to `spring.main.show-banner`. " + + "With [Spring's relaxed binding](https://docs.spring.io/spring-boot/docs/2.5.6/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding), " + + "`kebab-case` may be used in properties files and still be converted to configuration beans. " + + "Note, an exception to this is the case of `@Value`, which is match-sensitive. For example, `@Value(\"${anExampleValue}\")` will not match `an-example-value`. " + + "[The Spring reference documentation recommends using `kebab-case` for properties where possible](https://docs.spring.io/spring-boot/docs/2.5.6/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding)."; } @Override @@ -62,20 +62,23 @@ public String getDescription() { @Override public TreeVisitor getVisitor() { - return Preconditions.check(new FindSourceFiles("**/application*.{yml,yaml}"), new YamlIsoVisitor() { - @Override - public Yaml.Mapping.Entry visitMappingEntry(Yaml.Mapping.Entry entry, ExecutionContext ctx) { - Yaml.Mapping.Entry e = super.visitMappingEntry(entry, ctx); - if (e.getKey() instanceof Yaml.Scalar) { - String key = e.getKey().getValue(); - String asKebabCase = NameCaseConvention.LOWER_HYPHEN.format(key); - if (!key.equals(asKebabCase)) { - return e.withKey(((Yaml.Scalar) e.getKey()).withValue(asKebabCase)); + return Preconditions.check(Preconditions.or( + new FindSourceFiles("**/application*.yml").getVisitor(), + new FindSourceFiles("**/application*.yaml").getVisitor()), + new YamlIsoVisitor() { + @Override + public Yaml.Mapping.Entry visitMappingEntry(Yaml.Mapping.Entry entry, ExecutionContext ctx) { + Yaml.Mapping.Entry e = super.visitMappingEntry(entry, ctx); + if (e.getKey() instanceof Yaml.Scalar) { + String key = e.getKey().getValue(); + String asKebabCase = NameCaseConvention.LOWER_HYPHEN.format(key); + if (!key.equals(asKebabCase)) { + return e.withKey(((Yaml.Scalar) e.getKey()).withValue(asKebabCase)); + } + } + return e; } - } - return e; - } - }); + }); } }