Skip to content

Commit d12300e

Browse files
authored
Merge branch 'main' into stats-issue-4876
2 parents e739361 + 34e4aa8 commit d12300e

File tree

20 files changed

+300
-174
lines changed

20 files changed

+300
-174
lines changed

rewrite-core/src/main/java/org/openrewrite/internal/ListUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public static <T> List<T> insert(@Nullable List<T> ls, @Nullable T t, int index)
350350
* @return A new list with expanded or modified elements, or the original list if unchanged.
351351
*/
352352
@Contract("null, _ -> null; !null, _ -> !null")
353-
public static <T> @Nullable List<T> flatMap(@Nullable List<T> ls, Function<T, Object> flatMap) {
353+
public static <T> @Nullable List<T> flatMap(@Nullable List<T> ls, Function<T, @Nullable Object> flatMap) {
354354
return flatMap(ls, (i, t) -> flatMap.apply(t));
355355
}
356356

rewrite-core/src/main/java/org/openrewrite/internal/PropertyPlaceholderHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ protected String parseStringValue(String value, Function<String, @Nullable Strin
121121
}
122122

123123
// Proceed with unprocessed value.
124-
startIndex = result.indexOf(placeholderPrefix, endIndex + placeholderSuffix.length());
124+
startIndex = result.indexOf(placeholderPrefix, endIndex);
125125
visitedPlaceholders.remove(originalPlaceholder);
126126
} else {
127127
startIndex = -1;

rewrite-core/src/main/java/org/openrewrite/text/PlainText.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@
4343
@Value
4444
@Builder
4545
@AllArgsConstructor(access = AccessLevel.PRIVATE)
46+
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
4647
public class PlainText implements SourceFileWithReferences, Tree, RpcCodec<PlainText> {
4748

4849
@Builder.Default
4950
@With
51+
@EqualsAndHashCode.Include
5052
UUID id = Tree.randomId();
5153

5254
@With

rewrite-core/src/test/java/org/openrewrite/config/DeclarativeRecipeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ void maxCyclesNested() {
372372
)
373373
);
374374
rewriteRun(
375-
spec -> spec.recipe(root).cycles(10).cycles(3).expectedCyclesThatMakeChanges(3),
375+
spec -> spec.recipe(root).cycles(10).cycles(3).expectedCyclesThatMakeChanges(2),
376376
text("1", "1+1+1")
377377
);
378378
assertThat(cycleCount).hasValue(3);

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

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,40 @@
2222
class PropertyPlaceholderHelperTest {
2323

2424
@Test
25-
void dashed() {
25+
void nested() {
26+
var helper = new PropertyPlaceholderHelper("%%{", "}", null);
27+
var s = helper.replacePlaceholders("%%{%%{k1}}", k -> switch (k) {
28+
case "k1" -> "k2";
29+
case "k2" -> "jon";
30+
default -> throw new UnsupportedOperationException();
31+
});
32+
assertThat(s).isEqualTo("jon");
33+
}
34+
35+
@Test
36+
void notOnlyPlaceholders() {
37+
var helper = new PropertyPlaceholderHelper("%%{", "}", null);
38+
var s = helper.replacePlaceholders("Oh, %%{k1} there %%{k2}!", k -> switch (k) {
39+
case "k1" -> "hi";
40+
case "k2" -> "jon";
41+
default -> throw new UnsupportedOperationException();
42+
});
43+
assertThat(s).isEqualTo("Oh, hi there jon!");
44+
}
45+
46+
@Test
47+
void dashedSeparation() {
48+
var helper = new PropertyPlaceholderHelper("%%{", "}", null);
49+
var s = helper.replacePlaceholders("%%{k1}-%%{k2}", k -> switch (k) {
50+
case "k1" -> "hi";
51+
case "k2" -> "jon";
52+
default -> throw new UnsupportedOperationException();
53+
});
54+
assertThat(s).isEqualTo("hi-jon");
55+
}
56+
57+
@Test
58+
void spaceSeparation() {
2659
var helper = new PropertyPlaceholderHelper("%%{", "}", null);
2760
var s = helper.replacePlaceholders("%%{k1} %%{k2}", k -> switch (k) {
2861
case "k1" -> "hi";
@@ -31,4 +64,39 @@ void dashed() {
3164
});
3265
assertThat(s).isEqualTo("hi jon");
3366
}
67+
68+
@Test
69+
void noSeparation() {
70+
var helper = new PropertyPlaceholderHelper("%%{", "}", null);
71+
var s = helper.replacePlaceholders("%%{k1}%%{k2}", k -> switch (k) {
72+
case "k1" -> "hi";
73+
case "k2" -> "jon";
74+
default -> throw new UnsupportedOperationException();
75+
});
76+
assertThat(s).isEqualTo("hijon");
77+
}
78+
79+
@Test
80+
void withValueSeparatorAndValueReplacement() {
81+
var helper = new PropertyPlaceholderHelper("%%{", "}", ",");
82+
var s = helper.replacePlaceholders("%%{k1,oh} %%{k2}", k -> switch (k) {
83+
case "k1" -> "hi";
84+
case "k2" -> "jon";
85+
// Note: this needs to not throw an exception because there won't be a match for "k1,oh" as a placeholder
86+
default -> null;
87+
});
88+
assertThat(s).isEqualTo("hi jon");
89+
}
90+
91+
@Test
92+
void withValueSeparatorAndNullReplacement() {
93+
var helper = new PropertyPlaceholderHelper("%%{", "}", ",");
94+
var s = helper.replacePlaceholders("%%{k1,oh}%%{k2}", k -> switch (k) {
95+
case "k1" -> null;
96+
case "k2" -> "jon";
97+
// Note: this needs to not throw an exception because there won't be a match for "k1,oh" as a placeholder
98+
default -> null;
99+
});
100+
assertThat(s).isEqualTo("ohjon");
101+
}
34102
}

rewrite-gradle/src/main/java/org/openrewrite/gradle/Assertions.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import org.openrewrite.test.SourceSpec;
2727
import org.openrewrite.test.SourceSpecs;
2828
import org.openrewrite.test.UncheckedConsumer;
29+
import org.openrewrite.text.PlainText;
30+
import org.openrewrite.text.PlainTextParser;
2931

3032
import java.nio.file.Paths;
3133
import java.util.List;
@@ -178,4 +180,29 @@ public static SourceSpecs settingsGradleKts(@Language("kotlin") @Nullable String
178180
spec.accept(gradle);
179181
return gradle;
180182
}
183+
184+
static SourceSpecs lockFile(@Nullable String before) {
185+
return lockFile(before, s -> {
186+
});
187+
}
188+
189+
static SourceSpecs lockFile(@Nullable String before, Consumer<SourceSpec<PlainText>> spec) {
190+
SourceSpec<PlainText> lockFile = new SourceSpec<>(PlainText.class, null, PlainTextParser.builder(), before, null);
191+
lockFile.path("gradle.lockfile");
192+
spec.accept(lockFile);
193+
return lockFile;
194+
}
195+
196+
static SourceSpecs lockFile(@Nullable String before, @Nullable String after) {
197+
return lockFile(before, after, s -> {
198+
});
199+
}
200+
201+
static SourceSpecs lockFile(@Nullable String before, @Nullable String after,
202+
Consumer<SourceSpec<PlainText>> spec) {
203+
SourceSpec<PlainText> lockFile = new SourceSpec<>(PlainText.class, null, PlainTextParser.builder(), before, s-> after);
204+
lockFile.path("gradle.lockfile");
205+
spec.accept(lockFile);
206+
return lockFile;
207+
}
181208
}

0 commit comments

Comments
 (0)