Skip to content

Commit 2b7ac8b

Browse files
committed
Update configuration description and add regression tests
Document the \${...} escape syntax in the ChangePluginConfiguration @option description so users know how to pass literal Maven property references. Add regression tests to ensure existing behavior is preserved: - Unresolved placeholders are left as-is - Normal resolution still works - Backslashes not before a placeholder prefix are preserved
1 parent 7534309 commit 2b7ac8b

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

rewrite-core/src/test/java/org/openrewrite/internal/PropertyPlaceholderHelperTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,31 @@ void mixedEscapedAndResolvedPlaceholders() {
112112
assertThat(s).isEqualTo("hello ${java.version}");
113113
}
114114

115+
@Test
116+
void unresolvedPlaceholderLeftAsIs() {
117+
var helper = new PropertyPlaceholderHelper("${", "}", null);
118+
var s = helper.replacePlaceholders("${unresolved}", k -> null);
119+
assertThat(s).isEqualTo("${unresolved}");
120+
}
121+
122+
@Test
123+
void normalResolutionStillWorks() {
124+
var helper = new PropertyPlaceholderHelper("${", "}", null);
125+
var s = helper.replacePlaceholders("${greeting} ${name}", k -> switch (k) {
126+
case "greeting" -> "hello";
127+
case "name" -> "world";
128+
default -> null;
129+
});
130+
assertThat(s).isEqualTo("hello world");
131+
}
132+
133+
@Test
134+
void backslashNotBeforePrefixIsPreserved() {
135+
var helper = new PropertyPlaceholderHelper("${", "}", null);
136+
var s = helper.replacePlaceholders("path\\to\\file", k -> null);
137+
assertThat(s).isEqualTo("path\\to\\file");
138+
}
139+
115140
@Test
116141
void withValueSeparatorAndNullReplacement() {
117142
var helper = new PropertyPlaceholderHelper("%%{", "}", ",");

rewrite-maven/src/main/java/org/openrewrite/maven/ChangePluginConfiguration.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ public class ChangePluginConfiguration extends Recipe {
5050
@Option(displayName = "Configuration",
5151
description = "Plugin configuration provided as raw XML overriding any existing configuration. " +
5252
"Configuration inside `<executions>` blocks will not be altered. " +
53-
"Supplying `null` will remove any existing configuration.",
53+
"Supplying `null` will remove any existing configuration. " +
54+
"To include a literal `${...}` property reference in the configuration " +
55+
"(e.g. a Maven property like `${java.version}`), escape it as `\\${...}` " +
56+
"in your recipe YAML to prevent it from being resolved as a recipe placeholder.",
5457
example = "<foo>bar</foo>",
5558
required = false)
5659
@Nullable

0 commit comments

Comments
 (0)