Skip to content

Commit

Permalink
fixes #432 (#434)
Browse files Browse the repository at this point in the history
Co-authored-by: Nick McKinney <[email protected]>
  • Loading branch information
nmck257 and Nick McKinney authored Sep 11, 2023
1 parent 894ae05 commit 4e5820b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public String getDescription() {
String newPropertyKey;

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

return new TreeVisitor<Tree, ExecutionContext>() {
@Override
Expand All @@ -80,7 +80,7 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
Tree newTree = propertiesChangePropertyKey.getVisitor().visit(tree, ctx);
// for compatibility with yaml syntax, a spring property key will never have both a (scalar) value and also subproperties
if (newTree == tree) {
newTree = (Properties.File) subpropertiesChangePropertyKey.getVisitor().visit(tree, ctx);
newTree = subpropertiesChangePropertyKey.getVisitor().visit(tree, ctx);
}
tree = newTree;
}
Expand Down
8 changes: 1 addition & 7 deletions src/main/resources/META-INF/rewrite/spring-boot-22.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ recipeList:
- org.openrewrite.java.spring.ChangeSpringPropertyKey:
oldPropertyKey: logging.file
newPropertyKey: logging.file.name
except: [ path ]
except: [ .+ ]
- org.openrewrite.java.spring.ChangeSpringPropertyKey:
oldPropertyKey: logging.path
newPropertyKey: logging.file.path
Expand Down Expand Up @@ -130,12 +130,6 @@ recipeList:
- org.openrewrite.java.spring.ChangeSpringPropertyKey:
oldPropertyKey: spring.reactor.stacktrace-mode.enabled
newPropertyKey: spring.reactor.debug-agent.enabled
- org.openrewrite.java.spring.ChangeSpringPropertyKey:
oldPropertyKey: logging.file
newPropertyKey: logging.file.name
- org.openrewrite.java.spring.ChangeSpringPropertyKey:
oldPropertyKey: logging.path
newPropertyKey: logging.file.path
- org.openrewrite.java.spring.ChangeSpringPropertyKey:
oldPropertyKey: management.endpoints.jmx.unique-names
newPropertyKey: spring.jmx.unique-names
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.Issue;
import org.openrewrite.test.RewriteTest;

import java.util.List;
Expand Down Expand Up @@ -199,4 +200,22 @@ void avoidRegenerativeChanges() {
);
}

@Issue("https://github.com/openrewrite/rewrite-spring/issues/432")
@Test
void loggingFileSubproperties() {
rewriteRun(
spec -> spec.recipeFromResources("org.openrewrite.java.spring.boot2.SpringBootProperties_2_2"),
properties("""
logging.file.max-size=10MB
logging.file.max-history=10
logging.path=${user.home}/some-folder
""","""
logging.file.max-size=10MB
logging.file.max-history=10
logging.file.path=${user.home}/some-folder
"""
)
);
}

}

0 comments on commit 4e5820b

Please sign in to comment.