From d8497e955a8ef966e95600260b980f1d0ca1a7ec Mon Sep 17 00:00:00 2001 From: Andrzej Jarmoniuk Date: Sat, 17 Sep 2022 14:00:25 +0200 Subject: [PATCH] Removing UpdateScope + refactoring VersionsHelper --- .../AbstractVersionsReportRenderer.java | 128 ++-- .../versions/DependencyUpdatesRenderer.java | 15 +- .../DependencyUpdatesXmlRenderer.java | 30 +- .../DisplayDependencyUpdatesMojo.java | 39 +- .../mojo/versions/PluginUpdatesDetails.java | 7 +- .../mojo/versions/PluginUpdatesRenderer.java | 74 +- .../versions/PropertyUpdatesRenderer.java | 15 +- .../versions/api/AbstractVersionDetails.java | 162 ++--- .../versions/api/DefaultVersionsHelper.java | 12 - .../codehaus/mojo/versions/api/Segment.java | 53 ++ .../mojo/versions/api/UpdateScope.java | 656 ------------------ .../mojo/versions/api/VersionDetails.java | 204 +----- .../mojo/versions/api/VersionsHelper.java | 12 - .../versions/ordering/VersionComparator.java | 1 + 14 files changed, 288 insertions(+), 1120 deletions(-) create mode 100644 src/main/java/org/codehaus/mojo/versions/api/Segment.java delete mode 100644 src/main/java/org/codehaus/mojo/versions/api/UpdateScope.java diff --git a/src/main/java/org/codehaus/mojo/versions/AbstractVersionsReportRenderer.java b/src/main/java/org/codehaus/mojo/versions/AbstractVersionsReportRenderer.java index 470f9c4a1..e79d29b6f 100644 --- a/src/main/java/org/codehaus/mojo/versions/AbstractVersionsReportRenderer.java +++ b/src/main/java/org/codehaus/mojo/versions/AbstractVersionsReportRenderer.java @@ -36,10 +36,16 @@ import org.codehaus.mojo.versions.api.ArtifactAssociation; import org.codehaus.mojo.versions.api.ArtifactVersions; import org.codehaus.mojo.versions.api.PropertyVersions; -import org.codehaus.mojo.versions.api.UpdateScope; import org.codehaus.plexus.i18n.I18N; import org.codehaus.plexus.util.StringUtils; +import static java.util.Optional.empty; +import static java.util.Optional.of; +import static org.codehaus.mojo.versions.api.Segment.INCREMENTAL; +import static org.codehaus.mojo.versions.api.Segment.MAJOR; +import static org.codehaus.mojo.versions.api.Segment.MINOR; +import static org.codehaus.mojo.versions.api.Segment.SUBINCREMENTAL; + /** * Base class for report renderers. * @@ -122,7 +128,7 @@ protected void renderDependencySummaryTableRow( Dependency dependency, ArtifactV { sink.tableRow(); sink.tableCell(); - ArtifactVersion[] allUpdates = details.getAllUpdates( UpdateScope.ANY ); + ArtifactVersion[] allUpdates = details.getAllUpdates( empty() ); if ( allUpdates == null || allUpdates.length == 0 ) { renderSuccessIcon(); @@ -161,37 +167,37 @@ protected void renderDependencySummaryTableRow( Dependency dependency, ArtifactV } sink.tableCell(); - if ( details.getNewestUpdate( UpdateScope.SUBINCREMENTAL ) != null ) + if ( details.getNewestUpdate( of( SUBINCREMENTAL ) ) != null ) { safeBold(); - sink.text( details.getNewestUpdate( UpdateScope.SUBINCREMENTAL ).toString() ); + sink.text( details.getNewestUpdate( of( SUBINCREMENTAL ) ).toString() ); safeBold_(); } sink.tableCell_(); sink.tableCell(); - if ( details.getNewestUpdate( UpdateScope.INCREMENTAL ) != null ) + if ( details.getNewestUpdate( of( INCREMENTAL ) ) != null ) { safeBold(); - sink.text( details.getNewestUpdate( UpdateScope.INCREMENTAL ).toString() ); + sink.text( details.getNewestUpdate( of( INCREMENTAL ) ).toString() ); safeBold_(); } sink.tableCell_(); sink.tableCell(); - if ( details.getNewestUpdate( UpdateScope.MINOR ) != null ) + if ( details.getNewestUpdate( of( MINOR ) ) != null ) { safeBold(); - sink.text( details.getNewestUpdate( UpdateScope.MINOR ).toString() ); + sink.text( details.getNewestUpdate( of( MINOR ) ).toString() ); safeBold_(); } sink.tableCell_(); sink.tableCell(); - if ( details.getNewestUpdate( UpdateScope.MAJOR ) != null ) + if ( details.getNewestUpdate( of( MAJOR ) ) != null ) { safeBold(); - sink.text( details.getNewestUpdate( UpdateScope.MAJOR ).toString() ); + sink.text( details.getNewestUpdate( of( MAJOR ) ).toString() ); safeBold_(); } sink.tableCell_(); @@ -323,26 +329,26 @@ protected void renderDependencyDetailTable( Dependency dependency, ArtifactVersi sink.text( getText( "report.status" ) ); sink.tableHeaderCell_(); sink.tableCell( cellAttributes ); - ArtifactVersion[] versions = details.getAllUpdates( UpdateScope.ANY ); - if ( details.getOldestUpdate( UpdateScope.SUBINCREMENTAL ) != null ) + ArtifactVersion[] versions = details.getAllUpdates( empty() ); + if ( details.getOldestUpdate( of( SUBINCREMENTAL ) ) != null ) { renderWarningIcon(); sink.nonBreakingSpace(); sink.text( getText( "report.otherUpdatesAvailable" ) ); } - else if ( details.getOldestUpdate( UpdateScope.INCREMENTAL ) != null ) + else if ( details.getOldestUpdate( of( INCREMENTAL ) ) != null ) { renderWarningIcon(); sink.nonBreakingSpace(); sink.text( getText( "report.incrementalUpdatesAvailable" ) ); } - else if ( details.getOldestUpdate( UpdateScope.MINOR ) != null ) + else if ( details.getOldestUpdate( of( MINOR ) ) != null ) { renderWarningIcon(); sink.nonBreakingSpace(); sink.text( getText( "report.minorUpdatesAvailable" ) ); } - else if ( details.getOldestUpdate( UpdateScope.MAJOR ) != null ) + else if ( details.getOldestUpdate( of( MAJOR ) ) != null ) { renderWarningIcon(); sink.nonBreakingSpace(); @@ -426,14 +432,14 @@ else if ( details.getOldestUpdate( UpdateScope.MAJOR ) != null ) { sink.lineBreak(); } - boolean bold = equals( versions[i], details.getOldestUpdate( UpdateScope.SUBINCREMENTAL ) ) - || equals( versions[i], details.getNewestUpdate( UpdateScope.SUBINCREMENTAL ) ) - || equals( versions[i], details.getOldestUpdate( UpdateScope.INCREMENTAL ) ) - || equals( versions[i], details.getNewestUpdate( UpdateScope.INCREMENTAL ) ) - || equals( versions[i], details.getOldestUpdate( UpdateScope.MINOR ) ) - || equals( versions[i], details.getNewestUpdate( UpdateScope.MINOR ) ) - || equals( versions[i], details.getOldestUpdate( UpdateScope.MAJOR ) ) - || equals( versions[i], details.getNewestUpdate( UpdateScope.MAJOR ) ); + boolean bold = equals( versions[i], details.getOldestUpdate( of( SUBINCREMENTAL ) ) ) + || equals( versions[i], details.getNewestUpdate( of( SUBINCREMENTAL ) ) ) + || equals( versions[i], details.getOldestUpdate( of( INCREMENTAL ) ) ) + || equals( versions[i], details.getNewestUpdate( of( INCREMENTAL ) ) ) + || equals( versions[i], details.getOldestUpdate( of( MINOR ) ) ) + || equals( versions[i], details.getNewestUpdate( of( MINOR ) ) ) + || equals( versions[i], details.getOldestUpdate( of( MAJOR ) ) ) + || equals( versions[i], details.getNewestUpdate( of( MAJOR ) ) ); if ( bold ) { safeBold(); @@ -444,35 +450,35 @@ else if ( details.getOldestUpdate( UpdateScope.MAJOR ) != null ) safeBold_(); sink.nonBreakingSpace(); safeItalic(); - if ( equals( versions[i], details.getOldestUpdate( UpdateScope.SUBINCREMENTAL ) ) ) + if ( equals( versions[i], details.getOldestUpdate( of( SUBINCREMENTAL ) ) ) ) { sink.text( getText( "report.nextVersion" ) ); } - else if ( equals( versions[i], details.getNewestUpdate( UpdateScope.SUBINCREMENTAL ) ) ) + else if ( equals( versions[i], details.getNewestUpdate( of( SUBINCREMENTAL ) ) ) ) { sink.text( getText( "report.latestSubIncremental" ) ); } - else if ( equals( versions[i], details.getOldestUpdate( UpdateScope.INCREMENTAL ) ) ) + else if ( equals( versions[i], details.getOldestUpdate( of( INCREMENTAL ) ) ) ) { sink.text( getText( "report.nextIncremental" ) ); } - else if ( equals( versions[i], details.getNewestUpdate( UpdateScope.INCREMENTAL ) ) ) + else if ( equals( versions[i], details.getNewestUpdate( of( INCREMENTAL ) ) ) ) { sink.text( getText( "report.latestIncremental" ) ); } - else if ( equals( versions[i], details.getOldestUpdate( UpdateScope.MINOR ) ) ) + else if ( equals( versions[i], details.getOldestUpdate( of( MINOR ) ) ) ) { sink.text( getText( "report.nextMinor" ) ); } - else if ( equals( versions[i], details.getNewestUpdate( UpdateScope.MINOR ) ) ) + else if ( equals( versions[i], details.getNewestUpdate( of( MINOR ) ) ) ) { sink.text( getText( "report.latestMinor" ) ); } - else if ( equals( versions[i], details.getOldestUpdate( UpdateScope.MAJOR ) ) ) + else if ( equals( versions[i], details.getOldestUpdate( of( MAJOR ) ) ) ) { sink.text( getText( "report.nextMajor" ) ); } - else if ( equals( versions[i], details.getNewestUpdate( UpdateScope.MAJOR ) ) ) + else if ( equals( versions[i], details.getNewestUpdate( of( MAJOR ) ) ) ) { sink.text( getText( "report.latestMajor" ) ); } @@ -522,7 +528,7 @@ protected void renderPropertySummaryTableRow( Property property, PropertyVersion { sink.tableRow(); sink.tableCell(); - if ( versions.getAllUpdates( UpdateScope.ANY ).length == 0 ) + if ( versions.getAllUpdates( empty() ).length == 0 ) { renderSuccessIcon(); } @@ -539,37 +545,37 @@ protected void renderPropertySummaryTableRow( Property property, PropertyVersion sink.tableCell_(); sink.tableCell(); - if ( versions.getNewestUpdate( UpdateScope.SUBINCREMENTAL ) != null ) + if ( versions.getNewestUpdate( of( SUBINCREMENTAL ) ) != null ) { safeBold(); - sink.text( versions.getNewestUpdate( UpdateScope.SUBINCREMENTAL ).toString() ); + sink.text( versions.getNewestUpdate( of( SUBINCREMENTAL ) ).toString() ); safeBold_(); } sink.tableCell_(); sink.tableCell(); - if ( versions.getNewestUpdate( UpdateScope.INCREMENTAL ) != null ) + if ( versions.getNewestUpdate( of( INCREMENTAL ) ) != null ) { safeBold(); - sink.text( versions.getNewestUpdate( UpdateScope.INCREMENTAL ).toString() ); + sink.text( versions.getNewestUpdate( of( INCREMENTAL ) ).toString() ); safeBold_(); } sink.tableCell_(); sink.tableCell(); - if ( versions.getNewestUpdate( UpdateScope.MINOR ) != null ) + if ( versions.getNewestUpdate( of( MINOR ) ) != null ) { safeBold(); - sink.text( versions.getNewestUpdate( UpdateScope.MINOR ).toString() ); + sink.text( versions.getNewestUpdate( of( MINOR ) ).toString() ); safeBold_(); } sink.tableCell_(); sink.tableCell(); - if ( versions.getNewestUpdate( UpdateScope.MAJOR ) != null ) + if ( versions.getNewestUpdate( of( MAJOR ) ) != null ) { safeBold(); - sink.text( versions.getNewestUpdate( UpdateScope.MAJOR ).toString() ); + sink.text( versions.getNewestUpdate( of( MAJOR ) ).toString() ); safeBold_(); } sink.tableCell_(); @@ -618,27 +624,27 @@ protected void renderPropertyDetailTable( Property property, PropertyVersions ve sink.text( getText( "report.status" ) ); sink.tableHeaderCell_(); sink.tableCell( cellAttributes ); - ArtifactVersion[] artifactVersions = versions.getAllUpdates( UpdateScope.ANY ); + ArtifactVersion[] artifactVersions = versions.getAllUpdates( empty() ); Set rangeVersions = getVersionsInRange( property, versions, artifactVersions ); - if ( versions.getOldestUpdate( UpdateScope.SUBINCREMENTAL ) != null ) + if ( versions.getOldestUpdate( of( SUBINCREMENTAL ) ) != null ) { renderWarningIcon(); sink.nonBreakingSpace(); sink.text( getText( "report.otherUpdatesAvailable" ) ); } - else if ( versions.getOldestUpdate( UpdateScope.INCREMENTAL ) != null ) + else if ( versions.getOldestUpdate( of( INCREMENTAL ) ) != null ) { renderWarningIcon(); sink.nonBreakingSpace(); sink.text( getText( "report.incrementalUpdatesAvailable" ) ); } - else if ( versions.getOldestUpdate( UpdateScope.MINOR ) != null ) + else if ( versions.getOldestUpdate( of( MINOR ) ) != null ) { renderWarningIcon(); sink.nonBreakingSpace(); sink.text( getText( "report.minorUpdatesAvailable" ) ); } - else if ( versions.getOldestUpdate( UpdateScope.MAJOR ) != null ) + else if ( versions.getOldestUpdate( of( MAJOR ) ) != null ) { renderWarningIcon(); sink.nonBreakingSpace(); @@ -701,14 +707,14 @@ else if ( versions.getOldestUpdate( UpdateScope.MAJOR ) != null ) sink.lineBreak(); } boolean allowed = ( rangeVersions.contains( artifactVersions[i].toString() ) ); - boolean bold = equals( artifactVersions[i], versions.getOldestUpdate( UpdateScope.SUBINCREMENTAL ) ) - || equals( artifactVersions[i], versions.getNewestUpdate( UpdateScope.SUBINCREMENTAL ) ) - || equals( artifactVersions[i], versions.getOldestUpdate( UpdateScope.INCREMENTAL ) ) - || equals( artifactVersions[i], versions.getNewestUpdate( UpdateScope.INCREMENTAL ) ) - || equals( artifactVersions[i], versions.getOldestUpdate( UpdateScope.MINOR ) ) - || equals( artifactVersions[i], versions.getNewestUpdate( UpdateScope.MINOR ) ) - || equals( artifactVersions[i], versions.getOldestUpdate( UpdateScope.MAJOR ) ) - || equals( artifactVersions[i], versions.getNewestUpdate( UpdateScope.MAJOR ) ); + boolean bold = equals( artifactVersions[i], versions.getOldestUpdate( of( SUBINCREMENTAL ) ) ) + || equals( artifactVersions[i], versions.getNewestUpdate( of( SUBINCREMENTAL ) ) ) + || equals( artifactVersions[i], versions.getOldestUpdate( of( INCREMENTAL ) ) ) + || equals( artifactVersions[i], versions.getNewestUpdate( of( INCREMENTAL ) ) ) + || equals( artifactVersions[i], versions.getOldestUpdate( of( MINOR ) ) ) + || equals( artifactVersions[i], versions.getNewestUpdate( of( MINOR ) ) ) + || equals( artifactVersions[i], versions.getOldestUpdate( of( MAJOR ) ) ) + || equals( artifactVersions[i], versions.getNewestUpdate( of( MAJOR ) ) ); if ( !allowed ) { sink.text( "* " ); @@ -727,35 +733,35 @@ else if ( versions.getOldestUpdate( UpdateScope.MAJOR ) != null ) } sink.nonBreakingSpace(); safeItalic(); - if ( equals( artifactVersions[i], versions.getOldestUpdate( UpdateScope.SUBINCREMENTAL ) ) ) + if ( equals( artifactVersions[i], versions.getOldestUpdate( of( SUBINCREMENTAL ) ) ) ) { sink.text( getText( "report.nextVersion" ) ); } - else if ( equals( artifactVersions[i], versions.getNewestUpdate( UpdateScope.SUBINCREMENTAL ) ) ) + else if ( equals( artifactVersions[i], versions.getNewestUpdate( of( SUBINCREMENTAL ) ) ) ) { sink.text( getText( "report.latestSubIncremental" ) ); } - else if ( equals( artifactVersions[i], versions.getOldestUpdate( UpdateScope.INCREMENTAL ) ) ) + else if ( equals( artifactVersions[i], versions.getOldestUpdate( of( INCREMENTAL ) ) ) ) { sink.text( getText( "report.nextIncremental" ) ); } - else if ( equals( artifactVersions[i], versions.getNewestUpdate( UpdateScope.INCREMENTAL ) ) ) + else if ( equals( artifactVersions[i], versions.getNewestUpdate( of( INCREMENTAL ) ) ) ) { sink.text( getText( "report.latestIncremental" ) ); } - else if ( equals( artifactVersions[i], versions.getOldestUpdate( UpdateScope.MINOR ) ) ) + else if ( equals( artifactVersions[i], versions.getOldestUpdate( of( MINOR ) ) ) ) { sink.text( getText( "report.nextMinor" ) ); } - else if ( equals( artifactVersions[i], versions.getNewestUpdate( UpdateScope.MINOR ) ) ) + else if ( equals( artifactVersions[i], versions.getNewestUpdate( of( MINOR ) ) ) ) { sink.text( getText( "report.latestMinor" ) ); } - else if ( equals( artifactVersions[i], versions.getOldestUpdate( UpdateScope.MAJOR ) ) ) + else if ( equals( artifactVersions[i], versions.getOldestUpdate( of( MAJOR ) ) ) ) { sink.text( getText( "report.nextMajor" ) ); } - else if ( equals( artifactVersions[i], versions.getNewestUpdate( UpdateScope.MAJOR ) ) ) + else if ( equals( artifactVersions[i], versions.getNewestUpdate( of( MAJOR ) ) ) ) { sink.text( getText( "report.latestMajor" ) ); } diff --git a/src/main/java/org/codehaus/mojo/versions/DependencyUpdatesRenderer.java b/src/main/java/org/codehaus/mojo/versions/DependencyUpdatesRenderer.java index 3295b1a8c..647b86587 100644 --- a/src/main/java/org/codehaus/mojo/versions/DependencyUpdatesRenderer.java +++ b/src/main/java/org/codehaus/mojo/versions/DependencyUpdatesRenderer.java @@ -27,10 +27,15 @@ import org.apache.maven.doxia.sink.Sink; import org.apache.maven.model.Dependency; import org.codehaus.mojo.versions.api.ArtifactVersions; -import org.codehaus.mojo.versions.api.UpdateScope; import org.codehaus.mojo.versions.utils.DependencyComparator; import org.codehaus.plexus.i18n.I18N; +import static java.util.Optional.of; +import static org.codehaus.mojo.versions.api.Segment.INCREMENTAL; +import static org.codehaus.mojo.versions.api.Segment.MAJOR; +import static org.codehaus.mojo.versions.api.Segment.MINOR; +import static org.codehaus.mojo.versions.api.Segment.SUBINCREMENTAL; + /** * @since 1.0-beta-1 */ @@ -118,19 +123,19 @@ private void renderSummaryTotalsTable( Map allUpda int numCur = 0; for ( ArtifactVersions details : allUpdates.values() ) { - if ( details.getOldestUpdate( UpdateScope.SUBINCREMENTAL ) != null ) + if ( details.getOldestUpdate( of( SUBINCREMENTAL ) ) != null ) { numAny++; } - else if ( details.getOldestUpdate( UpdateScope.INCREMENTAL ) != null ) + else if ( details.getOldestUpdate( of( INCREMENTAL ) ) != null ) { numInc++; } - else if ( details.getOldestUpdate( UpdateScope.MINOR ) != null ) + else if ( details.getOldestUpdate( of( MINOR ) ) != null ) { numMin++; } - else if ( details.getOldestUpdate( UpdateScope.MAJOR ) != null ) + else if ( details.getOldestUpdate( of( MAJOR ) ) != null ) { numMaj++; } diff --git a/src/main/java/org/codehaus/mojo/versions/DependencyUpdatesXmlRenderer.java b/src/main/java/org/codehaus/mojo/versions/DependencyUpdatesXmlRenderer.java index eb89ee036..ec9aa2db3 100644 --- a/src/main/java/org/codehaus/mojo/versions/DependencyUpdatesXmlRenderer.java +++ b/src/main/java/org/codehaus/mojo/versions/DependencyUpdatesXmlRenderer.java @@ -24,15 +24,23 @@ import java.util.Collection; import java.util.Map; import java.util.Map.Entry; +import java.util.Optional; import java.util.TreeMap; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.model.Dependency; import org.apache.maven.reporting.MavenReportException; import org.codehaus.mojo.versions.api.ArtifactVersions; -import org.codehaus.mojo.versions.api.UpdateScope; +import org.codehaus.mojo.versions.api.Segment; import org.codehaus.mojo.versions.utils.DependencyComparator; +import static java.util.Optional.empty; +import static java.util.Optional.of; +import static org.codehaus.mojo.versions.api.Segment.INCREMENTAL; +import static org.codehaus.mojo.versions.api.Segment.MAJOR; +import static org.codehaus.mojo.versions.api.Segment.MINOR; +import static org.codehaus.mojo.versions.api.Segment.SUBINCREMENTAL; + /** * XML renderer for DependencyUpdatesReport creates an xml file in target directory and writes report about available * dependency/dependency management updates. @@ -145,19 +153,19 @@ public static String getSummaryBlock( Collection allUpdates ) int numCur = 0; for ( ArtifactVersions details : allUpdates ) { - if ( details.getOldestUpdate( UpdateScope.SUBINCREMENTAL ) != null ) + if ( details.getOldestUpdate( of( SUBINCREMENTAL ) ) != null ) { numAny++; } - else if ( details.getOldestUpdate( UpdateScope.INCREMENTAL ) != null ) + else if ( details.getOldestUpdate( of( INCREMENTAL ) ) != null ) { numInc++; } - else if ( details.getOldestUpdate( UpdateScope.MINOR ) != null ) + else if ( details.getOldestUpdate( of( MINOR ) ) != null ) { numMin++; } - else if ( details.getOldestUpdate( UpdateScope.MAJOR ) != null ) + else if ( details.getOldestUpdate( of( MAJOR ) ) != null ) { numMaj++; } @@ -190,17 +198,17 @@ public static String getVersionsBlocks( ArtifactVersions versions ) sBuilder.append( TAB ).append( TAB ).append( TAB ).append( wrapElement( versions.isCurrentVersionDefined() ? versions.getCurrentVersion().toString() : versions.getArtifact().getVersionRange().toString(), CURRENT_VERSION ) ).append( NL ); - ArtifactVersion nextVersion = versions.getOldestUpdate( UpdateScope.ANY ); + ArtifactVersion nextVersion = versions.getOldestUpdate( empty() ); if ( nextVersion != null ) { sBuilder.append( TAB ).append( TAB ).append( TAB ).append( wrapElement( nextVersion.toString(), NEXT_VERSION ) ).append( NL ); - String incrementalsBlock = getVersionsInScopeBlock( versions, UpdateScope.INCREMENTAL ); + String incrementalsBlock = getVersionsInScopeBlock( versions, of( INCREMENTAL ) ); sBuilder.append( incrementalsBlock ); - String minorsBlock = getVersionsInScopeBlock( versions, UpdateScope.MINOR ); + String minorsBlock = getVersionsInScopeBlock( versions, of( MINOR ) ); sBuilder.append( minorsBlock ); - String majorsBlock = getVersionsInScopeBlock( versions, UpdateScope.MAJOR ); + String majorsBlock = getVersionsInScopeBlock( versions, of( MAJOR ) ); sBuilder.append( majorsBlock ); String status = null; @@ -259,9 +267,9 @@ private static String getDependencyInfoBlock( Map return sBuilder.toString(); } - private static String getVersionsInScopeBlock( ArtifactVersions av, UpdateScope scope ) + private static String getVersionsInScopeBlock( ArtifactVersions av, Optional scope ) { - String versionsTag = scope.toString().toLowerCase() + "s"; + String versionsTag = scope.map( s -> s.name().toLowerCase() + "s" ).orElse( "any" ); StringBuilder sBuilder = new StringBuilder(); ArtifactVersion nextVersion = av.getOldestUpdate( scope ); diff --git a/src/main/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojo.java b/src/main/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojo.java index 73a4f353a..fc98c1d1d 100644 --- a/src/main/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojo.java +++ b/src/main/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojo.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.Set; import java.util.TreeSet; import java.util.stream.Collectors; @@ -43,14 +44,19 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.codehaus.mojo.versions.api.ArtifactVersions; -import org.codehaus.mojo.versions.api.UpdateScope; +import org.codehaus.mojo.versions.api.Segment; import org.codehaus.mojo.versions.filtering.DependencyFilter; import org.codehaus.mojo.versions.filtering.WildcardMatcher; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.DependencyComparator; import org.codehaus.plexus.util.StringUtils; +import static java.util.Optional.empty; +import static java.util.Optional.of; import static org.apache.commons.lang3.StringUtils.countMatches; +import static org.codehaus.mojo.versions.api.Segment.INCREMENTAL; +import static org.codehaus.mojo.versions.api.Segment.MAJOR; +import static org.codehaus.mojo.versions.api.Segment.MINOR; /** * Displays all dependencies that have newer versions available. @@ -669,31 +675,14 @@ private DependencyManagement getProjectDependencyManagement( MavenProject projec } } - private UpdateScope calculateUpdateScope() + private Optional calculateUpdateScope() { - UpdateScope result = UpdateScope.ANY; - if ( !allowAnyUpdates ) - { - if ( allowMajorUpdates ) - { - result = UpdateScope.MAJOR; - } - else - { - if ( allowMinorUpdates ) - { - result = UpdateScope.MINOR; - } - else - { - if ( allowIncrementalUpdates ) - { - result = UpdateScope.INCREMENTAL; - } - } - } - } - return result; + return !allowAnyUpdates + ? allowMajorUpdates ? of( MAJOR ) + : allowMinorUpdates ? of( MINOR ) + : allowIncrementalUpdates ? of( INCREMENTAL ) + : empty() + : empty(); } private void logUpdates( Map updates, String section ) diff --git a/src/main/java/org/codehaus/mojo/versions/PluginUpdatesDetails.java b/src/main/java/org/codehaus/mojo/versions/PluginUpdatesDetails.java index f8f7af328..a4fd2db23 100644 --- a/src/main/java/org/codehaus/mojo/versions/PluginUpdatesDetails.java +++ b/src/main/java/org/codehaus/mojo/versions/PluginUpdatesDetails.java @@ -25,7 +25,8 @@ import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.model.Dependency; import org.codehaus.mojo.versions.api.ArtifactVersions; -import org.codehaus.mojo.versions.api.UpdateScope; + +import static java.util.Optional.empty; /** * Details of a plugin's updates. @@ -65,7 +66,7 @@ public Map getDependencyVersions() */ public boolean isArtifactUpdateAvailable() { - return artifactVersions.getAllUpdates( UpdateScope.ANY, includeSnapshots ).length > 0; + return artifactVersions.getAllUpdates( empty(), includeSnapshots ).length > 0; } /** @@ -77,7 +78,7 @@ public boolean isDependencyUpdateAvailable() { for ( ArtifactVersions versions : dependencyVersions.values() ) { - ArtifactVersion[] dependencyUpdates = versions.getAllUpdates( UpdateScope.ANY, includeSnapshots ); + ArtifactVersion[] dependencyUpdates = versions.getAllUpdates( empty(), includeSnapshots ); if ( dependencyUpdates != null && dependencyUpdates.length > 0 ) { return true; diff --git a/src/main/java/org/codehaus/mojo/versions/PluginUpdatesRenderer.java b/src/main/java/org/codehaus/mojo/versions/PluginUpdatesRenderer.java index 2154e53bf..bf887b8a6 100644 --- a/src/main/java/org/codehaus/mojo/versions/PluginUpdatesRenderer.java +++ b/src/main/java/org/codehaus/mojo/versions/PluginUpdatesRenderer.java @@ -32,10 +32,16 @@ import org.apache.maven.model.Dependency; import org.apache.maven.model.Plugin; import org.codehaus.mojo.versions.api.ArtifactVersions; -import org.codehaus.mojo.versions.api.UpdateScope; import org.codehaus.mojo.versions.utils.PluginComparator; import org.codehaus.plexus.i18n.I18N; +import static java.util.Optional.empty; +import static java.util.Optional.of; +import static org.codehaus.mojo.versions.api.Segment.INCREMENTAL; +import static org.codehaus.mojo.versions.api.Segment.MAJOR; +import static org.codehaus.mojo.versions.api.Segment.MINOR; +import static org.codehaus.mojo.versions.api.Segment.SUBINCREMENTAL; + /** * @since 1.0-beta-1 */ @@ -105,19 +111,19 @@ private void renderSummaryTotalsTable( Map allUpda for ( PluginUpdatesDetails pluginDetails : allUpdates.values() ) { ArtifactVersions details = pluginDetails.getArtifactVersions(); - if ( details.getOldestUpdate( UpdateScope.SUBINCREMENTAL ) != null ) + if ( details.getOldestUpdate( of( SUBINCREMENTAL ) ) != null ) { numAny++; } - else if ( details.getOldestUpdate( UpdateScope.INCREMENTAL ) != null ) + else if ( details.getOldestUpdate( of( INCREMENTAL ) ) != null ) { numInc++; } - else if ( details.getOldestUpdate( UpdateScope.MINOR ) != null ) + else if ( details.getOldestUpdate( of( MINOR ) ) != null ) { numMin++; } - else if ( details.getOldestUpdate( UpdateScope.MAJOR ) != null ) + else if ( details.getOldestUpdate( of( MAJOR ) ) != null ) { numMaj++; } @@ -292,37 +298,37 @@ private void renderPluginSummary( Plugin plugin, PluginUpdatesDetails details ) sink.tableCell_(); sink.tableCell(); - if ( details.getArtifactVersions().getNewestUpdate( UpdateScope.SUBINCREMENTAL ) != null ) + if ( details.getArtifactVersions().getNewestUpdate( of( SUBINCREMENTAL ) ) != null ) { safeBold(); - sink.text( details.getArtifactVersions().getNewestUpdate( UpdateScope.SUBINCREMENTAL ).toString() ); + sink.text( details.getArtifactVersions().getNewestUpdate( of( SUBINCREMENTAL ) ).toString() ); safeBold_(); } sink.tableCell_(); sink.tableCell(); - if ( details.getArtifactVersions().getNewestUpdate( UpdateScope.INCREMENTAL ) != null ) + if ( details.getArtifactVersions().getNewestUpdate( of( INCREMENTAL ) ) != null ) { safeBold(); - sink.text( details.getArtifactVersions().getNewestUpdate( UpdateScope.INCREMENTAL ).toString() ); + sink.text( details.getArtifactVersions().getNewestUpdate( of( INCREMENTAL ) ).toString() ); safeBold_(); } sink.tableCell_(); sink.tableCell(); - if ( details.getArtifactVersions().getNewestUpdate( UpdateScope.MINOR ) != null ) + if ( details.getArtifactVersions().getNewestUpdate( of( MINOR ) ) != null ) { safeBold(); - sink.text( details.getArtifactVersions().getNewestUpdate( UpdateScope.MINOR ).toString() ); + sink.text( details.getArtifactVersions().getNewestUpdate( of( MINOR ) ).toString() ); safeBold_(); } sink.tableCell_(); sink.tableCell(); - if ( details.getArtifactVersions().getNewestUpdate( UpdateScope.MAJOR ) != null ) + if ( details.getArtifactVersions().getNewestUpdate( of( MAJOR ) ) != null ) { safeBold(); - sink.text( details.getArtifactVersions().getNewestUpdate( UpdateScope.MAJOR ).toString() ); + sink.text( details.getArtifactVersions().getNewestUpdate( of( MAJOR ) ).toString() ); safeBold_(); } sink.tableCell_(); @@ -360,26 +366,26 @@ private void renderPluginDetail( Plugin plugin, PluginUpdatesDetails details ) sink.text( getText( "report.status" ) ); sink.tableHeaderCell_(); sink.tableCell( cellAttributes ); - ArtifactVersion[] versions = details.getArtifactVersions().getAllUpdates( UpdateScope.ANY ); - if ( details.getArtifactVersions().getOldestUpdate( UpdateScope.SUBINCREMENTAL ) != null ) + ArtifactVersion[] versions = details.getArtifactVersions().getAllUpdates( empty() ); + if ( details.getArtifactVersions().getOldestUpdate( of( SUBINCREMENTAL ) ) != null ) { renderWarningIcon(); sink.nonBreakingSpace(); sink.text( getText( "report.otherUpdatesAvailable" ) ); } - else if ( details.getArtifactVersions().getOldestUpdate( UpdateScope.INCREMENTAL ) != null ) + else if ( details.getArtifactVersions().getOldestUpdate( of( INCREMENTAL ) ) != null ) { renderWarningIcon(); sink.nonBreakingSpace(); sink.text( getText( "report.incrementalUpdatesAvailable" ) ); } - else if ( details.getArtifactVersions().getOldestUpdate( UpdateScope.MINOR ) != null ) + else if ( details.getArtifactVersions().getOldestUpdate( of( MINOR ) ) != null ) { renderWarningIcon(); sink.nonBreakingSpace(); sink.text( getText( "report.minorUpdatesAvailable" ) ); } - else if ( details.getArtifactVersions().getOldestUpdate( UpdateScope.MAJOR ) != null ) + else if ( details.getArtifactVersions().getOldestUpdate( of( MAJOR ) ) != null ) { renderWarningIcon(); sink.nonBreakingSpace(); @@ -431,15 +437,15 @@ else if ( details.getArtifactVersions().getOldestUpdate( UpdateScope.MAJOR ) != sink.lineBreak(); } boolean bold = equals( - versions[i], details.getArtifactVersions().getOldestUpdate( UpdateScope.SUBINCREMENTAL ) ) + versions[i], details.getArtifactVersions().getOldestUpdate( of( SUBINCREMENTAL ) ) ) || equals( versions[i], - details.getArtifactVersions().getNewestUpdate( UpdateScope.SUBINCREMENTAL ) ) - || equals( versions[i], details.getArtifactVersions().getOldestUpdate( UpdateScope.INCREMENTAL ) ) - || equals( versions[i], details.getArtifactVersions().getNewestUpdate( UpdateScope.INCREMENTAL ) ) - || equals( versions[i], details.getArtifactVersions().getOldestUpdate( UpdateScope.MINOR ) ) - || equals( versions[i], details.getArtifactVersions().getNewestUpdate( UpdateScope.MINOR ) ) - || equals( versions[i], details.getArtifactVersions().getOldestUpdate( UpdateScope.MAJOR ) ) - || equals( versions[i], details.getArtifactVersions().getNewestUpdate( UpdateScope.MAJOR ) ); + details.getArtifactVersions().getNewestUpdate( of( SUBINCREMENTAL ) ) ) + || equals( versions[i], details.getArtifactVersions().getOldestUpdate( of( INCREMENTAL ) ) ) + || equals( versions[i], details.getArtifactVersions().getNewestUpdate( of( INCREMENTAL ) ) ) + || equals( versions[i], details.getArtifactVersions().getOldestUpdate( of( MINOR ) ) ) + || equals( versions[i], details.getArtifactVersions().getNewestUpdate( of( MINOR ) ) ) + || equals( versions[i], details.getArtifactVersions().getOldestUpdate( of( MAJOR ) ) ) + || equals( versions[i], details.getArtifactVersions().getNewestUpdate( of( MAJOR ) ) ); if ( bold ) { safeBold(); @@ -451,42 +457,42 @@ else if ( details.getArtifactVersions().getOldestUpdate( UpdateScope.MAJOR ) != sink.nonBreakingSpace(); safeItalic(); if ( equals( versions[i], - details.getArtifactVersions().getOldestUpdate( UpdateScope.SUBINCREMENTAL ) ) ) + details.getArtifactVersions().getOldestUpdate( of( SUBINCREMENTAL ) ) ) ) { sink.text( getText( "report.nextVersion" ) ); } else if ( equals( versions[i], - details.getArtifactVersions().getNewestUpdate( UpdateScope.SUBINCREMENTAL ) ) ) + details.getArtifactVersions().getNewestUpdate( of( SUBINCREMENTAL ) ) ) ) { sink.text( getText( "report.latestSubIncremental" ) ); } else if ( equals( versions[i], - details.getArtifactVersions().getOldestUpdate( UpdateScope.INCREMENTAL ) ) ) + details.getArtifactVersions().getOldestUpdate( of( INCREMENTAL ) ) ) ) { sink.text( getText( "report.nextIncremental" ) ); } else if ( equals( versions[i], - details.getArtifactVersions().getNewestUpdate( UpdateScope.INCREMENTAL ) ) ) + details.getArtifactVersions().getNewestUpdate( of( INCREMENTAL ) ) ) ) { sink.text( getText( "report.latestIncremental" ) ); } else if ( equals( versions[i], - details.getArtifactVersions().getOldestUpdate( UpdateScope.MINOR ) ) ) + details.getArtifactVersions().getOldestUpdate( of( MINOR ) ) ) ) { sink.text( getText( "report.nextMinor" ) ); } else if ( equals( versions[i], - details.getArtifactVersions().getNewestUpdate( UpdateScope.MINOR ) ) ) + details.getArtifactVersions().getNewestUpdate( of( MINOR ) ) ) ) { sink.text( getText( "report.latestMinor" ) ); } else if ( equals( versions[i], - details.getArtifactVersions().getOldestUpdate( UpdateScope.MAJOR ) ) ) + details.getArtifactVersions().getOldestUpdate( of( MAJOR ) ) ) ) { sink.text( getText( "report.nextMajor" ) ); } else if ( equals( versions[i], - details.getArtifactVersions().getNewestUpdate( UpdateScope.MAJOR ) ) ) + details.getArtifactVersions().getNewestUpdate( of( MAJOR ) ) ) ) { sink.text( getText( "report.latestMajor" ) ); } diff --git a/src/main/java/org/codehaus/mojo/versions/PropertyUpdatesRenderer.java b/src/main/java/org/codehaus/mojo/versions/PropertyUpdatesRenderer.java index e46530d2f..b3d4686bb 100644 --- a/src/main/java/org/codehaus/mojo/versions/PropertyUpdatesRenderer.java +++ b/src/main/java/org/codehaus/mojo/versions/PropertyUpdatesRenderer.java @@ -25,10 +25,15 @@ import org.apache.maven.doxia.sink.Sink; import org.codehaus.mojo.versions.api.PropertyVersions; -import org.codehaus.mojo.versions.api.UpdateScope; import org.codehaus.mojo.versions.utils.PropertyComparator; import org.codehaus.plexus.i18n.I18N; +import static java.util.Optional.of; +import static org.codehaus.mojo.versions.api.Segment.INCREMENTAL; +import static org.codehaus.mojo.versions.api.Segment.MAJOR; +import static org.codehaus.mojo.versions.api.Segment.MINOR; +import static org.codehaus.mojo.versions.api.Segment.SUBINCREMENTAL; + /** * @since 1.0-beta-1 */ @@ -108,19 +113,19 @@ private void renderSummaryTotalsTable( Map allUpdate int numCur = 0; for ( PropertyVersions details : allUpdates.values() ) { - if ( details.getOldestUpdate( UpdateScope.SUBINCREMENTAL ) != null ) + if ( details.getOldestUpdate( of( SUBINCREMENTAL ) ) != null ) { numAny++; } - else if ( details.getOldestUpdate( UpdateScope.INCREMENTAL ) != null ) + else if ( details.getOldestUpdate( of( INCREMENTAL ) ) != null ) { numInc++; } - else if ( details.getOldestUpdate( UpdateScope.MINOR ) != null ) + else if ( details.getOldestUpdate( of( MINOR ) ) != null ) { numMin++; } - else if ( details.getOldestUpdate( UpdateScope.MAJOR ) != null ) + else if ( details.getOldestUpdate( of( MAJOR ) ) != null ) { numMaj++; } 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 1f5a9b71e..2bab33c80 100644 --- a/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java +++ b/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java @@ -73,12 +73,6 @@ protected AbstractVersionDetails() { } - protected AbstractVersionDetails( ArtifactVersion currentVersion, boolean includeSnapshots ) - { - this.currentVersion = currentVersion; - this.includeSnapshots = includeSnapshots; - } - public final boolean isCurrentVersionDefined() { return getCurrentVersion() != null; @@ -273,23 +267,11 @@ public final ArtifactVersion[] getNewerVersions( String versionString, int upper return getVersions( restriction, includeSnapshots ); } - public final ArtifactVersion getOldestVersion( ArtifactVersion lowerBound, ArtifactVersion upperBound ) - { - return getOldestVersion( lowerBound, upperBound, true ); - } - public final ArtifactVersion getOldestVersion( VersionRange versionRange, boolean includeSnapshots ) { return getOldestVersion( versionRange, null, includeSnapshots ); } - public final ArtifactVersion getOldestVersion( ArtifactVersion lowerBound, ArtifactVersion upperBound, - boolean includeSnapshots ) - { - Restriction restriction = new Restriction( lowerBound, false, upperBound, false ); - return getOldestVersion( restriction, includeSnapshots ); - } - public final ArtifactVersion getOldestVersion( Restriction restriction, boolean includeSnapshots ) { @@ -356,88 +338,61 @@ public final ArtifactVersion[] getVersions( VersionRange versionRange, Restricti return result.toArray( new ArtifactVersion[0] ); } - public final ArtifactVersion getOldestUpdate( ArtifactVersion currentVersion, UpdateScope updateScope ) - { - return getOldestUpdate( currentVersion, updateScope, isIncludeSnapshots() ); - } - - public final ArtifactVersion getNewestUpdate( ArtifactVersion currentVersion, UpdateScope updateScope ) - { - return getNewestUpdate( currentVersion, updateScope, isIncludeSnapshots() ); - } - - public final ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, UpdateScope updateScope ) - { - return getAllUpdates( currentVersion, updateScope, isIncludeSnapshots() ); - } - - public ArtifactVersion getOldestUpdate( ArtifactVersion currentVersion, VersionRange versionRange ) - { - return getOldestUpdate( currentVersion, versionRange, isIncludeSnapshots() ); - } - - public ArtifactVersion getNewestUpdate( ArtifactVersion currentVersion, VersionRange versionRange ) - { - return getNewestUpdate( currentVersion, versionRange, isIncludeSnapshots() ); - } - - public ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, VersionRange versionRange ) - { - return getAllUpdates( currentVersion, versionRange, isIncludeSnapshots() ); - } - - public final ArtifactVersion getOldestUpdate( ArtifactVersion currentVersion, UpdateScope updateScope, + public final ArtifactVersion getOldestUpdate( ArtifactVersion currentVersion, Optional updateScope, boolean includeSnapshots ) { - return updateScope.getOldestUpdate( this, currentVersion, includeSnapshots ); + try + { + return getOldestVersion( restrictionFor( currentVersion, updateScope ), includeSnapshots ); + } + catch ( InvalidSegmentException e ) + { + return null; + } } - public final ArtifactVersion getNewestUpdate( ArtifactVersion currentVersion, UpdateScope updateScope, + public final ArtifactVersion getNewestUpdate( ArtifactVersion currentVersion, Optional updateScope, boolean includeSnapshots ) { - return updateScope.getNewestUpdate( this, currentVersion, includeSnapshots ); + try + { + return getNewestVersion( restrictionFor( currentVersion, updateScope ), includeSnapshots ); + } + catch ( InvalidSegmentException e ) + { + return null; + } } - public final ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, UpdateScope updateScope, + public final ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, Optional updateScope, boolean includeSnapshots ) { - return updateScope.getAllUpdates( this, currentVersion, includeSnapshots ); - } - - public ArtifactVersion getOldestUpdate( ArtifactVersion currentVersion, VersionRange versionRange, - boolean includeSnapshots ) - { - return getOldestVersion( versionRange, includeSnapshots ); - } - - public ArtifactVersion getNewestUpdate( ArtifactVersion currentVersion, VersionRange versionRange, - boolean includeSnapshots ) - { - return getNewestVersion( versionRange, includeSnapshots ); - } - - public ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, VersionRange versionRange, - boolean includeSnapshots ) - { - return new ArtifactVersion[0]; // To change body of implemented methods use File | Settings | File Templates. + try + { + return getVersions( restrictionFor( currentVersion, updateScope ), includeSnapshots ); + } + catch ( InvalidSegmentException e ) + { + return null; + } } - public final ArtifactVersion getOldestUpdate( UpdateScope updateScope ) + public final ArtifactVersion getOldestUpdate( Optional updateScope ) { return getOldestUpdate( updateScope, isIncludeSnapshots() ); } - public final ArtifactVersion getNewestUpdate( UpdateScope updateScope ) + public final ArtifactVersion getNewestUpdate( Optional updateScope ) { return getNewestUpdate( updateScope, isIncludeSnapshots() ); } - public final ArtifactVersion[] getAllUpdates( UpdateScope updateScope ) + public final ArtifactVersion[] getAllUpdates( Optional updateScope ) { return getAllUpdates( updateScope, isIncludeSnapshots() ); } - public final ArtifactVersion getOldestUpdate( UpdateScope updateScope, boolean includeSnapshots ) + public final ArtifactVersion getOldestUpdate( Optional updateScope, boolean includeSnapshots ) { if ( isCurrentVersionDefined() ) { @@ -446,7 +401,7 @@ public final ArtifactVersion getOldestUpdate( UpdateScope updateScope, boolean i return null; } - public final ArtifactVersion getNewestUpdate( UpdateScope updateScope, boolean includeSnapshots ) + public final ArtifactVersion getNewestUpdate( Optional updateScope, boolean includeSnapshots ) { if ( isCurrentVersionDefined() ) { @@ -455,7 +410,7 @@ public final ArtifactVersion getNewestUpdate( UpdateScope updateScope, boolean i return null; } - public final ArtifactVersion[] getAllUpdates( UpdateScope updateScope, boolean includeSnapshots ) + public final ArtifactVersion[] getAllUpdates( Optional updateScope, boolean includeSnapshots ) { if ( isCurrentVersionDefined() ) { @@ -464,33 +419,11 @@ public final ArtifactVersion[] getAllUpdates( UpdateScope updateScope, boolean i return null; } - public final ArtifactVersion getOldestUpdate( VersionRange versionRange ) - { - return getOldestUpdate( versionRange, isIncludeSnapshots() ); - } - - public final ArtifactVersion getNewestUpdate( VersionRange versionRange ) - { - return getNewestUpdate( versionRange, isIncludeSnapshots() ); - } - public final ArtifactVersion[] getAllUpdates( VersionRange versionRange ) { return getAllUpdates( versionRange, isIncludeSnapshots() ); } - public ArtifactVersion getOldestUpdate( VersionRange versionRange, boolean includeSnapshots ) - { - Restriction restriction = new Restriction( getCurrentVersion(), false, null, false ); - return getOldestVersion( versionRange, restriction, includeSnapshots ); - } - - public ArtifactVersion getNewestUpdate( VersionRange versionRange, boolean includeSnapshots ) - { - Restriction restriction = new Restriction( getCurrentVersion(), false, null, false ); - return getNewestVersion( versionRange, restriction, includeSnapshots ); - } - public ArtifactVersion[] getAllUpdates( VersionRange versionRange, boolean includeSnapshots ) { Restriction restriction = new Restriction( getCurrentVersion(), false, null, false ); @@ -573,7 +506,7 @@ protected Optional getLowerBound( ArtifactVersion version, int unchanged * Checks if the candidate version is in the range of the restriction. * a custom comparator is/can be used to have milestones and rcs before final releases, * which is not yet possible with {@link Restriction#containsVersion(ArtifactVersion)}. - * @param restriction the range to check against. + * @PARAM RESTRICTION THE RANGE TO CHECK AGAINST. * @param candidate the version to check. * @return true if the candidate version is within the range of the restriction parameter. */ @@ -590,11 +523,28 @@ private boolean isVersionInRestriction( Restriction restriction, ArtifactVersion { return false; } - if ( ( !includeLower && lower == 0 ) || ( !includeUpper && upper == 0 ) ) - { - return false; - } - return true; + return ( includeLower || lower != 0 ) && ( includeUpper || upper != 0 ); } + /** + * Helper method to get the artifact boundaries for computing updates + * + * @param currentVersion The current version. + * @param scope scope of the restriction or Optional.empty() for no restriction + * @return {@linkplain Restriction} object based on the arguments + * @throws InvalidSegmentException if {@code segment} ∉ [0, segmentCount) + */ + protected Restriction restrictionFor( ArtifactVersion currentVersion, Optional scope ) + throws InvalidSegmentException + { + VersionComparator versionComparator = getVersionComparator(); + ArtifactVersion lowerBound = scope.isPresent() && scope.get().value() < Segment.SUBINCREMENTAL.value() + ? versionComparator.incrementSegment( currentVersion, scope.get().value() ) + : currentVersion; + ArtifactVersion upperBound = scope.isPresent() && scope.get().value() > Segment.MAJOR.value() + ? versionComparator.incrementSegment( currentVersion, scope.get().value() - 1 ) + : null; + return new Restriction( lowerBound, lowerBound != currentVersion, + upperBound, false ); + } } diff --git a/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java b/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java index 3251311d6..7331d857c 100644 --- a/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java +++ b/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java @@ -671,18 +671,6 @@ public ArtifactVersion createArtifactVersion( String version ) return new DefaultArtifactVersion( version ); } - @Override - public ArtifactVersions lookupArtifactUpdates( Artifact artifact, boolean allowSnapshots, - boolean usePluginRepositories ) - throws ArtifactMetadataRetrievalException - { - ArtifactVersions artifactVersions = lookupArtifactVersions( artifact, usePluginRepositories ); - - artifactVersions.setIncludeSnapshots( allowSnapshots ); - - return artifactVersions; - } - @Override public Map lookupDependenciesUpdates( Set dependencies, boolean usePluginRepositories ) diff --git a/src/main/java/org/codehaus/mojo/versions/api/Segment.java b/src/main/java/org/codehaus/mojo/versions/api/Segment.java new file mode 100644 index 000000000..b64e8abc2 --- /dev/null +++ b/src/main/java/org/codehaus/mojo/versions/api/Segment.java @@ -0,0 +1,53 @@ +package org.codehaus.mojo.versions.api; + +/* + * 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. + */ + +/** + * Indicates the segment along with its 0-based index + * + * @author Andrzej Jarmoniuk + */ +public enum Segment implements Comparable +{ + MAJOR( 0 ), MINOR( 1 ), INCREMENTAL( 2 ), SUBINCREMENTAL( 3 ); + + private final int index; + + Segment( int index ) + { + this.index = index; + } + + /** + * Returns the 0-based sendex index + * + * @return 0-based sendex index + */ + public int value() + { + return index; + } + + @Override + public String toString() + { + return name(); + } +} diff --git a/src/main/java/org/codehaus/mojo/versions/api/UpdateScope.java b/src/main/java/org/codehaus/mojo/versions/api/UpdateScope.java deleted file mode 100644 index 5dbdb2eb3..000000000 --- a/src/main/java/org/codehaus/mojo/versions/api/UpdateScope.java +++ /dev/null @@ -1,656 +0,0 @@ -package org.codehaus.mojo.versions.api; - -/* - * 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.io.ObjectStreamException; -import java.io.Serializable; -import java.io.StreamCorruptedException; -import java.util.HashMap; -import java.util.Map; - -import org.apache.maven.artifact.versioning.ArtifactVersion; -import org.apache.maven.artifact.versioning.Restriction; -import org.codehaus.mojo.versions.ordering.InvalidSegmentException; -import org.codehaus.mojo.versions.ordering.VersionComparator; - -/** - * Scopes of version updates. - * - * @author Stephen Connolly - * todo: convert this class to a Java 1.5 enum once we move to Java 1.5 - * @since 1.0-beta-1 - */ -public abstract class UpdateScope - implements Comparable, Serializable -{ - - /** - * Versions which are less than an incremental update. - * - * @since 1.0-beta-1 - */ - public static final UpdateScope SUBINCREMENTAL = new UpdateScope( "SUBINCREMENTAL", 0 ) - { - /** {@inheritDoc} */ - public ArtifactVersion getOldestUpdate( VersionDetails versionDetails, ArtifactVersion currentVersion, - boolean includeSnapshots ) - { - VersionComparator versionComparator = versionDetails.getVersionComparator(); - try - { - if ( versionComparator.getSegmentCount( currentVersion ) < 3 ) - { - return null; - } - ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 2 ); - Restriction restriction = new Restriction( currentVersion, false, upperBound, false ); - return versionDetails.getOldestVersion( restriction, includeSnapshots ); - } - catch ( InvalidSegmentException e ) - { - throw new RuntimeException( e ); - } - } - - /** {@inheritDoc} */ - public ArtifactVersion getNewestUpdate( VersionDetails versionDetails, ArtifactVersion currentVersion, - boolean includeSnapshots ) - { - VersionComparator versionComparator = versionDetails.getVersionComparator(); - try - { - if ( versionComparator.getSegmentCount( currentVersion ) < 3 ) - { - return null; - } - ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 2 ); - Restriction restriction = new Restriction( currentVersion, false, upperBound, false ); - return versionDetails.getNewestVersion( restriction, includeSnapshots ); - } - catch ( InvalidSegmentException e ) - { - throw new RuntimeException( e ); - } - } - - /** {@inheritDoc} */ - public ArtifactVersion[] getAllUpdates( VersionDetails versionDetails, ArtifactVersion currentVersion, - boolean includeSnapshots ) - { - VersionComparator versionComparator = versionDetails.getVersionComparator(); - try - { - if ( versionComparator.getSegmentCount( currentVersion ) < 3 ) - { - return null; - } - ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 2 ); - Restriction restriction = new Restriction( currentVersion, false, upperBound, false ); - return versionDetails.getVersions( restriction, includeSnapshots ); - } - catch ( InvalidSegmentException e ) - { - throw new RuntimeException( e ); - } - } - - }; - - /** - * Incremental version updates, that is the third segment of the version number, for example 1.0.0.15 - * to 1.0.1.0. - * - * @since 1.0-beta-1 - */ - public static final UpdateScope INCREMENTAL = new UpdateScope( "INCREMENTAL", 1 ) - { - /** {@inheritDoc} */ - public ArtifactVersion getOldestUpdate( VersionDetails versionDetails, ArtifactVersion currentVersion, - boolean includeSnapshots ) - { - VersionComparator versionComparator = versionDetails.getVersionComparator(); - try - { - if ( versionComparator.getSegmentCount( currentVersion ) < 3 ) - { - return null; - } - ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 2 ); - ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 1 ); - Restriction restriction = new Restriction( lowerBound, true, upperBound, false ); - return versionDetails.getOldestVersion( restriction, includeSnapshots ); - } - catch ( InvalidSegmentException e ) - { - throw new RuntimeException( e ); - } - } - - /** {@inheritDoc} */ - public ArtifactVersion getNewestUpdate( VersionDetails versionDetails, ArtifactVersion currentVersion, - boolean includeSnapshots ) - { - VersionComparator versionComparator = versionDetails.getVersionComparator(); - try - { - if ( versionComparator.getSegmentCount( currentVersion ) < 3 ) - { - return null; - } - ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 2 ); - ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 1 ); - Restriction restriction = new Restriction( lowerBound, true, upperBound, false ); - return versionDetails.getNewestVersion( restriction, includeSnapshots ); - } - catch ( InvalidSegmentException e ) - { - throw new RuntimeException( e ); - } - } - - /** {@inheritDoc} */ - public ArtifactVersion[] getAllUpdates( VersionDetails versionDetails, ArtifactVersion currentVersion, - boolean includeSnapshots ) - { - VersionComparator versionComparator = versionDetails.getVersionComparator(); - try - { - if ( versionComparator.getSegmentCount( currentVersion ) < 3 ) - { - return null; - } - ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 2 ); - ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 1 ); - Restriction restriction = new Restriction( lowerBound, true, upperBound, false ); - return versionDetails.getVersions( restriction, includeSnapshots ); - } - catch ( InvalidSegmentException e ) - { - throw new RuntimeException( e ); - } - } - - }; - - /** - * Minor version updates, that is the second segment of the version number, for example 1.0.0.15 to - * 1.1.0.0. - * - * @since 1.0-beta-1 - */ - public static final UpdateScope MINOR = new UpdateScope( "MINOR", 2 ) - { - /** {@inheritDoc} */ - public ArtifactVersion getOldestUpdate( VersionDetails versionDetails, ArtifactVersion currentVersion, - boolean includeSnapshots ) - { - VersionComparator versionComparator = versionDetails.getVersionComparator(); - try - { - if ( versionComparator.getSegmentCount( currentVersion ) < 2 ) - { - return null; - } - ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 1 ); - ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 0 ); - Restriction restriction = new Restriction( lowerBound, true, upperBound, false ); - return versionDetails.getOldestVersion( restriction, includeSnapshots ); - } - catch ( InvalidSegmentException e ) - { - throw new RuntimeException( e ); - } - } - - /** {@inheritDoc} */ - public ArtifactVersion getNewestUpdate( VersionDetails versionDetails, ArtifactVersion currentVersion, - boolean includeSnapshots ) - { - VersionComparator versionComparator = versionDetails.getVersionComparator(); - try - { - if ( versionComparator.getSegmentCount( currentVersion ) < 2 ) - { - return null; - } - ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 1 ); - ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 0 ); - Restriction restriction = new Restriction( lowerBound, true, upperBound, false ); - return versionDetails.getNewestVersion( restriction, includeSnapshots ); - } - catch ( InvalidSegmentException e ) - { - throw new RuntimeException( e ); - } - } - - /** {@inheritDoc} */ - public ArtifactVersion[] getAllUpdates( VersionDetails versionDetails, ArtifactVersion currentVersion, - boolean includeSnapshots ) - { - VersionComparator versionComparator = versionDetails.getVersionComparator(); - try - { - if ( versionComparator.getSegmentCount( currentVersion ) < 2 ) - { - return null; - } - ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 1 ); - ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 0 ); - Restriction restriction = new Restriction( lowerBound, true, upperBound, false ); - return versionDetails.getVersions( restriction, includeSnapshots ); - } - catch ( InvalidSegmentException e ) - { - throw new RuntimeException( e ); - } - } - - }; - - /** - * Major version updates, that is the first segment of the version number, for example 1.0.0.15 to - * 2.0.0.0. - * - * @since 1.0-beta-1 - */ - public static final UpdateScope MAJOR = new UpdateScope( "MAJOR", 3 ) - { - /** {@inheritDoc} */ - public ArtifactVersion getOldestUpdate( VersionDetails versionDetails, ArtifactVersion currentVersion, - boolean includeSnapshots ) - { - VersionComparator versionComparator = versionDetails.getVersionComparator(); - try - { - if ( versionComparator.getSegmentCount( currentVersion ) < 1 ) - { - return null; - } - ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 0 ); - Restriction restriction = new Restriction( lowerBound, true, null, false ); - return versionDetails.getOldestVersion( restriction, includeSnapshots ); - } - catch ( InvalidSegmentException e ) - { - throw new RuntimeException( e ); - } - } - - /** {@inheritDoc} */ - public ArtifactVersion getNewestUpdate( VersionDetails versionDetails, ArtifactVersion currentVersion, - boolean includeSnapshots ) - { - VersionComparator versionComparator = versionDetails.getVersionComparator(); - try - { - if ( versionComparator.getSegmentCount( currentVersion ) < 1 ) - { - return null; - } - ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 0 ); - Restriction restriction = new Restriction( lowerBound, true, null, false ); - return versionDetails.getNewestVersion( restriction, includeSnapshots ); - } - catch ( InvalidSegmentException e ) - { - throw new RuntimeException( e ); - } - } - - /** {@inheritDoc} */ - public ArtifactVersion[] getAllUpdates( VersionDetails versionDetails, ArtifactVersion currentVersion, - boolean includeSnapshots ) - { - VersionComparator versionComparator = versionDetails.getVersionComparator(); - try - { - if ( versionComparator.getSegmentCount( currentVersion ) < 1 ) - { - return null; - } - ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 0 ); - Restriction restriction = new Restriction( lowerBound, true, null, false ); - return versionDetails.getVersions( restriction, includeSnapshots ); - } - catch ( InvalidSegmentException e ) - { - throw new RuntimeException( e ); - } - } - - }; - - /** - * Any version updates. - * - * @since 1.0-beta-1 - */ - public static final UpdateScope ANY = new UpdateScope( "ANY", 4 ) - { - /** {@inheritDoc} */ - public ArtifactVersion getOldestUpdate( VersionDetails versionDetails, ArtifactVersion currentVersion, - boolean includeSnapshots ) - { - Restriction restriction = new Restriction( currentVersion, false, null, false ); - return versionDetails.getOldestVersion( restriction, includeSnapshots ); - } - - /** {@inheritDoc} */ - public ArtifactVersion getNewestUpdate( VersionDetails versionDetails, ArtifactVersion currentVersion, - boolean includeSnapshots ) - { - Restriction restriction = new Restriction( currentVersion, false, null, false ); - return versionDetails.getNewestVersion( restriction, includeSnapshots ); - } - - /** {@inheritDoc} */ - public ArtifactVersion[] getAllUpdates( VersionDetails versionDetails, ArtifactVersion currentVersion, - boolean includeSnapshots ) - { - Restriction restriction = new Restriction( currentVersion, false, null, false ); - return versionDetails.getVersions( restriction, includeSnapshots ); - } - - }; - - /** - * Returns the next version after the specified current version within this scope. - * - * @param versionDetails The versions to select from. - * @param currentVersion The current version. - * @param includeSnapshots Whether to include snapshots. - * @return The next version within this scope or null if there is no version within this scope. - */ - public abstract ArtifactVersion getOldestUpdate( VersionDetails versionDetails, ArtifactVersion currentVersion, - boolean includeSnapshots ); - - /** - * Returns the newest version after the specified current version within this scope. - * - * @param versionDetails The versions to select from. - * @param currentVersion The current version. - * @param includeSnapshots Whether to include snapshots. - * @return The newest version within this scope or null if there is no version within this scope. - */ - public abstract ArtifactVersion getNewestUpdate( VersionDetails versionDetails, ArtifactVersion currentVersion, - boolean includeSnapshots ); - - /** - * Returns all versions newer than the specified current version within this scope. - * - * @param versionDetails The versions to select from. - * @param currentVersion The current version. - * @param includeSnapshots Whether to include snapshots. - * @return All newer versions within this scope. - */ - public abstract ArtifactVersion[] getAllUpdates( VersionDetails versionDetails, ArtifactVersion currentVersion, - boolean includeSnapshots ); - - /** - * The name of this constant, as declared in the declaration. Most programmers should use the {@link #toString} - * method rather than accessing this field. - */ - private final String name; - - /** - * Returns the name of this enum constant, exactly as declared in its enum declaration. - *

- * Most programmers should use the {@link #toString} method in preference to this one, as the toString method may - * return a more user-friendly name. This method is designed primarily for use in specialized situations where - * correctness depends on getting the exact name, which will not vary from release to release. - *

- * - * @return the name of this enum constant - */ - public final String name() - { - return name; - } - - /** - * The ordinal of this enumeration constant (its position in the enum declaration, where the initial constant is - * assigned an ordinal of zero). - *

- * Most programmers will have no use for this field. - *

- */ - private final int ordinal; - - /** - * Returns the ordinal of this enumeration constant (its position in its enum declaration, where the initial - * constant is assigned an ordinal of zero). - *

- * Most programmers will have no use for this method. - *

- * - * @return the ordinal of this enumeration constant - */ - public final int ordinal() - { - return ordinal; - } - - /** - * Sole constructor. Programmers cannot invoke this constructor. - * - * @param name - The name of this enum constant, which is the identifier used to declare it. - * @param ordinal - The ordinal of this enumeration constant (its position in the enum declaration, where the - * initial constant is assigned an ordinal of zero). - */ - private UpdateScope( String name, int ordinal ) - { - this.name = name; - this.ordinal = ordinal; - } - - /** - * {@inheritDoc} - */ - public String toString() - { - return name; - } - - /** - * {@inheritDoc} - */ - public boolean equals( Object o ) - { - return this == o; - } - - /** - * {@inheritDoc} - */ - public int hashCode() - { - return super.hashCode(); - } - - /** - * Throws CloneNotSupportedException. This guarantees that levels are never cloned, which is necessary to preserve - * their "singleton" status. - * - * @return (neverreturns) - */ - protected final Object clone() - throws CloneNotSupportedException - { - throw new CloneNotSupportedException(); - } - - /** - * Compares this enum with the specified object for order. Returns a negative integer, zero, or a positive integer - * as this object is less than, equal to, or greater than the specified object. - *

- * Enum constants are only comparable to other enum constants of the same enum type. The natural order implemented - * by this method is the order in which the constants are declared. - *

- */ - public final int compareTo( UpdateScope other ) - { - UpdateScope self = this; - if ( self.getClass() != other.getClass() ) - { - throw new ClassCastException(); - } - return self.ordinal - other.ordinal; - } - - /** - * Returns the Class object corresponding to this enum constant's enum type. Two enum constants e1 and e2 are of the - * same enum type if and only if e1.getDeclaringClass() == e2.getDeclaringClass(). (The value returned by this - * method may differ from the one returned by the {@link Object#getClass} method for enum constants with - * constant-specific class bodies.) - * - * @return the Class object corresponding to this enum constant's enum type - */ - public final Class getDeclaringClass() - { - return getClass(); - } - - /** - * Returns the enum constant of the specified enum type with the specified name. The name must match exactly an - * identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.) - * - * @param name the name of the constant to return - * @return the enum constant of the specified enum type with the specified name - * @throws IllegalArgumentException if the specified enum type has no constant with the specified name, or the - * specified class object does not represent an enum type - * @throws NullPointerException if name is null - */ - public static UpdateScope valueOf( String name ) - { - UpdateScope result = LEVEL_CONSTANTS.get( name ); - if ( result != null ) - { - return result; - } - if ( name == null ) - { - throw new NullPointerException( "Name is null" ); - } - throw new IllegalArgumentException( "No enum const " + UpdateScope.class.getName() + "." + name ); - } - - public static UpdateScope[] values() - { - return new UpdateScope[] { SUBINCREMENTAL, INCREMENTAL, MINOR, MAJOR, ANY }; - } - - /** - * Classifies the type of update. - * - * @param comparator The version comparator to use for classifying. - * @param from The first version. - * @param to The second version. - * @return The update classification. - */ - public static UpdateScope classifyUpdate( VersionComparator comparator, ArtifactVersion from, ArtifactVersion to ) - throws InvalidSegmentException - { - if ( comparator.compare( from, to ) >= 0 ) - { - throw new IllegalArgumentException( "From version must be less than to version" ); - } - // the trick here is that incrementing from twice and to once, should give the same version - int matchSegment = 0; - for ( int segment = - Math.min( comparator.getSegmentCount( from ), comparator.getSegmentCount( to ) ); segment > 0; segment-- ) - { - ArtifactVersion f = comparator.incrementSegment( from, segment - 1 ); - f = comparator.incrementSegment( f, segment - 1 ); - ArtifactVersion t = comparator.incrementSegment( to, segment - 1 ); - if ( f.toString().equals( t.toString() ) ) - { - matchSegment = segment; - break; - } - } - switch ( matchSegment ) - { - case 0: - return MAJOR; - case 1: - return MINOR; - case 2: - return INCREMENTAL; - default: - return SUBINCREMENTAL; - } - } - - private static final Map LEVEL_CONSTANTS; - - static - { - Map map = new HashMap<>( 5 ); - map.put( SUBINCREMENTAL.name(), SUBINCREMENTAL ); - map.put( INCREMENTAL.name(), INCREMENTAL ); - map.put( MINOR.name(), MINOR ); - map.put( MAJOR.name(), MAJOR ); - map.put( ANY.name(), ANY ); - LEVEL_CONSTANTS = map; - } - - /** - * enum classes cannot have finalize methods. - */ - protected final void finalize() - throws Throwable - { - super.finalize(); - } - - /** - * We need to ensure that the singleton is used when deserializing. - * - * @return The correct singleton instance. - * @throws java.io.ObjectStreamException when things go wrong. - */ - private Object readResolve() - throws ObjectStreamException - { - if ( ordinal == SUBINCREMENTAL.ordinal ) - { - return SUBINCREMENTAL; - } - if ( ordinal == INCREMENTAL.ordinal ) - { - return INCREMENTAL; - } - if ( ordinal == MINOR.ordinal ) - { - return MINOR; - } - if ( ordinal == MAJOR.ordinal ) - { - return MAJOR; - } - if ( ordinal == ANY.ordinal ) - { - return ANY; - } - throw new StreamCorruptedException(); - } - -} 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 399efbeda..b7aa11b9f 100644 --- a/src/main/java/org/codehaus/mojo/versions/api/VersionDetails.java +++ b/src/main/java/org/codehaus/mojo/versions/api/VersionDetails.java @@ -19,6 +19,8 @@ * under the License. */ +import java.util.Optional; + import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.Restriction; import org.apache.maven.artifact.versioning.VersionRange; @@ -178,17 +180,6 @@ ArtifactVersion getNewestVersion( ArtifactVersion lowerBound, ArtifactVersion up */ ArtifactVersion getNewestVersion( VersionRange versionRange, boolean includeSnapshots ); - /** - * Returns the oldest version after the specified lowerBound, but less than the specified upper bound or - * null if no such version exists. - * - * @param lowerBound the lower bound or null if the lower limit is unbounded. - * @param upperBound the upper bound or null if the upper limit is unbounded. - * @return the next version between lowerBound and upperBound or null if no version is available. - * @since 1.0-beta-1 - */ - ArtifactVersion getOldestVersion( ArtifactVersion lowerBound, ArtifactVersion upperBound ); - /** * Returns the oldest version within the specified version range or null if no such version exists. * @@ -199,19 +190,6 @@ ArtifactVersion getNewestVersion( ArtifactVersion lowerBound, ArtifactVersion up */ ArtifactVersion getOldestVersion( VersionRange versionRange, boolean includeSnapshots ); - /** - * Returns the oldest version newer than the specified lower bound, but less than the specified upper bound or - * null if no such version exists. - * - * @param lowerBound the lower bound or null if the lower limit is unbounded. - * @param upperBound the upper bound or null if the upper limit is unbounded. - * @param includeSnapshots true if snapshots are to be included. - * @return the latest version between currentVersion and upperBound or null if no version is available. - * @since 1.0-beta-1 - */ - ArtifactVersion getOldestVersion( ArtifactVersion lowerBound, ArtifactVersion upperBound, - boolean includeSnapshots ); - /** * Returns the oldest version within the specified bounds or null if no such version exists. * @@ -234,43 +212,6 @@ ArtifactVersion getOldestVersion( ArtifactVersion lowerBound, ArtifactVersion up */ ArtifactVersion getOldestVersion( VersionRange versionRange, Restriction restriction, boolean includeSnapshots ); - /** - * Returns the oldest version newer than the specified current version, but within the 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. - * @return the oldest version after currentVersion within the specified update scope or null if no - * version is available. - * @since 1.0-beta-1 - */ - ArtifactVersion getOldestUpdate( ArtifactVersion currentVersion, UpdateScope updateScope ) - throws InvalidSegmentException; - - /** - * Returns the newest version newer than the specified current version, but within the 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. - * @return the newest version after currentVersion within the specified update scope or null if no - * version is available. - * @since 1.0-beta-1 - */ - ArtifactVersion getNewestUpdate( ArtifactVersion currentVersion, UpdateScope updateScope ) - throws InvalidSegmentException; - - /** - * Returns the all versions newer than the specified current version, but within the the specified update scope. - * - * @param currentVersion the lower bound or null if the lower limit is unbounded. - * @param updateScope the update scope to include. - * @return the all versions after currentVersion within the specified update scope. - * @since 1.0-beta-1 - */ - ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, UpdateScope updateScope ) - throws InvalidSegmentException; - /** * Returns the oldest version newer than the specified current version, but within the the specified update scope or * null if no such version exists. @@ -282,7 +223,7 @@ ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, UpdateScope upd * version is available. * @since 1.0-beta-1 */ - ArtifactVersion getOldestUpdate( ArtifactVersion currentVersion, UpdateScope updateScope, + ArtifactVersion getOldestUpdate( ArtifactVersion currentVersion, Optional updateScope, boolean includeSnapshots ) throws InvalidSegmentException; /** @@ -296,7 +237,7 @@ ArtifactVersion getOldestUpdate( ArtifactVersion currentVersion, UpdateScope upd * version is available. * @since 1.0-beta-1 */ - ArtifactVersion getNewestUpdate( ArtifactVersion currentVersion, UpdateScope updateScope, + ArtifactVersion getNewestUpdate( ArtifactVersion currentVersion, Optional updateScope, boolean includeSnapshots ) throws InvalidSegmentException; /** @@ -308,83 +249,9 @@ ArtifactVersion getNewestUpdate( ArtifactVersion currentVersion, UpdateScope upd * @return the all versions after currentVersion within the specified update scope. * @since 1.0-beta-1 */ - ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, UpdateScope updateScope, + ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, Optional updateScope, boolean includeSnapshots ) throws InvalidSegmentException; - /** - * Returns the oldest version newer than the specified current version, but within the 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 versionRange the version range to include. - * @return the oldest version after currentVersion within the specified update scope or null if no - * version is available. - * @since 1.0-beta-1 - */ - ArtifactVersion getOldestUpdate( ArtifactVersion currentVersion, VersionRange versionRange ); - - /** - * Returns the newest version newer than the specified current version, but within the 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 versionRange the version range to include. - * @return the newest version after currentVersion within the specified update scope or null if no - * version is available. - * @since 1.0-beta-1 - */ - ArtifactVersion getNewestUpdate( ArtifactVersion currentVersion, VersionRange versionRange ); - - /** - * Returns the all versions newer than the specified current version, but within the the specified update scope. - * - * @param currentVersion the lower bound or null if the lower limit is unbounded. - * @param versionRange the version range to include. - * @return the all versions after currentVersion within the specified update scope. - * @since 1.0-beta-1 - */ - ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, VersionRange versionRange ); - - /** - * Returns the oldest version newer than the specified current version, but within the 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 versionRange the version range to include. - * @param includeSnapshots true if snapshots are to be included. - * @return the oldest version after currentVersion within the specified update scope or null if no - * version is available. - * @since 1.0-beta-1 - */ - ArtifactVersion getOldestUpdate( ArtifactVersion currentVersion, VersionRange versionRange, - boolean includeSnapshots ); - - /** - * Returns the newest version newer than the specified current version, but within the 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 versionRange the version range 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. - * @since 1.0-beta-1 - */ - ArtifactVersion getNewestUpdate( ArtifactVersion currentVersion, VersionRange versionRange, - boolean includeSnapshots ); - - /** - * Returns the all versions newer than the specified current version, but within the the specified update scope. - * - * @param currentVersion the lower bound or null if the lower limit is unbounded. - * @param versionRange the version range to include. - * @param includeSnapshots true if snapshots are to be included. - * @return the all versions after currentVersion within the specified update scope. - * @since 1.0-beta-1 - */ - ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, VersionRange versionRange, - boolean includeSnapshots ); - /** * Returns true if and only if getCurrentVersion() != null. * @@ -430,7 +297,7 @@ ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, VersionRange ve * version is available. * @since 1.0-beta-1 */ - ArtifactVersion getOldestUpdate( UpdateScope updateScope ) throws InvalidSegmentException; + ArtifactVersion getOldestUpdate( Optional updateScope ) throws InvalidSegmentException; /** * Returns the newest version newer than the specified current version, but within the the specified update scope or @@ -441,7 +308,7 @@ ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, VersionRange ve * version is available. * @since 1.0-beta-1 */ - ArtifactVersion getNewestUpdate( UpdateScope updateScope ) throws InvalidSegmentException; + ArtifactVersion getNewestUpdate( Optional updateScope ) throws InvalidSegmentException; /** * Returns the all versions newer than the specified current version, but within the the specified update scope. @@ -450,7 +317,7 @@ ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, VersionRange ve * @return the all versions after currentVersion within the specified update scope. * @since 1.0-beta-1 */ - ArtifactVersion[] getAllUpdates( UpdateScope updateScope ) throws InvalidSegmentException; + ArtifactVersion[] getAllUpdates( Optional updateScope ) throws InvalidSegmentException; /** * Returns the oldest version newer than the specified current version, but within the the specified update scope or @@ -462,7 +329,8 @@ ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, VersionRange ve * version is available. * @since 1.0-beta-1 */ - ArtifactVersion getOldestUpdate( UpdateScope updateScope, boolean includeSnapshots ) throws InvalidSegmentException; + ArtifactVersion getOldestUpdate( Optional updateScope, boolean includeSnapshots ) + throws InvalidSegmentException; /** * Returns the newest version newer than the specified current version, but within the the specified update scope or @@ -474,7 +342,8 @@ ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, VersionRange ve * version is available. * @since 1.0-beta-1 */ - ArtifactVersion getNewestUpdate( UpdateScope updateScope, boolean includeSnapshots ) throws InvalidSegmentException; + ArtifactVersion getNewestUpdate( Optional updateScope, boolean includeSnapshots ) + throws InvalidSegmentException; /** * Returns the all versions newer than the specified current version, but within the the specified update scope. @@ -484,29 +353,8 @@ ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, VersionRange ve * @return the all versions after currentVersion within the specified update scope. * @since 1.0-beta-1 */ - ArtifactVersion[] getAllUpdates( UpdateScope updateScope, boolean includeSnapshots ) throws InvalidSegmentException; - - /** - * Returns the oldest version newer than the current version, but within the the specified update scope or - * null if no such version exists. - * - * @param versionRange the version range to include. - * @return the oldest version after currentVersion within the specified update scope or null if no - * version is available. - * @since 1.0-beta-1 - */ - ArtifactVersion getOldestUpdate( VersionRange versionRange ); - - /** - * Returns the newest version newer than the specified current version, but within the the specified update scope or - * null if no such version exists. - * - * @param versionRange the version range to include. - * @return the newest version after currentVersion within the specified update scope or null if no - * version is available. - * @since 1.0-beta-1 - */ - ArtifactVersion getNewestUpdate( VersionRange versionRange ); + ArtifactVersion[] getAllUpdates( Optional updateScope, boolean includeSnapshots ) + throws InvalidSegmentException; /** * Returns the all versions newer than the specified current version, but within the the specified update scope. @@ -517,30 +365,6 @@ ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, VersionRange ve */ ArtifactVersion[] getAllUpdates( VersionRange versionRange ); - /** - * Returns the oldest version newer than the specified current version, but within the the specified update scope or - * null if no such version exists. - * - * @param versionRange the version range to include. - * @param includeSnapshots true if snapshots are to be included. - * @return the oldest version after currentVersion within the specified update scope or null if no - * version is available. - * @since 1.0-beta-1 - */ - ArtifactVersion getOldestUpdate( VersionRange versionRange, boolean includeSnapshots ); - - /** - * Returns the newest version newer than the specified current version, but within the the specified update scope or - * null if no such version exists. - * - * @param versionRange the version range 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. - * @since 1.0-beta-1 - */ - ArtifactVersion getNewestUpdate( VersionRange versionRange, boolean includeSnapshots ); - /** * Returns the all versions newer than the specified current version, but within the the specified update scope. * diff --git a/src/main/java/org/codehaus/mojo/versions/api/VersionsHelper.java b/src/main/java/org/codehaus/mojo/versions/api/VersionsHelper.java index 9cd8fa826..3d5777967 100644 --- a/src/main/java/org/codehaus/mojo/versions/api/VersionsHelper.java +++ b/src/main/java/org/codehaus/mojo/versions/api/VersionsHelper.java @@ -158,18 +158,6 @@ Artifact createDependencyArtifact( String groupId, String artifactId, String ver ArtifactVersions lookupArtifactVersions( Artifact artifact, boolean usePluginRepositories ) throws ArtifactMetadataRetrievalException; - /** - * Looks up the updates of an artifact. - * - * @param artifact The artifact to look up - * @param allowSnapshots Include snapshots in the list of updates. - * @param usePluginRepositories Search the plugin repositories. - * @return The artifact update details. - * @throws ArtifactMetadataRetrievalException When things go wrong. - */ - ArtifactVersions lookupArtifactUpdates( Artifact artifact, boolean allowSnapshots, boolean usePluginRepositories ) - throws ArtifactMetadataRetrievalException; - /** * Looks up the updates for a set of dependencies. * diff --git a/src/main/java/org/codehaus/mojo/versions/ordering/VersionComparator.java b/src/main/java/org/codehaus/mojo/versions/ordering/VersionComparator.java index fbf6fb14e..11f2af07f 100644 --- a/src/main/java/org/codehaus/mojo/versions/ordering/VersionComparator.java +++ b/src/main/java/org/codehaus/mojo/versions/ordering/VersionComparator.java @@ -45,6 +45,7 @@ public interface VersionComparator * @param segment The segment number to increment. * @return An artifact version with the specified segment incremented. * @since 1.0-beta-1 + * @throws InvalidSegmentException if {@code segment} ∉ [0, segmentCount) */ ArtifactVersion incrementSegment( ArtifactVersion artifactVersion, int segment ) throws InvalidSegmentException; }