From e7fc279a51984448a75a37996f22264676d53f56 Mon Sep 17 00:00:00 2001 From: Jozef Vilcek Date: Fri, 17 Apr 2020 13:11:30 +0200 Subject: [PATCH] Allow dependency project not to use scoverage --- ...ultiModuleWithPartialScoverageUseTest.java | 20 ++++++++++++ .../a/build.gradle | 0 .../a/src/main/scala/org/hello/a/WorldA.scala | 8 +++++ .../b/build.gradle | 0 .../b/src/main/scala/org/hello/b/WorldB.scala | 8 +++++ .../build.gradle | 32 +++++++++++++++++++ .../settings.gradle | 1 + .../src/main/scala/org/hello/World.scala | 11 +++++++ .../org/scoverage/ScoveragePlugin.groovy | 4 +-- 9 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 src/functionalTest/java/org.scoverage/ScalaMultiModuleWithPartialScoverageUseTest.java create mode 100644 src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/a/build.gradle create mode 100644 src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/a/src/main/scala/org/hello/a/WorldA.scala create mode 100644 src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/b/build.gradle create mode 100644 src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/b/src/main/scala/org/hello/b/WorldB.scala create mode 100644 src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/build.gradle create mode 100644 src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/settings.gradle create mode 100644 src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/src/main/scala/org/hello/World.scala diff --git a/src/functionalTest/java/org.scoverage/ScalaMultiModuleWithPartialScoverageUseTest.java b/src/functionalTest/java/org.scoverage/ScalaMultiModuleWithPartialScoverageUseTest.java new file mode 100644 index 0000000..53d469f --- /dev/null +++ b/src/functionalTest/java/org.scoverage/ScalaMultiModuleWithPartialScoverageUseTest.java @@ -0,0 +1,20 @@ +package org.scoverage; + +import org.junit.Test; + +public class ScalaMultiModuleWithPartialScoverageUseTest extends ScoverageFunctionalTest { + + public ScalaMultiModuleWithPartialScoverageUseTest() { + super("scala-multi-module-with-partial-scoverage-use"); + } + + @Test + public void reportScoverage() { + + AssertableBuildResult result = dryRun("clean", ScoveragePlugin.getREPORT_NAME()); + + result.assertTaskExists(ScoveragePlugin.getREPORT_NAME()); + result.assertTaskExists("b:" + ScoveragePlugin.getREPORT_NAME()); + } + +} diff --git a/src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/a/build.gradle b/src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/a/build.gradle new file mode 100644 index 0000000..e69de29 diff --git a/src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/a/src/main/scala/org/hello/a/WorldA.scala b/src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/a/src/main/scala/org/hello/a/WorldA.scala new file mode 100644 index 0000000..c07f298 --- /dev/null +++ b/src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/a/src/main/scala/org/hello/a/WorldA.scala @@ -0,0 +1,8 @@ +package org.hello.a + +class WorldA { + + def fooA(): String = { + "a" + } +} \ No newline at end of file diff --git a/src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/b/build.gradle b/src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/b/build.gradle new file mode 100644 index 0000000..e69de29 diff --git a/src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/b/src/main/scala/org/hello/b/WorldB.scala b/src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/b/src/main/scala/org/hello/b/WorldB.scala new file mode 100644 index 0000000..83a8f32 --- /dev/null +++ b/src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/b/src/main/scala/org/hello/b/WorldB.scala @@ -0,0 +1,8 @@ +package org.hello.b + +class WorldB { + + def fooB(): String = { + "b" + } +} \ No newline at end of file diff --git a/src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/build.gradle b/src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/build.gradle new file mode 100644 index 0000000..ea5f8aa --- /dev/null +++ b/src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/build.gradle @@ -0,0 +1,32 @@ +plugins { + id 'org.scoverage' apply false +} + +description = 'a multi-module Scala project that builds successfully and has modules which does not use scoverate plugin' + +allprojects { p -> + repositories { + jcenter() + } + + apply plugin: 'java' + apply plugin: 'scala' + + if (p.name != 'a') { + apply plugin: 'org.scoverage' + } + + dependencies { + + compile group: 'org.scala-lang', name: 'scala-library', version: "${scalaVersionMajor}.${scalaVersionMinor}.${scalaVersionBuild}" + + testCompile group: 'org.junit.platform', name: 'junit-platform-runner' + + testCompile group: 'org.scalatest', name: "scalatest_${scalaVersionMajor}.${scalaVersionMinor}" + } +} + +dependencies { + compile project(':a') + compile project(':b') +} \ No newline at end of file diff --git a/src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/settings.gradle b/src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/settings.gradle new file mode 100644 index 0000000..dd79722 --- /dev/null +++ b/src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/settings.gradle @@ -0,0 +1 @@ +include 'a', 'b' \ No newline at end of file diff --git a/src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/src/main/scala/org/hello/World.scala b/src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/src/main/scala/org/hello/World.scala new file mode 100644 index 0000000..bf64f3e --- /dev/null +++ b/src/functionalTest/resources/projects/scala-multi-module-with-partial-scoverage-use/src/main/scala/org/hello/World.scala @@ -0,0 +1,11 @@ +package org.hello + +import org.hello.a.WorldA +import org.hello.a.WorldB + +class World { + + def foo(): String = { + WorldA.foo() + WorldB.foo() + } +} \ No newline at end of file diff --git a/src/main/groovy/org/scoverage/ScoveragePlugin.groovy b/src/main/groovy/org/scoverage/ScoveragePlugin.groovy index a6f46a9..d1e47ca 100644 --- a/src/main/groovy/org/scoverage/ScoveragePlugin.groovy +++ b/src/main/groovy/org/scoverage/ScoveragePlugin.groovy @@ -161,8 +161,8 @@ class ScoveragePlugin implements Plugin { it instanceof ScalaCompile } originalCompilationDependencies.each { - def dependencyProjectCompileTask = it.project.tasks[COMPILE_NAME] - def dependencyProjectReportTask = it.project.tasks[REPORT_NAME] + def dependencyProjectCompileTask = it.project.tasks.findByName(COMPILE_NAME) + def dependencyProjectReportTask = it.project.tasks.findByName(REPORT_NAME) if (dependencyProjectCompileTask != null) { compileTask.dependsOn(dependencyProjectCompileTask) // we don't want this project's tests to affect the other project's report