Skip to content

Commit b37799b

Browse files
committed
Properly apply the update recipes in version order
This is extremely important as some recipes are additive and changing the order will affect the result. I noticed that because a project updated from 3.5 to 3.15 was updated to use quarkus-resteasy-client-jackson instead of quarkus-rest-client-jackson due to the recipes not applied in order. (cherry picked from commit c211c89)
1 parent 15569c3 commit b37799b

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/QuarkusUpdatesRepository.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@
44
import java.io.InputStream;
55
import java.nio.file.Files;
66
import java.nio.file.Path;
7-
import java.util.*;
7+
import java.util.ArrayList;
8+
import java.util.Arrays;
9+
import java.util.Comparator;
10+
import java.util.LinkedHashMap;
11+
import java.util.List;
12+
import java.util.Map;
13+
import java.util.Objects;
14+
import java.util.Optional;
15+
import java.util.Properties;
16+
import java.util.regex.Pattern;
817
import java.util.stream.Collectors;
918
import java.util.stream.Stream;
1019

@@ -26,6 +35,8 @@ private QuarkusUpdatesRepository() {
2635
}
2736

2837
private static final String QUARKUS_UPDATE_RECIPES_GA = "io.quarkus:quarkus-update-recipes";
38+
private static final Pattern VERSION_EXTRACTION_PATTERN = Pattern.compile("[.][^.]+$");
39+
2940
public static final String DEFAULT_UPDATE_RECIPES_VERSION = "LATEST";
3041

3142
public static final String DEFAULT_MAVEN_REWRITE_PLUGIN_VERSION = "4.46.0";
@@ -46,7 +57,7 @@ public static FetchResult fetchRecipes(MessageWriter log, MavenArtifactResolver
4657
}
4758

4859
List<String> artifacts = new ArrayList<>();
49-
Map<String, String> recipes = new HashMap<>();
60+
Map<String, String> recipes = new LinkedHashMap<>();
5061
String propRewritePluginVersion = null;
5162

5263
for (String gav : gavs) {
@@ -147,7 +158,7 @@ public String getRewritePluginVersion() {
147158
}
148159

149160
static boolean shouldApplyRecipe(String recipeFileName, String currentVersion, String targetVersion) {
150-
String recipeVersion = recipeFileName.replaceFirst("[.][^.]+$", "");
161+
String recipeVersion = VERSION_EXTRACTION_PATTERN.matcher(recipeFileName).replaceFirst("");
151162
final DefaultArtifactVersion recipeAVersion = new DefaultArtifactVersion(recipeVersion);
152163
final DefaultArtifactVersion currentAVersion = new DefaultArtifactVersion(currentVersion);
153164
final DefaultArtifactVersion targetAVersion = new DefaultArtifactVersion(targetVersion);
@@ -172,6 +183,7 @@ static Map<String, String> fetchUpdateRecipes(ResourceLoader resourceLoader, Str
172183
.matches("^\\d\\H+.ya?ml$"))
173184
.filter(p -> shouldApplyRecipe(p.getFileName().toString(),
174185
versions[0], versions[1]))
186+
.sorted(RecipeVersionComparator.INSTANCE)
175187
.map(p -> {
176188
try {
177189
return new String[] { p.toString(),
@@ -231,4 +243,18 @@ static List<String> applyStartsWith(String key, Map<String, String[]> recipeDire
231243
.collect(Collectors.toList());
232244
}
233245

246+
private static class RecipeVersionComparator implements Comparator<Path> {
247+
248+
private static final RecipeVersionComparator INSTANCE = new RecipeVersionComparator();
249+
250+
@Override
251+
public int compare(Path recipePath1, Path recipePath2) {
252+
DefaultArtifactVersion recipeVersion1 = new DefaultArtifactVersion(
253+
VERSION_EXTRACTION_PATTERN.matcher(recipePath1.getFileName().toString()).replaceFirst(""));
254+
DefaultArtifactVersion recipeVersion2 = new DefaultArtifactVersion(
255+
VERSION_EXTRACTION_PATTERN.matcher(recipePath2.getFileName().toString()).replaceFirst(""));
256+
257+
return recipeVersion1.compareTo(recipeVersion2);
258+
}
259+
}
234260
}

0 commit comments

Comments
 (0)