Skip to content

Commit b3c21c6

Browse files
committed
Fix NPE in aggregate report generation.
1 parent 163bbe9 commit b3c21c6

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/main/java/org/scoverage/plugin/SCoverageReportMojo.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
import java.io.File;
2424
import java.io.FileInputStream;
2525
import java.util.ArrayList;
26+
import java.util.ArrayDeque;
2627
import java.util.Arrays;
2728
import java.util.List;
2829
import java.util.Locale;
30+
import java.util.Queue;
2931
import java.util.ResourceBundle;
3032

3133
import org.apache.maven.doxia.module.xhtml.decoration.render.RenderingContext;
@@ -503,6 +505,31 @@ else if ( !module.getPackaging().equals( "pom" ) )
503505
scoverageDataDirs.size() ) );
504506
}
505507

508+
/* traverse up the module tree until a module isExecutionRoot */
509+
if ( topLevelModule == null )
510+
{
511+
Queue<MavenProject> candidateForTopLevelModules = new ArrayDeque<>(reactorProjects);
512+
while ( !candidateForTopLevelModules.isEmpty() )
513+
{
514+
MavenProject module = candidateForTopLevelModules.poll();
515+
if ( module.isExecutionRoot() )
516+
{
517+
topLevelModule = module;
518+
break;
519+
}
520+
if ( module.hasParent() )
521+
{
522+
candidateForTopLevelModules.add(module.getParent());
523+
}
524+
}
525+
}
526+
if ( topLevelModule == null )
527+
{
528+
// This exception should never be thrown.
529+
throw new IllegalStateException("Cannot find the top level module to write the " +
530+
"aggregated reports.");
531+
}
532+
506533
File topLevelModuleOutputDirectory = rebase( outputDirectory, topLevelModule );
507534
File topLevelModuleXmlOutputDirectory = rebase( xmlOutputDirectory, topLevelModule );
508535

0 commit comments

Comments
 (0)