29
29
import java .util .List ;
30
30
import java .util .Locale ;
31
31
import java .util .ResourceBundle ;
32
+ import java .util .concurrent .atomic .AtomicReference ;
32
33
33
34
import org .apache .maven .doxia .siterenderer .Renderer ;
34
35
import org .apache .maven .model .ReportPlugin ;
38
39
import org .apache .maven .project .MavenProject ;
39
40
import org .apache .maven .reporting .AbstractMavenReport ;
40
41
import org .apache .maven .reporting .MavenReportException ;
42
+ import org .apache .maven .shared .utils .io .FileUtils ;
41
43
import org .codehaus .mojo .taglist .beans .FileReport ;
42
44
import org .codehaus .mojo .taglist .beans .TagReport ;
43
45
import org .codehaus .mojo .taglist .output .TagListXMLComment ;
49
51
import org .codehaus .mojo .taglist .tags .InvalidTagException ;
50
52
import org .codehaus .mojo .taglist .tags .TagClass ;
51
53
import org .codehaus .mojo .taglist .tags .TagFactory ;
52
- import org .codehaus .plexus .util .FileUtils ;
53
54
import org .codehaus .plexus .util .IOUtil ;
54
55
import org .codehaus .plexus .util .PathTool ;
55
56
import org .codehaus .plexus .util .StringUtils ;
@@ -192,6 +193,8 @@ public class TagListReport
192
193
193
194
private String [] tags ;
194
195
196
+ private AtomicReference <List > sourceDirs = new AtomicReference <>();
197
+
195
198
/**
196
199
* {@inheritDoc}
197
200
*
@@ -424,7 +427,7 @@ private String getRelativePath( File location )
424
427
*/
425
428
public boolean canGenerateReport ()
426
429
{
427
- boolean canGenerate = !constructSourceDirs ().isEmpty ();
430
+ boolean canGenerate = !getSourceDirs ().isEmpty ();
428
431
if ( aggregate && !getProject ().isExecutionRoot () )
429
432
{
430
433
canGenerate = false ;
@@ -434,11 +437,11 @@ public boolean canGenerateReport()
434
437
435
438
/**
436
439
* Removes empty dirs from the list.
437
- *
440
+ *
438
441
* @param sourceDirectories the original list of directories.
439
442
* @return a new list containing only non empty dirs.
440
443
*/
441
- private List pruneSourceDirs ( List sourceDirectories )
444
+ private List pruneSourceDirs ( List sourceDirectories ) throws IOException
442
445
{
443
446
List pruned = new ArrayList ( sourceDirectories .size () );
444
447
for ( Iterator i = sourceDirectories .iterator (); i .hasNext (); )
@@ -454,45 +457,46 @@ private List pruneSourceDirs( List sourceDirectories )
454
457
455
458
/**
456
459
* Checks whether the given directory contains source files.
457
- *
460
+ *
458
461
* @param dir the source directory.
459
- * @return true if the folder or one of its subfolders contains at least 1 source file that matches includes/excludes.
462
+ * @return true if the folder or one of its subfolders contains at least 1 source file that matches
463
+ * includes/excludes.
460
464
*/
461
- private boolean hasSources ( File dir )
465
+ private boolean hasSources ( File dir ) throws IOException
462
466
{
463
- boolean found = false ;
464
467
if ( dir .exists () && dir .isDirectory () )
465
468
{
466
- try {
467
- if ( ! FileUtils .getFiles ( dir , getIncludesCommaSeparated (), getExcludesCommaSeparated () ).isEmpty () ) {
468
- found = true ;
469
- }
470
- } catch (IOException e ) {
471
- // should never get here
472
- getLog ().error ("Error whilst trying to scan the directory " + dir .getAbsolutePath (), e );
469
+ if ( !FileUtils .getFiles ( dir , getIncludesCommaSeparated (), getExcludesCommaSeparated () ).isEmpty () )
470
+ {
471
+ return true ;
473
472
}
473
+
474
474
File [] files = dir .listFiles ();
475
- if ( files != null ) {
476
- for ( int i = 0 ; i < files .length && !found ; i ++ ) {
475
+ if ( files != null )
476
+ {
477
+ for ( int i = 0 ; i < files .length ; i ++ )
478
+ {
477
479
File currentFile = files [i ];
478
- if ( currentFile .isDirectory () ) {
480
+ if ( currentFile .isDirectory () )
481
+ {
479
482
boolean hasSources = hasSources ( currentFile );
480
- if ( hasSources ) {
481
- found = true ;
483
+ if ( hasSources )
484
+ {
485
+ return true ;
482
486
}
483
487
}
484
488
}
485
489
}
486
490
}
487
- return found ;
491
+ return false ;
488
492
}
489
493
490
494
/**
491
495
* Construct the list of source directories to analyze.
492
- *
496
+ *
493
497
* @return the list of dirs.
494
498
*/
495
- public List constructSourceDirs ()
499
+ private List constructSourceDirs ()
496
500
{
497
501
List dirs = new ArrayList ( getProject ().getCompileSourceRoots () );
498
502
if ( !skipTestSources )
@@ -506,7 +510,6 @@ public List constructSourceDirs()
506
510
{
507
511
MavenProject reactorProject = (MavenProject ) i .next ();
508
512
509
- // TODO should this be more like ! "pom".equals(...)
510
513
if ( "java" .equals ( reactorProject .getArtifact ().getArtifactHandler ().getLanguage () ) )
511
514
{
512
515
dirs .addAll ( reactorProject .getCompileSourceRoots () );
@@ -518,18 +521,46 @@ public List constructSourceDirs()
518
521
}
519
522
}
520
523
521
- dirs = pruneSourceDirs ( dirs );
524
+ /*
525
+ * This try-catch is needed due to a missing declared exception in the
526
+ * 'canGenerateReport()' method. For this reason, neither the 'canGenerateReport()'
527
+ * nor the 'constructSourceDirs()' can throw exceptions.
528
+ * The exception itself is caused by a declaration from the FileUtils, but never used
529
+ * there. The FileUtils.getFiles() should be replaced by an NIO filter at some point.
530
+ */
531
+ try
532
+ {
533
+ dirs = pruneSourceDirs ( dirs );
534
+ }
535
+ catch ( IOException javaIoIOException )
536
+ {
537
+ getLog ().warn ( "Unable to prune source dirs." , javaIoIOException );
538
+ }
539
+
522
540
return dirs ;
523
541
}
524
542
543
+ protected List getSourceDirs ()
544
+ {
545
+ if ( sourceDirs .get () == null )
546
+ {
547
+ sourceDirs .compareAndSet ( null , constructSourceDirs () );
548
+ }
549
+
550
+ return sourceDirs .get ();
551
+ }
552
+
525
553
/**
526
554
* Get the files to include, as a comma separated list of patterns.
527
555
*/
528
556
String getIncludesCommaSeparated ()
529
557
{
530
- if ( includes != null ) {
531
- return String .join ("," , includes );
532
- } else {
558
+ if ( includes != null )
559
+ {
560
+ return String .join ( "," , includes );
561
+ }
562
+ else
563
+ {
533
564
return "" ;
534
565
}
535
566
}
0 commit comments