Skip to content

Commit

Permalink
report verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
sultan committed Nov 26, 2022
1 parent badd0c4 commit 6edac55
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public abstract class AbstractVersionDetails
*/
private boolean includeSnapshots = false;

protected boolean verbose = 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 @@ -144,6 +146,14 @@ public final void setIncludeSnapshots( boolean includeSnapshots )
}
}

public void setVerbose( boolean verbose )
{
synchronized ( currentVersionLock )
{
this.verbose = verbose;
}
}

@Override
public final ArtifactVersion[] getVersions()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,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 @@ -290,6 +296,7 @@ protected ArtifactVersion findLatestVersion( Artifact artifact, VersionRange ver
{
final ArtifactVersions artifactVersions =
getHelper().lookupArtifactVersions( artifact, usePluginRepositories );
artifactVersions.setVerbose( verboseDetail );
return artifactVersions.getNewestVersion( versionRange, includeSnapshots );
}
catch ( VersionRetrievalException e )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ && getProject().getOriginalModel().getDependencyManagement().getDependencies() !
{
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 @@ -114,7 +114,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 ( VersionRetrievalException e )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,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 @@ -162,7 +162,8 @@ protected void doGenerateReport( Locale locale, Sink sink )
{
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 @@ -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;
}

protected AbstractVersionsReportRenderer( I18N i18n, Sink sink, Locale locale, String bundleName, T model )
{
super( sink, i18n, locale, bundleName );
Expand Down Expand Up @@ -212,6 +226,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 Expand Up @@ -290,6 +308,10 @@ protected void renderDependencyDetailTable( Dependency artifact, ArtifactVersion
{
ArtifactVersion[] allUpdates = allUpdatesCache.get( details, empty() );
boolean upToDate = allUpdates == null || allUpdates.length == 0;
if ( upToDate && !verboseDetail )
{
return;
}

final SinkEventAttributes headerAttributes = new SinkEventAttributeSet();
headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "70%" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@

import java.util.Locale;
import java.util.Map;
import java.util.Optional;

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;
Expand Down Expand Up @@ -91,6 +93,13 @@ protected OverviewStats computeOverviewStats()

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

sink.section2();
sink.sectionTitle2();
sink.text( ArtifactUtils.versionlessKey( artifact.getGroupId(), artifact.getArtifactId() ) );
Expand Down
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 && !verboseDetail )
{
return;
}

sink.tableRow();
sink.tableCell();
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 @@ -181,6 +185,10 @@ protected void renderPropertyDetailTable( Property property, PropertyVersions de
{
ArtifactVersion[] allUpdates = allUpdatesCache.get( details, empty() );
boolean upToDate = allUpdates == null || allUpdates.length == 0;
if ( upToDate && !verboseDetail )
{
return;
}

final SinkEventAttributes headerAttributes = new SinkEventAttributeSet();
headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "70%" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,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 );
}
}

0 comments on commit 6edac55

Please sign in to comment.