From 8c2ef6eb1fde9ba965fd7d5d04e85c36e569f94a Mon Sep 17 00:00:00 2001 From: Swell <5782559+sultan@users.noreply.github.com> Date: Mon, 19 Sep 2022 14:00:03 +0200 Subject: [PATCH] #632 Fixed lower and upper bounds to keep milestones and rcs in the right majors. --- .../mojo/versions/UseLatestReleasesMojo.java | 10 +- .../mojo/versions/UseLatestSnapshotsMojo.java | 13 +- .../mojo/versions/UseLatestVersionsMojo.java | 9 +- .../versions/api/AbstractVersionDetails.java | 1 + .../ordering/MajorMinorIncrementalFilter.java | 122 ------------------ 5 files changed, 10 insertions(+), 145 deletions(-) delete mode 100644 src/main/java/org/codehaus/mojo/versions/ordering/MajorMinorIncrementalFilter.java diff --git a/src/main/java/org/codehaus/mojo/versions/UseLatestReleasesMojo.java b/src/main/java/org/codehaus/mojo/versions/UseLatestReleasesMojo.java index 7afa71d298..3613f131dd 100644 --- a/src/main/java/org/codehaus/mojo/versions/UseLatestReleasesMojo.java +++ b/src/main/java/org/codehaus/mojo/versions/UseLatestReleasesMojo.java @@ -50,7 +50,6 @@ import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.Segment; import org.codehaus.mojo.versions.ordering.InvalidSegmentException; -import org.codehaus.mojo.versions.ordering.MajorMinorIncrementalFilter; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.DependencyBuilder; @@ -151,8 +150,6 @@ private void useLatestReleases( ModifiedPomXMLEventReader pom, Collection unchangedSegment = determineUnchangedSegment( allowMajorUpdates, allowMinorUpdates, allowIncrementalUpdates ); - MajorMinorIncrementalFilter majorMinorIncfilter = - new MajorMinorIncrementalFilter( allowMajorUpdates, allowMinorUpdates, allowIncrementalUpdates ); for ( Dependency dep : dependencies ) { @@ -185,10 +182,9 @@ private void useLatestReleases( ModifiedPomXMLEventReader pom, Collection 0 ) { String newVersion = filteredVersions[filteredVersions.length - 1].toString(); diff --git a/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java b/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java index 023265a752..50ee454d9f 100644 --- a/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java +++ b/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java @@ -48,7 +48,6 @@ import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.Segment; import org.codehaus.mojo.versions.ordering.InvalidSegmentException; -import org.codehaus.mojo.versions.ordering.MajorMinorIncrementalFilter; import org.codehaus.mojo.versions.ordering.VersionComparator; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.DependencyBuilder; @@ -151,8 +150,6 @@ private void useLatestSnapshots( ModifiedPomXMLEventReader pom, Collection unchangedSegment = determineUnchangedSegment( allowMajorUpdates, allowMinorUpdates, allowIncrementalUpdates ); - MajorMinorIncrementalFilter majorMinorIncfilter = - new MajorMinorIncrementalFilter( allowMajorUpdates, allowMinorUpdates, allowIncrementalUpdates ); for ( Dependency dep : dependencies ) { @@ -201,6 +198,7 @@ private void useLatestSnapshots( ModifiedPomXMLEventReader pom, Collection snapshotsOnly = new ArrayList<>(); @@ -212,13 +210,8 @@ private void useLatestSnapshots( ModifiedPomXMLEventReader pom, Collection 0 ) { latestVersion = filteredVersions[filteredVersions.length - 1].toString(); diff --git a/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojo.java b/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojo.java index 172da4e174..fd10d8a537 100644 --- a/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojo.java +++ b/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojo.java @@ -45,7 +45,6 @@ import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.Segment; import org.codehaus.mojo.versions.ordering.InvalidSegmentException; -import org.codehaus.mojo.versions.ordering.MajorMinorIncrementalFilter; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.DependencyBuilder; @@ -167,8 +166,6 @@ private void useLatestVersions( ModifiedPomXMLEventReader pom, Collection unchangedSegment = determineUnchangedSegment( allowMajorUpdates, allowMinorUpdates, allowIncrementalUpdates ); - MajorMinorIncrementalFilter majorMinorIncfilter = - new MajorMinorIncrementalFilter( allowMajorUpdates, allowMinorUpdates, allowIncrementalUpdates ); for ( Dependency dep : dependencies ) { @@ -199,10 +196,10 @@ private void useLatestVersions( ModifiedPomXMLEventReader pom, Collection 0 ) { String newVersion = filteredVersions[filteredVersions.length - 1].toString(); diff --git a/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java b/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java index 8f0fff4f1f..1d03bcdc2c 100644 --- a/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java +++ b/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java @@ -266,6 +266,7 @@ public final ArtifactVersion[] getNewerVersions( String versionString, Optional< : getVersionComparator().incrementSegment( lowerBound, upperBoundSegment.get() ); Restriction restriction = new Restriction( lowerBound, allowDowngrade, upperBound, allowDowngrade ); + // TODO shouldn't allowDowngrade boolean be passed to this call ? return getVersions( restriction, includeSnapshots ); } diff --git a/src/main/java/org/codehaus/mojo/versions/ordering/MajorMinorIncrementalFilter.java b/src/main/java/org/codehaus/mojo/versions/ordering/MajorMinorIncrementalFilter.java deleted file mode 100644 index 39b7cba69d..0000000000 --- a/src/main/java/org/codehaus/mojo/versions/ordering/MajorMinorIncrementalFilter.java +++ /dev/null @@ -1,122 +0,0 @@ -package org.codehaus.mojo.versions.ordering; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * - * http://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. - */ - -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; - -import org.apache.maven.artifact.versioning.ArtifactVersion; -import org.codehaus.mojo.versions.api.AbstractVersionDetails; - -/** - * This class will handle the edge cases where a version update would have happened based on the usage of version ranges - * to limit the replacement of the versions. We have currently the following scenario: The user defined - * allowMajorUpdates=false and allowMinorUpdates=true. An given artifact - * groupId:artifactId:2.0.8 and a repository which contains the following versions of this artifact: - *
    - *
  • 2.0.11
  • - *
  • 2.1.0-M1
  • - *
  • 2.2.1
  • - *
  • 3.0-beta-3
  • - *
  • 3.0
  • - *
  • 3.1.0
  • - *
  • 3.3.0
  • - *
