Skip to content

Commit

Permalink
report verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
sultan committed Oct 17, 2022
1 parent bce8646 commit 3ccad1b
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ public abstract class AbstractVersionsReport<T>
@Parameter( property = "allowSnapshots", defaultValue = "false" )
protected boolean allowSnapshots;

@Parameter( property = "verboseSummary", defaultValue = "true" )
protected boolean verboseSummary = true;

@Parameter( property = "verboseDetail", defaultValue = "true" )
protected boolean verboseDetail = true;

/**
* Our versions helper.
*/
Expand Down Expand Up @@ -293,6 +299,7 @@ protected ArtifactVersion findLatestVersion( Artifact artifact, VersionRange ver
{
final ArtifactVersions artifactVersions =
getHelper().lookupArtifactVersions( artifact, usePluginRepositories );
artifactVersions.setVerboseDetail( verboseDetail );
return artifactVersions.getNewestVersion( versionRange, includeSnapshots );
}
catch ( ArtifactMetadataRetrievalException e )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ && getProject().getOriginalModel().getDependencyManagement().getDependencies() !
new DependencyUpdatesModel( dependencyUpdates, dependencyManagementUpdates );
if ( "html".equals( format ) )
{
rendererFactory.createReportRenderer( getOutputName(), sink, locale, model ).render();
rendererFactory.createReportRenderer( getOutputName(), sink, locale, model,
verboseSummary, verboseDetail ).render();
}
else if ( "xml".equals( format ) )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected void doGenerateReport( Locale locale, Sink sink ) throws MavenReportEx
.withScope( artifactVersions.getArtifact().getScope() )
.withType( artifactVersions.getArtifact().getType() )
.withClassifier( artifactVersions.getArtifact().getClassifier() )
.build(), artifactVersions ) )
.build(), artifactVersions ), verboseSummary, verboseDetail )
.render();
}
catch ( ArtifactMetadataRetrievalException e )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ protected void doGenerateReport( Locale locale, Sink sink ) throws MavenReportEx
{
if ( "html".equals( format ) )
{
rendererFactory.createReportRenderer( getOutputName(), getSink(), locale, model ).render();
rendererFactory.createReportRenderer( getOutputName(), getSink(), locale, model,
verboseSummary, verboseDetail ).render();
}
else if ( "xml".equals( format ) )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected void doGenerateReport( Locale locale, Sink sink )
throw new MavenReportException( e.getMessage(), e );
}
rendererFactory.createReportRenderer( getOutputName(), getSink(), locale,
new PropertyUpdatesModel( updateSet ) ).render();
new PropertyUpdatesModel( updateSet ), verboseSummary, verboseDetail ).render();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@

import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
Expand All @@ -49,6 +51,10 @@ public abstract class AbstractVersionDetails
implements VersionDetails
{

private static final Pattern PREVIEW_PATTERN =
Pattern.compile( "(?i)(?:.*[-.](a|alpha|b|beta|m|mr|preview|rc|cr|rm)"
+ "(\\d{0,2}[a-z]?|\\d{6}\\.\\d{4})|\\d{8}(?:\\.?\\d{6})?)$" );

/**
* The current version. Guarded by {@link #currentVersionLock}.
*
Expand All @@ -63,6 +69,8 @@ public abstract class AbstractVersionDetails
*/
private boolean includeSnapshots = false;

protected boolean verboseDetail = true;

/**
* Not sure if we need to be thread safe, but there's no harm being careful, after all we could be invoked from an
* IDE.
Expand Down Expand Up @@ -123,6 +131,14 @@ public final void setIncludeSnapshots( boolean includeSnapshots )
}
}

public void setVerboseDetail( boolean verboseDetail )
{
synchronized ( currentVersionLock )
{
this.verboseDetail = verboseDetail;
}
}

@Override
public final ArtifactVersion[] getVersions()
{
Expand Down Expand Up @@ -285,7 +301,7 @@ public final ArtifactVersion[] getVersions( VersionRange versionRange, Restricti
boolean includeSnapshots )
{
final VersionComparator versionComparator = getVersionComparator();
Set<ArtifactVersion> result = new TreeSet<>( versionComparator );
TreeSet<ArtifactVersion> result = new TreeSet<>( versionComparator );
for ( ArtifactVersion candidate : getVersions( includeSnapshots ) )
{
if ( versionRange != null && !ArtifactVersions.isVersionInRange( candidate, versionRange ) )
Expand All @@ -302,6 +318,48 @@ public final ArtifactVersion[] getVersions( VersionRange versionRange, Restricti
}
result.add( candidate );
}

// filter out intermediate minor versions.
if ( !verboseDetail )
{
String current = ".";
boolean needOneMore = false;
Iterator<ArtifactVersion> rev = result.descendingIterator(); // be cautious to keep latest ones.
for ( Iterator<ArtifactVersion> it = rev; it.hasNext(); )
{
ArtifactVersion version = it.next();
boolean isPreview = PREVIEW_PATTERN.matcher( version.toString() ).matches();

// encountered a version in same Major.Minor version, remove it.
if ( version.toString().startsWith( current + "." ) || version.toString().startsWith( current + "-" ) )
{
if ( needOneMore && !isPreview )
{
needOneMore = false;
continue;
}
it.remove();
continue;
}

// if last version is a pre-release, also search for the last release.
needOneMore = isPreview;

// encountered a new Major.Minor version, keep it.
int indexOf = StringUtils.ordinalIndexOf( version.toString(), ".", Segment.MINOR.value() + 1 );
if ( indexOf > -1 )
{
current = version.toString().substring( 0, indexOf );
continue;
}
indexOf = version.toString().indexOf( "-" );
if ( indexOf > -1 )
{
current = version.toString().substring( 0, indexOf );
}
}
}

return result.toArray( new ArtifactVersion[0] );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ public abstract class AbstractVersionsReportRenderer<T> extends VersionsReportRe
protected ArtifactVersionsCache allUpdatesCache
= new ArtifactVersionsCache( AbstractVersionDetails::getAllUpdates );

protected boolean verboseSummary = true;

protected boolean verboseDetail = true;

public void setVerboseSummary( boolean verboseSummary )
{
this.verboseSummary = verboseSummary;
}

public void setVerboseDetail( boolean verboseDetail )
{
this.verboseDetail = verboseDetail;
}

/**
* Constructor to be called by the dependency injection framework
* @param i18n i18n object to be injected
Expand Down Expand Up @@ -136,59 +150,11 @@ protected void renderOverview()
*/
protected <Q extends OverviewStats> 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 );
}

