Skip to content

Commit

Permalink
caching repeated call of methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sultan committed Oct 2, 2022
1 parent e7aa406 commit 7290571
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@
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.
*
Expand Down Expand Up @@ -118,6 +111,7 @@ protected boolean equals( ArtifactVersion v1, ArtifactVersion v2 )
|| ( v1 != null && v2 != null && v1.toString().equals( v2.toString() ) );
}

// TODO unused. remove ?
protected void renderDependencySummaryTableRow( Dependency dependency, ArtifactVersions details )
{
renderDependencySummaryTableRow( dependency, details, true, true, true );
Expand All @@ -129,7 +123,7 @@ protected void renderDependencySummaryTableRow( Dependency dependency, ArtifactV
{
sink.tableRow();
sink.tableCell();
ArtifactVersion[] allUpdates = details.getAllUpdates( empty() );
ArtifactVersion[] allUpdates = details.getCacheAllUpdates();
if ( allUpdates == null || allUpdates.length == 0 )
{
renderSuccessIcon();
Expand Down Expand Up @@ -168,37 +162,37 @@ protected void renderDependencySummaryTableRow( Dependency dependency, ArtifactV
}

sink.tableCell();
if ( details.getNewestUpdate( of( SUBINCREMENTAL ) ) != null )
if ( details.getCacheNewestSubIncremental() != null )
{
safeBold();
sink.text( details.getNewestUpdate( of( SUBINCREMENTAL ) ).toString() );
sink.text( details.getCacheNewestSubIncremental().toString() );
safeBold_();
}
sink.tableCell_();

sink.tableCell();
if ( details.getNewestUpdate( of( INCREMENTAL ) ) != null )
if ( details.getCacheNewestIncremental() != null )
{
safeBold();
sink.text( details.getNewestUpdate( of( INCREMENTAL ) ).toString() );
sink.text( details.getCacheNewestIncremental().toString() );
safeBold_();
}
sink.tableCell_();

sink.tableCell();
if ( details.getNewestUpdate( of( MINOR ) ) != null )
if ( details.getCacheNewestMinor() != null )
{
safeBold();
sink.text( details.getNewestUpdate( of( MINOR ) ).toString() );
sink.text( details.getCacheNewestMinor().toString() );
safeBold_();
}
sink.tableCell_();

sink.tableCell();
if ( details.getNewestUpdate( of( MAJOR ) ) != null )
if ( details.getCacheNewestMajor() != null )
{
safeBold();
sink.text( details.getNewestUpdate( of( MAJOR ) ).toString() );
sink.text( details.getCacheNewestMajor().toString() );
safeBold_();
}
sink.tableCell_();
Expand Down Expand Up @@ -330,26 +324,26 @@ protected void renderDependencyDetailTable( Dependency dependency, ArtifactVersi
sink.text( getText( "report.status" ) );
sink.tableHeaderCell_();
sink.tableCell( cellAttributes );
ArtifactVersion[] versions = details.getAllUpdates( empty() );
if ( details.getOldestUpdate( of( SUBINCREMENTAL ) ) != null )
ArtifactVersion[] versions = details.getCacheAllUpdates();
if ( details.getCacheOldestSubIncremental() != null )
{
renderWarningIcon();
sink.nonBreakingSpace();
sink.text( getText( "report.otherUpdatesAvailable" ) );
}
else if ( details.getOldestUpdate( of( INCREMENTAL ) ) != null )
else if ( details.getCacheOldestIncremental() != null )
{
renderWarningIcon();
sink.nonBreakingSpace();
sink.text( getText( "report.incrementalUpdatesAvailable" ) );
}
else if ( details.getOldestUpdate( of( MINOR ) ) != null )
else if ( details.getCacheOldestMinor() != null )
{
renderWarningIcon();
sink.nonBreakingSpace();
sink.text( getText( "report.minorUpdatesAvailable" ) );
}
else if ( details.getOldestUpdate( of( MAJOR ) ) != null )
else if ( details.getCacheOldestMajor() != null )
{
renderWarningIcon();
sink.nonBreakingSpace();
Expand Down Expand Up @@ -490,7 +484,7 @@ protected void renderPropertySummaryTableRow( Property property, PropertyVersion
{
sink.tableRow();
sink.tableCell();
if ( versions.getAllUpdates( empty() ).length == 0 )
if ( versions.getCacheAllUpdates().length == 0 )
{
renderSuccessIcon();
}
Expand All @@ -507,37 +501,37 @@ protected void renderPropertySummaryTableRow( Property property, PropertyVersion
sink.tableCell_();

sink.tableCell();
if ( versions.getNewestUpdate( of( SUBINCREMENTAL ) ) != null )
if ( versions.getCacheNewestSubIncremental() != null )
{
safeBold();
sink.text( versions.getNewestUpdate( of( SUBINCREMENTAL ) ).toString() );
sink.text( versions.getCacheNewestSubIncremental().toString() );
safeBold_();
}
sink.tableCell_();

sink.tableCell();
if ( versions.getNewestUpdate( of( INCREMENTAL ) ) != null )
if ( versions.getCacheNewestIncremental() != null )
{
safeBold();
sink.text( versions.getNewestUpdate( of( INCREMENTAL ) ).toString() );
sink.text( versions.getCacheNewestIncremental().toString() );
safeBold_();
}
sink.tableCell_();

sink.tableCell();
if ( versions.getNewestUpdate( of( MINOR ) ) != null )
if ( versions.getCacheNewestMinor() != null )
{
safeBold();
sink.text( versions.getNewestUpdate( of( MINOR ) ).toString() );
sink.text( versions.getCacheNewestMinor().toString() );
safeBold_();
}
sink.tableCell_();

sink.tableCell();
if ( versions.getNewestUpdate( of( MAJOR ) ) != null )
if ( versions.getCacheNewestMajor() != null )
{
safeBold();
sink.text( versions.getNewestUpdate( of( MAJOR ) ).toString() );
sink.text( versions.getCacheNewestMajor().toString() );
safeBold_();
}
sink.tableCell_();
Expand Down Expand Up @@ -586,27 +580,27 @@ protected void renderPropertyDetailTable( Property property, PropertyVersions ve
sink.text( getText( "report.status" ) );
sink.tableHeaderCell_();
sink.tableCell( cellAttributes );
ArtifactVersion[] artifactVersions = versions.getAllUpdates( empty() );
ArtifactVersion[] artifactVersions = versions.getCacheAllUpdates();
Set<String> rangeVersions = getVersionsInRange( property, versions, artifactVersions );
if ( versions.getOldestUpdate( of( SUBINCREMENTAL ) ) != null )
if ( versions.getCacheOldestSubIncremental() != null )
{
renderWarningIcon();
sink.nonBreakingSpace();
sink.text( getText( "report.otherUpdatesAvailable" ) );
}
else if ( versions.getOldestUpdate( of( INCREMENTAL ) ) != null )
else if ( versions.getCacheOldestIncremental() != null )
{
renderWarningIcon();
sink.nonBreakingSpace();
sink.text( getText( "report.incrementalUpdatesAvailable" ) );
}
else if ( versions.getOldestUpdate( of( MINOR ) ) != null )
else if ( versions.getCacheOldestMinor() != null )
{
renderWarningIcon();
sink.nonBreakingSpace();
sink.text( getText( "report.minorUpdatesAvailable" ) );
}
else if ( versions.getOldestUpdate( of( MAJOR ) ) != null )
else if ( versions.getCacheOldestMajor() != null )
{
renderWarningIcon();
sink.nonBreakingSpace();
Expand Down Expand Up @@ -781,35 +775,35 @@ private Set<String> getVersionsInRange( Property property, PropertyVersions vers
protected String getLabel( ArtifactVersion version, AbstractVersionDetails versions )
{
String label = null;
if ( equals( version, versions.getNewestUpdate( of( MAJOR ) ) ) )
if ( equals( version, versions.getCacheNewestMajor() ) )
{
label = getText( "report.latestMajor" );
}
else if ( equals( version, versions.getOldestUpdate( of( MAJOR ) ) ) )
else if ( equals( version, versions.getCacheOldestMajor() ) )
{
label = getText( "report.nextMajor" );
}
else if ( equals( version, versions.getNewestUpdate( of( MINOR ) ) ) )
else if ( equals( version, versions.getCacheNewestMinor() ) )
{
label = getText( "report.latestMinor" );
}
else if ( equals( version, versions.getOldestUpdate( of( MINOR ) ) ) )
else if ( equals( version, versions.getCacheOldestMinor() ) )
{
label = getText( "report.nextMinor" );
}
else if ( equals( version, versions.getNewestUpdate( of( INCREMENTAL ) ) ) )
else if ( equals( version, versions.getCacheNewestIncremental() ) )
{
label = getText( "report.latestIncremental" );
}
else if ( equals( version, versions.getOldestUpdate( of( INCREMENTAL ) ) ) )
else if ( equals( version, versions.getCacheOldestIncremental() ) )
{
label = getText( "report.nextIncremental" );
}
else if ( equals( version, versions.getNewestUpdate( of( SUBINCREMENTAL ) ) ) )
else if ( equals( version, versions.getCacheNewestSubIncremental() ) )
{
label = getText( "report.latestSubIncremental" );
}
else if ( equals( version, versions.getOldestUpdate( of( SUBINCREMENTAL ) ) ) )
else if ( equals( version, versions.getCacheOldestSubIncremental() ) )
{
label = getText( "report.nextVersion" );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,11 @@
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.model.Dependency;
import org.codehaus.mojo.versions.api.AbstractVersionDetails;
import org.codehaus.mojo.versions.api.ArtifactVersions;
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
*/
Expand All @@ -61,6 +56,11 @@ protected void renderBody()
Map<Dependency, ArtifactVersions> allUpdates = new TreeMap<>( new DependencyComparator() );
allUpdates.putAll( dependencyManagementUpdates );
allUpdates.putAll( dependencyUpdates );
// caching
for ( AbstractVersionDetails details : allUpdates.values() )
{
details.prepareCache();
}

sink.section1();
sink.sectionTitle1();
Expand All @@ -69,13 +69,9 @@ protected void renderBody()
sink.paragraph();
sink.text( getText( "report.overview.text" ) );
sink.paragraph_();

renderSummaryTotalsTable( allUpdates );

renderDependencyManagementSummary();

renderDependencySummary();

sink.section1_();

sink.section1();
Expand All @@ -85,7 +81,6 @@ protected void renderBody()
sink.paragraph();
sink.text( getText( "report.detail.text" ) );
sink.paragraph_();

for ( Map.Entry<Dependency, ArtifactVersions> entry : allUpdates.entrySet() )
{
renderDependencyDetail( entry.getKey(), entry.getValue() );
Expand Down Expand Up @@ -133,19 +128,19 @@ protected void renderSummaryTotalsTable( Map<Dependency, ArtifactVersions> allUp
int numCur = 0;
for ( ArtifactVersions details : allUpdates.values() )
{
if ( details.getOldestUpdate( of( SUBINCREMENTAL ) ) != null )
if ( details.getCacheOldestSubIncremental() != null )
{
numAny++;
}
else if ( details.getOldestUpdate( of( INCREMENTAL ) ) != null )
else if ( details.getCacheOldestIncremental() != null )
{
numInc++;
}
else if ( details.getOldestUpdate( of( MINOR ) ) != null )
else if ( details.getCacheOldestMinor() != null )
{
numMin++;
}
else if ( details.getOldestUpdate( of( MAJOR ) ) != null )
else if ( details.getCacheOldestMajor() != null )
{
numMaj++;
}
Expand Down
Loading

0 comments on commit 7290571

Please sign in to comment.