Group sets of sourcepaths per project, in prepare of usage of module-source-path.

git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1816292 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
index df24821..b6ecbe0 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -1977,15 +1977,18 @@
             throw new MavenReportException( "Failed to generate javadoc options file: " + e.getMessage(), e );

         }

 

-        Collection<String> sourcePaths = getSourcePaths();

-        List<String> files = getFiles( sourcePaths );

+        Collection<Collection<String>> sourcePaths = getSourcePaths();

+        

+        Collection<String> collectedSourcePaths = collect( sourcePaths );

+        

+        List<String> files = getFiles( collectedSourcePaths );

         if ( !canGenerateReport( files ) )

         {

             return;

         }

 

-        List<String> packageNames = getPackageNames( sourcePaths, files );

-        List<String> filesWithUnnamedPackages = getFilesWithUnnamedPackages( sourcePaths, files );

+        List<String> packageNames = getPackageNames( collectedSourcePaths, files );

+        List<String> filesWithUnnamedPackages = getFilesWithUnnamedPackages( collectedSourcePaths, files );

 

         // ----------------------------------------------------------------------

         // Find the javadoc executable and version

@@ -2177,6 +2180,16 @@
         }

     }

 

+    protected final Collection<String> collect( Collection<Collection<String>> sourcePaths )

+    {

+        Collection<String> collectedSourcePaths = new LinkedHashSet<>();

+        for ( Collection<String> sp : sourcePaths )

+        {

+            collectedSourcePaths.addAll( sp );

+        }

+        return collectedSourcePaths;

+    }

+

     /**

      * Method to get the files on the specified source paths

      *

@@ -2211,14 +2224,16 @@
      * @throws MavenReportException {@link MavenReportException}

      * @see JavadocUtil#pruneDirs(MavenProject, List)

      */

-    protected Collection<String> getSourcePaths()

+    protected Collection<Collection<String>> getSourcePaths()

         throws MavenReportException

     {

-        Collection<String> sourcePaths;

+        Collection<Collection<String>> allSourcePaths = new ArrayList<>();

 

         if ( StringUtils.isEmpty( sourcepath ) )

         {

-            sourcePaths = new ArrayList<>( JavadocUtil.pruneDirs( project, getProjectSourceRoots( project ) ) );

+            

+            Collection<String> sourcePaths =

+                new ArrayList<>( JavadocUtil.pruneDirs( project, getProjectSourceRoots( project ) ) );

 

             if ( project.getExecutionProject() != null )

             {

@@ -2240,11 +2255,11 @@
                     sourcePaths.addAll( l );

                 }

             }

-

             if ( includeDependencySources )

             {

                 sourcePaths.addAll( getDependencySourcePaths() );

             }

+            allSourcePaths.add( sourcePaths );

 

             if ( isAggregator() && project.isExecutionRoot() )

             {

@@ -2252,6 +2267,8 @@
                 {

                     if ( subProject != project )

                     {

+                        Collection<String> additionalSourcePaths = new ArrayList<>();

+

                         List<String> sourceRoots = getProjectSourceRoots( subProject );

 

                         if ( subProject.getExecutionProject() != null )

@@ -2262,7 +2279,7 @@
                         ArtifactHandler artifactHandler = subProject.getArtifact().getArtifactHandler();

                         if ( "java".equals( artifactHandler.getLanguage() ) )

                         {

-                            sourcePaths.addAll( JavadocUtil.pruneDirs( subProject, sourceRoots ) );

+                            additionalSourcePaths.addAll( JavadocUtil.pruneDirs( subProject, sourceRoots ) );

                         }

 

                         if ( getJavadocDirectory() != null )

@@ -2275,16 +2292,17 @@
                             {

                                 Collection<String> l = JavadocUtil.pruneDirs( subProject, Collections.singletonList(

                                         javadocDir.getAbsolutePath() ) );

-                                sourcePaths.addAll( l );

+                                additionalSourcePaths.addAll( l );

                             }

                         }

+                        allSourcePaths.add( additionalSourcePaths );

                     }

                 }

             }

         }

         else

         {

-            sourcePaths = new ArrayList<>( Arrays.asList( JavadocUtil.splitPath( sourcepath ) ) );

+            Collection<String> sourcePaths = new ArrayList<>( Arrays.asList( JavadocUtil.splitPath( sourcepath ) ) );

             sourcePaths = JavadocUtil.pruneDirs( project, sourcePaths );

             if ( getJavadocDirectory() != null )

             {

@@ -2292,11 +2310,10 @@
                     getJavadocDirectory().getAbsolutePath() ) );

                 sourcePaths.addAll( l );

             }

+            allSourcePaths.add( sourcePaths );

         }

 

-        sourcePaths = JavadocUtil.pruneDirs( project, sourcePaths );

-

-        return sourcePaths;

+        return allSourcePaths;

     }

 

     /**

@@ -4624,9 +4641,11 @@
      * @throws MavenReportException if any

      * @see <a href="http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#javadocoptions">http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#javadocoptions</a>

      */

-    private void addJavadocOptions( List<String> arguments, Collection<String> sourcePaths )

+    private void addJavadocOptions( List<String> arguments, Collection<Collection<String>> allSourcePaths )

         throws MavenReportException

     {

+        Collection<String> sourcePaths = collect( allSourcePaths );

+        

         validateJavadocOptions();

 

         // see com.sun.tools.javadoc.Start#parseAndExecute(String argv[])

@@ -4721,6 +4740,7 @@
         {

             sourcepath = StringUtils.join( sourcePaths.iterator(), File.pathSeparator );

         }

+        

         addArgIfNotEmpty( arguments, "-sourcepath", JavadocUtil.quotedPathArgument( getSourcePath( sourcePaths ) ) );

 

         if ( StringUtils.isNotEmpty( sourcepath ) && isJavaDocVersionAtLeast( SINCE_JAVADOC_1_5 ) )

diff --git a/src/main/java/org/apache/maven/plugins/javadoc/JavadocReport.java b/src/main/java/org/apache/maven/plugins/javadoc/JavadocReport.java
index 3e8d01a..76b68c7 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocReport.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocReport.java
@@ -240,7 +240,7 @@
             List<String> files;

             try

             {

-                sourcePaths = getSourcePaths();

+                sourcePaths = collect( getSourcePaths() );

                 files = getFiles( sourcePaths );

             }

             catch ( MavenReportException e )