You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2023/01/31 00:05:49 UTC

[maven-reporting-impl] branch MSHARED-1168 updated (e6bf452 -> 6cfaa9b)

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

hboutemy pushed a change to branch MSHARED-1168
in repository https://gitbox.apache.org/repos/asf/maven-reporting-impl.git


    omit e6bf452  [MSHARED-1168] support markup output
     add f6a1018  [MSHARED-1160] Upgrade to Doxia/Doxia Sitetools to 2.0.0-M4
     add b647c49  [maven-release-plugin] prepare release maven-reporting-impl-4.0.0-M3
     add 6a14f44  [maven-release-plugin] prepare for next development iteration
     add e720aa1  [MSHARED-1174] Don't wrap elements in anchors
     new 6cfaa9b  [MSHARED-1168] support markup output

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   (e6bf452)
            \
             N -- N -- N   refs/heads/MSHARED-1168 (6cfaa9b)

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:
 pom.xml                                            |  8 +++----
 .../maven/reporting/AbstractMavenReport.java       | 28 +++++++++++++++++++---
 .../reporting/AbstractMavenReportRenderer.java     |  4 ++--
 3 files changed, 31 insertions(+), 9 deletions(-)


[maven-reporting-impl] 01/01: [MSHARED-1168] support markup output

Posted by hb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a commit to branch MSHARED-1168
in repository https://gitbox.apache.org/repos/asf/maven-reporting-impl.git

commit 6cfaa9bd7779fc3370bf56d10c3f9abebb54f9fe
Author: Hervé Boutemy <hb...@apache.org>
AuthorDate: Sun Nov 27 19:41:43 2022 +0100

    [MSHARED-1168] support markup output
---
 pom.xml                                            | 12 +++
 .../maven/reporting/its/custom/ExternalReport.java |  2 +
 .../use-as-direct-mojo-markup/invoker.properties   | 20 +++++
 src/it/use-as-direct-mojo-markup/pom.xml           | 33 +++++++++
 src/it/use-as-direct-mojo-markup/verify.groovy     | 34 +++++++++
 .../maven/reporting/AbstractMavenReport.java       | 86 +++++++++++++++++++++-
 6 files changed, 185 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index 325060d..1cbbbce 100644
--- a/pom.xml
+++ b/pom.xml
@@ -111,6 +111,7 @@
       <artifactId>doxia-sink-api</artifactId>
       <version>${doxiaVersion}</version>
     </dependency>
+    <!-- Doxia site rendering -->
     <dependency>
       <groupId>org.apache.maven.doxia</groupId>
       <artifactId>doxia-decoration-model</artifactId>
@@ -131,6 +132,17 @@
       <artifactId>doxia-site-renderer</artifactId>
       <version>${doxiaSitetoolsVersion}</version>
     </dependency>
+    <!-- Doxia markup rendering -->
+    <dependency>
+      <groupId>org.apache.maven.doxia</groupId>
+      <artifactId>doxia-module-apt</artifactId>
+      <version>${doxiaVersion}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.doxia</groupId>
+      <artifactId>doxia-module-xdoc</artifactId>
+      <version>${doxiaVersion}</version>
+    </dependency>
 
     <!-- misc -->
     <dependency>
