Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
<sitePluginVersion>${maven-site-plugin.version}</sitePluginVersion>
<sisuMavenPluginVersion>${sisu-maven-plugin.version}</sisuMavenPluginVersion>
<fluidoVersion>${maven-fluido-skin.version}</fluidoVersion>
<modelloNamespaceRuleVersion>2.1.0</modelloNamespaceRuleVersion>
<modelloNamespaceRuleVersion>3.0.0</modelloNamespaceRuleVersion>
<modelloNamespaceReportVersion>2.0.0</modelloNamespaceReportVersion>
<byteBuddyVersion>1.17.2</byteBuddyVersion>

Expand Down
2 changes: 1 addition & 1 deletion rules.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<ruleset comparisonMethod="maven"/>
<ruleset/>
2 changes: 1 addition & 1 deletion versions-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-util</artifactId>
<scope>test</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Objects;
import java.util.Optional;
Expand All @@ -34,13 +35,14 @@
import org.apache.maven.artifact.versioning.Restriction;
import org.apache.maven.artifact.versioning.VersionRange;
import org.codehaus.mojo.versions.ordering.BoundArtifactVersion;
import org.codehaus.mojo.versions.ordering.DefaultSegmentCounter;
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
import org.codehaus.mojo.versions.ordering.VersionComparator;
import org.codehaus.mojo.versions.utils.ArtifactVersionService;

import static java.util.Collections.reverseOrder;
import static java.util.Optional.empty;
import static java.util.Optional.of;
import static java.util.Optional.ofNullable;
import static org.codehaus.mojo.versions.api.Segment.MAJOR;
import static org.codehaus.mojo.versions.api.Segment.SUBINCREMENTAL;

Expand Down Expand Up @@ -85,7 +87,7 @@ protected ArtifactVersion getHighestLowerBound(ArtifactVersion lowerBoundVersion
return getCurrentVersionRange().getRestrictions().stream()
.map(Restriction::getLowerBound)
.filter(Objects::nonNull)
.max(getVersionComparator())
.max(Comparator.naturalOrder())
.orElse(lowerBoundVersion);
}

Expand Down Expand Up @@ -269,7 +271,7 @@ public Optional<ArtifactVersion> getNewestVersion(
return Arrays.stream(getVersions(includeSnapshots))
.filter(candidate -> isVersionInRestriction(lookupRestriction, candidate))
.filter(candidate -> includeSnapshots || !ArtifactUtils.isSnapshot(candidate.toString()))
.max(getVersionComparator());
.max(Comparator.naturalOrder());
}

@Override
Expand All @@ -284,7 +286,7 @@ public final ArtifactVersion[] getVersions(
.filter(candidate -> versionRange == null || ArtifactVersions.isVersionInRange(candidate, versionRange))
.filter(candidate -> restriction == null || isVersionInRestriction(restriction, candidate))
.filter(candidate -> includeSnapshots || !ArtifactUtils.isSnapshot(candidate.toString()))
.sorted(getVersionComparator())
.sorted(Comparator.naturalOrder())
.distinct()
.toArray(ArtifactVersion[]::new);
}
Expand Down Expand Up @@ -345,7 +347,7 @@ protected Optional<String> getLowerBound(ArtifactVersion version, Optional<Segme
return empty();
}

