diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/DependencyVersion.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/DependencyVersion.java index a2a1acb57e..1e71a1d07d 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/DependencyVersion.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/DependencyVersion.java @@ -55,7 +55,7 @@ public interface DependencyVersion extends Comparable { static DependencyVersion parse(String version) { List> parsers = Arrays.asList(CalendarVersionDependencyVersion::parse, ArtifactVersionDependencyVersion::parse, ReleaseTrainDependencyVersion::parse, - NumericQualifierDependencyVersion::parse, CombinedPatchAndQualifierDependencyVersion::parse, + MultipleComponentsDependencyVersion::parse, CombinedPatchAndQualifierDependencyVersion::parse, LeadingZeroesDependencyVersion::parse, UnstructuredDependencyVersion::parse); for (Function parser : parsers) { DependencyVersion result = parser.apply(version); diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/NumericQualifierDependencyVersion.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/MultipleComponentsDependencyVersion.java similarity index 73% rename from buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/NumericQualifierDependencyVersion.java rename to buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/MultipleComponentsDependencyVersion.java index 363def7d80..abd33b667d 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/NumericQualifierDependencyVersion.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/MultipleComponentsDependencyVersion.java @@ -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; } diff --git a/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/DependencyVersionTests.java b/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/DependencyVersionTests.java index c8a74d0bf4..2f8e9bbea8 100644 --- a/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/DependencyVersionTests.java +++ b/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/DependencyVersionTests.java @@ -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 diff --git a/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/NumericQualifierDependencyVersionTests.java b/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/MultipleComponentsDependencyVersionTests.java similarity index 64% rename from buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/NumericQualifierDependencyVersionTests.java rename to buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/MultipleComponentsDependencyVersionTests.java index ae09f53794..5f8bdbbd50 100644 --- a/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/NumericQualifierDependencyVersionTests.java +++ b/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/MultipleComponentsDependencyVersionTests.java @@ -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); } }