Add bomr support for 5 component version numbers

Closes gh-29928
pull/33815/head
Moritz Halbritter 2 years ago
parent d652491e20
commit d5e541226b

@ -55,7 +55,7 @@ public interface DependencyVersion extends Comparable<DependencyVersion> {
static DependencyVersion parse(String version) {
List<Function<String, DependencyVersion>> parsers = Arrays.asList(CalendarVersionDependencyVersion::parse,
ArtifactVersionDependencyVersion::parse, ReleaseTrainDependencyVersion::parse,
NumericQualifierDependencyVersion::parse, CombinedPatchAndQualifierDependencyVersion::parse,
MultipleComponentsDependencyVersion::parse, CombinedPatchAndQualifierDependencyVersion::parse,
LeadingZeroesDependencyVersion::parse, UnstructuredDependencyVersion::parse);
for (Function<String, DependencyVersion> parser : parsers) {
DependencyVersion result = parser.apply(version);

@ -21,16 +21,18 @@ import org.apache.maven.artifact.versioning.ComparableVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
/**
* A fallback {@link DependencyVersion} to handle versions with four components that
* cannot be handled by {@link ArtifactVersion} because the fourth component is numeric.
* A fallback {@link DependencyVersion} to handle versions with four or five components
* that cannot be handled by {@link ArtifactVersion} because the fourth component is
* numeric.
*
* @author Andy Wilkinson
* @author Moritz Halbritter
*/
final class NumericQualifierDependencyVersion extends ArtifactVersionDependencyVersion {
final class MultipleComponentsDependencyVersion extends ArtifactVersionDependencyVersion {
private final String original;
private NumericQualifierDependencyVersion(ArtifactVersion artifactVersion, String original) {
private MultipleComponentsDependencyVersion(ArtifactVersion artifactVersion, String original) {
super(artifactVersion, new ComparableVersion(original));
this.original = original;
}
@ -40,15 +42,15 @@ final class NumericQualifierDependencyVersion extends ArtifactVersionDependencyV
return this.original;
}
static NumericQualifierDependencyVersion parse(String input) {
static MultipleComponentsDependencyVersion parse(String input) {
String[] components = input.split("\\.");
if (components.length == 4) {
if (components.length == 4 || components.length == 5) {
ArtifactVersion artifactVersion = new DefaultArtifactVersion(
components[0] + "." + components[1] + "." + components[2]);
if (artifactVersion.getQualifier() != null && artifactVersion.getQualifier().equals(input)) {
return null;
}
return new NumericQualifierDependencyVersion(artifactVersion, input);
return new MultipleComponentsDependencyVersion(artifactVersion, input);
}
return null;
}

@ -24,6 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link DependencyVersion}.
*
* @author Andy Wilkinson
* @author Moritz Halbritter
*/
class DependencyVersionTests {
@ -39,7 +40,12 @@ class DependencyVersionTests {
@Test
void parseWhenMavenLikeVersionWithNumericQualifierShouldReturnNumericQualifierDependencyVersion() {
assertThat(DependencyVersion.parse("1.2.3.4")).isInstanceOf(NumericQualifierDependencyVersion.class);
assertThat(DependencyVersion.parse("1.2.3.4")).isInstanceOf(MultipleComponentsDependencyVersion.class);
}
@Test
void parseWhe5ComponentsShouldReturnNumericQualifierDependencyVersion() {
assertThat(DependencyVersion.parse("1.2.3.4.5")).isInstanceOf(MultipleComponentsDependencyVersion.class);
}
@Test

@ -21,11 +21,12 @@ import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link NumericQualifierDependencyVersion}.
* Tests for {@link MultipleComponentsDependencyVersion}.
*
* @author Andy Wilkinson
* @author Moritz Halbritter
*/
class NumericQualifierDependencyVersionTests {
class MultipleComponentsDependencyVersionTests {
@Test
void isNewerThanOnVersionWithNumericQualifierWhenInputHasNoQualifierShouldReturnTrue() {
@ -47,8 +48,28 @@ class NumericQualifierDependencyVersionTests {
assertThat(version("2.9.9.20190806").isNewerThan(version("2.9.9.20190806"))).isFalse();
}
private NumericQualifierDependencyVersion version(String version) {
return NumericQualifierDependencyVersion.parse(version);
@Test
void isNewerThanWorksWith5Components() {
assertThat(version("21.4.0.0.1").isNewerThan(version("21.1.0.0"))).isTrue();
}
@Test
void isNewerThanWorksWith5ComponentsAndLastComponentIsConsidered() {
assertThat(version("21.1.0.0.1").isNewerThan(version("21.1.0.0"))).isTrue();
}
@Test
void isSameMajorAndNewerThanWorksWith5Components() {
assertThat(version("21.4.0.0.1").isSameMajorAndNewerThan(version("21.1.0.0"))).isTrue();
}
@Test
void isSameMinorAndNewerThanWorksWith5Components() {
assertThat(version("21.4.0.0.1").isSameMinorAndNewerThan(version("21.1.0.0"))).isFalse();
}
private MultipleComponentsDependencyVersion version(String version) {
return MultipleComponentsDependencyVersion.parse(version);
}
}
Loading…
Cancel
Save