maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rfscho...@apache.org
Subject [maven-javadoc-plugin] 01/08: Map files to their sourcepath
Date Thu, 27 Dec 2018 16:55:44 GMT
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch refactor
in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git

commit f32817bc403311eb3c8356802c93c64bd686c354
Author: rfscholte <rfscholte@apache.org>
AuthorDate: Wed Dec 26 13:35:34 2018 +0100

    Map files to their sourcepath
---
 .../maven/plugins/javadoc/AbstractJavadocMojo.java | 64 +++++++++++++---------
 .../maven/plugins/javadoc/JavadocReport.java       |  4 +-
 2 files changed, 39 insertions(+), 29 deletions(-)

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 e7c8bbc..d76d9b2 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -127,6 +127,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Properties;
 import java.util.Set;
 import java.util.StringTokenizer;
@@ -1992,7 +1993,7 @@ public abstract class AbstractJavadocMojo
         
         Collection<String> collectedSourcePaths = collect( sourcePaths.values() );
         
-        List<String> files = getFiles( collectedSourcePaths );
+        Map<String, Collection<String>> files = getFiles( collectedSourcePaths
);
         if ( !canGenerateReport( files ) )
         {
             return;
@@ -2020,9 +2021,9 @@ public abstract class AbstractJavadocMojo
         }
         else
         {
-            packageNames = getPackageNames( collectedSourcePaths, files );
+            packageNames = getPackageNames( files );
         }
-        List<String> filesWithUnnamedPackages = getFilesWithUnnamedPackages( collectedSourcePaths,
files );
+        List<String> filesWithUnnamedPackages = getFilesWithUnnamedPackages( files
);
 
         // ----------------------------------------------------------------------
         // Javadoc output directory as File
@@ -2135,10 +2136,16 @@ public abstract class AbstractJavadocMojo
             // ----------------------------------------------------------------------
             // Write argfile file and include it in the command line
             // ----------------------------------------------------------------------
+            
+            List<String> allFiles = new ArrayList<>();
+            for ( Collection<String> filesValues : files.values() )
+            {
+                allFiles.addAll( filesValues );
+            }
 
             if ( !files.isEmpty() )
             {
-                addCommandLineArgFile( cmd, javadocOutputDirectory, files );
+                addCommandLineArgFile( cmd, javadocOutputDirectory, allFiles );
             }
         }
 
@@ -2216,23 +2223,25 @@ public abstract class AbstractJavadocMojo
      * @return a List that contains the specific path for every source file
      * @throws MavenReportException {@link MavenReportException}
      */
-    protected List<String> getFiles( Collection<String> sourcePaths )
+    protected Map<String, Collection<String>> getFiles( Collection<String>
sourcePaths )
         throws MavenReportException
     {
-        List<String> files = new ArrayList<>();
+        Map<String, Collection<String>> mappedFiles = new LinkedHashMap<>(
sourcePaths.size() );
         if ( StringUtils.isEmpty( subpackages ) )
         {
             Collection<String> excludedPackages = getExcludedPackages();
             
             for ( String sourcePath : sourcePaths )
             {
+                List<String> files = new ArrayList<>();
                 File sourceDirectory = new File( sourcePath );
                 files.addAll( JavadocUtil.getFilesFromSource( sourceDirectory, sourceFileIncludes,
sourceFileExcludes,
                                                               excludedPackages ) );
+                mappedFiles.put( sourcePath, files );
             }
         }
 
-        return files;
+        return mappedFiles;
     }
 
     /**
@@ -2503,16 +2512,17 @@ public abstract class AbstractJavadocMojo
      * @param files the project files
      * @return a boolean that indicates whether javadoc report can be generated or not
      */
-    protected boolean canGenerateReport( List<String> files )
+    protected boolean canGenerateReport( Map<String, Collection<String>> files
)
     {
-        boolean canGenerate = true;
-
-        if ( files.isEmpty() && StringUtils.isEmpty( subpackages ) )
+        for ( Collection<String> filesValues : files.values() )
         {
-            canGenerate = false;
+            if ( !filesValues.isEmpty() )
+            {
+                return true;
+            }
         }
 
-        return canGenerate;
+        return !StringUtils.isEmpty( subpackages );
     }
 
     // ----------------------------------------------------------------------
