From 095257e08f2193ac2971ebd3048d813845aebe5e Mon Sep 17 00:00:00 2001 From: Swell <5782559+sultan@users.noreply.github.com> Date: Sun, 16 Oct 2022 14:29:26 +0200 Subject: [PATCH] Fix Reports Success/Warning icons, counts --- .../ordering/AbstractVersionComparator.java | 13 ++----------- .../reporting/AbstractVersionsReportRenderer.java | 11 ++++++----- .../versions/reporting/PluginOverviewStats.java | 10 +++++----- .../reporting/PluginUpdatesReportRenderer.java | 2 +- .../reporting/VersionsReportRendererBase.java | 4 ++-- 5 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/codehaus/mojo/versions/ordering/AbstractVersionComparator.java b/src/main/java/org/codehaus/mojo/versions/ordering/AbstractVersionComparator.java index 1baeea0a35..ecc87f1a39 100644 --- a/src/main/java/org/codehaus/mojo/versions/ordering/AbstractVersionComparator.java +++ b/src/main/java/org/codehaus/mojo/versions/ordering/AbstractVersionComparator.java @@ -59,17 +59,8 @@ public final int getSegmentCount( ArtifactVersion v ) */ public final ArtifactVersion incrementSegment( ArtifactVersion v, Segment segment ) throws InvalidSegmentException { - if ( VersionComparators.isSnapshot( v ) ) - { - return VersionComparators.copySnapshot( v, innerIncrementSegment( VersionComparators.stripSnapshot( v ), - segment ) ); - } - int segmentCount = getSegmentCount( v ); - if ( segment.value() >= segmentCount ) - { - throw new InvalidSegmentException( segment, segmentCount, v ); - } - return innerIncrementSegment( v, segment ); + return VersionComparators.copySnapshot( v, innerIncrementSegment( VersionComparators.stripSnapshot( v ), + segment ) ); } protected abstract ArtifactVersion innerIncrementSegment( ArtifactVersion v, Segment segment ) diff --git a/src/main/java/org/codehaus/mojo/versions/reporting/AbstractVersionsReportRenderer.java b/src/main/java/org/codehaus/mojo/versions/reporting/AbstractVersionsReportRenderer.java index ba1c0a6bab..e25008bf65 100644 --- a/src/main/java/org/codehaus/mojo/versions/reporting/AbstractVersionsReportRenderer.java +++ b/src/main/java/org/codehaus/mojo/versions/reporting/AbstractVersionsReportRenderer.java @@ -136,11 +136,11 @@ protected void renderOverview() */ protected void renderOverviewTableRow( Q stats ) { - renderStatRow( "report.overview.numUpToDate", stats.getUpToDate() ); - renderStatRow( "report.overview.numNewerVersionAvailable", stats.getAny() ); - renderStatRow( "report.overview.numNewerIncrementalAvailable", stats.getIncremental() ); - renderStatRow( "report.overview.numNewerMinorAvailable", stats.getMinor() ); - renderStatRow( "report.overview.numNewerMajorAvailable", stats.getMajor() ); + renderStatRow( "report.overview.numUpToDate", stats.getUpToDate(), true ); + renderStatRow( "report.overview.numNewerVersionAvailable", stats.getAny(), false ); + renderStatRow( "report.overview.numNewerIncrementalAvailable", stats.getIncremental(), false ); + renderStatRow( "report.overview.numNewerMinorAvailable", stats.getMinor(), false ); + renderStatRow( "report.overview.numNewerMajorAvailable", stats.getMajor(), false ); } /** @@ -421,6 +421,7 @@ protected void renderTableHeaderCells( String... keys ) protected String getLabel( ArtifactVersion version, AbstractVersionDetails details ) { + if ( equals( version, newestUpdateCache.get( details, of( SUBINCREMENTAL ) ) ) ) { return getText( "report.latestSubIncremental" ); diff --git a/src/main/java/org/codehaus/mojo/versions/reporting/PluginOverviewStats.java b/src/main/java/org/codehaus/mojo/versions/reporting/PluginOverviewStats.java index 5275c17e4f..2d215b75cf 100644 --- a/src/main/java/org/codehaus/mojo/versions/reporting/PluginOverviewStats.java +++ b/src/main/java/org/codehaus/mojo/versions/reporting/PluginOverviewStats.java @@ -55,7 +55,7 @@ public void incrementDependencies() * * @param updates collection of all version updates, typically from {@linkplain PluginUpdatesModel#getAllUpdates()} * @param cache if not null, cache to retrieve the version information, initialised with - * the {@link ArtifactVersions#getOldestUpdate(Optional)} update information + * the {@link ArtifactVersions#getNewestUpdate(Optional)} update information * @param always equal to {@linkplain PluginOverviewStats} * @param always equal to {@linkplain org.codehaus.mojo.versions.PluginUpdatesDetails} * @return instance of the {@linkplain PluginOverviewStats}, initialised with the update information @@ -66,19 +66,19 @@ public static T fromUpdate PluginOverviewStats stats = new PluginOverviewStats(); updates.forEach( details -> { - if ( getOldestUpdate( cache, details, of( SUBINCREMENTAL ) ) != null ) + if ( getNewestUpdate( cache, details, of( SUBINCREMENTAL ) ) != null ) { stats.incrementAny(); } - else if ( getOldestUpdate( cache, details, of( INCREMENTAL ) ) != null ) + else if ( getNewestUpdate( cache, details, of( INCREMENTAL ) ) != null ) { stats.incrementIncremental(); } - else if ( getOldestUpdate( cache, details, of( MINOR ) ) != null ) + else if ( getNewestUpdate( cache, details, of( MINOR ) ) != null ) { stats.incrementMinor(); } - else if ( getOldestUpdate( cache, details, of( MAJOR ) ) != null ) + else if ( getNewestUpdate( cache, details, of( MAJOR ) ) != null ) { stats.incrementMajor(); } diff --git a/src/main/java/org/codehaus/mojo/versions/reporting/PluginUpdatesReportRenderer.java b/src/main/java/org/codehaus/mojo/versions/reporting/PluginUpdatesReportRenderer.java index f7a2451931..6d0713cd41 100644 --- a/src/main/java/org/codehaus/mojo/versions/reporting/PluginUpdatesReportRenderer.java +++ b/src/main/java/org/codehaus/mojo/versions/reporting/PluginUpdatesReportRenderer.java @@ -144,7 +144,7 @@ protected void renderOverviewTableRow( T stats ) { super.renderOverviewTableRow( stats ); super.renderStatRow( "report.overview.numNewerDependenciesAvailable", - ( (PluginOverviewStats) stats ).getDependencies() ); + ( (PluginOverviewStats) stats ).getDependencies(), false ); } protected void renderSummaryTableRow( Dependency artifact, PluginUpdatesDetails details ) diff --git a/src/main/java/org/codehaus/mojo/versions/reporting/VersionsReportRendererBase.java b/src/main/java/org/codehaus/mojo/versions/reporting/VersionsReportRendererBase.java index 057355e8f2..472a42c4d8 100644 --- a/src/main/java/org/codehaus/mojo/versions/reporting/VersionsReportRendererBase.java +++ b/src/main/java/org/codehaus/mojo/versions/reporting/VersionsReportRendererBase.java @@ -86,11 +86,11 @@ protected void renderSuccessIcon() sink.figureGraphics( "images/icon_success_sml.gif" ); } - protected void renderStatRow( String textKey, int statCount ) + protected void renderStatRow( String textKey, int statCount, boolean forceSuccessIcon ) { sink.tableRow(); sink.tableCell(); - if ( statCount == 0 ) + if ( statCount == 0 || forceSuccessIcon ) { renderSuccessIcon(); }