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

hboutemy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-pdf-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new cbaa1f2  [MPDF-87] honour reporting.excludeDefaults like 
maven-site-plugin
cbaa1f2 is described below

commit cbaa1f295bf6fc097e8aa83007afb4648332b30b
Author: Hervé Boutemy <hbout...@apache.org>
AuthorDate: Fri Mar 2 21:58:55 2018 +0100

    [MPDF-87] honour reporting.excludeDefaults like maven-site-plugin
---
 .../java/org/apache/maven/plugins/pdf/PdfMojo.java | 89 ++++++++++++++++------
 1 file changed, 64 insertions(+), 25 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java 
b/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java
index 7c1371f..ac41cc1 100644
--- a/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java
+++ b/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java
@@ -66,6 +66,8 @@ import 
org.apache.maven.doxia.siterenderer.SiteRenderingContext;
 import org.apache.maven.doxia.tools.SiteTool;
 import org.apache.maven.doxia.tools.SiteToolException;
 import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.ReportPlugin;
+import org.apache.maven.model.Reporting;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
@@ -311,10 +313,10 @@ public class PdfMojo
     /**
      * Reports (Maven 3).
      *
-     * @since 1.4
+     * @since 1.5
      */
-    @Parameter( defaultValue = "${project.reporting.plugins}", readonly = true 
)
-    private org.apache.maven.model.ReportPlugin[] reportingPlugins;
+    @Parameter( defaultValue = "${project.reporting}", readonly = true )
+    private Reporting reporting;
 
     // ----------------------------------------------------------------------
     // Instance fields
@@ -628,7 +630,9 @@ public class PdfMojo
         for ( final Locale locale : getAvailableLocales() )
         {
             String excludes = getDefaultExcludesWithLocales( 
getAvailableLocales(), getDefaultLocale() );
-            List<String> siteFiles = FileUtils.getFileNames( siteDirectory, 
"**/*", excludes, false );
+            List<String> siteFiles =
+                siteDirectory.exists() ? FileUtils.getFileNames( 
siteDirectory, "**/*", excludes, false )
+                                : new ArrayList<String>();
             File siteDirectoryLocale = new File( siteDirectory, 
locale.getLanguage() );
             if ( !locale.getLanguage().equals( 
getDefaultLocale().getLanguage() ) && siteDirectoryLocale.exists() )
             {
@@ -1047,29 +1051,32 @@ public class PdfMojo
 
         File generatedReport = new File( outDir, report.getOutputName() + 
".xml" );
 
-        String excludes = getDefaultExcludesWithLocales( 
getAvailableLocales(), getDefaultLocale() );
-        List<String> files =
-            FileUtils.getFileNames( siteDirectory, "*/" + 
report.getOutputName() + ".*", excludes, false );
-        if ( !locale.getLanguage().equals( defaultLocale.getLanguage() ) )
-        {
-            files =
-                FileUtils.getFileNames( new File( siteDirectory, 
locale.getLanguage() ), "*/"
-                    + report.getOutputName() + ".*", excludes, false );
-        }
-
-        if ( files.size() != 0 )
+        if ( siteDirectory.exists() )
         {
-            String displayLanguage = locale.getDisplayLanguage( Locale.ENGLISH 
);
-
-            if ( getLog().isInfoEnabled() )
+            String excludes = getDefaultExcludesWithLocales( 
getAvailableLocales(), getDefaultLocale() );
+            List<String> files =
+                FileUtils.getFileNames( siteDirectory, "*/" + 
report.getOutputName() + ".*", excludes, false );
+            if ( !locale.getLanguage().equals( defaultLocale.getLanguage() ) )
             {
-                getLog().info(
-                               "Skipped \"" + report.getName( locale ) + "\" 
report, file \""
-                                   + report.getOutputName() + "\" already 
exists for the " + displayLanguage
-                                   + " version." );
+                files =
+                    FileUtils.getFileNames( new File( siteDirectory, 
locale.getLanguage() ), "*/"
+                        + report.getOutputName() + ".*", excludes, false );
+            }
+    
+            if ( files.size() != 0 )
+            {
+                String displayLanguage = locale.getDisplayLanguage( 
Locale.ENGLISH );
+    
+                if ( getLog().isInfoEnabled() )
+                {
+                    getLog().info(
+                                   "Skipped \"" + report.getName( locale ) + 
"\" report, file \""
+                                       + report.getOutputName() + "\" already 
exists for the " + displayLanguage
+                                       + " version." );
+                }
+    
+                return;
             }
-
-            return;
         }
 
         if ( getLog().isInfoEnabled() )
@@ -1404,7 +1411,7 @@ public class PdfMojo
         mavenReportExecutorRequest.setLocalRepository( localRepository );
         mavenReportExecutorRequest.setMavenSession( session );
         mavenReportExecutorRequest.setProject( project );
-        mavenReportExecutorRequest.setReportPlugins( reportingPlugins );
+        mavenReportExecutorRequest.setReportPlugins( getReportingPlugins() );
 
         MavenReportExecutor mavenReportExecutor;
         try
@@ -1419,6 +1426,38 @@ public class PdfMojo
     }
 
     /**
+     * Get the report plugins from reporting section, adding if necessary 
(i.e. not excluded)
+     * default reports (i.e. maven-project-info-reports)
+     *
+     * @return the effective list of reports
+     * @since 1.5
+     */
+    private ReportPlugin[] getReportingPlugins()
+    {
+        List<ReportPlugin> reportingPlugins = reporting.getPlugins();
+
+        // MSITE-806: add default report plugin like done in 
maven-model-builder DefaultReportingConverter
+        boolean hasMavenProjectInfoReportsPlugin = false;
+        for ( ReportPlugin plugin : reportingPlugins )
+        {
+            if ( "org.apache.maven.plugins".equals( plugin.getGroupId() )
+                && "maven-project-info-reports-plugin".equals( 
plugin.getArtifactId() ) )
+            {
+                hasMavenProjectInfoReportsPlugin = true;
+                break;
+            }
+        }
+
+        if ( !reporting.isExcludeDefaults() && 
!hasMavenProjectInfoReportsPlugin )
+        {
+            ReportPlugin mpir = new ReportPlugin();
+            mpir.setArtifactId( "maven-project-info-reports-plugin" );
+            reportingPlugins.add( mpir );
+        }
+        return reportingPlugins.toArray( new 
ReportPlugin[reportingPlugins.size()] );
+    }
+
+    /**
      * Check the current Maven version to see if it's Maven 3.0 or newer.
      */
     protected static boolean isMaven3OrMore()

-- 
To stop receiving notification emails like this one, please contact
hbout...@apache.org.

Reply via email to