Update Bomr to treat CalVer versions as newer than release train versions
Closes gh-23451
This commit is contained in:
@@ -80,7 +80,7 @@ class ArtifactVersionDependencyVersion extends AbstractDependencyVersion {
|
||||
return this.artifactVersion.toString();
|
||||
}
|
||||
|
||||
private Optional<ArtifactVersionDependencyVersion> extractArtifactVersionDependencyVersion(
|
||||
protected Optional<ArtifactVersionDependencyVersion> extractArtifactVersionDependencyVersion(
|
||||
DependencyVersion other) {
|
||||
ArtifactVersionDependencyVersion artifactVersion = null;
|
||||
if (other instanceof ArtifactVersionDependencyVersion) {
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.build.bom.bomr.version;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.maven.artifact.versioning.ArtifactVersion;
|
||||
import org.apache.maven.artifact.versioning.ComparableVersion;
|
||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||
|
||||
/**
|
||||
* A specialization of {@link ArtifactVersionDependencyVersion} for calendar versions.
|
||||
* Calendar versions are always considered to be newer than
|
||||
* {@link ReleaseTrainDependencyVersion release train versions}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
class CalendarVersionDependencyVersion extends ArtifactVersionDependencyVersion {
|
||||
|
||||
private static final Pattern CALENDAR_VERSION_PATTERN = Pattern.compile("\\d{4}\\.\\d+\\.\\d+(-.+)?");
|
||||
|
||||
protected CalendarVersionDependencyVersion(ArtifactVersion artifactVersion) {
|
||||
super(artifactVersion);
|
||||
}
|
||||
|
||||
protected CalendarVersionDependencyVersion(ArtifactVersion artifactVersion, ComparableVersion comparableVersion) {
|
||||
super(artifactVersion, comparableVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNewerThan(DependencyVersion other) {
|
||||
if (other instanceof ReleaseTrainDependencyVersion) {
|
||||
return true;
|
||||
}
|
||||
return super.isNewerThan(other);
|
||||
}
|
||||
|
||||
static CalendarVersionDependencyVersion parse(String version) {
|
||||
if (!CALENDAR_VERSION_PATTERN.matcher(version).matches()) {
|
||||
return null;
|
||||
}
|
||||
ArtifactVersion artifactVersion = new DefaultArtifactVersion(version);
|
||||
if (artifactVersion.getQualifier() != null && artifactVersion.getQualifier().equals(version)) {
|
||||
return null;
|
||||
}
|
||||
return new CalendarVersionDependencyVersion(artifactVersion);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -53,10 +53,10 @@ public interface DependencyVersion extends Comparable<DependencyVersion> {
|
||||
boolean isSameMinorAndNewerThan(DependencyVersion other);
|
||||
|
||||
static DependencyVersion parse(String version) {
|
||||
List<Function<String, DependencyVersion>> parsers = Arrays.asList(ArtifactVersionDependencyVersion::parse,
|
||||
ReleaseTrainDependencyVersion::parse, NumericQualifierDependencyVersion::parse,
|
||||
CombinedPatchAndQualifierDependencyVersion::parse, LeadingZeroesDependencyVersion::parse,
|
||||
UnstructuredDependencyVersion::parse);
|
||||
List<Function<String, DependencyVersion>> parsers = Arrays.asList(CalendarVersionDependencyVersion::parse,
|
||||
ArtifactVersionDependencyVersion::parse, ReleaseTrainDependencyVersion::parse,
|
||||
NumericQualifierDependencyVersion::parse, CombinedPatchAndQualifierDependencyVersion::parse,
|
||||
LeadingZeroesDependencyVersion::parse, UnstructuredDependencyVersion::parse);
|
||||
for (Function<String, DependencyVersion> parser : parsers) {
|
||||
DependencyVersion result = parser.apply(version);
|
||||
if (result != null) {
|
||||
|
||||
@@ -64,6 +64,9 @@ final class ReleaseTrainDependencyVersion implements DependencyVersion {
|
||||
|
||||
@Override
|
||||
public boolean isNewerThan(DependencyVersion other) {
|
||||
if (other instanceof CalendarVersionDependencyVersion) {
|
||||
return false;
|
||||
}
|
||||
if (!(other instanceof ReleaseTrainDependencyVersion)) {
|
||||
return true;
|
||||
}
|
||||
@@ -78,6 +81,9 @@ final class ReleaseTrainDependencyVersion implements DependencyVersion {
|
||||
|
||||
@Override
|
||||
public boolean isSameMinorAndNewerThan(DependencyVersion other) {
|
||||
if (other instanceof CalendarVersionDependencyVersion) {
|
||||
return false;
|
||||
}
|
||||
if (!(other instanceof ReleaseTrainDependencyVersion)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user