Merge branch '2.7.x'

Closes gh-33793
pull/33838/head
Moritz Halbritter 2 years ago
commit af04d4ae46

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

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

@ -24,6 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link DependencyVersion}. * Tests for {@link DependencyVersion}.
* *
* @author Andy Wilkinson * @author Andy Wilkinson
* @author Moritz Halbritter
*/ */
class DependencyVersionTests { class DependencyVersionTests {
@ -39,7 +40,12 @@ class DependencyVersionTests {
@Test @Test
void parseWhenMavenLikeVersionWithNumericQualifierShouldReturnNumericQualifierDependencyVersion() { 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 @Test

@ -21,11 +21,12 @@ import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link NumericQualifierDependencyVersion}. * Tests for {@link MultipleComponentsDependencyVersion}.
* *
* @author Andy Wilkinson * @author Andy Wilkinson
* @author Moritz Halbritter
*/ */
class NumericQualifierDependencyVersionTests { class MultipleComponentsDependencyVersionTests {
@Test @Test
void isNewerThanOnVersionWithNumericQualifierWhenInputHasNoQualifierShouldReturnTrue() { void isNewerThanOnVersionWithNumericQualifierWhenInputHasNoQualifierShouldReturnTrue() {
@ -47,8 +48,28 @@ class NumericQualifierDependencyVersionTests {
assertThat(version("2.9.9.20190806").isNewerThan(version("2.9.9.20190806"))).isFalse(); assertThat(version("2.9.9.20190806").isNewerThan(version("2.9.9.20190806"))).isFalse();
} }
private NumericQualifierDependencyVersion version(String version) { @Test
return NumericQualifierDependencyVersion.parse(version); 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