From c53b1e6861a1a0cba5c96bfa7d061ebd119166b0 Mon Sep 17 00:00:00 2001 From: Andrzej Jarmoniuk Date: Mon, 10 Oct 2022 16:22:17 +0200 Subject: [PATCH] Adding some of the remaining AbstractVersionDetails methods to the interface --- .../versions/api/AbstractVersionDetails.java | 75 +++++---- .../mojo/versions/api/VersionDetails.java | 158 ++++++++++++------ 2 files changed, 150 insertions(+), 83 deletions(-) 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 747a448e47..e2830d4c6e 100644 --- a/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java +++ b/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java @@ -75,11 +75,13 @@ protected AbstractVersionDetails() { } + @Override public final boolean isCurrentVersionDefined() { return getCurrentVersion() != null; } + @Override public final ArtifactVersion getCurrentVersion() { synchronized ( currentVersionLock ) @@ -88,6 +90,7 @@ public final ArtifactVersion getCurrentVersion() } } + @Override public final void setCurrentVersion( ArtifactVersion currentVersion ) { synchronized ( currentVersionLock ) @@ -96,11 +99,13 @@ public final void setCurrentVersion( ArtifactVersion currentVersion ) } } + @Override public final void setCurrentVersion( String currentVersion ) { setCurrentVersion( currentVersion == null ? null : new DefaultArtifactVersion( currentVersion ) ); } + @Override public final boolean isIncludeSnapshots() { synchronized ( currentVersionLock ) @@ -109,6 +114,7 @@ public final boolean isIncludeSnapshots() } } + @Override public final void setIncludeSnapshots( boolean includeSnapshots ) { synchronized ( currentVersionLock ) @@ -117,23 +123,28 @@ public final void setIncludeSnapshots( boolean includeSnapshots ) } } + @Override public final ArtifactVersion[] getVersions() { return getVersions( isIncludeSnapshots() ); } + @Override public abstract ArtifactVersion[] getVersions( boolean includeSnapshots ); + @Override public final ArtifactVersion[] getVersions( VersionRange versionRange, boolean includeSnapshots ) { return getVersions( versionRange, null, includeSnapshots ); } + @Override public final ArtifactVersion[] getVersions( ArtifactVersion lowerBound, ArtifactVersion upperBound ) { return getVersions( lowerBound, upperBound, isIncludeSnapshots() ); } + @Override public final ArtifactVersion[] getVersions( ArtifactVersion lowerBound, ArtifactVersion upperBound, boolean includeSnapshots ) { @@ -141,17 +152,13 @@ public final ArtifactVersion[] getVersions( ArtifactVersion lowerBound, Artifact return getVersions( restriction, includeSnapshots ); } - private ArtifactVersion[] getNewerVersions( ArtifactVersion version, boolean includeSnapshots ) - { - Restriction restriction = new Restriction( version, false, null, false ); - return getVersions( restriction, includeSnapshots ); - } - + @Override public final ArtifactVersion getNewestVersion( ArtifactVersion lowerBound, ArtifactVersion upperBound ) { return getNewestVersion( lowerBound, upperBound, isIncludeSnapshots() ); } + @Override public final ArtifactVersion getNewestVersion( ArtifactVersion lowerBound, ArtifactVersion upperBound, boolean includeSnapshots ) { @@ -159,6 +166,7 @@ public final ArtifactVersion getNewestVersion( ArtifactVersion lowerBound, Artif return getNewestVersion( restriction, includeSnapshots ); } + @Override public final ArtifactVersion getNewestVersion( VersionRange versionRange, Restriction restriction, boolean includeSnapshots ) { @@ -170,6 +178,7 @@ private static Iterable reverse( T[] array ) return Arrays.stream( array ).sorted( Collections.reverseOrder() ).collect( Collectors.toList() ); } + @Override public final ArtifactVersion getNewestVersion( VersionRange versionRange, Restriction restriction, boolean includeSnapshots, boolean allowDowngrade ) { @@ -194,16 +203,19 @@ public final ArtifactVersion getNewestVersion( VersionRange versionRange, Restri return null; } + @Override public final ArtifactVersion getNewestVersion( Restriction restriction, boolean includeSnapshots ) { return getNewestVersion( null, restriction, includeSnapshots ); } + @Override public final ArtifactVersion getNewestVersion( VersionRange versionRange, boolean includeSnapshots ) { return getNewestVersion( versionRange, null, includeSnapshots ); } + @Override public final boolean containsVersion( String version ) { for ( ArtifactVersion candidate : getVersions( true ) ) @@ -216,25 +228,20 @@ public final boolean containsVersion( String version ) return false; } + private ArtifactVersion[] getNewerVersions( ArtifactVersion version, boolean includeSnapshots ) + { + Restriction restriction = new Restriction( version, false, null, false ); + return getVersions( restriction, includeSnapshots ); + } + + @Override public final ArtifactVersion[] getNewerVersions( String version, boolean includeSnapshots ) { return getNewerVersions( new DefaultArtifactVersion( version ), includeSnapshots ); } - /** - * Returns an array of newer versions than the given version, given the upper bound segment and whether snapshots - * should be included. - * - * @param version current version - * @param upperBoundSegment the upper bound segment; empty() means no upper bound - * @param includeSnapshots whether snapshot versions should be included - * @return array of newer versions fulfilling the criteria - * @throws InvalidSegmentException if the requested segment is outside the bounds (less than 1 or greater than - * the segment count) - * @deprecated please use {@link AbstractVersionDetails#getNewerVersions(String, Optional, boolean, boolean)}, - * boolean, boolean)} instead - */ @Deprecated + @Override public final ArtifactVersion[] getNewerVersions( String version, Optional upperBoundSegment, boolean includeSnapshots ) throws InvalidSegmentException @@ -242,19 +249,7 @@ public final ArtifactVersion[] getNewerVersions( String version, Optional upperBoundSegment, boolean includeSnapshots, boolean allowDowngrade ) throws InvalidSegmentException @@ -279,17 +274,20 @@ public final ArtifactVersion[] getNewerVersions( String versionString, Optional< return getVersions( restriction, includeSnapshots ); } + @Override public final ArtifactVersion getOldestVersion( VersionRange versionRange, boolean includeSnapshots ) { return getOldestVersion( versionRange, null, includeSnapshots ); } + @Override public final ArtifactVersion getOldestVersion( Restriction restriction, boolean includeSnapshots ) { return getOldestVersion( null, restriction, includeSnapshots ); } + @Override public final ArtifactVersion getOldestVersion( VersionRange versionRange, Restriction restriction, boolean includeSnapshots ) { @@ -321,11 +319,13 @@ else if ( versionComparator.compare( oldest, candidate ) > 0 ) return oldest; } + @Override public final ArtifactVersion[] getVersions( Restriction restriction, boolean includeSnapshots ) { return getVersions( null, restriction, includeSnapshots ); } + @Override public final ArtifactVersion[] getVersions( VersionRange versionRange, Restriction restriction, boolean includeSnapshots ) { @@ -350,6 +350,7 @@ public final ArtifactVersion[] getVersions( VersionRange versionRange, Restricti return result.toArray( new ArtifactVersion[0] ); } + @Override public final ArtifactVersion getOldestUpdate( ArtifactVersion currentVersion, Optional updateScope, boolean includeSnapshots ) { @@ -364,6 +365,7 @@ public final ArtifactVersion getOldestUpdate( ArtifactVersion currentVersion, Op } } + @Override public final ArtifactVersion getNewestUpdate( ArtifactVersion currentVersion, Optional updateScope, boolean includeSnapshots ) { @@ -378,6 +380,7 @@ public final ArtifactVersion getNewestUpdate( ArtifactVersion currentVersion, Op } } + @Override public final ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, Optional updateScope, boolean includeSnapshots ) { @@ -392,21 +395,25 @@ public final ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, Op } } + @Override public final ArtifactVersion getOldestUpdate( Optional updateScope ) { return getOldestUpdate( updateScope, isIncludeSnapshots() ); } + @Override public final ArtifactVersion getNewestUpdate( Optional updateScope ) { return getNewestUpdate( updateScope, isIncludeSnapshots() ); } + @Override public final ArtifactVersion[] getAllUpdates( Optional updateScope ) { return getAllUpdates( updateScope, isIncludeSnapshots() ); } + @Override public final ArtifactVersion getOldestUpdate( Optional updateScope, boolean includeSnapshots ) { if ( isCurrentVersionDefined() ) @@ -416,6 +423,7 @@ public final ArtifactVersion getOldestUpdate( Optional updateScope, boo return null; } + @Override public final ArtifactVersion getNewestUpdate( Optional updateScope, boolean includeSnapshots ) { if ( isCurrentVersionDefined() ) @@ -425,6 +433,7 @@ public final ArtifactVersion getNewestUpdate( Optional updateScope, boo return null; } + @Override public final ArtifactVersion[] getAllUpdates( Optional updateScope, boolean includeSnapshots ) { if ( isCurrentVersionDefined() ) @@ -434,11 +443,13 @@ public final ArtifactVersion[] getAllUpdates( Optional updateScope, boo return null; } + @Override public final ArtifactVersion[] getAllUpdates( VersionRange versionRange ) { return getAllUpdates( versionRange, isIncludeSnapshots() ); } + @Override public ArtifactVersion[] getAllUpdates( VersionRange versionRange, boolean includeSnapshots ) { Restriction restriction = new Restriction( getCurrentVersion(), false, null, false ); diff --git a/src/main/java/org/codehaus/mojo/versions/api/VersionDetails.java b/src/main/java/org/codehaus/mojo/versions/api/VersionDetails.java index 60b48fe1a9..c42c9745f3 100644 --- a/src/main/java/org/codehaus/mojo/versions/api/VersionDetails.java +++ b/src/main/java/org/codehaus/mojo/versions/api/VersionDetails.java @@ -44,6 +44,42 @@ public interface VersionDetails */ boolean containsVersion( String version ); + /** + * Returns true if and only if getCurrentVersion() != null. + * + * @return true if and only if getCurrentVersion() != null. + * @since 1.0-beta-1 + */ + boolean isCurrentVersionDefined(); + + /** + * Sets the current version. + * + * @param currentVersion The new current version. + * @since 1.0-beta-1 + */ + void setCurrentVersion( ArtifactVersion currentVersion ); + + /** + * Sets the current version. + * + * @param currentVersion The new current version. + * @since 1.0-beta-1 + */ + void setCurrentVersion( String currentVersion ); + + boolean isIncludeSnapshots(); + + void setIncludeSnapshots( boolean includeSnapshots ); + + /** + * Retrieves the current version. + * + * @return The current version (may be null). + * @since 1.0-beta-1 + */ + ArtifactVersion getCurrentVersion(); + /** * Gets the rule for version comparison of this artifact. * @@ -122,6 +158,19 @@ public interface VersionDetails */ ArtifactVersion[] getVersions( VersionRange versionRange, Restriction restriction, boolean includeSnapshots ); + /** + * Returns the latest version given the version range, restricition, whether to include snapshots and/or + * allow downgrades, or {@code null} if no such version exists. + * + * @param versionRange range to look for the versions + * @param restriction restriction restricting the version lookup + * @param includeSnapshots true if snapshots are to be included. + * @param allowDowngrade whether downgrades are allowed + * @return the latest version satisfying the conditions or null if no version is available. + */ + ArtifactVersion getNewestVersion( VersionRange versionRange, Restriction restriction, + boolean includeSnapshots, boolean allowDowngrade ); + /** * Returns the latest version newer than the specified lowerBound, but less than the specified upper bound or * null if no such version exists. @@ -180,6 +229,64 @@ ArtifactVersion getNewestVersion( ArtifactVersion lowerBound, ArtifactVersion up */ ArtifactVersion getNewestVersion( VersionRange versionRange, boolean includeSnapshots ); + /** + * Returns the newest version newer than the specified current version, but within the specified update scope or + * null if no such version exists. + * + * @param currentVersion the lower bound or null if the lower limit is unbounded. + * @param updateScope the update scope to include. + * @param includeSnapshots true if snapshots are to be included. + * @return the newest version after currentVersion within the specified update scope or null if no + * version is available. + * @throws InvalidSegmentException thrown if the updateScope is greater than the number of segments + * @since 1.0-beta-1 + */ + ArtifactVersion getNewestUpdate( ArtifactVersion currentVersion, Optional updateScope, + boolean includeSnapshots ) throws InvalidSegmentException; + + /** + * Returns an array of newer versions than the given version, given whether snapshots + * should be included. + * + * @param version current version in String format + * @param includeSnapshots whether snapshot versions should be included + * @return array of newer versions fulfilling the criteria + */ + ArtifactVersion[] getNewerVersions( String version, boolean includeSnapshots ); + + /** + * Returns an array of newer versions than the given version, given the upper bound segment and whether snapshots + * should be included. + * + * @param version current version + * @param upperBoundSegment the upper bound segment; empty() means no upper bound + * @param includeSnapshots whether snapshot versions should be included + * @return array of newer versions fulfilling the criteria + * @throws InvalidSegmentException if the requested segment is outside the bounds (less than 1 or greater than + * the segment count) + * @deprecated please use {@link AbstractVersionDetails#getNewerVersions(String, Optional, boolean, boolean)}, + * boolean, boolean)} instead + */ + ArtifactVersion[] getNewerVersions( String version, Optional upperBoundSegment, + boolean includeSnapshots ) throws InvalidSegmentException; + + /** + * Returns an array of newer versions than the given version, given the upper bound segment and whether snapshots + * should be included. + * + * @param versionString current version + * @param upperBoundSegment the upper bound segment; empty() means no upper bound + * @param includeSnapshots whether snapshot versions should be included + * @param allowDowngrade whether to allow downgrading if the current version is a snapshots and snapshots + * are disallowed + * @return array of newer versions fulfilling the criteria + * @throws InvalidSegmentException if the requested segment is outside the bounds (less than 1 or greater than + * the segment count) + */ + ArtifactVersion[] getNewerVersions( String versionString, Optional upperBoundSegment, + boolean includeSnapshots, boolean allowDowngrade ) + throws InvalidSegmentException; + /** * Returns the oldest version within the specified version range or null if no such version exists. * @@ -227,21 +334,6 @@ ArtifactVersion getNewestVersion( ArtifactVersion lowerBound, ArtifactVersion up ArtifactVersion getOldestUpdate( ArtifactVersion currentVersion, Optional updateScope, boolean includeSnapshots ) throws InvalidSegmentException; - /** - * Returns the newest version newer than the specified current version, but within the specified update scope or - * null if no such version exists. - * - * @param currentVersion the lower bound or null if the lower limit is unbounded. - * @param updateScope the update scope to include. - * @param includeSnapshots true if snapshots are to be included. - * @return the newest version after currentVersion within the specified update scope or null if no - * version is available. - * @throws InvalidSegmentException thrown if the updateScope is greater than the number of segments - * @since 1.0-beta-1 - */ - ArtifactVersion getNewestUpdate( ArtifactVersion currentVersion, Optional updateScope, - boolean includeSnapshots ) throws InvalidSegmentException; - /** * Returns the all versions newer than the specified current version, but within the specified update scope. * @@ -255,42 +347,6 @@ ArtifactVersion getNewestUpdate( ArtifactVersion currentVersion, Optional updateScope, boolean includeSnapshots ) throws InvalidSegmentException; - /** - * Returns true if and only if getCurrentVersion() != null. - * - * @return true if and only if getCurrentVersion() != null. - * @since 1.0-beta-1 - */ - boolean isCurrentVersionDefined(); - - /** - * Sets the current version. - * - * @param currentVersion The new current version. - * @since 1.0-beta-1 - */ - void setCurrentVersion( ArtifactVersion currentVersion ); - - /** - * Sets the current version. - * - * @param currentVersion The new current version. - * @since 1.0-beta-1 - */ - void setCurrentVersion( String currentVersion ); - - boolean isIncludeSnapshots(); - - void setIncludeSnapshots( boolean includeSnapshots ); - - /** - * Retrieves the current version. - * - * @return The current version (may be null). - * @since 1.0-beta-1 - */ - ArtifactVersion getCurrentVersion(); - /** * Returns the oldest version newer than the current version, but within the specified update scope or * null if no such version exists.