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/02 21:36:29 UTC

[maven-reporting-impl] branch render-with-skins created (now 907b053)

This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a change to branch render-with-skins
in repository https://gitbox.apache.org/repos/asf/maven-reporting-impl.git


      at 907b053  Render with Skins

This branch includes the following new commits:

     new 907b053  Render with Skins

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-reporting-impl] 01/01: Render with Skins

Posted by mi...@apache.org.
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

commit 907b0532826a0e247a11c0e95d110cde05f58d26
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Sat Jul 2 23:34:37 2022 +0200

    Render with Skins
---
 pom.xml                                            |  10 ++
 .../maven/reporting/AbstractMavenReport.java       | 116 ++++++++++++++++-----
 2 files changed, 98 insertions(+), 28 deletions(-)

diff --git a/pom.xml b/pom.xml
index 0bdb47d..eabb46b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -89,6 +89,11 @@
       <artifactId>maven-core</artifactId>
       <version>${mavenVersion}</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact</artifactId>
+      <version>${mavenVersion}</version>
+    </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-plugin-api</artifactId>
@@ -116,6 +121,11 @@
       <artifactId>doxia-core</artifactId>
       <version>${doxiaVersion}</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven.doxia</groupId>
+      <artifactId>doxia-integration-tools</artifactId>
+      <version>${doxiaSitetoolsVersion}</version>
+    </dependency>
     <dependency>
       <groupId>org.apache.maven.doxia</groupId>
       <artifactId>doxia-site-renderer</artifactId>
diff --git a/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java b/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java
index 2ef82d9..2451d74 100644
--- a/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java
+++ b/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java
@@ -19,14 +19,19 @@ package org.apache.maven.reporting;
  * under the License.
  */
 
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.doxia.sink.Sink;
 import org.apache.maven.doxia.sink.SinkFactory;
 import org.apache.maven.doxia.site.decoration.DecorationModel;
+import org.apache.maven.doxia.site.decoration.Skin;
 import org.apache.maven.doxia.siterenderer.Renderer;
 import org.apache.maven.doxia.siterenderer.RendererException;
 import org.apache.maven.doxia.siterenderer.RenderingContext;
 import org.apache.maven.doxia.siterenderer.SiteRenderingContext;
 import org.apache.maven.doxia.siterenderer.sink.SiteRendererSink;
+import org.apache.maven.doxia.tools.SiteTool;
+import org.apache.maven.doxia.tools.SiteToolException;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugins.annotations.Component;
@@ -35,12 +40,15 @@ import org.apache.maven.project.MavenProject;
 import org.apache.maven.shared.utils.WriterFactory;
 import org.codehaus.plexus.util.ReaderFactory;
 
+import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
+
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.io.Writer;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 
@@ -90,6 +98,24 @@ public abstract class AbstractMavenReport
     @Parameter( property = "outputEncoding", defaultValue = "${project.reporting.outputEncoding}", readonly = true )
     private String outputEncoding;
 
+    /**
+     * The local repository.
+     */
+    @Parameter( defaultValue = "${localRepository}", readonly = true )
+    protected ArtifactRepository localRepository;
+
+    /**
+     * Remote repositories used for the project.
+     */
+    @Parameter( defaultValue = "${project.remoteArtifactRepositories}", readonly = true )
+    protected List<ArtifactRepository> remoteRepositories;
+
+    /**
+     * SiteTool.
+     */
+    @Component
+    protected SiteTool siteTool;
+
     /**
      * Doxia Site Renderer component.
      */
@@ -126,19 +152,17 @@ public abstract class AbstractMavenReport
 
         Locale locale = Locale.getDefault();
 
-        SiteRenderingContext siteContext = new SiteRenderingContext();
-        siteContext.setDecoration( new DecorationModel() );
-        siteContext.setTemplateName( "org/apache/maven/doxia/siterenderer/resources/default-site.vm" );
-        siteContext.setLocale( locale );
-        siteContext.setTemplateProperties( getTemplateProperties() );
+        try
+        {
+            SiteRenderingContext siteContext = createSiteRenderingContext( locale );
 
-        // TODO Replace null with real value
-        RenderingContext context = new RenderingContext( outputDirectory, filename, null );
+            // copy resources
+            siteRenderer.copyResources( siteContext, outputDirectory );
 
-        SiteRendererSink sink = new SiteRendererSink( context );
+            // TODO Replace null with real value
+            RenderingContext docRenderingContext = new RenderingContext( outputDirectory, filename, null );
 
-        try
-        {
+            SiteRendererSink sink = new SiteRendererSink( docRenderingContext );
 
             generate( sink, null, locale );
 
@@ -147,12 +171,16 @@ public abstract class AbstractMavenReport
                 outputDirectory.mkdirs();
 
                 try ( Writer writer =
-                    new OutputStreamWriter( new FileOutputStream( new File( outputDirectory, filename ) ),
-                                            getOutputEncoding() ) )
+                      new OutputStreamWriter( new FileOutputStream( new File( outputDirectory, filename ) ),
+                                              getOutputEncoding() ) )
                 {
+                    // render report
                     getSiteRenderer().mergeDocumentIntoSite( writer, sink, siteContext );
                 }
             }
+
+            // copy generated resources also
+            siteRenderer.copyResources( siteContext, outputDirectory );
         }
         catch ( RendererException | IOException | MavenReportException e )
         {
@@ -161,24 +189,56 @@ public abstract class AbstractMavenReport
         }
     }
 
-    /**
-     * create template properties like done in maven-site-plugin's
-     * <code>AbstractSiteRenderingMojo.createSiteRenderingContext( Locale )</code>
-     * @return properties
-     */
-    private Map<String, Object> getTemplateProperties()
-    {
-        Map<String, Object> templateProperties = new HashMap<>();
-        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() )
+    private SiteRenderingContext createSiteRenderingContext( Locale locale )
+        throws MavenReportException, IOException
         {
-            templateProperties.put( (String) entry.getKey(), entry.getValue() );
+            DecorationModel decorationModel = new DecorationModel();
+            Skin 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() );
+            }
+
+            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() );
+
+                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 );
+            }
+
+            // Generate static site
+            context.setRootDirectory( project.getBasedir() );
+
+            return context;
         }
-        return templateProperties;
-    }
 
     /**
      * Generate a report.