From 0f720569fadcecc2e9ddc3f47c461a7dd994af3e Mon Sep 17 00:00:00 2001 From: Sumeet Gajjar Date: Wed, 2 Feb 2022 21:37:08 -0800 Subject: [PATCH 1/3] Fix NPE in aggregate report generation. --- .../scoverage/plugin/SCoverageReportMojo.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main/java/org/scoverage/plugin/SCoverageReportMojo.java b/src/main/java/org/scoverage/plugin/SCoverageReportMojo.java index 60bdad1a..8f98c356 100644 --- a/src/main/java/org/scoverage/plugin/SCoverageReportMojo.java +++ b/src/main/java/org/scoverage/plugin/SCoverageReportMojo.java @@ -23,9 +23,11 @@ import java.io.File; import java.io.FileInputStream; import java.util.ArrayList; +import java.util.ArrayDeque; import java.util.Arrays; import java.util.List; import java.util.Locale; +import java.util.Queue; import java.util.ResourceBundle; import java.util.concurrent.atomic.AtomicInteger; @@ -535,6 +537,31 @@ else if ( !module.getPackaging().equals( "pom" ) ) scoverageDataDirs.size() ) ); } + /* traverse up the module tree until a module isExecutionRoot */ + if ( topLevelModule == null ) + { + Queue candidateForTopLevelModules = new ArrayDeque<>(reactorProjects); + while ( !candidateForTopLevelModules.isEmpty() ) + { + MavenProject module = candidateForTopLevelModules.poll(); + if ( module.isExecutionRoot() ) + { + topLevelModule = module; + break; + } + if ( module.hasParent() ) + { + candidateForTopLevelModules.add(module.getParent()); + } + } + } + if ( topLevelModule == null ) + { + // This exception should never be thrown. + throw new IllegalStateException("Cannot find the top level module to write the " + + "aggregated reports."); + } + File topLevelModuleOutputDirectory = rebase( outputDirectory, topLevelModule ); File topLevelModuleXmlOutputDirectory = rebase( xmlOutputDirectory, topLevelModule ); From e90b566ff0c27451d7d4ac0ffcfe6694136ba810 Mon Sep 17 00:00:00 2001 From: Sumeet Gajjar Date: Wed, 2 Feb 2022 21:45:45 -0800 Subject: [PATCH 2/3] Update readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7ace3280..bed8d51b 100644 --- a/README.md +++ b/README.md @@ -158,7 +158,8 @@ or There is no separate mojo for aggregated reports, there is `aggregate` parameter. To additionally generate aggregated SCoverage report for root module, when generating regular reports, set `aggregate` parameter value to `true`. -It works only in multimodule projects. +It works only in multimodule projects, the aggregated report will be generated in the current +execution root. It can be configured by defining `aggregate` plugin configuration parameter or `scoverage.aggregate` project property. From ccbd8d097bf6d71aff07f54454c99f0c9a9c7651 Mon Sep 17 00:00:00 2001 From: Eugene Platonov Date: Tue, 26 Dec 2023 20:31:07 -0500 Subject: [PATCH 3/3] Add a test for NPE in #103 --- .../invoker.properties | 1 + .../module01/pom.xml | 16 +++++ .../src/main/scala/pkg01/HelloService1.scala | 12 ++++ .../test/scala/pkg01/HelloServiceTest.scala | 14 ++++ .../module02/pom.xml | 23 +++++++ .../module02/submodule02_01/pom.xml | 16 +++++ .../main/scala/pkg02_01/HelloService2.scala | 12 ++++ .../scala/pkg02_01/HelloServiceTest.scala | 14 ++++ .../module02/submodule02_02/pom.xml | 16 +++++ .../main/scala/pkg02_02/HelloService2.scala | 12 ++++ .../scala/pkg02_02/HelloServiceTest.scala | 14 ++++ .../test_report_for_some_submodules/pom.xml | 65 +++++++++++++++++++ .../validate.groovy | 14 ++++ 13 files changed, 229 insertions(+) create mode 100644 src/it/test_report_for_some_submodules/invoker.properties create mode 100644 src/it/test_report_for_some_submodules/module01/pom.xml create mode 100644 src/it/test_report_for_some_submodules/module01/src/main/scala/pkg01/HelloService1.scala create mode 100644 src/it/test_report_for_some_submodules/module01/src/test/scala/pkg01/HelloServiceTest.scala create mode 100644 src/it/test_report_for_some_submodules/module02/pom.xml create mode 100644 src/it/test_report_for_some_submodules/module02/submodule02_01/pom.xml create mode 100644 src/it/test_report_for_some_submodules/module02/submodule02_01/src/main/scala/pkg02_01/HelloService2.scala create mode 100644 src/it/test_report_for_some_submodules/module02/submodule02_01/src/test/scala/pkg02_01/HelloServiceTest.scala create mode 100644 src/it/test_report_for_some_submodules/module02/submodule02_02/pom.xml create mode 100644 src/it/test_report_for_some_submodules/module02/submodule02_02/src/main/scala/pkg02_02/HelloService2.scala create mode 100644 src/it/test_report_for_some_submodules/module02/submodule02_02/src/test/scala/pkg02_02/HelloServiceTest.scala create mode 100644 src/it/test_report_for_some_submodules/pom.xml create mode 100644 src/it/test_report_for_some_submodules/validate.groovy diff --git a/src/it/test_report_for_some_submodules/invoker.properties b/src/it/test_report_for_some_submodules/invoker.properties new file mode 100644 index 00000000..9e7f6ddc --- /dev/null +++ b/src/it/test_report_for_some_submodules/invoker.properties @@ -0,0 +1 @@ +invoker.goals=clean scoverage:report -e -ntp -pl module01 -pl module02/submodule02_02 \ No newline at end of file diff --git a/src/it/test_report_for_some_submodules/module01/pom.xml b/src/it/test_report_for_some_submodules/module01/pom.xml new file mode 100644 index 00000000..0f5fb7f6 --- /dev/null +++ b/src/it/test_report_for_some_submodules/module01/pom.xml @@ -0,0 +1,16 @@ + + + + + + it.scoverage-maven-plugin + test_report_for_some_submodules + 1.0-SNAPSHOT + ../pom.xml + + + 4.0.0 + module01 + Test Scoverage report works for specified submodules: Module 1 + + \ No newline at end of file diff --git a/src/it/test_report_for_some_submodules/module01/src/main/scala/pkg01/HelloService1.scala b/src/it/test_report_for_some_submodules/module01/src/main/scala/pkg01/HelloService1.scala new file mode 100644 index 00000000..9d7c7380 --- /dev/null +++ b/src/it/test_report_for_some_submodules/module01/src/main/scala/pkg01/HelloService1.scala @@ -0,0 +1,12 @@ +package pkg01 + +class HelloService1 +{ + def hello = + { + "Hello from module 1" + } + +} + +object HelloService1 extends HelloService1 diff --git a/src/it/test_report_for_some_submodules/module01/src/test/scala/pkg01/HelloServiceTest.scala b/src/it/test_report_for_some_submodules/module01/src/test/scala/pkg01/HelloServiceTest.scala new file mode 100644 index 00000000..9cac7025 --- /dev/null +++ b/src/it/test_report_for_some_submodules/module01/src/test/scala/pkg01/HelloServiceTest.scala @@ -0,0 +1,14 @@ +package pkg01 + +import org.junit.Test; +import org.junit.Assert.assertEquals + +class HelloServiceTest +{ + @Test + def test1() + { + assertEquals("Hello from module 1", HelloService1.hello) + } + +} diff --git a/src/it/test_report_for_some_submodules/module02/pom.xml b/src/it/test_report_for_some_submodules/module02/pom.xml new file mode 100644 index 00000000..2238724b --- /dev/null +++ b/src/it/test_report_for_some_submodules/module02/pom.xml @@ -0,0 +1,23 @@ + + + + + + it.scoverage-maven-plugin + test_report_for_some_submodules + 1.0-SNAPSHOT + ../pom.xml + + + 4.0.0 + module02 + pom + Test Scoverage report works for specified submodules: Module 2 + + + submodule02_01 + submodule02_02 + + + + \ No newline at end of file diff --git a/src/it/test_report_for_some_submodules/module02/submodule02_01/pom.xml b/src/it/test_report_for_some_submodules/module02/submodule02_01/pom.xml new file mode 100644 index 00000000..8320d7dd --- /dev/null +++ b/src/it/test_report_for_some_submodules/module02/submodule02_01/pom.xml @@ -0,0 +1,16 @@ + + + + + + it.scoverage-maven-plugin + module02 + 1.0-SNAPSHOT + ../pom.xml + + + 4.0.0 + submodule02_01 + Test Scoverage report works for specified submodules: SubModule 2_1 + + \ No newline at end of file diff --git a/src/it/test_report_for_some_submodules/module02/submodule02_01/src/main/scala/pkg02_01/HelloService2.scala b/src/it/test_report_for_some_submodules/module02/submodule02_01/src/main/scala/pkg02_01/HelloService2.scala new file mode 100644 index 00000000..876f99d9 --- /dev/null +++ b/src/it/test_report_for_some_submodules/module02/submodule02_01/src/main/scala/pkg02_01/HelloService2.scala @@ -0,0 +1,12 @@ +package pkg02_01 + +class HelloService2 +{ + def hello = + { + "Hello from submodule02_01" + } + +} + +object HelloService2 extends HelloService2 diff --git a/src/it/test_report_for_some_submodules/module02/submodule02_01/src/test/scala/pkg02_01/HelloServiceTest.scala b/src/it/test_report_for_some_submodules/module02/submodule02_01/src/test/scala/pkg02_01/HelloServiceTest.scala new file mode 100644 index 00000000..b0a42fa8 --- /dev/null +++ b/src/it/test_report_for_some_submodules/module02/submodule02_01/src/test/scala/pkg02_01/HelloServiceTest.scala @@ -0,0 +1,14 @@ +package pkg02_01 + +import org.junit.Test; +import org.junit.Assert.assertEquals + +class HelloServiceTest +{ + @Test + def test2() + { + assertEquals("Hello from submodule02_01", HelloService2.hello) + } + +} diff --git a/src/it/test_report_for_some_submodules/module02/submodule02_02/pom.xml b/src/it/test_report_for_some_submodules/module02/submodule02_02/pom.xml new file mode 100644 index 00000000..0dc2be4c --- /dev/null +++ b/src/it/test_report_for_some_submodules/module02/submodule02_02/pom.xml @@ -0,0 +1,16 @@ + + + + + + it.scoverage-maven-plugin + module02 + 1.0-SNAPSHOT + ../pom.xml + + + 4.0.0 + submodule02_02 + Test Scoverage report works for specified submodules: SubModule 2_2 + + \ No newline at end of file diff --git a/src/it/test_report_for_some_submodules/module02/submodule02_02/src/main/scala/pkg02_02/HelloService2.scala b/src/it/test_report_for_some_submodules/module02/submodule02_02/src/main/scala/pkg02_02/HelloService2.scala new file mode 100644 index 00000000..c6adc0dd --- /dev/null +++ b/src/it/test_report_for_some_submodules/module02/submodule02_02/src/main/scala/pkg02_02/HelloService2.scala @@ -0,0 +1,12 @@ +package pkg02_02 + +class HelloService2 +{ + def hello = + { + "Hello from submodule02_02" + } + +} + +object HelloService2 extends HelloService2 diff --git a/src/it/test_report_for_some_submodules/module02/submodule02_02/src/test/scala/pkg02_02/HelloServiceTest.scala b/src/it/test_report_for_some_submodules/module02/submodule02_02/src/test/scala/pkg02_02/HelloServiceTest.scala new file mode 100644 index 00000000..3abbf03a --- /dev/null +++ b/src/it/test_report_for_some_submodules/module02/submodule02_02/src/test/scala/pkg02_02/HelloServiceTest.scala @@ -0,0 +1,14 @@ +package pkg02_02 + +import org.junit.Test; +import org.junit.Assert.assertEquals + +class HelloServiceTest +{ + @Test + def test2() + { + assertEquals("Hello from submodule02_02", HelloService2.hello) + } + +} diff --git a/src/it/test_report_for_some_submodules/pom.xml b/src/it/test_report_for_some_submodules/pom.xml new file mode 100644 index 00000000..790a4525 --- /dev/null +++ b/src/it/test_report_for_some_submodules/pom.xml @@ -0,0 +1,65 @@ + + + + 4.0.0 + + + it.scoverage-maven-plugin + integration_tests_parent + 1.0-SNAPSHOT + ../integration_tests_parent/pom.xml + + + test_report_for_some_submodules + 1.0-SNAPSHOT + pom + Test Scoverage report works for specified submodules + Test Scoverage report works for specified submodules + + + 2.13 + 12 + + + + module01 + module02 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + net.alchim31.maven + scala-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + + @project.groupId@ + @project.artifactId@ + + true + + + + + + + + + @project.groupId@ + @project.artifactId@ + + true + + + + + diff --git a/src/it/test_report_for_some_submodules/validate.groovy b/src/it/test_report_for_some_submodules/validate.groovy new file mode 100644 index 00000000..44bbbc5c --- /dev/null +++ b/src/it/test_report_for_some_submodules/validate.groovy @@ -0,0 +1,14 @@ +try { + + def aggregatedScoverageFile = new File(basedir, "target/scoverage.xml") + assert aggregatedScoverageFile.exists() + + def aggregatedReportFile = new File(basedir, "target/site/scoverage/index.html") + assert aggregatedReportFile.exists() + + return true + +} catch (Throwable e) { + e.printStackTrace() + return false +}