Skip to content

Commit 141498f

Browse files
sumeetgajjarjozic
authored andcommitted
Fix NPE in aggregate report generation.
1 parent e81c12d commit 141498f

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
import java.util.concurrent.atomic.AtomicInteger;
3133

@@ -535,6 +537,31 @@ else if ( !module.getPackaging().equals( "pom" ) )
535537
scoverageDataDirs.size() ) );
536538
}
537539

540+
/* traverse up the module tree until a module isExecutionRoot */
541+
if ( topLevelModule == null )
542+
{
543+
Queue<MavenProject> candidateForTopLevelModules = new ArrayDeque<>(reactorProjects);
544+
while ( !candidateForTopLevelModules.isEmpty() )
545+
{
546+
MavenProject module = candidateForTopLevelModules.poll();
547+
if ( module.isExecutionRoot() )
548+
{
549+
topLevelModule = module;
550+
break;
551+
}
552+
if ( module.hasParent() )
553+
{
554+
candidateForTopLevelModules.add(module.getParent());
555+
}
556+
}
557+
}
558+
if ( topLevelModule == null )
559+
{
560+
// This exception should never be thrown.
561+
throw new IllegalStateException("Cannot find the top level module to write the " +
562+
"aggregated reports.");
563+
}
564+
538565
File topLevelModuleOutputDirectory = rebase( outputDirectory, topLevelModule );
539566
File topLevelModuleXmlOutputDirectory = rebase( xmlOutputDirectory, topLevelModule );
540567

0 commit comments

Comments
 (0)