[MSHARED-271] support multiple execution of a report because it can happen in multiple reportSets

git-svn-id: https://svn.apache.org/repos/asf/maven/shared/trunk@1465279 13f79535-47bb-0310-9956-ffa450edef68
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 378392a..f923791 100644
--- a/src/main/java/org/apache/maven/reporting/exec/DefaultMavenReportExecutor.java
+++ b/src/main/java/org/apache/maven/reporting/exec/DefaultMavenReportExecutor.java
@@ -23,10 +23,7 @@
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.LinkedHashMap;
 import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
 import java.util.Set;
 
 import org.apache.maven.artifact.repository.RepositoryRequest;
@@ -184,7 +181,7 @@
         PluginDescriptor pluginDescriptor =
             mavenPluginManagerHelper.getPluginDescriptor( plugin, remoteRepositories, session );
 
-        Map<String, PlexusConfiguration> goalsWithConfiguration = new LinkedHashMap<String, PlexusConfiguration>();
+        List<GoalWithConf> goalsWithConfiguration = new ArrayList<GoalWithConf>();
 
         if ( reportPlugin.getReportSets().isEmpty() && reportPlugin.getReports().isEmpty() )
         {
@@ -192,7 +189,8 @@
             List<MojoDescriptor> mojoDescriptors = pluginDescriptor.getMojos();
             for ( MojoDescriptor mojoDescriptor : mojoDescriptors )
             {
-                goalsWithConfiguration.put( mojoDescriptor.getGoal(), mojoDescriptor.getConfiguration() );
+                goalsWithConfiguration.add( new GoalWithConf( mojoDescriptor.getGoal(),
+                                                              mojoDescriptor.getConfiguration() ) );
             }
         }
         else
@@ -201,29 +199,31 @@
             {
                 for ( String report : reportSet.getReports() )
                 {
-                    goalsWithConfiguration.put( report, reportSet.getConfiguration() );
+                    goalsWithConfiguration.add( new GoalWithConf( report, reportSet.getConfiguration() ) );
                 }
             }
 
             for ( String report : reportPlugin.getReports() )
             {
-                goalsWithConfiguration.put( report, reportPlugin.getConfiguration() );
+                goalsWithConfiguration.add( new GoalWithConf( report, reportPlugin.getConfiguration() ) );
             }
         }
 
         List<MavenReportExecution> reports = new ArrayList<MavenReportExecution>();
-        for ( Entry<String, PlexusConfiguration> entry : goalsWithConfiguration.entrySet() )
+        for ( GoalWithConf report : goalsWithConfiguration )
         {
-            MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( entry.getKey() );
+            MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( report.getGoal() );
             if ( mojoDescriptor == null )
             {
-                throw new MojoNotFoundException( entry.getKey(), pluginDescriptor );
+                throw new MojoNotFoundException( report.getGoal(), pluginDescriptor );
             }
 
-            MojoExecution mojoExecution = new MojoExecution( plugin, entry.getKey(), "report:" + entry.getKey() );
+            MojoExecution mojoExecution = new MojoExecution( plugin, report.getGoal(), "report:" + report.getGoal() );
 
-            mojoExecution.setConfiguration( mergeConfiguration( mojoDescriptor.getMojoConfiguration(), reportPlugin.getConfiguration(),
-                                                   entry.getValue(), mojoDescriptor.getParameterMap().keySet() ) );
+            mojoExecution.setConfiguration( mergeConfiguration( mojoDescriptor.getMojoConfiguration(),
+                                                                reportPlugin.getConfiguration(),
+                                                                report.getConfiguration(),
+                                                                mojoDescriptor.getParameterMap().keySet() ) );
 
             mojoExecution.setMojoDescriptor( mojoDescriptor );
 
@@ -578,5 +578,27 @@
                 buildPlugin.getDependencies().addAll( configuredPlugin.getDependencies() );
             }
         }
