Skip to content

Commit

Permalink
work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejj0 committed Oct 4, 2022
1 parent 30784d6 commit 267f3cc
Show file tree
Hide file tree
Showing 4 changed files with 245 additions and 204 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import org.apache.maven.doxia.sink.SinkEventAttributes;
import org.apache.maven.doxia.sink.impl.SinkEventAttributeSet;
import org.apache.maven.model.Dependency;
import org.apache.maven.reporting.AbstractMavenReportRenderer;
import org.codehaus.mojo.versions.api.AbstractVersionDetails;
import org.codehaus.mojo.versions.api.ArtifactVersions;
import org.codehaus.mojo.versions.api.ReportRenderer;
import org.codehaus.plexus.i18n.I18N;
Expand All @@ -48,28 +46,8 @@
* @author Stephen Connolly
* @since 1.0-beta-1
*/
public abstract class AbstractVersionsReportRenderer<T> extends AbstractMavenReportRenderer implements ReportRenderer
public abstract class AbstractVersionsReportRenderer<T> extends VersionsReportRendererBase implements ReportRenderer
{
/**
* Internationalization component.
*
* @since 1.0-beta-1
*/
protected final I18N i18n;

/**
* The locale we are rendering for.
*
* @since 1.0-beta-1
*/
protected Locale locale;

/**
* The name of the bundle containing our I18n resources.
*
* @since 1.0-beta-1
*/
protected String bundleName;

/**
* Model of the object being rendered
Expand All @@ -84,10 +62,7 @@ public abstract class AbstractVersionsReportRenderer<T> extends AbstractMavenRep
*/
protected AbstractVersionsReportRenderer( I18N i18n, Sink sink, Locale locale, String bundleName, T model )
{
super( sink );
this.locale = locale;
this.bundleName = bundleName;
this.i18n = i18n;
super( sink, i18n, locale, bundleName );
this.model = model;
}

Expand Down Expand Up @@ -220,43 +195,42 @@ protected <Q extends OverviewStats> void renderOverviewTableRow( Q stats )
*/
protected abstract void renderDetails();

protected void renderDependencySummaryTable( Map<Dependency, ArtifactVersions> map, boolean includeScope,
boolean includeClassifier, boolean includeType )
protected void renderSummaryTable( Map<Dependency, ArtifactVersions> contents, boolean hasScope )
{
sink.table();
renderDependencySummaryTableHeader( includeScope, includeClassifier, includeType );
map.forEach( ( key, value ) -> renderDependencySummaryTableRow( key, value, includeScope, includeClassifier,
includeType ) );
renderDependencySummaryTableHeader( includeScope, includeClassifier, includeType );

sink.tableRow();
renderSummaryTableHeader( hasScope, true );
sink.tableRow_();

contents.forEach( ( artifact, artifactVersions ) ->
renderSummaryTableRow( artifact, artifactVersions, hasScope ) );

sink.tableRow();
renderSummaryTableHeader( hasScope, true );
sink.tableRow_();

sink.table_();
}

private void renderDependencySummaryTableHeader( boolean includeScope, boolean includeClassifier,
boolean includeType )
protected void renderSummaryTableHeader( boolean hasScope, boolean hasType )
{
sink.tableRow();
renderTableHeaderCells( "report.status", "report.groupId", "report.artifactId",
"report.currentVersion" );
if ( includeScope )
if ( hasScope )
{
renderTableHeaderCells( "report.scope" );
}
if ( includeClassifier )
{
renderTableHeaderCells( "report.classifier" );
}
if ( includeType )
if ( hasType )
{
renderTableHeaderCells( "report.type" );
renderTableHeaderCells( "report.classifier", "report.type" );
}
renderTableHeaderCells( "report.latestSubIncremental", "report.latestIncremental", "report.latestMinor",
"report.latestMajor" );
sink.tableRow_();
renderTableHeaderCells( "report.latestSubIncremental",
"report.latestIncremental", "report.latestMinor", "report.latestMajor" );
}

private void renderDependencySummaryTableRow( Dependency artifact, ArtifactVersions artifactVersions,
boolean includeScope, boolean includeClassifier,
boolean includeType )
protected void renderSummaryTableRow( Dependency artifact, ArtifactVersions artifactVersions,
boolean includeScope )
{
sink.tableRow();
sink.tableCell();
Expand Down Expand Up @@ -285,18 +259,12 @@ private void renderDependencySummaryTableRow( Dependency artifact, ArtifactVersi
sink.text( artifact.getScope() );
sink.tableCell_();
}
if ( includeClassifier )
{
sink.tableCell();
sink.text( artifact.getClassifier() );
sink.tableCell_();
}
if ( includeType )
{
sink.tableCell();
sink.text( artifact.getType() );
sink.tableCell_();
}
sink.tableCell();
sink.text( artifact.getClassifier() );
sink.tableCell_();
sink.tableCell();
sink.text( artifact.getType() );
sink.tableCell_();

sink.tableCell();
if ( artifactVersions.getNewestUpdate( of( SUBINCREMENTAL ) ) != null )
Expand Down Expand Up @@ -338,8 +306,7 @@ private void renderDependencySummaryTableRow( Dependency artifact, ArtifactVersi
}

@SuppressWarnings( "checkstyle:MethodLength" )
protected void renderDependencyDetailTable( Dependency artifact, ArtifactVersions details, boolean includeScope,
boolean includeClassifier, boolean includeType )
protected void renderDependencyDetailTable( Dependency artifact, ArtifactVersions details, boolean includeScope )
{
final SinkEventAttributes headerAttributes = new SinkEventAttributeSet();
headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "20%" );
Expand Down Expand Up @@ -420,28 +387,22 @@ else if ( details.getOldestUpdate( of( MAJOR ) ) != null )
sink.tableCell_();
sink.tableRow_();
}
if ( includeClassifier )
{
sink.tableRow();
sink.tableHeaderCell( headerAttributes );
sink.text( getText( "report.classifier" ) );
sink.tableHeaderCell_();
sink.tableCell( cellAttributes );
sink.text( artifact.getClassifier() );
sink.tableCell_();
sink.tableRow_();
}
if ( includeType )
{
sink.tableRow();
sink.tableHeaderCell( headerAttributes );
sink.text( getText( "report.type" ) );
sink.tableHeaderCell_();
sink.tableCell( cellAttributes );
sink.text( artifact.getType() );
sink.tableCell_();
sink.tableRow_();
}
sink.tableRow();
sink.tableHeaderCell( headerAttributes );
sink.text( getText( "report.classifier" ) );
sink.tableHeaderCell_();
sink.tableCell( cellAttributes );
sink.text( artifact.getClassifier() );
sink.tableCell_();
sink.tableRow_();
sink.tableRow();
sink.tableHeaderCell( headerAttributes );
sink.text( getText( "report.type" ) );
sink.tableHeaderCell_();
sink.tableCell( cellAttributes );
sink.text( artifact.getType() );
sink.tableCell_();
sink.tableRow_();
if ( versions != null && versions.length > 0 )
{
sink.tableRow();
Expand Down Expand Up @@ -477,109 +438,6 @@ else if ( details.getOldestUpdate( of( MAJOR ) ) != null )
sink.table_();
}

public String getTitle()
{
return getText( "report.title" );
}

/**
* Gets the localized message for this report.
*
* @param key the message key.
* @return the message.
*/
public String getText( String key )
{
return i18n.getString( bundleName, locale, key );
}

protected void renderWarningIcon()
{
sink.figureGraphics( "images/icon_warning_sml.gif" );
}

protected void renderSuccessIcon()
{
sink.figureGraphics( "images/icon_success_sml.gif" );
}

protected boolean equals( ArtifactVersion v1, ArtifactVersion v2 )
{
return v1 == v2 || ( v1 != null && v1.equals( v2 ) )
|| ( v1 != null && v2 != null && v1.toString().equals( v2.toString() ) );
}

protected void safeBold()
{
try
{
sink.bold();
}
catch ( NoSuchMethodError e )
{
// ignore Maven 2.1.0
}
}

@SuppressWarnings( "checkstyle:MethodName" )
protected void safeBold_()
{
try
{
sink.bold_();
}
catch ( NoSuchMethodError e )
{
// ignore Maven 2.1.0
}
}

protected void safeItalic()
{
try
{
sink.italic();
}
catch ( NoSuchMethodError e )
{
// ignore Maven 2.1.0
}
}

@SuppressWarnings( "checkstyle:MethodName" )
protected void safeItalic_()
{
try
{
sink.italic_();
}
catch ( NoSuchMethodError e )
{
// ignore Maven 2.1.0
}
}

protected String getLabel( ArtifactVersion version, AbstractVersionDetails versions )
{
return equals( version, versions.getNewestUpdate( of( MAJOR ) ) )
? getText( "report.latestMajor" )
: equals( version, versions.getOldestUpdate( of( MAJOR ) ) )
? getText( "report.nextMajor" )
: equals( version, versions.getNewestUpdate( of( MINOR ) ) )
? getText( "report.latestMinor" )
: equals( version, versions.getOldestUpdate( of( MINOR ) ) )
? getText( "report.nextMinor" )
: equals( version, versions.getNewestUpdate( of( INCREMENTAL ) ) )
? getText( "report.latestIncremental" )
: equals( version, versions.getOldestUpdate( of( INCREMENTAL ) ) )
? getText( "report.nextIncremental" )
: equals( version, versions.getNewestUpdate( of( SUBINCREMENTAL ) ) )
? getText( "report.latestSubIncremental" )
: equals( version, versions.getOldestUpdate( of( SUBINCREMENTAL ) ) )
? getText( "report.nextVersion" )
: null;
}

/**
* Renders a table header containing elements denoted by the given keys
* @param keys variable argument list containing keys of the property file to retrieve the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected void renderTable( String titleKey, Map<Dependency, ArtifactVersions> c
}
else
{
renderDependencySummaryTable( contents, true, true, true );
renderSummaryTable( contents, true );
}
sink.section2_();
}
Expand Down Expand Up @@ -128,7 +128,7 @@ protected void renderDependencyDetail( Dependency artifact, ArtifactVersions det
sink.sectionTitle2();
sink.text( ArtifactUtils.versionlessKey( artifact.getGroupId(), artifact.getArtifactId() ) );
sink.sectionTitle2_();
renderDependencyDetailTable( artifact, details, true, true, true );
renderDependencyDetailTable( artifact, details, true );
sink.section2_();
}
}
Loading

0 comments on commit 267f3cc

Please sign in to comment.