From f19d5a5580a96a6ea64528b8dab45a1a587a1905 Mon Sep 17 00:00:00 2001 From: Markus Winter Date: Fri, 8 Mar 2024 13:40:47 +0100 Subject: [PATCH] sort according to VersionNumber comparator (#697) the file plugin-versions.json is the base for sorting the releases of a plugin on the plugins page at https://plugins.jenkins.io The sorting with string causes wrong ordering in some cases as described in https://github.com/jenkins-infra/plugin-site/issues/1336 By sorting with the Comparator of VersionNumber we get the same sorting as in other places. --- .../java/io/jenkins/update_center/json/PluginVersions.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/io/jenkins/update_center/json/PluginVersions.java b/src/main/java/io/jenkins/update_center/json/PluginVersions.java index 247c4008f..e18ddd966 100644 --- a/src/main/java/io/jenkins/update_center/json/PluginVersions.java +++ b/src/main/java/io/jenkins/update_center/json/PluginVersions.java @@ -20,8 +20,7 @@ public class PluginVersions { public Map releases = new LinkedHashMap<>(); PluginVersions(Map artifacts) { - // TODO this is suboptimal sorting (we'd rather sort by VersionNumber, not its string representation) but imitates existing behavior - for (VersionNumber versionNumber : artifacts.keySet().stream().sorted(Comparator.comparing(VersionNumber::toString)).collect(Collectors.toList())) { + for (VersionNumber versionNumber : artifacts.keySet().stream().sorted().collect(Collectors.toList())) { try { if (releases.put(versionNumber.toString(), new PluginVersionsEntry(artifacts.get(versionNumber))) != null) { throw new IllegalStateException("Duplicate key");