Skip to content

Commit fa4e1c9

Browse files
committed
Work around PathUtils limitation for now
1 parent d1ebfb4 commit fa4e1c9

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/main/java/org/openrewrite/java/spring/PropertiesToKebabCase.java

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ public String getDisplayName() {
3636
@Override
3737
public String getDescription() {
3838
return "Normalize Spring properties to use lowercase and hyphen-separated syntax. " +
39-
"For example, changing `spring.main.showBanner` to `spring.main.show-banner`. " +
40-
"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), " +
41-
"`kebab-case` may be used in properties files and still be converted to configuration beans. " +
42-
"Note, an exception to this is the case of `@Value`, which is match-sensitive. For example, `@Value(\"${anExampleValue}\")` will not match `an-example-value`. " +
43-
"[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).";
39+
"For example, changing `spring.main.showBanner` to `spring.main.show-banner`. " +
40+
"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), " +
41+
"`kebab-case` may be used in properties files and still be converted to configuration beans. " +
42+
"Note, an exception to this is the case of `@Value`, which is match-sensitive. For example, `@Value(\"${anExampleValue}\")` will not match `an-example-value`. " +
43+
"[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).";
4444
}
4545

4646
@Override
@@ -62,20 +62,23 @@ public String getDescription() {
6262

6363
@Override
6464
public TreeVisitor<?, ExecutionContext> getVisitor() {
65-
return Preconditions.check(new FindSourceFiles("**/application*.{yml,yaml}"), new YamlIsoVisitor<ExecutionContext>() {
66-
@Override
67-
public Yaml.Mapping.Entry visitMappingEntry(Yaml.Mapping.Entry entry, ExecutionContext ctx) {
68-
Yaml.Mapping.Entry e = super.visitMappingEntry(entry, ctx);
69-
if (e.getKey() instanceof Yaml.Scalar) {
70-
String key = e.getKey().getValue();
71-
String asKebabCase = NameCaseConvention.LOWER_HYPHEN.format(key);
72-
if (!key.equals(asKebabCase)) {
73-
return e.withKey(((Yaml.Scalar) e.getKey()).withValue(asKebabCase));
65+
return Preconditions.check(Preconditions.or(
66+
new FindSourceFiles("**/application*.yml").getVisitor(),
67+
new FindSourceFiles("**/application*.yaml").getVisitor()),
68+
new YamlIsoVisitor<ExecutionContext>() {
69+
@Override
70+
public Yaml.Mapping.Entry visitMappingEntry(Yaml.Mapping.Entry entry, ExecutionContext ctx) {
71+
Yaml.Mapping.Entry e = super.visitMappingEntry(entry, ctx);
72+
if (e.getKey() instanceof Yaml.Scalar) {
73+
String key = e.getKey().getValue();
74+
String asKebabCase = NameCaseConvention.LOWER_HYPHEN.format(key);
75+
if (!key.equals(asKebabCase)) {
76+
return e.withKey(((Yaml.Scalar) e.getKey()).withValue(asKebabCase));
77+
}
78+
}
79+
return e;
7480
}
75-
}
76-
return e;
77-
}
78-
});
81+
});
7982
}
8083
}
8184

0 commit comments

Comments
 (0)