int segmentCount = getVersionComparator().getSegmentCount(version);
int segmentCount = DefaultSegmentCounter.INSTANCE.getSegmentCount(version);
if (unchangedSegment.get().value() > segmentCount) {
throw new InvalidSegmentException(unchangedSegment.get(), segmentCount, version);
}
Expand Down Expand Up @@ -382,9 +384,8 @@ public boolean isVersionInRestriction(Restriction restriction, ArtifactVersion c
ArtifactVersion upperBound = restriction.getUpperBound();
boolean includeLower = restriction.isLowerBoundInclusive();
boolean includeUpper = restriction.isUpperBoundInclusive();
final VersionComparator versionComparator = getVersionComparator();
int lower = lowerBound == null ? -1 : versionComparator.compare(lowerBound, candidate);
int upper = upperBound == null ? +1 : versionComparator.compare(upperBound, candidate);
int lower = ofNullable(lowerBound).map(b -> b.compareTo(candidate)).orElse(-1);
int upper = ofNullable(upperBound).map(b -> b.compareTo(candidate)).orElse(1);
if (lower > 0 || upper < 0) {
return false;
}
Expand All @@ -401,7 +402,7 @@ public boolean isVersionInRestriction(Restriction restriction, ArtifactVersion c
*/
public final ArtifactVersion getReportNewestUpdate(Optional<Segment> updateScope, boolean includeSnapshots) {
return getArtifactVersionStream(updateScope, includeSnapshots)
.min(Collections.reverseOrder(getVersionComparator()))
.min(Collections.reverseOrder())
.orElse(null);
}

Expand All @@ -412,8 +413,8 @@ public final ArtifactVersion getReportNewestUpdate(Optional<Segment> updateScope
* @return all versions after currentVersion within the specified update scope.
*/
public final ArtifactVersion[] getReportUpdates(Optional<Segment> updateScope, boolean includeSnapshots) {
TreeSet<ArtifactVersion> versions = getArtifactVersionStream(updateScope, includeSnapshots)
.collect(Collectors.toCollection(() -> new TreeSet<>(getVersionComparator())));
TreeSet<ArtifactVersion> versions =
getArtifactVersionStream(updateScope, includeSnapshots).collect(Collectors.toCollection(TreeSet::new));
// filter out intermediate minor versions.
if (!verboseDetail) {
int major = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.Restriction;
import org.apache.maven.artifact.versioning.VersionRange;
import org.codehaus.mojo.versions.ordering.VersionComparator;

/**
* Holds the results of a search for versions of an artifact.
Expand All @@ -55,25 +54,16 @@ public class ArtifactVersions extends AbstractVersionDetails implements Comparab
*/
private final SortedSet<ArtifactVersion> versions;

/**
* The version comparison rule that is used for this artifact.
*
* @since 1.0-alpha-3
*/
private final VersionComparator versionComparator;

/**
* Creates a new {@link ArtifactVersions} instance.
*
* @param artifact The artifact.
* @param versions The versions.
* @param versionComparator The version comparison rule.
* @since 1.0-alpha-3
*/
public ArtifactVersions(Artifact artifact, List<ArtifactVersion> versions, VersionComparator versionComparator) {
public ArtifactVersions(Artifact artifact, List<ArtifactVersion> versions) {
this.artifact = artifact;
this.versionComparator = versionComparator;
this.versions = new TreeSet<>(versionComparator);
this.versions = new TreeSet<>();
this.versions.addAll(versions);
setCurrentVersion(artifact.getVersion());
setCurrentVersionRange(artifact.getVersionRange());
Expand All @@ -87,7 +77,6 @@ public ArtifactVersions(Artifact artifact, List<ArtifactVersion> versions, Versi
*/
public ArtifactVersions(ArtifactVersions other) {
artifact = other.artifact;
versionComparator = other.versionComparator;
versions = other.versions;
setCurrentVersion(other.getCurrentVersion());
setCurrentVersionRange(other.getCurrentVersionRange());
Expand Down Expand Up @@ -121,13 +110,12 @@ public boolean equals(Object o) {
.append(getArtifact().getVersion(), that.getArtifact().getVersion())
.append(getArtifact().getScope(), that.getArtifact().getScope())
.append(getVersions(true), that.getVersions(true))
.append(getVersionComparator(), that.getVersionComparator())
.isEquals();
}

@Override
public int hashCode() {
return Objects.hash(getArtifact(), Arrays.hashCode(getVersions(true)), getVersionComparator());
return Objects.hash(getArtifact(), Arrays.hashCode(getVersions(true)));
}

/**
Expand Down Expand Up @@ -230,15 +218,10 @@ public boolean isEmpty(boolean includeSnapshots) {
: versions.stream().map(Object::toString).allMatch(ArtifactUtils::isSnapshot);
}

public VersionComparator getVersionComparator() {
return versionComparator;
}

/**
* {@inheritDoc}
*/
public String toString() {
return "ArtifactVersions" + "{artifact=" + artifact + ", versions=" + versions + ", versionComparator="
+ versionComparator + '}';
return "ArtifactVersions" + "{artifact=" + artifact + ", versions=" + versions + '}';
}
}
Loading
Loading