You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2022/07/03 19:14:22 UTC
[maven-reporting-impl] branch render-with-skins updated: Rework and document skin
This is an automated email from the ASF dual-hosted git repository.
michaelo pushed a commit to branch render-with-skins
in repository https://gitbox.apache.org/repos/asf/maven-reporting-impl.git
The following commit(s) were added to refs/heads/render-with-skins by this push:
new 609f900 Rework and document skin
609f900 is described below
commit 609f900232181032447d6ad49a5fa486dbcd6f44
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Sun Jul 3 21:14:12 2022 +0200
Rework and document skin
---
.../maven/reporting/AbstractMavenReport.java | 112 ++++++++++++---------
1 file changed, 66 insertions(+), 46 deletions(-)
diff --git a/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java b/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java
index 9c69963..7f86702 100644
--- a/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java
+++ b/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java
@@ -110,8 +110,15 @@ public abstract class AbstractMavenReport
@Parameter( defaultValue = "${project.remoteArtifactRepositories}", readonly = true )
protected List<ArtifactRepository> remoteRepositories;
+ /**
+ * The skin to use when the report generation is invoked directly as a standalone Mojo.
+ * <p>
+ * The default skin is {@code org.apache.maven.skins:maven-fluido-skin:1.11.1}
+ *
+ * @see Skin
+ */
@Parameter
- Skin skin;
+ protected Skin skin;
/**
* SiteTool.
@@ -194,57 +201,49 @@ public abstract class AbstractMavenReport
private SiteRenderingContext createSiteRenderingContext( Locale locale )
throws MavenReportException, IOException
+ {
+ DecorationModel decorationModel = new DecorationModel();
+ decorationModel.setSkin( getSkin() );
+
+ Map<String, Object> templateProperties = new HashMap<>();
+ // We tell the skin that we are rendering in standalone mode
+ templateProperties.put( "standalone", Boolean.TRUE );
+ templateProperties.put( "project", getProject() );
+ templateProperties.put( "inputEncoding", getInputEncoding() );
+ templateProperties.put( "outputEncoding", getOutputEncoding() );
+
+ // Put any of the properties in directly into the Velocity context
+ for ( Map.Entry<Object, Object> entry : getProject().getProperties().entrySet() )
{
- DecorationModel decorationModel = new DecorationModel();
- if ( skin == null )
- {
- skin = new Skin();
- skin.setGroupId( "org.apache.maven.skins" );
- skin.setArtifactId( "maven-fluido-skin" );
- skin.setVersion( "1.11.1" );
- }
- decorationModel.setSkin( skin );
-
- Map<String, Object> templateProperties = new HashMap<>();
- // We tell the skin that we are rendering in standalone mode
- templateProperties.put( "standalone", Boolean.TRUE );
- templateProperties.put( "project", getProject() );
- templateProperties.put( "inputEncoding", getInputEncoding() );
- templateProperties.put( "outputEncoding", getOutputEncoding() );
-
- // Put any of the properties in directly into the Velocity context
- for ( Map.Entry<Object, Object> entry : getProject().getProperties().entrySet() )
- {
- templateProperties.put( (String) entry.getKey(), entry.getValue() );
- }
+ templateProperties.put( (String) entry.getKey(), entry.getValue() );
+ }
- SiteRenderingContext context;
- try
- {
- Artifact skinArtifact =
- siteTool.getSkinArtifactFromRepository( localRepository, remoteRepositories, decorationModel );
+ SiteRenderingContext context;
+ try
+ {
+ Artifact skinArtifact =
+ siteTool.getSkinArtifactFromRepository( localRepository, remoteRepositories, decorationModel );
- // TODO Do we need this?
- getLog().info( buffer().a( "Rendering content with " ).strong( skinArtifact.getId()
- + " skin" ).a( '.' ).toString() );
+ getLog().info( buffer().a( "Rendering content with " ).strong( skinArtifact.getId()
+ + " skin" ).a( '.' ).toString() );
- context = siteRenderer.createContextForSkin( skinArtifact, templateProperties, decorationModel,
- project.getName(), locale );
- }
- catch ( SiteToolException e )
- {
- throw new MavenReportException( "SiteToolException while preparing skin", e );
- }
- catch ( RendererException e )
- {
- throw new MavenReportException( "RendererException while preparing context for skin", e );
- }
+ context = siteRenderer.createContextForSkin( skinArtifact, templateProperties, decorationModel,
+ project.getName(), locale );
+ }
+ catch ( SiteToolException e )
+ {
+ throw new MavenReportException( "Failed to retrieve skin artifact", e );
+ }
+ catch ( RendererException e )
+ {
+ throw new MavenReportException( "Failed to create context for skin", e );
+ }
- // Generate static site
- context.setRootDirectory( project.getBasedir() );
+ // Generate static site
+ context.setRootDirectory( project.getBasedir() );
- return context;
- }
+ return context;
+ }
/**
* Generate a report.
@@ -352,6 +351,27 @@ public abstract class AbstractMavenReport
return ( outputEncoding == null ) ? WriterFactory.UTF_8 : outputEncoding;
}
+ /**
+ * Gets the skin
+ *
+ * @return the skin for this standalone report
+ */
+ protected Skin getSkin()
+ {
+ if ( skin == null )
+ {
+ Skin skin = new Skin();
+ skin.setGroupId( "org.apache.maven.skins" );
+ skin.setArtifactId( "maven-fluido-skin" );
+ skin.setVersion( "1.11.1" );
+ return skin;
+ }
+ else
+ {
+ return skin;
+ }
+ }
+
/**
* Actions when closing the report.
*/