- * The {@link AbstractVersionDetails#getNewerVersions(String, Optional, boolean, boolean)} will use an upper version of - * 2.1.0 to limit the versions to use. The result of this would be using 2.1.0-M1 which - * contradicts the wish of the user of not updating the minor version. The root cause of this is the comparison of Maven - * versions which will defined 2.1.0-M1 as less than 2.1.0. The method - * {@link #filter(ArtifactVersion, ArtifactVersion[])} will filter out those versions which violate the configuration - * {@link #allowMajorUpdates}, {@link #allowMinorUpdates} {@link #allowIncrementalUpdates}. - * - * @author Karl Heinz Marbaise - */ -public class MajorMinorIncrementalFilter -{ - - private final boolean allowMajorUpdates; - - private final boolean allowMinorUpdates; - - private final boolean allowIncrementalUpdates; - - public MajorMinorIncrementalFilter( boolean allowMajorUpdates, boolean allowMinorUpdates, - boolean allowIncrementalUpdates ) - { - this.allowMajorUpdates = allowMajorUpdates; - this.allowMinorUpdates = allowMinorUpdates; - this.allowIncrementalUpdates = allowIncrementalUpdates; - } - - /** - * @param selectedVersion The version which will be checked. - * @param newerVersions The list of identified versions which are greater or equal than the selectedVersion. - * @return The cleaned up list which obeys usage of {@link #allowMajorUpdates}, {@link #allowMinorUpdates}, - * {@link #allowIncrementalUpdates}. - */ - public ArtifactVersion[] filter( ArtifactVersion selectedVersion, ArtifactVersion[] newerVersions ) - { - List versionsToUse = new LinkedList<>(); - for ( ArtifactVersion artifactVersion : newerVersions ) - { - if ( artifactVersion.getMajorVersion() != selectedVersion.getMajorVersion() ) - { - if ( allowMajorUpdates ) - { - if ( !versionsToUse.contains( artifactVersion ) ) - { - versionsToUse.add( artifactVersion ); - } - } - } - else if ( artifactVersion.getMinorVersion() != selectedVersion.getMinorVersion() ) - { - if ( allowMinorUpdates ) - { - if ( !versionsToUse.contains( artifactVersion ) ) - { - versionsToUse.add( artifactVersion ); - } - } - } - else if ( artifactVersion.getIncrementalVersion() != selectedVersion.getIncrementalVersion() ) - { - if ( allowIncrementalUpdates ) - { - if ( !versionsToUse.contains( artifactVersion ) ) - { - versionsToUse.add( artifactVersion ); - } - } - } - else - { - // build number or qualifier. Will already be sorted and higher - if ( !versionsToUse.contains( artifactVersion ) ) - { - versionsToUse.add( artifactVersion ); - } - } - } - return versionsToUse.toArray( new ArtifactVersion[0] ); - - } -}