Skip to content

Commit 990d0dd

Browse files
committed
Sequential migration from 2.3 to 3.1
1 parent 7e3e9c2 commit 990d0dd

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

boot-upgrade-iterative/src/main/java/com/example/bootupgrade/IterativeBoot3UpgradeExample.java

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,50 +79,50 @@ public static void main(String[] args) {
7979

8080
private static Map<String, List<String>> versionToRecipeMap = new HashMap<>();
8181
static {
82-
Map<List<String>, List<String>> map = Map.of(
83-
List.of("2.3.0", "2.3.1", "2.3.2", "2.3.4", "2.3.5.RELEASE"),
82+
versionToRecipeMap = Map.of(
83+
"2.3.5.RELEASE",
8484
List.of(
8585
"org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_4"
8686
),
8787

88-
List.of("2.4.0", "2.4.13"),
88+
"2.4.13",
8989
List.of(
9090
"org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_5"
9191
),
9292

93-
List.of("2.5.0", "2.5.15"),
93+
"2.5.15",
9494
List.of(
9595
"org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_6"
9696
),
9797

98-
List.of("2.6.0", "2.6.15"),
98+
"2.6.15",
9999
List.of(
100100
"org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_7"
101101
),
102102

103-
List.of("2.7.0", "2.7.17"),
103+
"2.7.17",
104104
List.of(
105-
"org.openrewrite.java.spring.boot2.UpgradeSpringBoot_3_0"
105+
"org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_0"
106106
),
107107

108-
List.of("3.0.0", "3.0.12"),
108+
"3.0.12",
109109
List.of(
110-
"org.openrewrite.java.spring.boot2.UpgradeSpringBoot_3_1"
110+
"org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_1"
111111
),
112112

113-
List.of("3.1.0", "3.1.5"),
113+
"3.1.5",
114114
List.of(
115-
"org.openrewrite.java.spring.boot2.UpgradeSpringBoot_3_2"
115+
"org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_2"
116116
)
117117
);
118-
map.keySet()
119-
.stream()
120-
.forEach(keys -> {
121-
keys.stream()
122-
.forEach(k -> {
123-
versionToRecipeMap.put(k, map.get(keys));
124-
});
125-
});
118+
// map.keySet()
119+
// .stream()
120+
// .forEach(keys -> {
121+
// keys.stream()
122+
// .forEach(k -> {
123+
// versionToRecipeMap.put(k, map.get(keys));
124+
// });
125+
// });
126126

127127
}
128128

@@ -212,8 +212,12 @@ private String calculateBranchName(String newBootVersion) {
212212
}
213213

214214
private String calculateNextBootVersion(String currentBootVersion) {
215-
String[] split = currentBootVersion.split("\\.");
216-
return split[0] + "." + (Integer.parseInt(split[1]) + 1) + ".x";
215+
List<String> sortedVersions = versionToRecipeMap.keySet().stream().sorted(String::compareTo).toList();
216+
int i = sortedVersions.indexOf(currentBootVersion);
217+
if(i>0) {
218+
return sortedVersions.get(i+1);
219+
}
220+
throw new IllegalArgumentException("No higher version found than %s.".formatted(currentBootVersion));
217221
}
218222

219223
private String extractSpringBootVersion(String pomXml) {

0 commit comments

Comments
 (0)