-    }   
+    }
+
+    private static class GoalWithConf
+    {
+        private final String goal;
+        private final PlexusConfiguration configuration;
+
+        public GoalWithConf( String goal, PlexusConfiguration configuration )
+        {
+            this.goal = goal;
+            this.configuration = configuration;
+        }
+
+        public String getGoal()
+        {
+            return goal;
+        }
+
+        public PlexusConfiguration getConfiguration()
+        {
+            return configuration;
+        }
+    }
 }
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 5f66e3d..a6c37bf 100644
--- a/src/test/java/org/apache/maven/reporting/exec/TestDefaultMavenReportExecutor.java
+++ b/src/test/java/org/apache/maven/reporting/exec/TestDefaultMavenReportExecutor.java
@@ -75,6 +75,39 @@
     public void testSimpleBuildReports()
         throws Exception
     {
+        ReportSet reportSet = new ReportSet();
+        reportSet.getReports().add( "test-javadoc" );
+        reportSet.getReports().add( "javadoc" );
+
+        List<MavenReportExecution> mavenReportExecutions = buildReports( reportSet );
+
+        assertNotNull( mavenReportExecutions );
+        assertEquals( 2, mavenReportExecutions.size() );
+        assertEquals( "testapidocs/index", mavenReportExecutions.get( 0 ).getMavenReport().getOutputName() );
+        assertEquals( "apidocs/index", mavenReportExecutions.get( 1 ).getMavenReport().getOutputName() );
+    }
+
+    public void testMultipleReportSets()
+        throws Exception
+    {
+        ReportSet reportSet = new ReportSet();
+        reportSet.getReports().add( "javadoc" );
+        ReportSet reportSet2 = new ReportSet();
+        reportSet2.getReports().add( "test-javadoc" );
+        reportSet2.getReports().add( "javadoc" );
+
+        List<MavenReportExecution> mavenReportExecutions = buildReports( reportSet, reportSet2 );
+
+        assertNotNull( mavenReportExecutions );
+        assertEquals( 3, mavenReportExecutions.size() );
+        assertEquals( "apidocs/index", mavenReportExecutions.get( 0 ).getMavenReport().getOutputName() );
+        assertEquals( "testapidocs/index", mavenReportExecutions.get( 1 ).getMavenReport().getOutputName() );
+        assertEquals( "apidocs/index", mavenReportExecutions.get( 2 ).getMavenReport().getOutputName() );
+    }
+
+    private List<MavenReportExecution> buildReports( ReportSet... javadocReportSets )
+        throws Exception
+    {
         ClassLoader orig = Thread.currentThread().getContextClassLoader();
         ClassRealm realm = getContainer().getContainerRealm();
 
@@ -99,10 +132,10 @@
             reportPlugin.setArtifactId( "maven-javadoc-plugin" );
             reportPlugin.setVersion( "2.7" );
 
-            ReportSet reportSet = new ReportSet();
-            reportSet.getReports().add( "test-javadoc" );
-            reportSet.getReports().add( "javadoc" );
-            reportPlugin.getReportSets().add( reportSet );
+            for ( ReportSet reportSet : javadocReportSets )
+            {
+                reportPlugin.getReportSets().add( reportSet );
+            }
 
             List<ReportPlugin> reportPlugins = Lists.newArrayList( reportPlugin );
 
@@ -110,13 +143,7 @@
 
             MavenReportExecutor mavenReportExecutor = lookup( MavenReportExecutor.class );
 
-            List<MavenReportExecution> mavenReportExecutions =
-                mavenReportExecutor.buildMavenReports( mavenReportExecutorRequest );
-
-            assertNotNull( mavenReportExecutions );
-            assertEquals( 2, mavenReportExecutions.size() );
-            assertEquals( "testapidocs/index", mavenReportExecutions.get( 0 ).getMavenReport().getOutputName() );
-            assertEquals( "apidocs/index", mavenReportExecutions.get( 1 ).getMavenReport().getOutputName() );
+            return mavenReportExecutor.buildMavenReports( mavenReportExecutorRequest );
         }
         finally
         {