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

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

commit 2f46537f655f1c7e91f6caff8101ee27b06a8554
Author: Michael Osipov <micha...@apache.org>
AuthorDate: Sat Jan 28 23:10:47 2023 +0100

    [MSHARED-1185] Introduce AbstractMavenReportRenderer#verbatimSource()
---
 .../reporting/its/custom/CustomReportRenderer.java    |  4 ++++
 src/it/use-as-direct-mojo/verify.groovy               | 11 +++++++++--
 src/it/use-as-site-report/verify.groovy               | 12 ++++++++++--
 .../maven/reporting/AbstractMavenReportRenderer.java  | 19 ++++++++++++++++++-
 4 files changed, 41 insertions(+), 5 deletions(-)

diff --git 
a/src/it/setup-reporting-plugin/src/main/java/org/apache/maven/reporting/its/custom/CustomReportRenderer.java
 
b/src/it/setup-reporting-plugin/src/main/java/org/apache/maven/reporting/its/custom/CustomReportRenderer.java
index 53536a8..ea75516 100644
--- 
a/src/it/setup-reporting-plugin/src/main/java/org/apache/maven/reporting/its/custom/CustomReportRenderer.java
+++ 
b/src/it/setup-reporting-plugin/src/main/java/org/apache/maven/reporting/its/custom/CustomReportRenderer.java
@@ -44,6 +44,10 @@ public class CustomReportRenderer
 
         text( "Custom Maven Report with Renderer content." );
 
+        verbatimText( "Custom verbatim text." );
+
+        verbatimSource( "var custom_code = true;" );
+
         endSection();
     }
 }
diff --git a/src/it/use-as-direct-mojo/verify.groovy 
b/src/it/use-as-direct-mojo/verify.groovy
index d1b9ee4..59438cd 100644
--- a/src/it/use-as-direct-mojo/verify.groovy
+++ b/src/it/use-as-direct-mojo/verify.groovy
@@ -25,10 +25,17 @@ assert f.text.contains( 'Custom Maven Report content.' );
 
 f = new File( site, 'custom-report-with-renderer.html' );
 assert f.exists();
-assert f.text.contains( 'Custom Maven Report with Renderer content.' );
+text = f.text.normalize();
+assert text.contains( 'Custom Maven Report with Renderer content.' );
+assert text.contains( '''\
+<div class="verbatim">
+<pre>Custom verbatim text.</pre></div>'''.normalize() );
+assert text.contains( '''\
+<div class="verbatim source">
+<pre>var custom_code = true;</pre></div>'''.normalize() );
 
 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
+return true;
diff --git a/src/it/use-as-site-report/verify.groovy 
b/src/it/use-as-site-report/verify.groovy
index d1b9ee4..105ed52 100644
--- a/src/it/use-as-site-report/verify.groovy
+++ b/src/it/use-as-site-report/verify.groovy
@@ -25,10 +25,18 @@ assert f.text.contains( 'Custom Maven Report content.' );
 
 f = new File( site, 'custom-report-with-renderer.html' );
 assert f.exists();
-assert f.text.contains( 'Custom Maven Report with Renderer content.' );
+text = f.text.normalize();
+assert text.contains( 'Custom Maven Report with Renderer content.' );
+// TODO align with use-as-direct-mojo as soon as Maven Site Plugin uses Doxia 
2.0.0-M5
+assert text.contains( '''\
+<div>
+<pre>Custom verbatim text.</pre></div>'''.normalize() );
+assert text.contains( '''\
+<div>
+<pre>var custom_code = true;</pre></div>'''.normalize() );
 
 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
+return true;
diff --git 
a/src/main/java/org/apache/maven/reporting/AbstractMavenReportRenderer.java 
b/src/main/java/org/apache/maven/reporting/AbstractMavenReportRenderer.java
index cd339d8..fd9aa8b 100644
--- a/src/main/java/org/apache/maven/reporting/AbstractMavenReportRenderer.java
+++ b/src/main/java/org/apache/maven/reporting/AbstractMavenReportRenderer.java
@@ -21,7 +21,7 @@ package org.apache.maven.reporting;
 
 import org.apache.maven.doxia.markup.Markup;
 import org.apache.maven.doxia.sink.Sink;
-
+import org.apache.maven.doxia.sink.impl.SinkEventAttributeSet;
 import org.apache.maven.shared.utils.StringUtils;
 
 import java.util.ArrayList;
@@ -407,6 +407,23 @@ public abstract class AbstractMavenReportRenderer
         }
     }
 
+    /**
+     * Convenience method to wrap source code as verbatim style in the current 
sink .
+     *
+     * @param source a source code, could be null.
+     * @see #text(String)
+     * @see Sink#verbatim(org.apache.maven.doxia.sink.SinkEventAttributes)
+     * @see Sink#verbatim_()
+     */
+    protected void verbatimSource( String source )
+    {
+        sink.verbatim( SinkEventAttributeSet.SOURCE );
+
+        text( source );
+
+        sink.verbatim_();
+    }
+
     /**
      * Convenience method to add a Javascript code in the current sink.
      *

Reply via email to