From 24d1320a0ac0eff992246f102c8fd983bce96341 Mon Sep 17 00:00:00 2001 From: Andrzej Jarmoniuk Date: Fri, 19 May 2023 20:14:50 +0200 Subject: [PATCH] Resolves #921: Refactoring segments; added the special case for restrictionForIgnoreScope --- .../versions/api/AbstractVersionDetails.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java b/versions-common/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java index a9c1b85005..f0e54e7035 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java @@ -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; @@ -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}. @@ -99,11 +95,17 @@ public Restriction restrictionForUnchangedSegment(Optional unchangedSeg } @Override - public Restriction restrictionForIgnoreScope(Optional ignored) { - ArtifactVersion nextVersion = ignored - .map(Segment::ofGreaterThan) - .map(s -> (ArtifactVersion) new BoundArtifactVersion(currentVersion, s)) - .orElse(currentVersion); + public Restriction restrictionForIgnoreScope(Optional 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); }