21
21
22
22
import java .io .File ;
23
23
import java .io .FileOutputStream ;
24
+ import java .io .IOException ;
24
25
import java .io .OutputStreamWriter ;
25
26
import java .util .ArrayList ;
26
27
import java .util .Collection ;
48
49
import org .codehaus .mojo .taglist .tags .InvalidTagException ;
49
50
import org .codehaus .mojo .taglist .tags .TagClass ;
50
51
import org .codehaus .mojo .taglist .tags .TagFactory ;
52
+ import org .codehaus .plexus .util .FileUtils ;
51
53
import org .codehaus .plexus .util .IOUtil ;
52
54
import org .codehaus .plexus .util .PathTool ;
53
55
import org .codehaus .plexus .util .StringUtils ;
@@ -72,6 +74,22 @@ public class TagListReport
72
74
/** Default locale used if the source file locale is null. */
73
75
private static final String DEFAULT_LOCALE = "en" ;
74
76
77
+ /**
78
+ * List of files to include. Specified as fileset patterns which are relative to the source directory.
79
+ *
80
+ * @since 3.0.0
81
+ */
82
+ @ Parameter ( defaultValue = "**/*.java" )
83
+ private String [] includes ;
84
+
85
+ /**
86
+ * List of files to exclude. Specified as fileset patterns which are relative to the source directory.
87
+ *
88
+ * @since 3.0.0
89
+ */
90
+ @ Parameter ( defaultValue = "" )
91
+ private String [] excludes ;
92
+
75
93
/**
76
94
* Specifies the directory where the xml output will be generated.
77
95
*
@@ -435,30 +453,33 @@ private List pruneSourceDirs( List sourceDirectories )
435
453
}
436
454
437
455
/**
438
- * Checks whether the given directory contains Java files.
456
+ * Checks whether the given directory contains source files.
439
457
*
440
458
* @param dir the source directory.
441
- * @return true if the folder or one of its subfolders contains at least 1 Java file.
459
+ * @return true if the folder or one of its subfolders contains at least 1 source file that matches includes/excludes .
442
460
*/
443
461
private boolean hasSources ( File dir )
444
462
{
445
463
boolean found = false ;
446
464
if ( dir .exists () && dir .isDirectory () )
447
465
{
448
- File [] files = dir .listFiles ();
449
- for ( int i = 0 ; i < files .length && !found ; i ++ )
450
- {
451
- File currentFile = files [i ];
452
- if ( currentFile .isFile () && currentFile .getName ().endsWith ( ".java" ) )
453
- {
466
+ try {
467
+ if ( ! FileUtils .getFiles ( dir , getIncludesCommaSeparated (), getExcludesCommaSeparated () ).isEmpty () ) {
454
468
found = true ;
455
469
}
456
- else if ( currentFile .isDirectory () )
457
- {
458
- boolean hasSources = hasSources ( currentFile );
459
- if ( hasSources )
460
- {
461
- found = true ;
470
+ } catch (IOException e ) {
471
+ // should never get here
472
+ getLog ().error ("Error whilst trying to scan the directory " + dir .getAbsolutePath (), e );
473
+ }
474
+ File [] files = dir .listFiles ();
475
+ if ( files != null ) {
476
+ for ( int i = 0 ; i < files .length && !found ; i ++ ) {
477
+ File currentFile = files [i ];
478
+ if ( currentFile .isDirectory () ) {
479
+ boolean hasSources = hasSources ( currentFile );
480
+ if ( hasSources ) {
481
+ found = true ;
482
+ }
462
483
}
463
484
}
464
485
}
@@ -485,6 +506,7 @@ public List constructSourceDirs()
485
506
{
486
507
MavenProject reactorProject = (MavenProject ) i .next ();
487
508
509
+ // TODO should this be more like ! "pom".equals(...)
488
510
if ( "java" .equals ( reactorProject .getArtifact ().getArtifactHandler ().getLanguage () ) )
489
511
{
490
512
dirs .addAll ( reactorProject .getCompileSourceRoots () );
@@ -501,6 +523,30 @@ public List constructSourceDirs()
501
523
}
502
524
503
525
/**
526
+ * Get the files to include, as a comma separated list of patterns.
527
+ */
528
+ String getIncludesCommaSeparated ()
529
+ {
530
+ if ( includes != null ) {
531
+ return String .join ("," , includes );
532
+ } else {
533
+ return "" ;
534
+ }
535
+ }
536
+
537
+ /**
538
+ * Get the files to exclude, as a comma separated list of patterns.
539
+ */
540
+ String getExcludesCommaSeparated ()
541
+ {
542
+ if ( excludes != null ) {
543
+ return String .join ("," , excludes );
544
+ } else {
545
+ return "" ;
546
+ }
547
+ }
548
+
549
+ /**
504
550
* Returns the Locale of the source files.
505
551
*
506
552
* @return The Locale of the source files.
0 commit comments