From d1cebdb32a573797dd0cd3ee14d8f429138071b8 Mon Sep 17 00:00:00 2001 From: Swell <5782559+sultan@users.noreply.github.com> Date: Thu, 24 Nov 2022 10:56:38 +0100 Subject: [PATCH] report verbosity --- .../versions/api/AbstractVersionDetails.java | 8 +++++++ .../mojo/versions/AbstractVersionsReport.java | 7 ++++++ .../versions/DependencyUpdatesReportMojo.java | 3 ++- .../versions/ParentUpdatesReportMojo.java | 2 +- .../versions/PluginUpdatesReportMojo.java | 3 ++- .../versions/PropertyUpdatesReportMojo.java | 3 ++- .../AbstractVersionsReportRenderer.java | 22 +++++++++++++++++++ .../DependencyUpdatesReportRenderer.java | 9 ++++++++ .../PluginUpdatesReportRenderer.java | 8 +++++++ .../PropertyUpdatesReportRenderer.java | 8 +++++++ .../reporting/ReportRendererFactory.java | 5 ++++- .../reporting/ReportRendererFactoryImpl.java | 18 ++++++++++----- 12 files changed, 86 insertions(+), 10 deletions(-) diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java b/versions-common/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java index 13e8966c88..0e5ed86ef0 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java @@ -176,6 +176,14 @@ public final void setIncludeSnapshots( boolean includeSnapshots ) } } + public void setVerbose( boolean verbose ) + { + synchronized ( currentVersionLock ) + { + this.verboseDetail = verbose; + } + } + @Override public final ArtifactVersion[] getVersions() { diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsReport.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsReport.java index 45e0b1654f..6d20236aba 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsReport.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsReport.java @@ -140,6 +140,12 @@ public abstract class AbstractVersionsReport @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. */ @@ -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 ) diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DependencyUpdatesReportMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DependencyUpdatesReportMojo.java index fb6fe624b5..ebe4d22893 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DependencyUpdatesReportMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DependencyUpdatesReportMojo.java @@ -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 ) ) { diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/ParentUpdatesReportMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/ParentUpdatesReportMojo.java index 83bb2ab4b5..41ba46c2d4 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/ParentUpdatesReportMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/ParentUpdatesReportMojo.java @@ -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 ) diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/PluginUpdatesReportMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/PluginUpdatesReportMojo.java index 40427c1962..cc6711a4ea 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/PluginUpdatesReportMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/PluginUpdatesReportMojo.java @@ -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 ) ) { diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/PropertyUpdatesReportMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/PropertyUpdatesReportMojo.java index 419fa786f5..6cc1884b88 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/PropertyUpdatesReportMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/PropertyUpdatesReportMojo.java @@ -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 ) ) { diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/AbstractVersionsReportRenderer.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/AbstractVersionsReportRenderer.java index 0b5117d9f3..22fe513882 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/AbstractVersionsReportRenderer.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/AbstractVersionsReportRenderer.java @@ -71,6 +71,20 @@ public abstract class AbstractVersionsReportRenderer extends VersionsReportRe protected final SinkEventAttributes headerAttributes = new SinkEventAttributeSet( SinkEventAttributes.WIDTH, "30%" ); + 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 ); @@ -234,6 +248,10 @@ protected void renderSummaryTableRow( Dependency artifact, ArtifactVersions deta details.setCurrentVersion( artifact.getVersion() ); ArtifactVersion[] allUpdates = allUpdatesCache.get( details, empty() ); boolean upToDate = allUpdates == null || allUpdates.length == 0; + if ( upToDate && !verboseSummary ) + { + return; + } sink.tableRow(); @@ -268,6 +286,10 @@ protected void renderDependencyDetailTable( Dependency artifact, ArtifactVersion { ArtifactVersion[] allUpdates = allUpdatesCache.get( details, empty() ); boolean upToDate = allUpdates == null || allUpdates.length == 0; + if ( upToDate && !verboseDetail ) + { + return; + } sink.table(); sink.tableRows( new int[] { Sink.JUSTIFY_RIGHT, Sink.JUSTIFY_LEFT }, false ); diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/DependencyUpdatesReportRenderer.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/DependencyUpdatesReportRenderer.java index 8072e31192..076b69f0ea 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/DependencyUpdatesReportRenderer.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/DependencyUpdatesReportRenderer.java @@ -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; @@ -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() ) ); diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/PluginUpdatesReportRenderer.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/PluginUpdatesReportRenderer.java index bd0e3c2b24..035f866871 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/PluginUpdatesReportRenderer.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/PluginUpdatesReportRenderer.java @@ -143,6 +143,10 @@ protected void renderOverviewTableRow( T stats ) protected void renderSummaryTableRow( Dependency artifact, PluginUpdatesDetails details ) { boolean upToDate = !details.isUpdateAvailable(); + if ( upToDate && !verboseSummary ) + { + return; + } sink.tableRow(); @@ -193,6 +197,10 @@ private void renderPluginDetailTable( PluginUpdatesDetails details ) // warning: using caches here might break plugin report ArtifactVersion[] allUpdates = details.getAllUpdates( empty() ); boolean upToDate = allUpdates == null || allUpdates.length == 0; + if ( upToDate && !verboseDetail ) + { + return; + } sink.table(); sink.tableRows( new int[] { Sink.JUSTIFY_RIGHT, Sink.JUSTIFY_LEFT }, false ); diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/PropertyUpdatesReportRenderer.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/PropertyUpdatesReportRenderer.java index 8b79da27b1..208b60f574 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/PropertyUpdatesReportRenderer.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/PropertyUpdatesReportRenderer.java @@ -106,6 +106,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(); @@ -123,6 +127,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; + } sink.table(); sink.tableRows( new int[] { Sink.JUSTIFY_RIGHT, Sink.JUSTIFY_LEFT }, false ); diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/ReportRendererFactory.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/ReportRendererFactory.java index 1b977ecc5c..ede5b4994d 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/ReportRendererFactory.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/ReportRendererFactory.java @@ -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 false if up to date rows should be filtered out of report table. + * @param verboseDetail false 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 createReportRenderer( String reportName, Sink sink, Locale locale, U model ) + T createReportRenderer( String reportName, Sink sink, Locale locale, U model, + boolean verboseSummary, boolean verboseDetail ) throws IllegalArgumentException; } diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/ReportRendererFactoryImpl.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/ReportRendererFactoryImpl.java index d1344a811c..36c09a717d 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/ReportRendererFactoryImpl.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/ReportRendererFactoryImpl.java @@ -57,29 +57,37 @@ public ReportRendererFactoryImpl( I18N i18N ) */ @Override @SuppressWarnings( "unchecked" ) - public T createReportRenderer( String reportName, Sink sink, Locale locale, U model ) + public 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 ); } }