[MSHARED-616] Dependencies inside pluginManagement are not taken into account in reporting

Following the fix introduced in MSITE-507, we also need to take into account the case where the reporting plugin is only present in the build/pluginManagement section. Otherwise, its dependencies are ignored.

git-svn-id: https://svn.apache.org/repos/asf/maven/shared/trunk@1782394 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/it/pluginManagement_dependencies/invoker.properties b/src/it/pluginManagement_dependencies/invoker.properties
new file mode 100644
index 0000000..8ad46b0
--- /dev/null
+++ b/src/it/pluginManagement_dependencies/invoker.properties
@@ -0,0 +1,18 @@
+# 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=clean site
\ No newline at end of file
diff --git a/src/it/pluginManagement_dependencies/pom.xml b/src/it/pluginManagement_dependencies/pom.xml
new file mode 100644
index 0000000..12d6735
--- /dev/null
+++ b/src/it/pluginManagement_dependencies/pom.xml
@@ -0,0 +1,72 @@
+<?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.shared.maren-reporting-exec.its</groupId>
+  <artifactId>pluginmanagement-dependencies</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <description>Tests that dependencies of build.pluginManagement are taken into account during reporting</description>
+  <url>https://issues.apache.org/jira/browse/MSHARED-616</url>
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <artifactId>maven-checkstyle-plugin</artifactId>
+          <version>2.17</version>
+          <dependencies>
+            <dependency>
+              <groupId>com.puppycrawl.tools</groupId>
+              <artifactId>checkstyle</artifactId>
+              <version>7.5</version>
+            </dependency>
+          </dependencies>
+        </plugin>
+        <plugin>
+          <artifactId>maven-site-plugin</artifactId>
+          <version>3.3</version>
+          <dependencies>
+            <dependency>
+              <groupId>@project.groupId@</groupId>
+              <artifactId>@project.artifactId@</artifactId>
+              <version>@project.version@</version>
+            </dependency>
+          </dependencies>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+  <reporting>
+    <plugins> 
+      <plugin>
+        <artifactId>maven-checkstyle-plugin</artifactId>
+        <reportSets>
+          <reportSet>
+            <reports>
+              <report>checkstyle</report>
+            </reports>
+          </reportSet>
+        </reportSets>
+      </plugin>
+    </plugins>
+  </reporting>
+</project>
diff --git a/src/it/pluginManagement_dependencies/verify.groovy b/src/it/pluginManagement_dependencies/verify.groovy
new file mode 100644
index 0000000..6084a7d
--- /dev/null
+++ b/src/it/pluginManagement_dependencies/verify.groovy
@@ -0,0 +1,26 @@
+
+/*
+ * 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.
+ */
+
+content = new File( basedir, 'build.log' ).text;
+
+assert !content.contains( 'com.puppycrawl.tools:checkstyle:jar:6.11.2' );
+assert content.contains( 'com.puppycrawl.tools:checkstyle:jar:7.5' );
+
+return true;
\ No newline at end of file
diff --git a/src/main/java/org/apache/maven/reporting/exec/DefaultMavenReportExecutor.java b/src/main/java/org/apache/maven/reporting/exec/DefaultMavenReportExecutor.java
index 1fa44f6..7daad6d 100644
--- a/src/main/java/org/apache/maven/reporting/exec/DefaultMavenReportExecutor.java
+++ b/src/main/java/org/apache/maven/reporting/exec/DefaultMavenReportExecutor.java
@@ -27,6 +27,7 @@
 import java.util.Set;
 
 import org.apache.maven.lifecycle.LifecycleExecutor;
+import org.apache.maven.model.Build;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.plugin.MavenPluginManager;
 import org.apache.maven.plugin.Mojo;
@@ -648,6 +649,7 @@
      * <li>dependencies</li>
      * </ul>
      * </p>
+     * The plugin could only be present in the dependency management section.
      * 
      * @param mavenReportExecutorRequest
      * @param buildPlugin
