diff --git a/src/main/java/org/codehaus/mojo/taglist/FileAnalyser.java b/src/main/java/org/codehaus/mojo/taglist/FileAnalyser.java index beceea8..8dfbcf1 100644 --- a/src/main/java/org/codehaus/mojo/taglist/FileAnalyser.java +++ b/src/main/java/org/codehaus/mojo/taglist/FileAnalyser.java @@ -83,6 +83,16 @@ public class FileAnalyser */ private Collection sourceDirs; + /** + * The files to include, as a comma separated list of patterns. + */ + private String includes; + + /** + * The files top exclude, as a comma separated list of patterns. + */ + private String excludes; + /** * Log for debug output. */ @@ -124,6 +134,8 @@ public FileAnalyser( TagListReport report, List tagClasses ) locale = report.getLocale(); noCommentString = report.getBundle().getString( "report.taglist.nocomment" ); this.tagClasses = tagClasses; + this.includes = report.getIncludesCommaSeparated(); + this.excludes = report.getExcludesCommaSeparated(); } /** @@ -171,7 +183,7 @@ private List findFilesToScan() { for ( Iterator iter = sourceDirs.iterator(); iter.hasNext(); ) { - filesList.addAll( FileUtils.getFiles( new File( (String) iter.next() ), "**/*.java", null ) ); + filesList.addAll( FileUtils.getFiles( new File( (String) iter.next() ), includes, excludes ) ); } } catch ( IOException e ) diff --git a/src/main/java/org/codehaus/mojo/taglist/TagListReport.java b/src/main/java/org/codehaus/mojo/taglist/TagListReport.java index 3dcc6f7..e39fc54 100644 --- a/src/main/java/org/codehaus/mojo/taglist/TagListReport.java +++ b/src/main/java/org/codehaus/mojo/taglist/TagListReport.java @@ -21,6 +21,7 @@ import java.io.File; import java.io.FileOutputStream; +import java.io.IOException; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Collection; @@ -48,6 +49,7 @@ import org.codehaus.mojo.taglist.tags.InvalidTagException; import org.codehaus.mojo.taglist.tags.TagClass; import org.codehaus.mojo.taglist.tags.TagFactory; +import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.PathTool; import org.codehaus.plexus.util.StringUtils; @@ -72,6 +74,22 @@ public class TagListReport /** Default locale used if the source file locale is null. */ private static final String DEFAULT_LOCALE = "en"; + /** + * List of files to include. Specified as fileset patterns which are relative to the source directory. + * + * @since 3.0.0 + */ + @Parameter( defaultValue = "**/*.java" ) + private String[] includes; + + /** + * List of files to exclude. Specified as fileset patterns which are relative to the source directory. + * + * @since 3.0.0 + */ + @Parameter( defaultValue = "" ) + private String[] excludes; + /** * Specifies the directory where the xml output will be generated. * @@ -435,30 +453,33 @@ private List pruneSourceDirs( List sourceDirectories ) } /** - * Checks whether the given directory contains Java files. + * Checks whether the given directory contains source files. * * @param dir the source directory. - * @return true if the folder or one of its subfolders contains at least 1 Java file. + * @return true if the folder or one of its subfolders contains at least 1 source file that matches includes/excludes. */ private boolean hasSources( File dir ) { boolean found = false; if ( dir.exists() && dir.isDirectory() ) { - File[] files = dir.listFiles(); - for ( int i = 0; i < files.length && !found; i++ ) - { - File currentFile = files[i]; - if ( currentFile.isFile() && currentFile.getName().endsWith( ".java" ) ) - { + try { + if ( ! FileUtils.getFiles( dir, getIncludesCommaSeparated(), getExcludesCommaSeparated() ).isEmpty() ) { found = true; } - else if ( currentFile.isDirectory() ) - { - boolean hasSources = hasSources( currentFile ); - if ( hasSources ) - { - found = true; + } catch (IOException e) { + // should never get here + getLog().error("Error whilst trying to scan the directory " + dir.getAbsolutePath(), e); + } + File[] files = dir.listFiles(); + if ( files != null ) { + for ( int i = 0; i < files.length && !found; i++ ) { + File currentFile = files[i]; + if ( currentFile.isDirectory() ) { + boolean hasSources = hasSources( currentFile ); + if ( hasSources ) { + found = true; + } } } } @@ -485,6 +506,7 @@ public List constructSourceDirs() { MavenProject reactorProject = (MavenProject) i.next(); + // TODO should this be more like ! "pom".equals(...) if ( "java".equals( reactorProject.getArtifact().getArtifactHandler().getLanguage() ) ) { dirs.addAll( reactorProject.getCompileSourceRoots() ); @@ -501,6 +523,30 @@ public List constructSourceDirs() } /** + * Get the files to include, as a comma separated list of patterns. + */ + String getIncludesCommaSeparated() + { + if ( includes != null ) { + return String.join(",", includes); + } else { + return ""; + } + } + + /** + * Get the files to exclude, as a comma separated list of patterns. + */ + String getExcludesCommaSeparated() + { + if ( excludes != null ) { + return String.join(",", excludes); + } else { + return ""; + } + } + + /** * Returns the Locale of the source files. * * @return The Locale of the source files.