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 9e053910f8b99814c1baec789f8938ec502a9b74 Author: rfscholte <rfscho...@apache.org> AuthorDate: Fri Dec 7 10:31:54 2018 +0100 [MJAVADOC-548] Directoryname mixed up with excludePackageNames --- .gitignore | 1 + .../com/foo/bar/internal/{NotApi.java => Api.java} | 4 +- src/it/projects/MJAVADOC-384/verify.bsh | 16 +++- .../maven/plugins/javadoc/AbstractJavadocMojo.java | 4 +- .../apache/maven/plugins/javadoc/JavadocUtil.java | 92 +++++++--------------- .../maven/plugins/javadoc/JavadocUtilTest.java | 14 ++++ 6 files changed, 61 insertions(+), 70 deletions(-) diff --git a/.gitignore b/.gitignore index 384de6f..bdbdf67 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ out/ .java-version /javadoc-options-javadoc-resources.xml .checkstyle +/src/it/mrm/3rdparty/_doclet-1.0.jar diff --git a/src/it/projects/MJAVADOC-384/src/main/java/com/foo/bar/internal/NotApi.java b/src/it/projects/MJAVADOC-384/src/main/java/com/foo/bar/internal/Api.java similarity index 95% rename from src/it/projects/MJAVADOC-384/src/main/java/com/foo/bar/internal/NotApi.java rename to src/it/projects/MJAVADOC-384/src/main/java/com/foo/bar/internal/Api.java index 53480de..7121d40 100644 --- a/src/it/projects/MJAVADOC-384/src/main/java/com/foo/bar/internal/NotApi.java +++ b/src/it/projects/MJAVADOC-384/src/main/java/com/foo/bar/internal/Api.java @@ -19,7 +19,7 @@ package com.foo.bar.internal; * under the License. */ -/** Not API */ -public class NotApi { +/** API */ +public class Api { } diff --git a/src/it/projects/MJAVADOC-384/verify.bsh b/src/it/projects/MJAVADOC-384/verify.bsh index dce4671..1c80f44 100644 --- a/src/it/projects/MJAVADOC-384/verify.bsh +++ b/src/it/projects/MJAVADOC-384/verify.bsh @@ -36,11 +36,19 @@ for ( File javadocFile : nonExistingJavadocFiles ) } } -File javadocFile = new File ( basedir, "target/site/apidocs/com/foo/bar/Api.html" ); -if ( !javadocFile.exists() ) +File[] existingJavadocFiles = new File[] { + new File( basedir, "target/site/apidocs/com/foo/bar/Api.html" ), + new File( basedir, "target/site/apidocs/com/foo/bar/internal/Api.html" ), +}; + +for ( File javadocFile : existingJavadocFiles ) { - System.err.println( javadocFile.getAbsolutePath() + " is missing." ); - return false; + if ( !javadocFile.exists() ) + { + System.err.println( javadocFile.getAbsolutePath() + " is missing." ); + return false; + } } + return true; 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 addcd36..2b65b2e 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java @@ -2214,8 +2214,8 @@ public abstract class AbstractJavadocMojo for ( String sourcePath : sourcePaths ) { File sourceDirectory = new File( sourcePath ); - JavadocUtil.addFilesFromSource( files, sourceDirectory, sourceFileIncludes, sourceFileExcludes, - excludedPackages ); + files.addAll( JavadocUtil.getFilesFromSource( sourceDirectory, sourceFileIncludes, sourceFileExcludes, + excludedPackages ) ); } } 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 22cab64..23fd546 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java @@ -333,70 +333,39 @@ public class JavadocUtil * Method that gets the files or classes that would be included in the javadocs using the subpackages parameter. * * @param sourceDirectory the directory where the source files are located - * @param fileList the list of all files found in the sourceDirectory + * @param fileList the list of all relative files found in the sourceDirectory * @param excludePackages package names to be excluded in the javadoc * @return a StringBuilder that contains the appended file names of the files to be included in the javadoc */ protected static List<String> getIncludedFiles( File sourceDirectory, String[] fileList, String[] excludePackages ) { List<String> files = new ArrayList<>(); + + List<Pattern> excludePackagePatterns = new ArrayList<>( excludePackages.length ); + for ( String excludePackage : excludePackages ) + { + excludePackagePatterns.add( Pattern.compile( excludePackage.replace( "\\", "\\\\" ) + .replace( ".", "\\." ) + .replace( "*", ".+" ) + .concat( "[\\\\/][^\\\\/]+\\.java" ) + ) ); + } - for ( String aFileList : fileList ) + for ( String file : fileList ) { - boolean include = true; - for ( int k = 0; k < excludePackages.length && include; k++ ) + boolean excluded = false; + for ( Pattern excludePackagePattern : excludePackagePatterns ) { - // handle wildcards (*) in the excludePackageNames - String[] excludeName = excludePackages[k].split( "[*]" ); - - if ( excludeName.length == 0 ) + if ( excludePackagePattern.matcher( file ).matches() ) { - continue; - } - - if ( excludeName.length > 1 ) - { - int u = 0; - while ( include && u < excludeName.length ) - { - if ( !"".equals( excludeName[u].trim() ) && aFileList.contains( excludeName[u] ) ) - { - include = false; - } - u++; - } - } - else - { - if ( aFileList.startsWith( sourceDirectory.toString() + File.separatorChar + excludeName[0] ) ) - { - if ( excludeName[0].endsWith( String.valueOf( File.separatorChar ) ) ) - { - int i = aFileList.lastIndexOf( File.separatorChar ); - String packageName = aFileList.substring( 0, i + 1 ); - File currentPackage = new File( packageName ); - File excludedPackage = new File( sourceDirectory, excludeName[0] ); - if ( currentPackage.equals( excludedPackage ) - && aFileList.substring( i ).contains( ".java" ) ) - { - include = true; - } - else - { - include = false; - } - } - else - { - include = false; - } - } + excluded = true; + break; } } - - if ( include ) + + if ( !excluded ) { - files.add( quotedPathArgument( aFileList ) ); + files.add( file ); } } @@ -455,13 +424,12 @@ public class JavadocUtil * Convenience method that gets the files to be included in the javadoc. * * @param sourceDirectory the directory where the source files are located - * @param files the variable that contains the appended filenames of the files to be included in the javadoc * @param excludePackages the packages to be excluded in the javadocs * @param sourceFileIncludes files to include. * @param sourceFileExcludes files to exclude. */ - protected static void addFilesFromSource( List<String> files, File sourceDirectory, List<String> sourceFileIncludes, - List<String> sourceFileExcludes, String[] excludePackages ) + protected static List<String> getFilesFromSource( File sourceDirectory, List<String> sourceFileIncludes, + List<String> sourceFileExcludes, String[] excludePackages ) { DirectoryScanner ds = new DirectoryScanner(); if ( sourceFileIncludes == null ) @@ -477,17 +445,17 @@ public class JavadocUtil ds.scan(); String[] fileList = ds.getIncludedFiles(); - String[] pathList = new String[fileList.length]; - for ( int x = 0; x < fileList.length; x++ ) - { - pathList[x] = new File( sourceDirectory, fileList[x] ).getAbsolutePath(); - } - if ( pathList.length != 0 ) + List<String> files = new ArrayList<>(); + if ( fileList.length != 0 ) { - List<String> tmpFiles = getIncludedFiles( sourceDirectory, pathList, excludePackages ); - files.addAll( tmpFiles ); + for ( String includedFile : getIncludedFiles( sourceDirectory, fileList, excludePackages ) ) + { + files.add( quotedPathArgument( new File( sourceDirectory, includedFile ).getAbsolutePath() ) ); + } } + + return files; } /** diff --git a/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java b/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java index 825c2a0..b4db5c5 100644 --- a/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java +++ b/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java @@ -1,5 +1,7 @@ package org.apache.maven.plugins.javadoc; +import static org.junit.Assert.assertArrayEquals; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -775,6 +777,18 @@ public class JavadocUtilTest assertEquals( path1 + ps + path2 + ps + path1 + ps + path2, JavadocUtil.unifyPathSeparator( path1 + ";" + path2 + ":" + path1 + ":" + path2 ) ); } + + + public void testGetIncludedFiles() throws Exception + { + File sourceDirectory = new File("target/it").getAbsoluteFile(); + String[] fileList = new String[] { "Main.java" }; + String[] excludePackages = new String[] { "*.it" }; + + List<String> includedFiles = JavadocUtil.getIncludedFiles( sourceDirectory, fileList, excludePackages ); + + assertArrayEquals( fileList, includedFiles.toArray( new String[0] ) ); + } private void stopSilently( Server server ) {