Skip to content

Commit

Permalink
report verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
sultan committed Oct 18, 2022
1 parent 47ff2e7 commit fe1eee3
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 12 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|rm|preview|rc|cr)"
+ "(\\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 @@ -216,6 +230,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 @@ -150,6 +150,10 @@ protected <T extends OverviewStats> void renderOverviewTableRow( T stats )
protected void renderSummaryTableRow( Dependency artifact, PluginUpdatesDetails details )
{
boolean upToDate = !details.isUpdateAvailable();
if ( upToDate && !verboseSummary )
{
return;
}

sink.tableRow();
sink.tableCell();
Expand Down Expand Up @@ -233,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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,37 @@ public ReportRendererFactoryImpl( I18N i18N )
*/
@Override
@SuppressWarnings( "unchecked" )
public <T extends ReportRenderer, U> T createReportRenderer( String reportName, Sink sink, Locale locale, U model )
public <T extends ReportRenderer, U> T createReportRenderer( String reportName, Sink sink, Locale locale, U model,
boolean verboseSummary, boolean verboseDetail )
throws IllegalArgumentException
{
AbstractVersionsReportRenderer renderer = null;
if ( DEPENDENCY_UPDATES_REPORT.equals( reportName ) )
{
return (T) new DependencyUpdatesReportRenderer<>( i18N, sink, locale, reportName,
renderer = new DependencyUpdatesReportRenderer<>( i18N, sink, locale, reportName,
(DependencyUpdatesModel) model );
}
if ( PLUGIN_UPDATES_REPORT.equals( reportName ) )
{
return (T) new PluginUpdatesReportRenderer( i18N, sink, locale, reportName,
renderer = new PluginUpdatesReportRenderer( i18N, sink, locale, reportName,
(PluginUpdatesModel) model );
}
if ( PROPERTY_UPDATES_REPORT.equals( reportName ) )
{
return (T) new PropertyUpdatesReportRenderer( i18N, sink, locale, reportName,
renderer = new PropertyUpdatesReportRenderer( i18N, sink, locale, reportName,
(PropertyUpdatesModel) model );
}
if ( PARENT_UPDATES_REPORT.equals( reportName ) )
{
return (T) new ParentUpdatesReportRenderer( i18N, sink, locale, reportName,
renderer = new ParentUpdatesReportRenderer( i18N, sink, locale, reportName,
(ParentUpdatesModel) model );
}
if ( renderer != null )
{
renderer.setVerboseSummary( verboseSummary );
renderer.setVerboseDetail( verboseDetail );
return (T) renderer;
}
throw new IllegalArgumentException( "Invalid report name: " + reportName );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,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 ) )
Expand Down

0 comments on commit fe1eee3

Please sign in to comment.