Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly apply the update recipes in version order #44183

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -26,6 +35,8 @@ private QuarkusUpdatesRepository() {
}

private static final String QUARKUS_UPDATE_RECIPES_GA = "io.quarkus:quarkus-update-recipes";
private static final Pattern VERSION_EXTRACTION_PATTERN = Pattern.compile("[.][^.]+$");

public static final String DEFAULT_UPDATE_RECIPES_VERSION = "LATEST";

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

List<String> artifacts = new ArrayList<>();
Map<String, String> recipes = new HashMap<>();
Map<String, String> recipes = new LinkedHashMap<>();
String propRewritePluginVersion = null;

for (String gav : gavs) {
Expand Down Expand Up @@ -147,7 +158,7 @@ public String getRewritePluginVersion() {
}

static boolean shouldApplyRecipe(String recipeFileName, String currentVersion, String targetVersion) {
String recipeVersion = recipeFileName.replaceFirst("[.][^.]+$", "");
String recipeVersion = VERSION_EXTRACTION_PATTERN.matcher(recipeFileName).replaceFirst("");
final DefaultArtifactVersion recipeAVersion = new DefaultArtifactVersion(recipeVersion);
final DefaultArtifactVersion currentAVersion = new DefaultArtifactVersion(currentVersion);
final DefaultArtifactVersion targetAVersion = new DefaultArtifactVersion(targetVersion);
Expand All @@ -172,6 +183,7 @@ static Map<String, String> fetchUpdateRecipes(ResourceLoader resourceLoader, Str
.matches("^\\d\\H+.ya?ml$"))
.filter(p -> shouldApplyRecipe(p.getFileName().toString(),
versions[0], versions[1]))
.sorted(RecipeVersionComparator.INSTANCE)
.map(p -> {
try {
return new String[] { p.toString(),
Expand Down Expand Up @@ -231,4 +243,18 @@ static List<String> applyStartsWith(String key, Map<String, String[]> recipeDire
.collect(Collectors.toList());
}

private static class RecipeVersionComparator implements Comparator<Path> {

private static final RecipeVersionComparator INSTANCE = new RecipeVersionComparator();

@Override
public int compare(Path recipePath1, Path recipePath2) {
DefaultArtifactVersion recipeVersion1 = new DefaultArtifactVersion(
VERSION_EXTRACTION_PATTERN.matcher(recipePath1.getFileName().toString()).replaceFirst(""));
DefaultArtifactVersion recipeVersion2 = new DefaultArtifactVersion(
VERSION_EXTRACTION_PATTERN.matcher(recipePath2.getFileName().toString()).replaceFirst(""));

return recipeVersion1.compareTo(recipeVersion2);
}
}
}
Loading