Skip to content

Commit

Permalink
ChangeSpringPropertyKey no longer expands entire affected yaml (#272)
Browse files Browse the repository at this point in the history
* ChangeSpringPropertyKey no longer expands entire affected yaml

* test fix

Co-authored-by: Nick McKinney <[email protected]>
  • Loading branch information
nmck257 and Nick McKinney authored Jan 19, 2023
1 parent cfd91d8 commit f701dc0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,13 @@ protected List<SourceFile> visit(List<SourceFile> before, ExecutionContext ctx)
new org.openrewrite.properties.ChangePropertyKey(oldPropertyKey, newPropertyKey, true, null, false);
org.openrewrite.properties.ChangePropertyKey subpropertiesChangePropertyKey =
new org.openrewrite.properties.ChangePropertyKey(Pattern.quote(oldPropertyKey + ".") + exceptRegex() + "(.*)", newPropertyKey + ".$1", true, null, true);
ExpandProperties expandYaml = new ExpandProperties();
return ListUtils.map(before, s -> {
if (s instanceof Yaml.Documents) {
Yaml.Documents after = (Yaml.Documents) yamlChangePropertyKey.getVisitor().visit(s, ctx);
if (after != s) {
s = (Yaml.Documents) expandYaml.getVisitor().visit(after, ctx);
}
s = (Yaml.Documents) yamlChangePropertyKey.getVisitor().visit(s, ctx);
} else if (s instanceof Properties.File) {
s = (Properties.File) propertiesChangePropertyKey.getVisitor().visit(s, ctx);
s = (Properties.File) subpropertiesChangePropertyKey.getVisitor().visit(s, ctx);
}

return s;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ void changeLastKey() {
""",
"""
server:
servlet:
path: /tmp/my-server-path
servlet.path: /tmp/my-server-path
"""
)
);
Expand Down Expand Up @@ -75,10 +74,7 @@ void changePropertyPath() {
"""
server:
port: 8888
servlet:
session:
cookie:
path: /tmp/my-server-path
servlet.session.cookie.path: /tmp/my-server-path
"""
)
);
Expand Down Expand Up @@ -113,15 +109,14 @@ void subproperties() {
""",
"""
spring:
web:
resources:
chain:
strategy:
content:
enabled: true
paths:
- /foo/**
- /bar/**
web.resources:
chain:
strategy:
content:
enabled: true
paths:
- /foo/**
- /bar/**
"""
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ void activateOnProfileDoNotMoveActivate() {
active: dev
---
spring:
config:
activate:
on-profile: prod
config.activate.on-profile: prod
""",
s -> s.path("src/main/resources/application.yml")
)
Expand Down

0 comments on commit f701dc0

Please sign in to comment.