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 2023/02/11 19:27:57 UTC

[maven-reporting-impl] branch MSHARED-1168 updated (cf11ede -> d810527)

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

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


 discard cf11ede  [MSHARED-1168] support markup output
     new d810527  [MSHARED-1168] Add support for 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   (cf11ede)
            \
             N -- N -- N   refs/heads/MSHARED-1168 (d810527)

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:
 .../org/apache/maven/reporting/AbstractMavenReport.java   | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)


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

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

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

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

    [MSHARED-1168] Add support for markup output
    
    This closes #13
---
 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       | 52 +++++++++++++++++++++-
 6 files changed, 152 insertions(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 3ccc898..ae575d9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -112,6 +112,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>
@@ -132,6 +133,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 c2acae8..597d0a5 100644
--- a/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java
+++ b/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java
@@ -48,6 +48,8 @@ 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.PlexusContainer;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 import org.codehaus.plexus.util.ReaderFactory;
 
 import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
@@ -150,6 +152,15 @@ public abstract class AbstractMavenReport extends AbstractMojo implements MavenM
     /** The current report output directory to use */
     private File reportOutputDirectory;
 
+    /**
+     * The report output format: null by default, to represent a site, but can be configured to a Doxia Sink id.
+     */
+    @Parameter(property = "output.format")
+    protected String outputFormat;
+
+    @Component
+    private PlexusContainer container;
+
     /**
      * This method is called when the report generation is invoked directly as a standalone Mojo.
      *
@@ -162,6 +173,43 @@ public abstract class AbstractMavenReport extends AbstractMojo implements MavenM
             return;
         }
 
+        if (outputFormat != null) {
+            reportToMarkup();
+        } else {
+            reportToSite();
+        }
+    }
+
+    private void reportToMarkup() throws MojoExecutionException {
+        getLog().info("Rendering to " + outputFormat + " markup");
+
+        if (!isExternalReport()) {
+            String filename = getOutputName() + '.' + outputFormat;
+            try {
+                sinkFactory = container.lookup(SinkFactory.class, outputFormat);
+                sink = sinkFactory.createSink(outputDirectory, filename);
+            } 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, filename), ioe);
+            }
+        }
+
+        try {
+            Locale locale = getLocale();
+            generate(sink, sinkFactory, locale);
+        } catch (MavenReportException e) {
+            throw new MojoExecutionException(
+                    "An error has occurred in " + getName(Locale.ENGLISH) + " report generation.", e);
+        } finally {
+            if (sink != null) {
+                sink.close();
+            }
+        }
+    }
+
+    private void reportToSite() throws MojoExecutionException {
         File outputDirectory = new File(getOutputDirectory());
 
         String filename = getOutputName() + ".html";
@@ -351,7 +399,9 @@ public abstract class AbstractMavenReport extends AbstractMojo implements MavenM
      * Actions when closing the report.
      */
     protected void closeReport() {
-        getSink().close();
+        if (getSink() != null) {
+            getSink().close();
+        }
     }
 
     /**