You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2018/12/09 14:45:45 UTC
[maven-javadoc-plugin] 04/05: Refactor
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch MJAVADOC-548
in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git
commit 555fd97d486c9009bd47704561f579c6f1cb875e
Author: rfscholte <rf...@apache.org>
AuthorDate: Sun Dec 9 14:00:44 2018 +0100
Refactor
---
.../maven/plugins/javadoc/AbstractJavadocMojo.java | 11 +++++++--
.../apache/maven/plugins/javadoc/JavadocUtil.java | 27 ++++++++--------------
2 files changed, 18 insertions(+), 20 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 efc45bc..c0eaaca 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -111,6 +111,7 @@ import java.net.URLClassLoader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Arrays;
@@ -2463,16 +2464,22 @@ public abstract class AbstractJavadocMojo
* @return a String that contains the exclude argument that will be used by javadoc
* @throws MavenReportException
*/
- private String getExcludedPackages( Collection<String> sourcePaths )
+ private String getExcludedPackages( Collection<String> sourceFolders )
throws MavenReportException
{
List<String> excludedNames = null;
+
+ Collection<Path> sourcePaths = new ArrayList<>( sourceFolders.size() );
+ for ( String folder : sourceFolders )
+ {
+ sourcePaths.add( Paths.get( folder ) );
+ }
if ( StringUtils.isNotEmpty( sourcepath ) && StringUtils.isNotEmpty( subpackages ) )
{
Collection<String> excludedPackages = getExcludedPackages();
- excludedNames = JavadocUtil.getExcludedNames( sourcePaths, excludedPackages );
+ excludedNames = JavadocUtil.getExcludedPackages( sourcePaths, excludedPackages );
}
String excludeArg = "";
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
index a9a547c..a6b0b9b 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
@@ -81,7 +81,6 @@ import java.nio.charset.IllegalCharsetNameException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
@@ -199,22 +198,15 @@ public class JavadocUtil
*
* @param sourcePaths the path to the source files
* @param excludedPackages the package names to be excluded in the javadoc
- * @return a List of the source files to be excluded in the generated javadoc
+ * @return a List of the packages to be excluded in the generated javadoc
*/
- protected static List<String> getExcludedNames( Collection<String> sourcePaths,
- Collection<String> excludedPackages )
+ protected static List<String> getExcludedPackages( Collection<Path> sourcePaths,
+ Collection<String> excludedPackages )
{
List<String> excludedNames = new ArrayList<>();
- for ( String path : sourcePaths )
+ for ( Path sourcePath : sourcePaths )
{
- for ( String file : getExcludedPackages( Paths.get( path ), excludedPackages ) )
- {
- String tmpStr = file.replace( '\\', '/' );
-
- String[] srcSplit = tmpStr.split( Pattern.quote( path.replace( '\\', '/' ) + '/' ) );
-
- excludedNames.add( srcSplit[1].replace( '/', '.' ) );
- }
+ excludedNames.addAll( getExcludedPackages( sourcePath, excludedPackages ) );
}
return excludedNames;
@@ -394,7 +386,7 @@ public class JavadocUtil
* @param excludePackagenames package names to be excluded in the javadoc
* @return a List of the packagenames to be excluded
*/
- protected static Collection<String> getExcludedPackages( Path sourceDirectory,
+ protected static Collection<String> getExcludedPackages( final Path sourceDirectory,
Collection<String> excludePackagenames )
{
final Collection<String> fileList = new ArrayList<>();
@@ -409,7 +401,7 @@ public class JavadocUtil
{
if ( file.getFileName().toString().endsWith( ".java" ) )
{
- fileList.add( file.toAbsolutePath().toString() );
+ fileList.add( sourceDirectory.relativize( file ).toString() );
}
return FileVisitResult.CONTINUE;
}
@@ -429,12 +421,11 @@ public class JavadocUtil
{
for ( String excludePart : excludeName )
{
- if ( !"".equals( excludePart.trim() ) && aFileList.contains( excludePart )
- && !sourceDirectory.toString().contains( excludePart ) )
+ if ( !"".equals( excludePart.trim() ) && aFileList.contains( excludePart ) )
{
int idx = aFileList.lastIndexOf( File.separatorChar );
- files.add( aFileList.substring( 0, idx ) );
+ files.add( aFileList.substring( 0, idx ).replace( File.separatorChar, '.' ) );
}
}
}