Skip to content

Commit 4e5820b

Browse files
nmck257Nick McKinney
andauthored
fixes #432 (#434)
Co-authored-by: Nick McKinney <[email protected]>
1 parent 894ae05 commit 4e5820b

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public String getDescription() {
5656
String newPropertyKey;
5757

5858
@Option(displayName = "Except",
59-
description = "If any of these property keys exist as direct children of `oldPropertyKey`, then they will not be moved to `newPropertyKey`.",
59+
description = "Regex. If any of these property keys exist as direct children of `oldPropertyKey`, then they will not be moved to `newPropertyKey`.",
6060
required = false)
6161
@Nullable
6262
List<String> except;
@@ -68,7 +68,7 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
6868
org.openrewrite.properties.ChangePropertyKey propertiesChangePropertyKey =
6969
new org.openrewrite.properties.ChangePropertyKey(oldPropertyKey, newPropertyKey, true, false);
7070
org.openrewrite.properties.ChangePropertyKey subpropertiesChangePropertyKey =
71-
new org.openrewrite.properties.ChangePropertyKey(Pattern.quote(oldPropertyKey + ".") + exceptRegex() + "(.*)", newPropertyKey + ".$1", true, true);
71+
new org.openrewrite.properties.ChangePropertyKey(Pattern.quote(oldPropertyKey + ".") + exceptRegex() + "(.+)", newPropertyKey + ".$1", true, true);
7272

7373
return new TreeVisitor<Tree, ExecutionContext>() {
7474
@Override
@@ -80,7 +80,7 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
8080
Tree newTree = propertiesChangePropertyKey.getVisitor().visit(tree, ctx);
8181
// for compatibility with yaml syntax, a spring property key will never have both a (scalar) value and also subproperties
8282
if (newTree == tree) {
83-
newTree = (Properties.File) subpropertiesChangePropertyKey.getVisitor().visit(tree, ctx);
83+
newTree = subpropertiesChangePropertyKey.getVisitor().visit(tree, ctx);
8484
}
8585
tree = newTree;
8686
}

src/main/resources/META-INF/rewrite/spring-boot-22.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ recipeList:
9090
- org.openrewrite.java.spring.ChangeSpringPropertyKey:
9191
oldPropertyKey: logging.file
9292
newPropertyKey: logging.file.name
93-
except: [ path ]
93+
except: [ .+ ]
9494
- org.openrewrite.java.spring.ChangeSpringPropertyKey:
9595
oldPropertyKey: logging.path
9696
newPropertyKey: logging.file.path
@@ -130,12 +130,6 @@ recipeList:
130130
- org.openrewrite.java.spring.ChangeSpringPropertyKey:
131131
oldPropertyKey: spring.reactor.stacktrace-mode.enabled
132132
newPropertyKey: spring.reactor.debug-agent.enabled
133-
- org.openrewrite.java.spring.ChangeSpringPropertyKey:
134-
oldPropertyKey: logging.file
135-
newPropertyKey: logging.file.name
136-
- org.openrewrite.java.spring.ChangeSpringPropertyKey:
137-
oldPropertyKey: logging.path
138-
newPropertyKey: logging.file.path
139133
- org.openrewrite.java.spring.ChangeSpringPropertyKey:
140134
oldPropertyKey: management.endpoints.jmx.unique-names
141135
newPropertyKey: spring.jmx.unique-names

src/test/java/org/openrewrite/java/spring/ChangeSpringPropertyKeyTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.junit.jupiter.api.Test;
1919
import org.openrewrite.DocumentExample;
20+
import org.openrewrite.Issue;
2021
import org.openrewrite.test.RewriteTest;
2122

2223
import java.util.List;
@@ -199,4 +200,22 @@ void avoidRegenerativeChanges() {
199200
);
200201
}
201202

203+
@Issue("https://github.com/openrewrite/rewrite-spring/issues/432")
204+
@Test
205+
void loggingFileSubproperties() {
206+
rewriteRun(
207+
spec -> spec.recipeFromResources("org.openrewrite.java.spring.boot2.SpringBootProperties_2_2"),
208+
properties("""
209+
logging.file.max-size=10MB
210+
logging.file.max-history=10
211+
logging.path=${user.home}/some-folder
212+
""","""
213+
logging.file.max-size=10MB
214+
logging.file.max-history=10
215+
logging.file.path=${user.home}/some-folder
216+
"""
217+
)
218+
);
219+
}
220+
202221
}

0 commit comments

Comments
 (0)