Skip to content

Commit

Permalink
Caching update information in reports to increase performance
Browse files Browse the repository at this point in the history
  • Loading branch information
sultan committed Oct 15, 2022
1 parent 954a853 commit 94c24ef
Show file tree
Hide file tree
Showing 16 changed files with 124 additions and 162 deletions.
6 changes: 3 additions & 3 deletions src/it/it-dependency-updates-report-001/verify.bsh
Original file line number Diff line number Diff line change
Expand Up @@ -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 +"\"" );
Expand All @@ -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 +"\"" );
Expand All @@ -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 +"\"" );
Expand Down
8 changes: 4 additions & 4 deletions src/it/it-dependency-updates-report-002/verify.bsh
Original file line number Diff line number Diff line change
Expand Up @@ -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 +"\"" );
Expand All @@ -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 +"\"" );
Expand All @@ -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 +"\"" );
Expand Down
6 changes: 3 additions & 3 deletions src/it/it-plugin-updates-report-001/verify.bsh
Original file line number Diff line number Diff line change
Expand Up @@ -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 +"\"" );
Expand Down
2 changes: 1 addition & 1 deletion src/it/it-plugin-updates-report-002/verify.bsh
Original file line number Diff line number Diff line change
Expand Up @@ -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 +"\"" );
Expand Down
2 changes: 1 addition & 1 deletion src/it/it-plugin-updates-report-003/verify.bsh
Original file line number Diff line number Diff line change
Expand Up @@ -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 +"\"" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public abstract class AbstractVersionsReportRenderer<T> 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 );
Expand Down Expand Up @@ -237,12 +237,12 @@ 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 )
{
sink.tableRow();
sink.tableCell();
ArtifactVersion[] allUpdates = artifactVersions.getAllUpdates( empty() );
ArtifactVersion[] allUpdates = allUpdatesCache.get( details, empty() );
if ( allUpdates == null || allUpdates.length == 0 )
{
renderSuccessIcon();
Expand Down Expand Up @@ -275,37 +275,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_();
Expand All @@ -328,25 +328,25 @@ protected void renderDependencyDetailTable( Dependency artifact, ArtifactVersion
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();
Expand Down Expand Up @@ -462,4 +462,29 @@ 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,19 @@ protected PluginOverviewStats computeOverviewStats()
PluginOverviewStats stats = new PluginOverviewStats();
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();
}
Expand Down Expand Up @@ -285,42 +285,64 @@ protected void renderSummaryTableRow( Dependency artifact, PluginUpdatesDetails
@SuppressWarnings( "checkstyle:MethodLength" )
private void renderPluginDetail( Dependency artifact, PluginUpdatesDetails plugin )
{
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() ) ) );
sink.sectionTitle2_();

renderPluginDetailTable( plugin );

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_();
}

private void renderPluginDetailTable( PluginUpdatesDetails plugin )
{
final SinkEventAttributes headerAttributes = new SinkEventAttributeSet();
headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "20%" );
final SinkEventAttributes cellAttributes = new SinkEventAttributeSet();
headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "80%" );
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 ( plugin.getNewestUpdate( of( SUBINCREMENTAL ) ) != null )
{
renderWarningIcon();
sink.nonBreakingSpace();
sink.text( getText( "report.otherUpdatesAvailable" ) );
}
else if ( plugin.getOldestUpdate( of( INCREMENTAL ) ) != null )
else if ( plugin.getNewestUpdate( of( INCREMENTAL ) ) != null )
{
renderWarningIcon();
sink.nonBreakingSpace();
sink.text( getText( "report.incrementalUpdatesAvailable" ) );
}
else if ( plugin.getOldestUpdate( of( MINOR ) ) != null )
else if ( plugin.getNewestUpdate( of( MINOR ) ) != null )
{
renderWarningIcon();
sink.nonBreakingSpace();
sink.text( getText( "report.minorUpdatesAvailable" ) );
}
else if ( plugin.getOldestUpdate( of( MAJOR ) ) != null )
else if ( plugin.getNewestUpdate( of( MAJOR ) ) != null )
{
renderWarningIcon();
sink.nonBreakingSpace();
Expand Down Expand Up @@ -391,22 +413,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_();
}
}

Loading

0 comments on commit 94c24ef

Please sign in to comment.