@@ -656,7 +658,12 @@
     private void mergePluginToReportPlugin( MavenReportExecutorRequest mavenReportExecutorRequest, Plugin buildPlugin,
                                             ReportPlugin reportPlugin )
     {
-        Plugin configuredPlugin = find( reportPlugin, mavenReportExecutorRequest.getProject().getBuild().getPlugins() );
+        Build build = mavenReportExecutorRequest.getProject().getBuild();
+        Plugin configuredPlugin = find( reportPlugin, build.getPlugins() );
+        if ( configuredPlugin == null && build.getPluginManagement() != null )
+        {
+            configuredPlugin = find( reportPlugin, build.getPluginManagement().getPlugins() );
+        }
         if ( configuredPlugin != null )
         {
             if ( !configuredPlugin.getDependencies().isEmpty() )
diff --git a/src/test/java/org/apache/maven/reporting/exec/TestDefaultMavenReportExecutor.java b/src/test/java/org/apache/maven/reporting/exec/TestDefaultMavenReportExecutor.java
index a6c37bf..8def289 100644
--- a/src/test/java/org/apache/maven/reporting/exec/TestDefaultMavenReportExecutor.java
+++ b/src/test/java/org/apache/maven/reporting/exec/TestDefaultMavenReportExecutor.java
@@ -32,6 +32,9 @@
 import org.apache.maven.execution.MavenExecutionResult;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.model.Build;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.PluginManagement;
 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.repository.RepositorySystem;
@@ -79,7 +82,8 @@
         reportSet.getReports().add( "test-javadoc" );
         reportSet.getReports().add( "javadoc" );
 
-        List<MavenReportExecution> mavenReportExecutions = buildReports( reportSet );
+        MavenProject mavenProject = getMavenProject();
+        List<MavenReportExecution> mavenReportExecutions = buildReports( mavenProject, reportSet );
 
         assertNotNull( mavenReportExecutions );
         assertEquals( 2, mavenReportExecutions.size() );
@@ -96,7 +100,8 @@
         reportSet2.getReports().add( "test-javadoc" );
         reportSet2.getReports().add( "javadoc" );
 
-        List<MavenReportExecution> mavenReportExecutions = buildReports( reportSet, reportSet2 );
+        MavenProject mavenProject = getMavenProject();
+        List<MavenReportExecution> mavenReportExecutions = buildReports( mavenProject, reportSet, reportSet2 );
 
         assertNotNull( mavenReportExecutions );
         assertEquals( 3, mavenReportExecutions.size() );
@@ -105,7 +110,35 @@
         assertEquals( "apidocs/index", mavenReportExecutions.get( 2 ).getMavenReport().getOutputName() );
     }
 
-    private List<MavenReportExecution> buildReports( ReportSet... javadocReportSets )
+    public void testReportingPluginWithDependenciesInPluginManagement()
+        throws Exception
+    {
+        ReportSet reportSet = new ReportSet();
+        reportSet.getReports().add( "javadoc" );
+
+        MavenProject mavenProject = getMavenProject();
+        Plugin plugin = new Plugin();
+        plugin.setGroupId( "org.apache.maven.plugins" );
+        plugin.setArtifactId( "maven-javadoc-plugin" );
+        plugin.setVersion( "2.7" );
+        Dependency dependency = new Dependency();
+        dependency.setGroupId( "commons-lang" );
+        dependency.setArtifactId( "commons-lang" );
+        dependency.setVersion( "2.6" );
+        plugin.getDependencies().add( dependency );
+        mavenProject.getBuild().setPluginManagement( new PluginManagement() );
+        mavenProject.getBuild().getPluginManagement().addPlugin( plugin );
+        List<MavenReportExecution> mavenReportExecutions = buildReports( mavenProject, reportSet );
+
+        assertNotNull( mavenReportExecutions );
+        assertEquals( 1, mavenReportExecutions.size() );
+        List<Dependency> dependencies = mavenReportExecutions.get( 0 ).getPlugin().getDependencies();
+        assertEquals( 1, dependencies.size() );
+        assertEquals( "commons-lang", dependencies.get( 0 ).getGroupId() );
+        assertEquals( "2.6", dependencies.get( 0 ).getVersion() );
+    }
+
+    private List<MavenReportExecution> buildReports( MavenProject mavenProject, ReportSet... javadocReportSets )
         throws Exception
     {
         ClassLoader orig = Thread.currentThread().getContextClassLoader();
@@ -118,8 +151,6 @@
 
             mavenReportExecutorRequest.setLocalRepository( getLocalArtifactRepository() );
 
-            MavenProject mavenProject = getMavenProject();
-
             mavenReportExecutorRequest.setProject( mavenProject );
 
             MavenSession mavenSession = getMavenSession( getLocalArtifactRepository(), mavenProject );