/**
Expand Down Expand Up @@ -242,6 +208,10 @@ protected void renderSummaryTableRow( Dependency artifact, ArtifactVersions deta
{
ArtifactVersion[] allUpdates = allUpdatesCache.get( details, empty() );
boolean upToDate = allUpdates == null || allUpdates.length == 0;
if ( upToDate && !verboseSummary )
{
return;
}

sink.tableRow();
sink.tableCell();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@
import java.util.Map;

import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.versioning.ArtifactVersion;
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.reporting.model.DependencyUpdatesModel;
import org.codehaus.plexus.i18n.I18N;

import static java.util.Optional.empty;

/**
* @param <K> type of the model
* @since 1.0-beta-1
Expand Down Expand Up @@ -91,11 +94,19 @@ protected OverviewStats computeOverviewStats()

protected void renderDependencyDetail( Dependency artifact, ArtifactVersions details )
{
ArtifactVersion[] allUpdates = allUpdatesCache.get( details, empty() );
boolean upToDate = allUpdates == null || allUpdates.length == 0;
if ( upToDate && !verboseDetail )
{
return;
}

sink.section2();
sink.sectionTitle2();
sink.text( ArtifactUtils.versionlessKey( artifact.getGroupId(), artifact.getArtifactId() ) );
sink.sectionTitle2_();
renderDependencyDetailTable( artifact, details, true );
sink.section2_();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,17 @@ protected void renderSummaryTableHeader( boolean hasScope, boolean hasType )
protected <T extends OverviewStats> 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();
if ( upToDate && !verboseSummary )
{
return;
}

sink.tableRow();
sink.tableCell();
Expand Down Expand Up @@ -237,6 +237,12 @@ protected void renderSummaryTableRow( Dependency artifact, PluginUpdatesDetails
@SuppressWarnings( "checkstyle:MethodLength" )
private void renderPluginDetail( Dependency artifact, PluginUpdatesDetails details )
{
boolean upToDate = !details.isUpdateAvailable();
if ( upToDate && !verboseDetail )
{
return;
}

sink.section2();
sink.sectionTitle2();
sink.text( MessageFormat.format( getText( "report.plugin" ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ private void renderPropertySummaryTableRow( Property property, PropertyVersions
{
ArtifactVersion[] allUpdates = allUpdatesCache.get( details, empty() );
boolean upToDate = allUpdates == null || allUpdates.length == 0;
if ( upToDate && !verboseSummary )
{
return;
}

sink.tableRow();
sink.tableCell();
Expand Down Expand Up @@ -425,6 +429,13 @@ else if ( newestUpdateCache.get( details, of( MAJOR ) ) != null )

private void renderPropertyDetail( Property property, PropertyVersions details )
{
ArtifactVersion[] allUpdates = allUpdatesCache.get( details, empty() );
boolean upToDate = allUpdates == null || allUpdates.length == 0;
if ( upToDate && !verboseDetail )
{
return;
}

sink.section2();
sink.sectionTitle2();
sink.text( "${" + property.getName() + "}" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ public interface ReportRendererFactory
* @param sink sink to use for rendering
* @param locale locale to use for rendering
* @param model data to render
* @param verboseSummary <code>false</code> if up to date rows should be filtered out of report table.
* @param verboseDetail <code>false</code> if up to date rows should be filtered out of report table.
* @return new report renderer
* @throws IllegalArgumentException thrown if the report with the given name could not be found
*/
<T extends ReportRenderer, U> T createReportRenderer( String reportName, Sink sink, Locale locale, U model )
<T extends ReportRenderer, U> T createReportRenderer( String reportName, Sink sink, Locale locale, U model,
boolean verboseSummary, boolean verboseDetail )
throws IllegalArgumentException;
}
Loading

0 comments on commit 3ccad1b

Please sign in to comment.