mirror of
https://gitee.com/dcren/initializr.git
synced 2025-09-18 17:48:14 +08:00
Fix Sagan metadata reader to not rely on JSON order
This commit makes sure that Spring Boot versions are sorted from the newest to the oldest, irrespective of the order of the metadata elements in the json response. Closes gh-1128
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,6 +18,7 @@ package io.spring.initializr.web.support;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
@@ -38,6 +39,8 @@ import org.springframework.web.client.RestTemplate;
|
||||
*/
|
||||
class SpringBootMetadataReader {
|
||||
|
||||
private static final Comparator<DefaultMetadataElement> VERSION_METADATA_ELEMENT_COMPARATOR = new VersionMetadataElementComparator();
|
||||
|
||||
private final JsonNode content;
|
||||
|
||||
/**
|
||||
@@ -64,6 +67,7 @@ class SpringBootMetadataReader {
|
||||
list.add(versionMetadata);
|
||||
}
|
||||
}
|
||||
list.sort(VERSION_METADATA_ELEMENT_COMPARATOR.reversed());
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -108,4 +112,17 @@ class SpringBootMetadataReader {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static class VersionMetadataElementComparator implements Comparator<DefaultMetadataElement> {
|
||||
|
||||
private static final VersionParser versionParser = VersionParser.DEFAULT;
|
||||
|
||||
@Override
|
||||
public int compare(DefaultMetadataElement o1, DefaultMetadataElement o2) {
|
||||
Version o1Version = versionParser.parse(o1.getId());
|
||||
Version o2Version = versionParser.parse(o2.getId());
|
||||
return o1Version.compareTo(o2Version);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -6,6 +6,20 @@
|
||||
"category": "active",
|
||||
"stackOverflowTags": "spring-boot",
|
||||
"projectReleases": [
|
||||
{
|
||||
"releaseStatus": "GENERAL_AVAILABILITY",
|
||||
"refDocUrl": "https://docs.spring.io/spring-boot/docs/2.4.0/reference/htmlsingle/",
|
||||
"apiDocUrl": "https://docs.spring.io/spring-boot/docs/2.4.0/api/",
|
||||
"groupId": "org.springframework.boot",
|
||||
"artifactId": "spring-boot",
|
||||
"repository": null,
|
||||
"preRelease": false,
|
||||
"generalAvailability": true,
|
||||
"versionDisplayName": "2.4.0",
|
||||
"current": true,
|
||||
"snapshot": false,
|
||||
"version": "2.4.0"
|
||||
},
|
||||
{
|
||||
"releaseStatus": "SNAPSHOT",
|
||||
"refDocUrl": "https://docs.spring.io/spring-boot/docs/2.5.0-M1/reference/htmlsingle/",
|
||||
@@ -44,20 +58,6 @@
|
||||
"snapshot": true,
|
||||
"version": "2.4.1-SNAPSHOT"
|
||||
},
|
||||
{
|
||||
"releaseStatus": "GENERAL_AVAILABILITY",
|
||||
"refDocUrl": "https://docs.spring.io/spring-boot/docs/2.4.0/reference/htmlsingle/",
|
||||
"apiDocUrl": "https://docs.spring.io/spring-boot/docs/2.4.0/api/",
|
||||
"groupId": "org.springframework.boot",
|
||||
"artifactId": "spring-boot",
|
||||
"repository": null,
|
||||
"preRelease": false,
|
||||
"generalAvailability": true,
|
||||
"versionDisplayName": "2.4.0",
|
||||
"current": true,
|
||||
"snapshot": false,
|
||||
"version": "2.4.0"
|
||||
},
|
||||
{
|
||||
"releaseStatus": "SNAPSHOT",
|
||||
"refDocUrl": "https://docs.spring.io/spring-boot/docs/2.3.8.BUILD-SNAPSHOT/reference/htmlsingle/",
|
||||
|
Reference in New Issue
Block a user