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 56733178c0241deb114e014609b16c9d9d7a9588 Author: rfscholte <rfscho...@apache.org> AuthorDate: Sun Dec 9 15:45:32 2018 +0100 Use regular expression to match excludePackageNames --- src/it/projects/MJAVADOC-497/pom.xml | 2 +- .../maven/plugins/javadoc/AbstractJavadocMojo.java | 10 ++++++++- .../apache/maven/plugins/javadoc/JavadocUtil.java | 24 +++++++++++++--------- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/it/projects/MJAVADOC-497/pom.xml b/src/it/projects/MJAVADOC-497/pom.xml index 9b89c69..c664cd7 100644 --- a/src/it/projects/MJAVADOC-497/pom.xml +++ b/src/it/projects/MJAVADOC-497/pom.xml @@ -46,7 +46,7 @@ <version>@pom.version@</version> <configuration> <subpackages>com.example.foo</subpackages> - <excludePackageNames>*.impl.*</excludePackageNames> + <excludePackageNames>**.impl</excludePackageNames> </configuration> </plugin> </plugins> 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 c0eaaca..4ff10ec 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java @@ -766,7 +766,14 @@ public abstract class AbstractJavadocMojo * Unconditionally excludes the specified packages and their subpackages from the list formed by * <code>-subpackages</code>. Multiple packages can be separated by commas (<code>,</code>), colons (<code>:</code>) * or semicolons (<code>;</code>). - * <br/> + * <p> + * Wildcards work as followed: + * <ul> + * <li>a wildcard at the beginning should match 1 or more folders</li> + * <li>any other wildcard must match exactly one folder</li> + * </ul> + * </p> + * <p> * Example: * <pre> * <excludePackageNames>*.internal:org.acme.exclude1.*:org.acme.exclude2</excludePackageNames> @@ -776,6 +783,7 @@ public abstract class AbstractJavadocMojo * <br/> * Since <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/javadoc/whatsnew-1.4.html#summary">Java * 1.4</a>. + * </p> */ @Parameter( property = "excludePackageNames" ) private String excludePackageNames; 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 a6b0b9b..2e24e06 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java @@ -389,6 +389,8 @@ public class JavadocUtil protected static Collection<String> getExcludedPackages( final Path sourceDirectory, Collection<String> excludePackagenames ) { + final String regexFileSeparator = File.separator.replace( "\\", "\\\\" ); + final Collection<String> fileList = new ArrayList<>(); try @@ -401,7 +403,7 @@ public class JavadocUtil { if ( file.getFileName().toString().endsWith( ".java" ) ) { - fileList.add( sourceDirectory.relativize( file ).toString() ); + fileList.add( sourceDirectory.relativize( file.getParent() ).toString() ); } return FileVisitResult.CONTINUE; } @@ -415,18 +417,20 @@ public class JavadocUtil List<String> files = new ArrayList<>(); for ( String excludePackagename : excludePackagenames ) { - String[] excludeName = excludePackagename.replace( '.', File.separatorChar ).split( "[*]" ); - + // Usage of wildcard was bad specified and bad implemented, i.e. using String.contains() + // without respecting surrounding context + // Following implementation should match requirements as defined in the examples: + // - A wildcard at the beginning should match 1 or more folders + // - Any other wildcard must match exactly one folder + Pattern p = Pattern.compile( excludePackagename.replace( ".", regexFileSeparator ) + .replaceFirst( "^\\*", ".+" ) + .replace( "*", "[^" + regexFileSeparator + "]+" ) ); + for ( String aFileList : fileList ) { - for ( String excludePart : excludeName ) + if ( p.matcher( aFileList ).matches() ) { - if ( !"".equals( excludePart.trim() ) && aFileList.contains( excludePart ) ) - { - int idx = aFileList.lastIndexOf( File.separatorChar ); - - files.add( aFileList.substring( 0, idx ).replace( File.separatorChar, '.' ) ); - } + files.add( aFileList.replace( File.separatorChar, '.' ) ); } } }