You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2013/04/06 19:32:18 UTC

svn commit: r1465279 - in /maven/shared/trunk/maven-reporting-exec/src: main/java/org/apache/maven/reporting/exec/DefaultMavenReportExecutor.java test/java/org/apache/maven/reporting/exec/TestDefaultMavenReportExecutor.java

Author: hboutemy
Date: Sat Apr  6 17:32:18 2013
New Revision: 1465279

URL: http://svn.apache.org/r1465279
Log:
[MSHARED-271] support multiple execution of a report because it can happen in multiple reportSets

Modified:
    maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/DefaultMavenReportExecutor.java
    maven/shared/trunk/maven-reporting-exec/src/test/java/org/apache/maven/reporting/exec/TestDefaultMavenReportExecutor.java

Modified: maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/DefaultMavenReportExecutor.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/DefaultMavenReportExecutor.java?rev=1465279&r1=1465278&r2=1465279&view=diff
==============================================================================
--- maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/DefaultMavenReportExecutor.java (original)
+++ maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/DefaultMavenReportExecutor.java Sat Apr  6 17:32:18 2013
@@ -23,10 +23,7 @@ import java.util.ArrayList;
 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 @@ public class DefaultMavenReportExecutor
         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 @@ public class DefaultMavenReportExecutor
             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 @@ public class DefaultMavenReportExecutor
             {
                 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 @@ public class DefaultMavenReportExecutor
                 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;
+        }
+    }
 }

Modified: maven/shared/trunk/maven-reporting-exec/src/test/java/org/apache/maven/reporting/exec/TestDefaultMavenReportExecutor.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-reporting-exec/src/test/java/org/apache/maven/reporting/exec/TestDefaultMavenReportExecutor.java?rev=1465279&r1=1465278&r2=1465279&view=diff
==============================================================================
--- maven/shared/trunk/maven-reporting-exec/src/test/java/org/apache/maven/reporting/exec/TestDefaultMavenReportExecutor.java (original)
+++ maven/shared/trunk/maven-reporting-exec/src/test/java/org/apache/maven/reporting/exec/TestDefaultMavenReportExecutor.java Sat Apr  6 17:32:18 2013
@@ -75,6 +75,39 @@ public class TestDefaultMavenReportExecu
     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 @@ public class TestDefaultMavenReportExecu
             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 @@ public class TestDefaultMavenReportExecu
 
             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
         {