svn commit: r1811487 - in /maven/plugins/trunk/maven-pdf-plugin/src: it/pdf-with-reporting-section/pom.xml main/java/org/apache/maven/plugins/pdf/PdfMojo.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1811487 - in /maven/plugins/trunk/maven-pdf-plugin/src: it/pdf-with-reporting-section/pom.xml main/java/org/apache/maven/plugins/pdf/PdfMojo.java

hboutemy
Author: hboutemy
Date: Sun Oct  8 12:56:42 2017
New Revision: 1811487

URL: http://svn.apache.org/viewvc?rev=1811487&view=rev
Log:
[MPDF-48] fixed second cause of failing reports: report.generate() require proper classloader context

Modified:
    maven/plugins/trunk/maven-pdf-plugin/src/it/pdf-with-reporting-section/pom.xml
    maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java

Modified: maven/plugins/trunk/maven-pdf-plugin/src/it/pdf-with-reporting-section/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/it/pdf-with-reporting-section/pom.xml?rev=1811487&r1=1811486&r2=1811487&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/src/it/pdf-with-reporting-section/pom.xml (original)
+++ maven/plugins/trunk/maven-pdf-plugin/src/it/pdf-with-reporting-section/pom.xml Sun Oct  8 12:56:42 2017
@@ -94,7 +94,8 @@ under the License.
           <reportSet>
             <reports>
               <report>cim</report>
-              <report>dependencies</report>
+              <report>dependencies</report><!-- generated xdoc is not valid XML: missing <table> -->
+              <report>dependency-convergence</report><!-- generated xdoc is not valid XML: missing <table> -->
               <report>dependency-info</report>
               <report>dependency-management</report>
               <report>issue-tracking</report>

Modified: maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java?rev=1811487&r1=1811486&r2=1811487&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java (original)
+++ maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java Sun Oct  8 12:56:42 2017
@@ -1124,7 +1124,7 @@ public class PdfMojo
             org.codehaus.doxia.sink.Sink proxy = (org.codehaus.doxia.sink.Sink) Proxy.newProxyInstance(
                 org.codehaus.doxia.sink.Sink.class.getClassLoader(),
                 new Class[] { org.codehaus.doxia.sink.Sink.class }, new SinkDelegate( sink ) );
-            report.generate( proxy, locale );
+            renderReportToSink( reportExec, locale, proxy );
         }
         catch ( MavenReportException e )
         {
@@ -1138,10 +1138,53 @@ public class PdfMojo
             }
         }
 
+        if ( getLog().isDebugEnabled() )
+        {
+            getLog().debug( "Writing generated xdoc to " + generatedReport );
+        }
         writeGeneratedReport( sw.toString(), generatedReport );
+        // TODO check that generated xdoc is valid XML, since it seems there are issues...
+
         getGeneratedMavenReports( locale ).add( report );
     }
 
+    private void renderReportToSink( MavenReportExecution reportExec, Locale locale, org.codehaus.doxia.sink.Sink sink )
+        throws MavenReportException
+    {
+        ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
+        try
+        {
+            if ( reportExec.getClassLoader() != null )
+            {
+                Thread.currentThread().setContextClassLoader( reportExec.getClassLoader() );
+            }
+    
+            MavenReport report = reportExec.getMavenReport();
+    
+            /*if ( report instanceof MavenMultiPageReport )
+            {
+                // extended multi-page API
+                ( (MavenMultiPageReport) report ).generate( mainSink, multiPageSinkFactory, locale );
+            }
+            else if ( generateMultiPage( locale, multiPageSinkFactory, mainSink ) )
+            {
+                // extended multi-page API for Maven 2.2, only accessible by reflection API
+            }
+            else
+            {*/
+            // old single-page-only API
+            report.generate( sink, locale );
+            //}
+        }
+        finally
+        {
+            if ( reportExec.getClassLoader() != null )
+            {
+                Thread.currentThread().setContextClassLoader( originalClassLoader );
+            }
+        }
+    }
+
     private boolean skipFailingReport( MavenReport report )
     {
         for ( String className : failingReportClassName )