diff --git a/src/it/it-dependency-updates-report-001/verify.bsh b/src/it/it-dependency-updates-report-001/verify.bsh index 289ca69b24..0298f0d67d 100644 --- a/src/it/it-dependency-updates-report-001/verify.bsh +++ b/src/it/it-dependency-updates-report-001/verify.bsh @@ -23,7 +23,7 @@ try System.out.println( "Result = \"" + result +"\"" ); return false; } - if ( result.indexOf( "1.1.1 Next Incremental" ) < 0) + if ( result.indexOf( "1.1.1" ) < 0) { System.out.println( "Did not identify next incremental" ); System.out.println( "Result = \"" + result +"\"" ); @@ -35,7 +35,7 @@ try System.out.println( "Result = \"" + result +"\"" ); return false; } - if ( result.indexOf( "1.2 Next Minor" ) < 0) + if ( result.indexOf( "1.2" ) < 0) { System.out.println( "Did not identify next minor version" ); System.out.println( "Result = \"" + result +"\"" ); @@ -47,7 +47,7 @@ try System.out.println( "Result = \"" + result +"\"" ); return false; } - if ( result.indexOf( "2.0 Next Major" ) < 0) + if ( result.indexOf( "2.0" ) < 0) { System.out.println( "Did not identify next major version" ); System.out.println( "Result = \"" + result +"\"" ); diff --git a/src/it/it-dependency-updates-report-002/verify.bsh b/src/it/it-dependency-updates-report-002/verify.bsh index 8422b69484..019b615555 100644 --- a/src/it/it-dependency-updates-report-002/verify.bsh +++ b/src/it/it-dependency-updates-report-002/verify.bsh @@ -17,13 +17,13 @@ try // System.out.println( "Result = \"" + result +"\"" ); // return false; // } -// if ( result.indexOf( "1.1.0-2 Next Version" ) < 0) +// if ( result.indexOf( "1.1.0-2" ) < 0) // { // System.out.println( "Did not identify next version" ); // System.out.println( "Result = \"" + result +"\"" ); // return false; // } -// if ( result.indexOf( "1.1.1 Next Incremental" ) < 0) +// if ( result.indexOf( "1.1.1" ) < 0) // { // System.out.println( "Did not identify next incremental" ); // System.out.println( "Result = \"" + result +"\"" ); @@ -35,7 +35,7 @@ try // System.out.println( "Result = \"" + result +"\"" ); // return false; // } -// if ( result.indexOf( "1.2 Next Minor" ) < 0) +// if ( result.indexOf( "1.2" ) < 0) // { // System.out.println( "Did not identify next minor version" ); // System.out.println( "Result = \"" + result +"\"" ); @@ -47,7 +47,7 @@ try // System.out.println( "Result = \"" + result +"\"" ); // return false; // } -// if ( result.indexOf( "2.0 Next Major" ) < 0) +// if ( result.indexOf( "2.0" ) < 0) // { // System.out.println( "Did not identify next major version" ); // System.out.println( "Result = \"" + result +"\"" ); diff --git a/src/it/it-plugin-updates-report-001/verify.bsh b/src/it/it-plugin-updates-report-001/verify.bsh index 003f5155ce..d1caa0219f 100644 --- a/src/it/it-plugin-updates-report-001/verify.bsh +++ b/src/it/it-plugin-updates-report-001/verify.bsh @@ -32,15 +32,15 @@ try return false; } if ( result.indexOf( "Group Id localhost Artifact Id dummy-maven-plugin Current Version 1.0 Newer versions 2.0 " - + "Next Major 2.1 3.0 3.1 Latest Major" ) < 0) + + "2.1 3.0 3.1 Latest Major" ) < 0) { System.out.println( "Did not identify plugin next versions" ); System.out.println( "Result = \"" + result +"\"" ); return false; } if ( result.indexOf( "Group Id localhost Artifact Id dummy-api Current Version 1.1 Classifier Type jar Newer " - + "versions 1.1.0-2 Latest Subincremental 1.1.1 Next Incremental 1.1.1-2 1.1.2 1.1.3 Latest Incremental 1.2 Next " - + "Minor 1.2.1 1.2.2 1.3 Latest Minor 2.0 Next Major 2.1 3.0 Latest Major" ) < 0) + + "versions 1.1.0-2 Latest Subincremental 1.1.1 1.1.1-2 1.1.2 1.1.3 Latest Incremental 1.2 " + + "1.2.1 1.2.2 1.3 Latest Minor 2.0 2.1 3.0 Latest Major" ) < 0) { System.out.println( "Did not identify dependency next versions" ); System.out.println( "Result = \"" + result +"\"" ); diff --git a/src/it/it-plugin-updates-report-002/verify.bsh b/src/it/it-plugin-updates-report-002/verify.bsh index ee113ae500..299dc4ca1e 100644 --- a/src/it/it-plugin-updates-report-002/verify.bsh +++ b/src/it/it-plugin-updates-report-002/verify.bsh @@ -26,7 +26,7 @@ try return false; } if ( result.indexOf( "Group Id localhost Artifact Id dummy-maven-plugin Current Version 1.0 Newer versions 2.0 " - + "Next Major 2.1 3.0 3.1 Latest Major" ) < 0) + + "2.1 3.0 3.1 Latest Major" ) < 0) { System.out.println( "Did not identify plugin next versions" ); System.out.println( "Result = \"" + result +"\"" ); diff --git a/src/it/it-plugin-updates-report-003/verify.bsh b/src/it/it-plugin-updates-report-003/verify.bsh index ee113ae500..299dc4ca1e 100644 --- a/src/it/it-plugin-updates-report-003/verify.bsh +++ b/src/it/it-plugin-updates-report-003/verify.bsh @@ -26,7 +26,7 @@ try return false; } if ( result.indexOf( "Group Id localhost Artifact Id dummy-maven-plugin Current Version 1.0 Newer versions 2.0 " - + "Next Major 2.1 3.0 3.1 Latest Major" ) < 0) + + "2.1 3.0 3.1 Latest Major" ) < 0) { System.out.println( "Did not identify plugin next versions" ); System.out.println( "Result = \"" + result +"\"" ); diff --git a/src/main/java/org/codehaus/mojo/versions/api/ArtifactVersionsCache.java b/src/main/java/org/codehaus/mojo/versions/api/ArtifactVersionsCache.java index 009070bcd3..e5aa2e384b 100644 --- a/src/main/java/org/codehaus/mojo/versions/api/ArtifactVersionsCache.java +++ b/src/main/java/org/codehaus/mojo/versions/api/ArtifactVersionsCache.java @@ -28,7 +28,7 @@ import org.apache.commons.lang3.tuple.Pair; /** - * Utility providing a cached {@link ArtifactVersions#getOldestUpdate(Optional)} API + * Utility providing a cached {@link ArtifactVersions#getNewestUpdate(Optional)} API */ public class ArtifactVersionsCache { 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 c3f9102038..e25008bf65 100644 --- a/src/main/java/org/codehaus/mojo/versions/reporting/AbstractVersionsReportRenderer.java +++ b/src/main/java/org/codehaus/mojo/versions/reporting/AbstractVersionsReportRenderer.java @@ -58,8 +58,8 @@ public abstract class AbstractVersionsReportRenderer extends VersionsReportRe */ protected T model; - protected ArtifactVersionsCache oldestUpdateCache - = new ArtifactVersionsCache( AbstractVersionDetails::getOldestUpdate ); + protected ArtifactVersionsCache newestUpdateCache + = new ArtifactVersionsCache( AbstractVersionDetails::getNewestUpdate ); protected ArtifactVersionsCache allUpdatesCache = new ArtifactVersionsCache( AbstractVersionDetails::getAllUpdates ); @@ -136,59 +136,11 @@ protected void renderOverview() */ protected void renderOverviewTableRow( Q stats ) { - sink.tableCell(); - renderSuccessIcon(); - sink.tableCell_(); - sink.tableCell(); - sink.text( getText( "report.overview.numUpToDate" ) ); - sink.tableCell_(); - sink.tableCell(); - sink.text( Integer.toString( stats.getUpToDate() ) ); - sink.tableCell_(); - sink.tableRow_(); - sink.tableRow(); - sink.tableCell(); - renderWarningIcon(); - sink.tableCell_(); - sink.tableCell(); - sink.text( getText( "report.overview.numNewerVersionAvailable" ) ); - sink.tableCell_(); - sink.tableCell(); - sink.text( Integer.toString( stats.getAny() ) ); - sink.tableCell_(); - sink.tableRow_(); - sink.tableRow(); - sink.tableCell(); - renderWarningIcon(); - sink.tableCell_(); - sink.tableCell(); - sink.text( getText( "report.overview.numNewerIncrementalAvailable" ) ); - sink.tableCell_(); - sink.tableCell(); - sink.text( Integer.toString( stats.getIncremental() ) ); - sink.tableCell_(); - sink.tableRow_(); - sink.tableRow(); - sink.tableCell(); - renderWarningIcon(); - sink.tableCell_(); - sink.tableCell(); - sink.text( getText( "report.overview.numNewerMinorAvailable" ) ); - sink.tableCell_(); - sink.tableCell(); - sink.text( Integer.toString( stats.getMinor() ) ); - sink.tableCell_(); - sink.tableRow_(); - sink.tableRow(); - sink.tableCell(); - renderWarningIcon(); - sink.tableCell_(); - sink.tableCell(); - sink.text( getText( "report.overview.numNewerMajorAvailable" ) ); - sink.tableCell_(); - sink.tableCell(); - sink.text( Integer.toString( stats.getMajor() ) ); - sink.tableCell_(); + 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 ); } /** @@ -237,13 +189,15 @@ protected void renderSummaryTableHeader( boolean hasScope, boolean hasType ) "report.latestIncremental", "report.latestMinor", "report.latestMajor" ); } - protected void renderSummaryTableRow( Dependency artifact, ArtifactVersions artifactVersions, - boolean includeScope ) + protected void renderSummaryTableRow( Dependency artifact, ArtifactVersions details, + boolean includeScope ) { + ArtifactVersion[] allUpdates = allUpdatesCache.get( details, empty() ); + boolean upToDate = allUpdates == null || allUpdates.length == 0; + sink.tableRow(); sink.tableCell(); - ArtifactVersion[] allUpdates = artifactVersions.getAllUpdates( empty() ); - if ( allUpdates == null || allUpdates.length == 0 ) + if ( upToDate ) { renderSuccessIcon(); } @@ -275,37 +229,37 @@ protected void renderSummaryTableRow( Dependency artifact, ArtifactVersions arti sink.tableCell_(); sink.tableCell(); - if ( artifactVersions.getNewestUpdate( of( SUBINCREMENTAL ) ) != null ) + if ( newestUpdateCache.get( details, of( SUBINCREMENTAL ) ) != null ) { safeBold(); - sink.text( artifactVersions.getNewestUpdate( of( SUBINCREMENTAL ) ).toString() ); + sink.text( newestUpdateCache.get( details, of( SUBINCREMENTAL ) ).toString() ); safeBold_(); } sink.tableCell_(); sink.tableCell(); - if ( artifactVersions.getNewestUpdate( of( INCREMENTAL ) ) != null ) + if ( newestUpdateCache.get( details, of( INCREMENTAL ) ) != null ) { safeBold(); - sink.text( artifactVersions.getNewestUpdate( of( INCREMENTAL ) ).toString() ); + sink.text( newestUpdateCache.get( details, of( INCREMENTAL ) ).toString() ); safeBold_(); } sink.tableCell_(); sink.tableCell(); - if ( artifactVersions.getNewestUpdate( of( MINOR ) ) != null ) + if ( newestUpdateCache.get( details, of( MINOR ) ) != null ) { safeBold(); - sink.text( artifactVersions.getNewestUpdate( of( MINOR ) ).toString() ); + sink.text( newestUpdateCache.get( details, of( MINOR ) ).toString() ); safeBold_(); } sink.tableCell_(); sink.tableCell(); - if ( artifactVersions.getNewestUpdate( of( MAJOR ) ) != null ) + if ( newestUpdateCache.get( details, of( MAJOR ) ) != null ) { safeBold(); - sink.text( artifactVersions.getNewestUpdate( of( MAJOR ) ).toString() ); + sink.text( newestUpdateCache.get( details, of( MAJOR ) ).toString() ); safeBold_(); } sink.tableCell_(); @@ -316,10 +270,13 @@ protected void renderSummaryTableRow( Dependency artifact, ArtifactVersions arti @SuppressWarnings( "checkstyle:MethodLength" ) protected void renderDependencyDetailTable( Dependency artifact, ArtifactVersions details, boolean includeScope ) { + ArtifactVersion[] allUpdates = allUpdatesCache.get( details, empty() ); + boolean upToDate = allUpdates == null || allUpdates.length == 0; + final SinkEventAttributes headerAttributes = new SinkEventAttributeSet(); - headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "20%" ); + headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "70%" ); final SinkEventAttributes cellAttributes = new SinkEventAttributeSet(); - headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "80%" ); + headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "30%" ); sink.table(); sink.tableRows( new int[] { Sink.JUSTIFY_RIGHT, Sink.JUSTIFY_LEFT }, false ); sink.tableRow(); @@ -327,26 +284,25 @@ protected void renderDependencyDetailTable( Dependency artifact, ArtifactVersion sink.text( getText( "report.status" ) ); sink.tableHeaderCell_(); sink.tableCell( cellAttributes ); - ArtifactVersion[] versions = allUpdatesCache.get( details, empty() ); - if ( oldestUpdateCache.get( details, of( SUBINCREMENTAL ) ) != null ) + if ( newestUpdateCache.get( details, of( SUBINCREMENTAL ) ) != null ) { renderWarningIcon(); sink.nonBreakingSpace(); sink.text( getText( "report.otherUpdatesAvailable" ) ); } - else if ( oldestUpdateCache.get( details, of( INCREMENTAL ) ) != null ) + else if ( newestUpdateCache.get( details, of( INCREMENTAL ) ) != null ) { renderWarningIcon(); sink.nonBreakingSpace(); sink.text( getText( "report.incrementalUpdatesAvailable" ) ); } - else if ( oldestUpdateCache.get( details, of( MINOR ) ) != null ) + else if ( newestUpdateCache.get( details, of( MINOR ) ) != null ) { renderWarningIcon(); sink.nonBreakingSpace(); sink.text( getText( "report.minorUpdatesAvailable" ) ); } - else if ( oldestUpdateCache.get( details, of( MAJOR ) ) != null ) + else if ( newestUpdateCache.get( details, of( MAJOR ) ) != null ) { renderWarningIcon(); sink.nonBreakingSpace(); @@ -411,25 +367,25 @@ else if ( oldestUpdateCache.get( details, of( MAJOR ) ) != null ) sink.text( artifact.getType() ); sink.tableCell_(); sink.tableRow_(); - if ( versions != null && versions.length > 0 ) + if ( !upToDate ) { sink.tableRow(); sink.tableHeaderCell( headerAttributes ); sink.text( getText( "report.updateVersions" ) ); sink.tableHeaderCell_(); sink.tableCell( cellAttributes ); - for ( int i = 0; i < versions.length; i++ ) + for ( int i = 0; i < allUpdates.length; i++ ) { if ( i > 0 ) { sink.lineBreak(); } - String label = getLabel( versions[i], details ); + String label = getLabel( allUpdates[i], details ); if ( label != null ) { safeBold(); } - sink.text( versions[i].toString() ); + sink.text( allUpdates[i].toString() ); if ( label != null ) { safeBold_(); @@ -462,4 +418,30 @@ protected void renderTableHeaderCells( String... keys ) sink.tableHeaderCell_(); } ); } + + protected String getLabel( ArtifactVersion version, AbstractVersionDetails details ) + { + + if ( equals( version, newestUpdateCache.get( details, of( SUBINCREMENTAL ) ) ) ) + { + return getText( "report.latestSubIncremental" ); + } + + if ( equals( version, newestUpdateCache.get( details, of( INCREMENTAL ) ) ) ) + { + return getText( "report.latestIncremental" ); + } + + if ( equals( version, newestUpdateCache.get( details, of( MINOR ) ) ) ) + { + return getText( "report.latestMinor" ); + } + + if ( equals( version, newestUpdateCache.get( details, of( MAJOR ) ) ) ) + { + return getText( "report.latestMajor" ); + } + + return null; + } } diff --git a/src/main/java/org/codehaus/mojo/versions/reporting/DependencyUpdatesReportRenderer.java b/src/main/java/org/codehaus/mojo/versions/reporting/DependencyUpdatesReportRenderer.java index c26c7ca785..2d8948280a 100644 --- a/src/main/java/org/codehaus/mojo/versions/reporting/DependencyUpdatesReportRenderer.java +++ b/src/main/java/org/codehaus/mojo/versions/reporting/DependencyUpdatesReportRenderer.java @@ -86,7 +86,7 @@ protected void renderTable( String titleKey, Map c @Override protected OverviewStats computeOverviewStats() { - return OverviewStats.fromUpdates( model.getAllUpdates().values(), oldestUpdateCache ); + return OverviewStats.fromUpdates( model.getAllUpdates().values(), newestUpdateCache ); } protected void renderDependencyDetail( Dependency artifact, ArtifactVersions details ) diff --git a/src/main/java/org/codehaus/mojo/versions/reporting/OverviewStats.java b/src/main/java/org/codehaus/mojo/versions/reporting/OverviewStats.java index bde72a9218..998a2b0f52 100644 --- a/src/main/java/org/codehaus/mojo/versions/reporting/OverviewStats.java +++ b/src/main/java/org/codehaus/mojo/versions/reporting/OverviewStats.java @@ -58,7 +58,7 @@ public class OverviewStats * @param updates collection of all version updates, typically from * {@linkplain org.codehaus.mojo.versions.reporting.model.DependencyUpdatesModel#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 subclass of {@linkplain OverviewStats} * @param subclass of {@linkplain ArtifactVersions} * @return instance of the {@linkplain OverviewStats} @@ -69,19 +69,19 @@ public static T fromUpdate OverviewStats stats = new OverviewStats(); 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(); } @@ -93,11 +93,11 @@ else if ( getOldestUpdate( cache, details, of( MAJOR ) ) != null ) return (T) stats; } - protected static ArtifactVersion getOldestUpdate( ArtifactVersionsCache cache, + protected static ArtifactVersion getNewestUpdate( ArtifactVersionsCache cache, V details, - Optional segment ) + Optional segment ) { - return cache != null ? cache.get( details, segment ) : details.getOldestUpdate( segment ); + return cache != null ? cache.get( details, segment ) : details.getNewestUpdate( segment ); } public int getMajor() 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 e1327dd56e..6d0713cd41 100644 --- a/src/main/java/org/codehaus/mojo/versions/reporting/PluginUpdatesReportRenderer.java +++ b/src/main/java/org/codehaus/mojo/versions/reporting/PluginUpdatesReportRenderer.java @@ -30,9 +30,7 @@ import org.apache.maven.doxia.sink.impl.SinkEventAttributeSet; import org.apache.maven.model.Dependency; import org.codehaus.mojo.versions.PluginUpdatesDetails; -import org.codehaus.mojo.versions.api.AbstractVersionDetails; import org.codehaus.mojo.versions.api.ArtifactVersions; -import org.codehaus.mojo.versions.api.ArtifactVersionsCache; import org.codehaus.mojo.versions.reporting.model.PluginUpdatesModel; import org.codehaus.plexus.i18n.I18N; @@ -48,8 +46,6 @@ */ public class PluginUpdatesReportRenderer extends AbstractVersionsReportRenderer { - protected ArtifactVersionsCache newestUpdateCache - = new ArtifactVersionsCache( AbstractVersionDetails::getNewestUpdate ); public PluginUpdatesReportRenderer( I18N i18n, Sink sink, Locale locale, String bundleName, PluginUpdatesModel model ) @@ -133,7 +129,7 @@ protected void renderSummaryTable( Map content @Override protected PluginOverviewStats computeOverviewStats() { - return PluginOverviewStats.fromUpdates( model.getAllUpdates().values(), oldestUpdateCache ); + return PluginOverviewStats.fromUpdates( model.getAllUpdates().values(), newestUpdateCache ); } @Override @@ -147,19 +143,17 @@ protected void renderSummaryTableHeader( boolean hasScope, boolean hasType ) protected void renderOverviewTableRow( T stats ) { super.renderOverviewTableRow( stats ); - sink.tableCell(); - sink.text( getText( "report.overview.numNewerDependenciesAvailable" ) ); - sink.tableCell_(); - sink.tableCell(); - sink.text( Integer.toString( ( (PluginOverviewStats) stats ).getDependencies() ) ); - sink.tableCell_(); + super.renderStatRow( "report.overview.numNewerDependenciesAvailable", + ( (PluginOverviewStats) stats ).getDependencies(), false ); } protected void renderSummaryTableRow( Dependency artifact, PluginUpdatesDetails details ) { + boolean upToDate = !details.isUpdateAvailable(); + sink.tableRow(); sink.tableCell(); - if ( !details.isUpdateAvailable() ) + if ( upToDate ) { renderSuccessIcon(); } @@ -237,44 +231,69 @@ protected void renderSummaryTableRow( Dependency artifact, PluginUpdatesDetails } @SuppressWarnings( "checkstyle:MethodLength" ) - private void renderPluginDetail( Dependency artifact, PluginUpdatesDetails plugin ) + private void renderPluginDetail( Dependency artifact, PluginUpdatesDetails details ) { - final SinkEventAttributes headerAttributes = new SinkEventAttributeSet(); - headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "20%" ); - final SinkEventAttributes cellAttributes = new SinkEventAttributeSet(); - headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "80%" ); sink.section2(); sink.sectionTitle2(); sink.text( MessageFormat.format( getText( "report.plugin" ), - ArtifactUtils.versionlessKey( plugin.getGroupId(), plugin.getArtifactId() ) ) ); + ArtifactUtils.versionlessKey( details.getGroupId(), details.getArtifactId() ) ) ); sink.sectionTitle2_(); + + renderPluginDetailTable( details ); + + if ( !details.getDependencyVersions().isEmpty() ) + { + sink.section3(); + sink.sectionTitle3(); + sink.text( MessageFormat.format( getText( "report.pluginDependencies" ), + ArtifactUtils.versionlessKey( details.getGroupId(), details.getArtifactId() ) ) ); + sink.sectionTitle3_(); + + renderSummaryTable( details.getDependencyVersions(), false ); + + sink.section3_(); + + details.getDependencyVersions().forEach( this::renderDependencyDetail ); + } + sink.section2_(); + } + + private void renderPluginDetailTable( PluginUpdatesDetails details ) + { + // warning: using caches here may break plugin report + ArtifactVersion[] allUpdates = details.getAllUpdates( empty() ); + boolean upToDate = allUpdates == null || allUpdates.length == 0; + + final SinkEventAttributes headerAttributes = new SinkEventAttributeSet(); + headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "70%" ); + final SinkEventAttributes cellAttributes = new SinkEventAttributeSet(); + headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "30%" ); sink.table(); - sink.tableRows( new int[] {Sink.JUSTIFY_RIGHT, Sink.JUSTIFY_LEFT}, false ); + sink.tableRows( new int[] { Sink.JUSTIFY_RIGHT, Sink.JUSTIFY_LEFT }, false ); sink.tableRow(); sink.tableHeaderCell( headerAttributes ); sink.text( getText( "report.status" ) ); sink.tableHeaderCell_(); sink.tableCell( cellAttributes ); - ArtifactVersion[] versions = plugin.getAllUpdates( empty() ); - if ( plugin.getOldestUpdate( of( SUBINCREMENTAL ) ) != null ) + if ( details.getNewestUpdate( of( SUBINCREMENTAL ) ) != null ) { renderWarningIcon(); sink.nonBreakingSpace(); sink.text( getText( "report.otherUpdatesAvailable" ) ); } - else if ( plugin.getOldestUpdate( of( INCREMENTAL ) ) != null ) + else if ( details.getNewestUpdate( of( INCREMENTAL ) ) != null ) { renderWarningIcon(); sink.nonBreakingSpace(); sink.text( getText( "report.incrementalUpdatesAvailable" ) ); } - else if ( plugin.getOldestUpdate( of( MINOR ) ) != null ) + else if ( details.getNewestUpdate( of( MINOR ) ) != null ) { renderWarningIcon(); sink.nonBreakingSpace(); sink.text( getText( "report.minorUpdatesAvailable" ) ); } - else if ( plugin.getOldestUpdate( of( MAJOR ) ) != null ) + else if ( details.getNewestUpdate( of( MAJOR ) ) != null ) { renderWarningIcon(); sink.nonBreakingSpace(); @@ -293,7 +312,7 @@ else if ( plugin.getOldestUpdate( of( MAJOR ) ) != null ) sink.text( getText( "report.groupId" ) ); sink.tableHeaderCell_(); sink.tableCell( cellAttributes ); - sink.text( plugin.getGroupId() ); + sink.text( details.getGroupId() ); sink.tableCell_(); sink.tableRow_(); sink.tableRow(); @@ -301,7 +320,7 @@ else if ( plugin.getOldestUpdate( of( MAJOR ) ) != null ) sink.text( getText( "report.artifactId" ) ); sink.tableHeaderCell_(); sink.tableCell( cellAttributes ); - sink.text( plugin.getArtifactId() ); + sink.text( details.getArtifactId() ); sink.tableCell_(); sink.tableRow_(); sink.tableRow(); @@ -309,28 +328,28 @@ else if ( plugin.getOldestUpdate( of( MAJOR ) ) != null ) sink.text( getText( "report.currentVersion" ) ); sink.tableHeaderCell_(); sink.tableCell( cellAttributes ); - sink.text( plugin.getVersion() ); + sink.text( details.getVersion() ); sink.tableCell_(); sink.tableRow_(); - if ( versions != null && versions.length > 0 ) + if ( !upToDate ) { sink.tableRow(); sink.tableHeaderCell( headerAttributes ); sink.text( getText( "report.updateVersions" ) ); sink.tableHeaderCell_(); sink.tableCell( cellAttributes ); - for ( int i = 0; i < versions.length; i++ ) + for ( int i = 0; i < allUpdates.length; i++ ) { if ( i > 0 ) { sink.lineBreak(); } - String label = getLabel( versions[i], plugin ); + String label = getLabel( allUpdates[i], details ); if ( label != null ) { safeBold(); } - sink.text( versions[i].toString() ); + sink.text( allUpdates[i].toString() ); if ( label != null ) { safeBold_(); @@ -345,22 +364,6 @@ else if ( plugin.getOldestUpdate( of( MAJOR ) ) != null ) } sink.tableRows_(); sink.table_(); - - if ( !plugin.getDependencyVersions().isEmpty() ) - { - sink.section3(); - sink.sectionTitle3(); - sink.text( MessageFormat.format( getText( "report.pluginDependencies" ), - ArtifactUtils.versionlessKey( plugin.getGroupId(), plugin.getArtifactId() ) ) ); - sink.sectionTitle3_(); - - renderSummaryTable( plugin.getDependencyVersions(), false ); - - sink.section3_(); - - plugin.getDependencyVersions().forEach( this::renderDependencyDetail ); - } - sink.section2_(); } } diff --git a/src/main/java/org/codehaus/mojo/versions/reporting/PropertyUpdatesReportRenderer.java b/src/main/java/org/codehaus/mojo/versions/reporting/PropertyUpdatesReportRenderer.java index fe5f2de286..ddb7287e82 100644 --- a/src/main/java/org/codehaus/mojo/versions/reporting/PropertyUpdatesReportRenderer.java +++ b/src/main/java/org/codehaus/mojo/versions/reporting/PropertyUpdatesReportRenderer.java @@ -114,11 +114,14 @@ protected void renderSummaryTable( Map contents ) sink.table_(); } - private void renderPropertySummaryTableRow( Property property, PropertyVersions versions ) + private void renderPropertySummaryTableRow( Property property, PropertyVersions details ) { + ArtifactVersion[] allUpdates = allUpdatesCache.get( details, empty() ); + boolean upToDate = allUpdates == null || allUpdates.length == 0; + sink.tableRow(); sink.tableCell(); - if ( versions.getAllUpdates( empty() ).length == 0 ) + if ( upToDate ) { renderSuccessIcon(); } @@ -131,41 +134,41 @@ private void renderPropertySummaryTableRow( Property property, PropertyVersions sink.text( "${" + property.getName() + "}" ); sink.tableCell_(); sink.tableCell(); - sink.text( versions.getCurrentVersion().toString() ); + sink.text( details.getCurrentVersion().toString() ); sink.tableCell_(); sink.tableCell(); - if ( versions.getNewestUpdate( of( SUBINCREMENTAL ) ) != null ) + if ( newestUpdateCache.get( details, of( SUBINCREMENTAL ) ) != null ) { safeBold(); - sink.text( versions.getNewestUpdate( of( SUBINCREMENTAL ) ).toString() ); + sink.text( newestUpdateCache.get( details, of( SUBINCREMENTAL ) ).toString() ); safeBold_(); } sink.tableCell_(); sink.tableCell(); - if ( versions.getNewestUpdate( of( INCREMENTAL ) ) != null ) + if ( newestUpdateCache.get( details, of( INCREMENTAL ) ) != null ) { safeBold(); - sink.text( versions.getNewestUpdate( of( INCREMENTAL ) ).toString() ); + sink.text( newestUpdateCache.get( details, of( INCREMENTAL ) ).toString() ); safeBold_(); } sink.tableCell_(); sink.tableCell(); - if ( versions.getNewestUpdate( of( MINOR ) ) != null ) + if ( newestUpdateCache.get( details, of( MINOR ) ) != null ) { safeBold(); - sink.text( versions.getNewestUpdate( of( MINOR ) ).toString() ); + sink.text( newestUpdateCache.get( details, of( MINOR ) ).toString() ); safeBold_(); } sink.tableCell_(); sink.tableCell(); - if ( versions.getNewestUpdate( of( MAJOR ) ) != null ) + if ( newestUpdateCache.get( details, of( MAJOR ) ) != null ) { safeBold(); - sink.text( versions.getNewestUpdate( of( MAJOR ) ).toString() ); + sink.text( newestUpdateCache.get( details, of( MAJOR ) ).toString() ); safeBold_(); } sink.tableCell_(); @@ -174,12 +177,15 @@ private void renderPropertySummaryTableRow( Property property, PropertyVersions } @SuppressWarnings( "checkstyle:MethodLength" ) - protected void renderPropertyDetailTable( Property property, PropertyVersions versions ) + protected void renderPropertyDetailTable( Property property, PropertyVersions details ) { + ArtifactVersion[] allUpdates = allUpdatesCache.get( details, empty() ); + boolean upToDate = allUpdates == null || allUpdates.length == 0; + final SinkEventAttributes headerAttributes = new SinkEventAttributeSet(); - headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "20%" ); + headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "70%" ); final SinkEventAttributes cellAttributes = new SinkEventAttributeSet(); - headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "80%" ); + headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "30%" ); sink.table(); sink.tableRows( new int[] { Sink.JUSTIFY_RIGHT, Sink.JUSTIFY_LEFT }, false ); sink.tableRow(); @@ -187,27 +193,25 @@ protected void renderPropertyDetailTable( Property property, PropertyVersions ve sink.text( getText( "report.status" ) ); sink.tableHeaderCell_(); sink.tableCell( cellAttributes ); - ArtifactVersion[] artifactVersions = versions.getAllUpdates( empty() ); - Set rangeVersions = getVersionsInRange( property, versions, artifactVersions ); - if ( versions.getOldestUpdate( of( SUBINCREMENTAL ) ) != null ) + if ( newestUpdateCache.get( details, of( SUBINCREMENTAL ) ) != null ) { renderWarningIcon(); sink.nonBreakingSpace(); sink.text( getText( "report.otherUpdatesAvailable" ) ); } - else if ( versions.getOldestUpdate( of( INCREMENTAL ) ) != null ) + else if ( newestUpdateCache.get( details, of( INCREMENTAL ) ) != null ) { renderWarningIcon(); sink.nonBreakingSpace(); sink.text( getText( "report.incrementalUpdatesAvailable" ) ); } - else if ( versions.getOldestUpdate( of( MINOR ) ) != null ) + else if ( newestUpdateCache.get( details, of( MINOR ) ) != null ) { renderWarningIcon(); sink.nonBreakingSpace(); sink.text( getText( "report.minorUpdatesAvailable" ) ); } - else if ( versions.getOldestUpdate( of( MAJOR ) ) != null ) + else if ( newestUpdateCache.get( details, of( MAJOR ) ) != null ) { renderWarningIcon(); sink.nonBreakingSpace(); @@ -235,7 +239,7 @@ else if ( versions.getOldestUpdate( of( MAJOR ) ) != null ) sink.text( getText( "report.associations" ) ); sink.tableHeaderCell_(); sink.tableCell( cellAttributes ); - ArtifactAssociation[] associations = versions.getAssociations(); + ArtifactAssociation[] associations = details.getAssociations(); for ( int i = 0; i < associations.length; i++ ) { if ( i > 0 ) @@ -252,25 +256,26 @@ else if ( versions.getOldestUpdate( of( MAJOR ) ) != null ) sink.text( getText( "report.currentVersion" ) ); sink.tableHeaderCell_(); sink.tableCell( cellAttributes ); - sink.text( versions.getCurrentVersion().toString() ); + sink.text( details.getCurrentVersion().toString() ); sink.tableCell_(); sink.tableRow_(); - if ( artifactVersions.length > 0 ) + if ( !upToDate ) { + Set rangeVersions = getVersionsInRange( property, details, allUpdates ); sink.tableRow(); sink.tableHeaderCell( headerAttributes ); sink.text( getText( "report.updateVersions" ) ); sink.tableHeaderCell_(); sink.tableCell( cellAttributes ); boolean someNotAllowed = false; - for ( int i = 0; i < artifactVersions.length; i++ ) + for ( int i = 0; i < allUpdates.length; i++ ) { if ( i > 0 ) { sink.lineBreak(); } - boolean allowed = ( rangeVersions.contains( artifactVersions[i].toString() ) ); - String label = getLabel( artifactVersions[i], versions ); + boolean allowed = ( rangeVersions.contains( allUpdates[i].toString() ) ); + String label = getLabel( allUpdates[i], details ); if ( !allowed ) { sink.text( "* " ); @@ -280,7 +285,7 @@ else if ( versions.getOldestUpdate( of( MAJOR ) ) != null ) { safeBold(); } - sink.text( artifactVersions[i].toString() ); + sink.text( allUpdates[i].toString() ); if ( label != null ) { if ( allowed ) @@ -394,19 +399,19 @@ protected OverviewStats computeOverviewStats() OverviewStats stats = new OverviewStats(); model.getAllUpdates().values().forEach( details -> { - if ( oldestUpdateCache.get( details, of( SUBINCREMENTAL ) ) != null ) + if ( newestUpdateCache.get( details, of( SUBINCREMENTAL ) ) != null ) { stats.incrementAny(); } - else if ( oldestUpdateCache.get( details, of( INCREMENTAL ) ) != null ) + else if ( newestUpdateCache.get( details, of( INCREMENTAL ) ) != null ) { stats.incrementIncremental(); } - else if ( oldestUpdateCache.get( details, of( MINOR ) ) != null ) + else if ( newestUpdateCache.get( details, of( MINOR ) ) != null ) { stats.incrementMinor(); } - else if ( oldestUpdateCache.get( details, of( MAJOR ) ) != null ) + else if ( newestUpdateCache.get( details, of( MAJOR ) ) != null ) { stats.incrementMajor(); } @@ -418,13 +423,13 @@ else if ( oldestUpdateCache.get( details, of( MAJOR ) ) != null ) return stats; } - private void renderPropertyDetail( Property property, PropertyVersions versions ) + private void renderPropertyDetail( Property property, PropertyVersions details ) { sink.section2(); sink.sectionTitle2(); sink.text( "${" + property.getName() + "}" ); sink.sectionTitle2_(); - renderPropertyDetailTable( property, versions ); + renderPropertyDetailTable( property, details ); sink.section2_(); } 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 28640a78f8..472a42c4d8 100644 --- a/src/main/java/org/codehaus/mojo/versions/reporting/VersionsReportRendererBase.java +++ b/src/main/java/org/codehaus/mojo/versions/reporting/VersionsReportRendererBase.java @@ -25,15 +25,8 @@ import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.doxia.sink.Sink; import org.apache.maven.reporting.AbstractMavenReportRenderer; -import org.codehaus.mojo.versions.api.AbstractVersionDetails; 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; - /** * Base class over AbstractVersionsReportRenderer providing base * utility methods @@ -93,6 +86,28 @@ protected void renderSuccessIcon() sink.figureGraphics( "images/icon_success_sml.gif" ); } + protected void renderStatRow( String textKey, int statCount, boolean forceSuccessIcon ) + { + sink.tableRow(); + sink.tableCell(); + if ( statCount == 0 || forceSuccessIcon ) + { + renderSuccessIcon(); + } + else + { + renderWarningIcon(); + } + sink.tableCell_(); + sink.tableCell(); + sink.text( getText( textKey ) ); + sink.tableCell_(); + sink.tableCell(); + sink.text( Integer.toString( statCount ) ); + sink.tableCell_(); + sink.tableRow_(); + } + protected boolean equals( ArtifactVersion v1, ArtifactVersion v2 ) { return v1 == v2 || ( v1 != null && v1.equals( v2 ) ) @@ -149,48 +164,4 @@ protected void safeItalic_() } } - protected String getLabel( ArtifactVersion version, AbstractVersionDetails versions ) - { - if ( equals( version, versions.getNewestUpdate( of( SUBINCREMENTAL ) ) ) ) - { - return getText( "report.latestSubIncremental" ); - } - - if ( equals( version, versions.getOldestUpdate( of( SUBINCREMENTAL ) ) ) ) - { - return getText( "report.nextVersion" ); - } - - if ( equals( version, versions.getOldestUpdate( of( INCREMENTAL ) ) ) ) - { - return getText( "report.nextIncremental" ); - } - - if ( equals( version, versions.getNewestUpdate( of( INCREMENTAL ) ) ) ) - { - return getText( "report.latestIncremental" ); - } - - if ( equals( version, versions.getOldestUpdate( of( MINOR ) ) ) ) - { - return getText( "report.nextMinor" ); - } - - if ( equals( version, versions.getNewestUpdate( of( MINOR ) ) ) ) - { - return getText( "report.latestMinor" ); - } - - if ( equals( version, versions.getOldestUpdate( of( MAJOR ) ) ) ) - { - return getText( "report.nextMajor" ); - } - - if ( equals( version, versions.getNewestUpdate( of( MAJOR ) ) ) ) - { - return getText( "report.latestMajor" ); - } - - return ""; - } } diff --git a/src/main/resources/dependency-updates-report.properties b/src/main/resources/dependency-updates-report.properties index 1c5eb9722d..9b8626d4a1 100644 --- a/src/main/resources/dependency-updates-report.properties +++ b/src/main/resources/dependency-updates-report.properties @@ -40,14 +40,9 @@ report.currentVersion=Current Version report.scope=Scope report.classifier=Classifier report.type=Type -report.newerVersion=Newer Version(s) -report.nextVersion=Next Version report.latestSubIncremental=Latest Subincremental -report.nextIncremental=Next Incremental report.latestIncremental=Latest Incremental -report.nextMinor=Next Minor report.latestMinor=Latest Minor -report.nextMajor=Next Major report.latestMajor=Latest Major report.updateVersions=Newer versions report.noUpdatesAvailable=No newer versions available. diff --git a/src/main/resources/parent-updates-report.properties b/src/main/resources/parent-updates-report.properties index 2ddf8b1650..9b900def42 100644 --- a/src/main/resources/parent-updates-report.properties +++ b/src/main/resources/parent-updates-report.properties @@ -39,13 +39,9 @@ report.currentVersion=Current Version report.scope=Scope report.classifier=Classifier report.type=Type -report.nextVersion=Next Version report.latestSubIncremental=Latest Subincremental -report.nextIncremental=Next Incremental report.latestIncremental=Latest Incremental -report.nextMinor=Next Minor report.latestMinor=Latest Minor -report.nextMajor=Next Major report.latestMajor=Latest Major report.updateVersions=Newer versions report.noUpdatesAvailable=No newer versions available. diff --git a/src/main/resources/plugin-updates-report.properties b/src/main/resources/plugin-updates-report.properties index c3a37ddc7c..deb1929afe 100644 --- a/src/main/resources/plugin-updates-report.properties +++ b/src/main/resources/plugin-updates-report.properties @@ -42,14 +42,9 @@ report.currentVersion=Current Version report.scope=Scope report.classifier=Classifier report.type=Type -report.newerVersion=Newer Version(s) -report.nextVersion=Next Version report.latestSubIncremental=Latest Subincremental -report.nextIncremental=Next Incremental report.latestIncremental=Latest Incremental -report.nextMinor=Next Minor report.latestMinor=Latest Minor -report.nextMajor=Next Major report.latestMajor=Latest Major report.dependencyStatus=Dependency status report.updateVersions=Newer versions diff --git a/src/main/resources/property-updates-report.properties b/src/main/resources/property-updates-report.properties index ed59150ed7..e0fe103cfb 100644 --- a/src/main/resources/property-updates-report.properties +++ b/src/main/resources/property-updates-report.properties @@ -37,14 +37,9 @@ report.detail.text= report.status=Status report.property=Property report.currentVersion=Current Version -report.newerVersion=Newer Version(s) -report.nextVersion=Next Version report.latestSubIncremental=Latest Subincremental -report.nextIncremental=Next Incremental report.latestIncremental=Latest Incremental -report.nextMinor=Next Minor report.latestMinor=Latest Minor -report.nextMajor=Next Major report.latestMajor=Latest Major report.updateVersions=Newer versions report.noUpdatesAvailable=No newer versions available. diff --git a/src/test/java/org/codehaus/mojo/versions/api/ArtifactVersionsTest.java b/src/test/java/org/codehaus/mojo/versions/api/ArtifactVersionsTest.java index 1cc1d974d2..05de76fc17 100644 --- a/src/test/java/org/codehaus/mojo/versions/api/ArtifactVersionsTest.java +++ b/src/test/java/org/codehaus/mojo/versions/api/ArtifactVersionsTest.java @@ -124,6 +124,6 @@ public void testReportLabels() Arrays.asList( versions ), new MavenVersionComparator() ); assertThat( instance.getNewestUpdate( of( SUBINCREMENTAL ) ).toString(), is( "1.1.0-2" ) ); - assertThat( instance.getOldestUpdate( of( INCREMENTAL ) ).toString(), is( "1.1.1" ) ); + assertThat( instance.getNewestUpdate( of( INCREMENTAL ) ).toString(), is( "1.1.3" ) ); } }