Skip to content

Commit

Permalink
Report mojo: find a top level module for "mvn -pl"
Browse files Browse the repository at this point in the history
  • Loading branch information
Albert Meltzer authored and kitbellew committed Dec 26, 2023
1 parent f67eb01 commit 85c5796
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/main/java/org/scoverage/plugin/SCoverageReportMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import scoverage.reporter.IOUtils;
import scoverage.serialize.Serializer;
import scoverage.reporter.CoberturaXmlWriter;
import scoverage.reporter.CoverageAggregator;
import scoverage.reporter.ScoverageHtmlWriter;
import scoverage.reporter.ScoverageXmlWriter;

Expand Down Expand Up @@ -513,6 +512,11 @@ else if ( !module.getPackaging().equals( "pom" ) )
}
}

if ( null == topLevelModule )
{
topLevelModule = findAncestorModuleWithShortestBasedir();
}

/* Empty report must be generated or top-level site will contain invalid link to non-existent Scoverage report
if ( scoverageDataDirs.isEmpty() )
{
Expand Down Expand Up @@ -547,6 +551,32 @@ else if ( !module.getPackaging().equals( "pom" ) )
getLog().info( "Coverage aggregated reports completed." );
}

private MavenProject findAncestorModuleWithShortestBasedir()
{
MavenProject topLevelModule = null;
for ( MavenProject module : reactorProjects )
{
if ( !module.hasParent() )
{
continue;
}

MavenProject ancestorModule = module.getParent();
while ( ancestorModule.hasParent() )
{
ancestorModule = ancestorModule.getParent();
}
if ( null != topLevelModule &&
topLevelModule.getBasedir().getAbsolutePath().length() <
ancestorModule.getBasedir().getAbsolutePath().length() )
{
continue;
}
topLevelModule = ancestorModule;
}
return null == topLevelModule ? project : topLevelModule;
}

private void writeReports( Coverage coverage, List<File> sourceRoots, File coberturaXmlOutputDirectory,
File scoverageXmlOutputDirectory, File scoverageHtmlOutputDirectory )
{
Expand Down

0 comments on commit 85c5796

Please sign in to comment.