Fix dependency version parser for version strings using dot as separator between version and modifier.
Closes #188
This commit is contained in:
@@ -37,7 +37,7 @@ import org.springframework.data.release.model.Version;
|
||||
@Value
|
||||
class DependencyVersion implements Comparable<DependencyVersion> {
|
||||
|
||||
private static Pattern VERSION = Pattern.compile("((?>(?>\\d+)[\\.]?)+)(-[a-zA-Z]+)?(\\d+)?");
|
||||
private static Pattern VERSION = Pattern.compile("((?>(?>\\d+)[\\.]?)+)((?>-)?[a-zA-Z]+)?(\\d+)?");
|
||||
private static Pattern NAME_VERSION = Pattern.compile("([A-Za-z]+)-(RELEASE|SR(\\d+)|SNAPSHOT|BUILD-SNAPSHOT)");
|
||||
|
||||
private static Comparator<DependencyVersion> VERSION_COMPARATOR = Comparator.comparing(DependencyVersion::getVersion)
|
||||
@@ -47,6 +47,7 @@ class DependencyVersion implements Comparable<DependencyVersion> {
|
||||
if (o1.getModifier().isEmpty() && !o2.getModifier().isEmpty()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!o1.getModifier().isEmpty() && o2.getModifier().isEmpty()) {
|
||||
return -1;
|
||||
}
|
||||
@@ -91,6 +92,9 @@ class DependencyVersion implements Comparable<DependencyVersion> {
|
||||
String modifier;
|
||||
String counter;
|
||||
String versionString = versionMatcher.group(1);
|
||||
|
||||
versionString = versionString.endsWith(".") ? versionString.substring(0, versionString.length() - 1)
|
||||
: versionString;
|
||||
try {
|
||||
version = Version.parse(versionString);
|
||||
} catch (RuntimeException e) {
|
||||
|
||||
@@ -42,6 +42,19 @@ class DependencyVersionUnitTests {
|
||||
assertThat(sorted).containsExactly("1.0.0-m1", "1.0.0-m2", "1.0.0-rc1", "1.0.0");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldConsiderSpringVersionOrder() {
|
||||
|
||||
List<String> sorted = Stream.of("1.0.0", "1.0.0.M1", "1.0.0.RC1", "1.0.0.M2") //
|
||||
.map(DependencyVersion::of) //
|
||||
.sorted() //
|
||||
.map(DependencyVersion::getIdentifier) //
|
||||
.collect(Collectors.toList());
|
||||
|
||||
System.out.println(sorted);
|
||||
assertThat(sorted).containsExactly("1.0.0.M1", "1.0.0.M2", "1.0.0.RC1", "1.0.0");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldConsiderReleaseTrainSortOrder() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user