Skip to content

Commit

Permalink
Resolves mojohaus#921: Refactoring segments; added the special case f…
Browse files Browse the repository at this point in the history
…or restrictionForIgnoreScope
  • Loading branch information
jarmoniuk committed May 19, 2023
1 parent a3e8410 commit 24d1320
Showing 1 changed file with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
*/

import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.Restriction;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.artifact.versioning.*;
import org.codehaus.mojo.versions.ordering.BoundArtifactVersion;
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
import org.codehaus.mojo.versions.ordering.VersionComparator;
Expand All @@ -37,8 +34,7 @@
import static java.util.Collections.reverseOrder;
import static java.util.Optional.empty;
import static java.util.Optional.of;
import static org.codehaus.mojo.versions.api.Segment.MAJOR;
import static org.codehaus.mojo.versions.api.Segment.SUBINCREMENTAL;
import static org.codehaus.mojo.versions.api.Segment.*;

/**
* Base class for {@link org.codehaus.mojo.versions.api.VersionDetails}.
Expand Down Expand Up @@ -99,11 +95,17 @@ public Restriction restrictionForUnchangedSegment(Optional<Segment> unchangedSeg
}

@Override
public Restriction restrictionForIgnoreScope(Optional<Segment> ignored) {
ArtifactVersion nextVersion = ignored
.map(Segment::ofGreaterThan)
.map(s -> (ArtifactVersion) new BoundArtifactVersion(currentVersion, s))
.orElse(currentVersion);
public Restriction restrictionForIgnoreScope(Optional<Segment> ignoredSegment) {
ArtifactVersion nextVersion;
if (ignoredSegment.map(s -> s == MAJOR).orElse(false)) {
// special case: we will ignore all possible version updates
nextVersion = DefaultArtifactVersionCache.of(String.valueOf(Integer.MAX_VALUE));
} else {
nextVersion = ignoredSegment
.map(Segment::ofGreaterThan)
.map(s -> (ArtifactVersion) new BoundArtifactVersion(currentVersion, s))
.orElse(currentVersion);
}
return new Restriction(nextVersion, false, null, false);
}

Expand Down

0 comments on commit 24d1320

Please sign in to comment.