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/04 20:50:59 UTC

[maven-reporting-impl] branch render-with-skins updated (f0f0715 -> 74c71e0)

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


 discard f0f0715  [MSHARED-1099] Render with a skin when report is run in standalone mode
     new 74c71e0  [MSHARED-1099] Render with a skin when report is run in standalone mode

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (f0f0715)
            \
             N -- N -- N   refs/heads/render-with-skins (74c71e0)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

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.


Summary of changes:
 .../java/org/apache/maven/reporting/AbstractMavenReport.java     | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)


[maven-reporting-impl] 01/01: [MSHARED-1099] Render with a skin when report is run in standalone mode

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 74c71e0cda61cb7045c956ec376d3208ec503c95
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Sat Jul 2 23:34:37 2022 +0200

    [MSHARED-1099] Render with a skin when report is run in standalone mode
    
    This closes #9
---
 pom.xml                                            |  10 ++
 .../maven/reporting/AbstractMavenReport.java       | 131 ++++++++++++++++++---
 2 files changed, 122 insertions(+), 19 deletions(-)

diff --git a/pom.xml b/pom.xml
index a4fc1ac..88a9b2f 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..0e83ed0 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,41 @@ public abstract class AbstractMavenReport
     @Parameter( property = "outputEncoding", defaultValue = "${project.reporting.outputEncoding}", readonly = true )
     private String outputEncoding;
 
+    /**
+     * The local repository.
+     */
+    @Parameter( defaultValue = "${localRepository}", readonly = true, required = true )
+    protected ArtifactRepository localRepository;
+
+    /**
+     * Remote repositories used for the project.
+     */
+    @Parameter( defaultValue = "${project.remoteArtifactRepositories}", readonly = true, required = true )
+    protected List<ArtifactRepository> remoteRepositories;
+
+    /**
+     * The skin to use when the report generation is invoked directly as a standalone Mojo.
+     * <p>
+     * <b>Default value is</b>:
+     * <pre>
+     * &lt;skin&gt;
+     *   &lt;groupId&gt;org.apache.maven.skins&lt;/groupId&gt;
+     *   &lt;artifactId&gt;maven-fluido-skin&lt;/artifactId&gt;
+     *   &lt;version&gt;1.11.1&lt;/version&gt;
+     * &lt;/skin&gt;
+     * </pre>
+     *
+     * @see Skin
+     */
+    @Parameter
+    protected Skin skin;
+
+    /**
+     * SiteTool.
+     */
+    @Component
+    protected SiteTool siteTool;
+
     /**
      * Doxia Site Renderer component.
      */
@@ -126,19 +169,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 +188,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,23 +206,50 @@ 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()
+    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() )
         {
             templateProperties.put( (String) entry.getKey(), entry.getValue() );
         }
-        return templateProperties;
+
+        SiteRenderingContext context;
+        try
+        {
+           Artifact skinArtifact =
+               siteTool.getSkinArtifactFromRepository( localRepository, remoteRepositories, decorationModel );
+
+           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( "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() );
+
+        return context;
     }
 
     /**
@@ -286,6 +358,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.
      */