diff --git a/src/it/setup-reporting-plugin/src/main/java/org/apache/maven/reporting/its/custom/ExternalReport.java b/src/it/setup-reporting-plugin/src/main/java/org/apache/maven/reporting/its/custom/ExternalReport.java
index 5ded0e7..2fbb6a9 100644
--- a/src/it/setup-reporting-plugin/src/main/java/org/apache/maven/reporting/its/custom/ExternalReport.java
+++ b/src/it/setup-reporting-plugin/src/main/java/org/apache/maven/reporting/its/custom/ExternalReport.java
@@ -85,6 +85,8 @@ public class ExternalReport
     private void executeExternalTool( String destination )
         throws IOException
     {
+        getLog().info( "Running external tool to " + destination );
+
         // demo implementation, to be replaced with effective tool
         File dest = new File( destination );
 
diff --git a/src/it/use-as-direct-mojo-markup/invoker.properties b/src/it/use-as-direct-mojo-markup/invoker.properties
new file mode 100644
index 0000000..3381aa4
--- /dev/null
+++ b/src/it/use-as-direct-mojo-markup/invoker.properties
@@ -0,0 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+invoker.goals.1 = org.apache.maven.reporting.its:custom-reporting-plugin:1.0-SNAPSHOT:custom -Doutput.format=xdoc
+invoker.goals.2 = org.apache.maven.reporting.its:custom-reporting-plugin:1.0-SNAPSHOT:custom-renderer -Doutput.format=apt
+invoker.goals.3 = org.apache.maven.reporting.its:custom-reporting-plugin:1.0-SNAPSHOT:external -Doutput.format=anything
diff --git a/src/it/use-as-direct-mojo-markup/pom.xml b/src/it/use-as-direct-mojo-markup/pom.xml
new file mode 100644
index 0000000..09dab3a
--- /dev/null
+++ b/src/it/use-as-direct-mojo-markup/pom.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.reporting.its</groupId>
+  <artifactId>use-as-direct-mojo</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <name>Use report as direct mojo</name>
+  <description>Use report directly as mojo: "mvn my-plugin:my-report"</description>
+</project>
diff --git a/src/it/use-as-direct-mojo-markup/verify.groovy b/src/it/use-as-direct-mojo-markup/verify.groovy
new file mode 100644
index 0000000..5773ff2
--- /dev/null
+++ b/src/it/use-as-direct-mojo-markup/verify.groovy
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+File site = new File( basedir, 'target/site/' )
+
+File f = new File( site, 'custom-report.xdoc' );
+assert f.exists();
+assert f.text.contains( 'Custom Maven Report content.' );
+
+f = new File( site, 'custom-report-with-renderer.apt' );
+assert f.exists();
+assert f.text.contains( 'Custom Maven Report with Renderer content.' );
+
+f = new File( site, 'external/report.html' );
+assert f.exists();
+assert f.text.contains( '<h1>External Report</h1>' );
+
+return true;
\ No newline at end of file
diff --git a/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java b/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java
index d3541ae..167e1ce 100644
--- a/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java
+++ b/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java
@@ -38,6 +38,12 @@ import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.shared.utils.WriterFactory;
+import org.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.codehaus.plexus.context.Context;
+import org.codehaus.plexus.context.ContextException;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
 import org.codehaus.plexus.util.ReaderFactory;
 
 import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
@@ -70,7 +76,7 @@ import java.util.Map;
  */
 public abstract class AbstractMavenReport
     extends AbstractMojo
-    implements MavenMultiPageReport
+    implements MavenMultiPageReport, Contextualizable
 {
     /**
      * The output directory for the report. Note that this parameter is only evaluated if the goal is run directly from
@@ -159,6 +165,14 @@ public abstract class AbstractMavenReport
     /** The current report output directory to use */
     private File reportOutputDirectory;
 
+    /**
+     * The output format: null by default, to represent a site, but can be configured to a Doxia sink.
+     */
+    @Parameter( property = "output.format" )
+    protected String outputFormat;
+
+    private PlexusContainer container;
+
     /**
      * This method is called when the report generation is invoked directly as a standalone Mojo.
      *
@@ -174,6 +188,62 @@ public abstract class AbstractMavenReport
             return;
         }
 
+        if ( outputFormat != null )
+        {
+            reportToMarkup();
+        }
+        else
+        {
+            reportToSite();
+        }
+    }
+
+    private void reportToMarkup()
+        throws MojoExecutionException
+    {
+        getLog().info( "Rendering to " + outputFormat + " markup" );
+
+        if ( !isExternalReport() )
+        {
+            try
+            {
+                sinkFactory = container.lookup( SinkFactory.class, outputFormat );
+                sink = sinkFactory.createSink( outputDirectory, getOutputName() + '.' + outputFormat );
+            }
+            catch ( ComponentLookupException cle )
+            {
+                throw new MojoExecutionException(
+                    "Cannot find SinkFactory for Doxia output format: " + outputFormat, cle );
+            }
+            catch ( IOException ioe )
+            {
+                throw new MojoExecutionException( "Cannot create sink to "
+                    + new File( outputDirectory, getOutputName() + '.' + outputFormat ), ioe );
+            }
+        }
+
+        try
+        {
+            Locale locale = Locale.getDefault();
+            generate( sink, sinkFactory, locale );
+        }
+        catch ( MavenReportException mre )
+        {
+            throw new MojoExecutionException(
+                    "An error has occurred in " + getName( Locale.ENGLISH ) + " report generation.", mre );
+        }
+        finally
+        {
+            if ( sink != null )
+            {
+                sink.close();
+            }
+        }
+    }
+
+    private void reportToSite()
+        throws MojoExecutionException
+    {
         File outputDirectory = new File( getOutputDirectory() );
 
         String filename = getOutputName() + ".html";
@@ -404,7 +474,10 @@ public abstract class AbstractMavenReport
      */
     protected void closeReport()
     {
-        getSink().close();
+        if ( getSink() != null )
+        {
+            getSink().close();
+        }
     }
 
     /**
@@ -447,4 +520,13 @@ public abstract class AbstractMavenReport
      */
     protected abstract void executeReport( Locale locale )
         throws MavenReportException;
+
+    /**
+     * {@inheritDoc}
+     */
+    public void contextualize( Context context )
+        throws ContextException
+    {
+        container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
+    }
 }