@@ -4346,9 +4356,9 @@ public abstract class AbstractJavadocMojo
      * @param files       not null
      * @return the list of package names for files in the sourcePaths
      */
-    private List<String> getPackageNames( Collection<String> sourcePaths, List<String>
files )
+    private List<String> getPackageNames( Map<String, Collection<String>>
sourcePaths )
     {
-        return getPackageNamesOrFilesWithUnnamedPackages( sourcePaths, files, true );
+        return getPackageNamesOrFilesWithUnnamedPackages( sourcePaths, true );
     }
 
     /**
@@ -4404,14 +4414,14 @@ public abstract class AbstractJavadocMojo
                 exportAllPackages = true;
             }
             
-            for ( String currentFile : getFiles( artifactSourcePaths ) )
+            for ( Map.Entry<String, Collection<String>> currentPathEntry : getFiles(
artifactSourcePaths ).entrySet() )
             {
-                currentFile = currentFile.replace( '\\', '/' );
+                String currentSourcePath = currentPathEntry.getKey().replace( '\\', '/' );
 
-                for ( String currentSourcePath : artifactSourcePaths )
+                for ( String currentFile : currentPathEntry.getValue() )
                 {
-                    currentSourcePath = currentSourcePath.replace( '\\', '/' );
-
+                    currentFile = currentFile.replace( '\\', '/' );
+                    
                     if ( currentFile.contains( currentSourcePath ) )
                     {
                         if ( !currentSourcePath.endsWith( "/" ) )
@@ -4452,9 +4462,9 @@ public abstract class AbstractJavadocMojo
      * @param files       not null
      * @return a list files with unnamed package names for files in the sourcePaths
      */
-    private List<String> getFilesWithUnnamedPackages( Collection<String> sourcePaths,
List<String> files )
+    private List<String> getFilesWithUnnamedPackages( Map<String, Collection<String>>
sourcePaths )
     {
-        return getPackageNamesOrFilesWithUnnamedPackages( sourcePaths, files, false );
+        return getPackageNamesOrFilesWithUnnamedPackages( sourcePaths, false );
     }
 
     /**
@@ -4465,7 +4475,7 @@ public abstract class AbstractJavadocMojo
      * @see #getFiles
      * @see #getSourcePaths()
      */
-    private List<String> getPackageNamesOrFilesWithUnnamedPackages( Collection<String>
sourcePaths, List<String> files,
+    private List<String> getPackageNamesOrFilesWithUnnamedPackages( Map<String,
Collection<String>> sourcePaths,
                                                                     boolean onlyPackageName
)
     {
         List<String> returnList = new ArrayList<>();
@@ -4475,13 +4485,13 @@ public abstract class AbstractJavadocMojo
             return returnList;
         }
 
-        for ( String currentFile : files )
+        for ( Entry<String, Collection<String>> currentPathEntry : sourcePaths.entrySet()
)
         {
-            currentFile = currentFile.replace( '\\', '/' );
+            String currentSourcePath = currentPathEntry.getKey().replace( '\\', '/' );
 
-            for ( String currentSourcePath : sourcePaths )
+            for ( String currentFile : currentPathEntry.getValue() )
             {
-                currentSourcePath = currentSourcePath.replace( '\\', '/' );
+                currentFile = currentFile.replace( '\\', '/' );
 
                 if ( !currentSourcePath.endsWith( "/" ) )
                 {
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 bbc034f..e31cc40 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocReport.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocReport.java
@@ -21,8 +21,8 @@ package org.apache.maven.plugins.javadoc;
 
 import java.io.File;
 import java.util.Collection;
-import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 import java.util.ResourceBundle;
 
 import org.apache.maven.doxia.siterenderer.RenderingContext;
@@ -229,7 +229,7 @@ public class JavadocReport
         if ( this.isAggregator() || !"pom".equals( this.project.getPackaging() ) )
         {
             Collection<String> sourcePaths;
-            List<String> files;
+            Map<String, Collection<String>> files;
             try
             {
                 sourcePaths = collect( getSourcePaths().values() );


Mime
View raw message