diff --git a/build.gradle b/build.gradle index 25d51c7..03f32f4 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ repositories { group 'org.scoverage' description = 'gradle-scoverage is a Gradle plugin for calculating code coverage using Scoverage' if (project.version == 'unspecified') { - version = '3.0.0-SNAPSHOT' + version = '6.0.0-SNAPSHOT' } ext { website = 'http://scoverage.org' diff --git a/src/functionalTest/java/org/scoverage/ScalaJavaAnnotationProcessorTest.java b/src/functionalTest/java/org/scoverage/ScalaJavaAnnotationProcessorTest.java new file mode 100644 index 0000000..ba82eae --- /dev/null +++ b/src/functionalTest/java/org/scoverage/ScalaJavaAnnotationProcessorTest.java @@ -0,0 +1,56 @@ +package org.scoverage; + +import org.gradle.testkit.runner.TaskOutcome; +import org.junit.Assert; +import org.junit.Test; + +import java.io.File; + +public class ScalaJavaAnnotationProcessorTest extends ScoverageFunctionalTest { + + public ScalaJavaAnnotationProcessorTest() { + super("scala-java-annotation-processor"); + } + + @Test + public void checkAndAggregateScoverage() throws Exception { + + AssertableBuildResult result = run("clean", ScoveragePlugin.getCHECK_NAME(), + ScoveragePlugin.getAGGREGATE_NAME()); + + result.assertTaskSkipped("java_only:" + ScoveragePlugin.getCOMPILE_NAME()); + + result.assertTaskSkipped(ScoveragePlugin.getREPORT_NAME()); + result.assertTaskSucceeded("mixed_scala_java:" + ScoveragePlugin.getREPORT_NAME()); + result.assertTaskSkipped("java_only:" + ScoveragePlugin.getREPORT_NAME()); + + result.assertTaskSucceeded(ScoveragePlugin.getCHECK_NAME()); + result.assertTaskSucceeded("mixed_scala_java:" + ScoveragePlugin.getCHECK_NAME()); + result.assertTaskSkipped("java_only:" + ScoveragePlugin.getCHECK_NAME()); + + result.assertTaskSucceeded(ScoveragePlugin.getAGGREGATE_NAME()); + + assertAllReportFilesExist(); + assertCoverage(100.0); + } + + private void assertAllReportFilesExist() { + + Assert.assertTrue(resolve(reportDir(), "index.html").exists()); + + assertMixedScalaJavaReportFilesExist(); + assertAggregationFilesExist(); + } + + private void assertAggregationFilesExist() { + + Assert.assertTrue(resolve(reportDir(), "mixed_scala_java/src/main/scala/org/hello/WorldScala.scala.html").exists()); + } + + private void assertMixedScalaJavaReportFilesExist() { + + File reportDir = reportDir(projectDir().toPath().resolve("mixed_scala_java").toFile()); + Assert.assertTrue(resolve(reportDir, "index.html").exists()); + Assert.assertTrue(resolve(reportDir, "src/main/scala/org/hello/WorldScala.scala.html").exists()); + } +} diff --git a/src/functionalTest/resources/projects/scala-java-annotation-processor/build.gradle b/src/functionalTest/resources/projects/scala-java-annotation-processor/build.gradle new file mode 100644 index 0000000..9e5797f --- /dev/null +++ b/src/functionalTest/resources/projects/scala-java-annotation-processor/build.gradle @@ -0,0 +1,50 @@ +plugins { + id 'org.scoverage' apply false +} + +description = 'a multi-module Scala and Java project using a Java annotation processor' + +allprojects { + repositories { + jcenter() + } +} + +def lombokVersion = '1.18.20' + +subprojects { + apply plugin: 'java' + + dependencies { + testImplementation group: 'org.junit.platform', name: 'junit-platform-runner', version: junitPlatformVersion + + compileOnly "org.projectlombok:lombok:$lombokVersion" + annotationProcessor "org.projectlombok:lombok:$lombokVersion" + + testCompileOnly "org.projectlombok:lombok:$lombokVersion" + testAnnotationProcessor "org.projectlombok:lombok:$lombokVersion" + } + + test { + useJUnitPlatform() + } +} + +/* +Because the Scala compiler doesn't support annotation processors, Java files using a Java annotation +processor MUST be compiled by the Java compiler. So we can't use the same +configuration as in `scala-java-multi-module` here. + +// A common practice in mixed java/scala modules to make Java code able to import Scala code +ext.configureSources = { set, name -> + set.scala.srcDir("src/$name/java") + set.java.srcDirs = [] +} +configureSources(sourceSets.main, 'main') +configureSources(sourceSets.test, 'test') +*/ + +apply plugin: 'org.scoverage' +scoverage { + minimumRate = 0.5 +} diff --git a/src/functionalTest/resources/projects/scala-java-annotation-processor/java_only/build.gradle b/src/functionalTest/resources/projects/scala-java-annotation-processor/java_only/build.gradle new file mode 100644 index 0000000..69fe4c7 --- /dev/null +++ b/src/functionalTest/resources/projects/scala-java-annotation-processor/java_only/build.gradle @@ -0,0 +1,3 @@ +dependencies { + testRuntimeOnly group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junitVersion +} diff --git a/src/functionalTest/resources/projects/scala-java-annotation-processor/java_only/src/main/java/org/hello/WorldJavaOnly.java b/src/functionalTest/resources/projects/scala-java-annotation-processor/java_only/src/main/java/org/hello/WorldJavaOnly.java new file mode 100644 index 0000000..27f643b --- /dev/null +++ b/src/functionalTest/resources/projects/scala-java-annotation-processor/java_only/src/main/java/org/hello/WorldJavaOnly.java @@ -0,0 +1,8 @@ +package org.hello; + +import lombok.Value; + +@Value +public class WorldJavaOnly { + private final String foo = "java_only"; +} diff --git a/src/functionalTest/resources/projects/scala-java-annotation-processor/java_only/src/test/java/org/hello/WorldJavaOnlyTest.java b/src/functionalTest/resources/projects/scala-java-annotation-processor/java_only/src/test/java/org/hello/WorldJavaOnlyTest.java new file mode 100644 index 0000000..9a029b2 --- /dev/null +++ b/src/functionalTest/resources/projects/scala-java-annotation-processor/java_only/src/test/java/org/hello/WorldJavaOnlyTest.java @@ -0,0 +1,11 @@ +package org.hello; + +import org.junit.Test; + +public class WorldJavaOnlyTest { + + @Test + public void foo() { + new WorldJavaOnly().foo(); + } +} diff --git a/src/functionalTest/resources/projects/scala-java-annotation-processor/lombok.config b/src/functionalTest/resources/projects/scala-java-annotation-processor/lombok.config new file mode 100644 index 0000000..3d2c462 --- /dev/null +++ b/src/functionalTest/resources/projects/scala-java-annotation-processor/lombok.config @@ -0,0 +1 @@ +lombok.accessors.fluent=true diff --git a/src/functionalTest/resources/projects/scala-java-annotation-processor/mixed_scala_java/build.gradle b/src/functionalTest/resources/projects/scala-java-annotation-processor/mixed_scala_java/build.gradle new file mode 100644 index 0000000..c0021f0 --- /dev/null +++ b/src/functionalTest/resources/projects/scala-java-annotation-processor/mixed_scala_java/build.gradle @@ -0,0 +1,14 @@ +apply plugin: 'scala' + +dependencies { + implementation group: 'org.scala-lang', name: 'scala-library', version: "${scalaVersionMajor}.${scalaVersionMinor}.${scalaVersionBuild}" + + testRuntimeOnly group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junitVersion + + testImplementation group: 'org.scalatest', name: "scalatest_${scalaVersionMajor}.${scalaVersionMinor}", version: scalatestVersion +} + +apply plugin: 'org.scoverage' +scoverage { + minimumRate = 0.5 +} diff --git a/src/functionalTest/resources/projects/scala-java-annotation-processor/mixed_scala_java/src/main/java/org/hello/WorldJava.java b/src/functionalTest/resources/projects/scala-java-annotation-processor/mixed_scala_java/src/main/java/org/hello/WorldJava.java new file mode 100644 index 0000000..0bcf847 --- /dev/null +++ b/src/functionalTest/resources/projects/scala-java-annotation-processor/mixed_scala_java/src/main/java/org/hello/WorldJava.java @@ -0,0 +1,8 @@ +package org.hello; + +import lombok.Value; + +@Value +public class WorldJava { + private final String foo = "java"; +} diff --git a/src/functionalTest/resources/projects/scala-java-annotation-processor/mixed_scala_java/src/main/scala/org/hello/WorldScala.scala b/src/functionalTest/resources/projects/scala-java-annotation-processor/mixed_scala_java/src/main/scala/org/hello/WorldScala.scala new file mode 100644 index 0000000..3e46057 --- /dev/null +++ b/src/functionalTest/resources/projects/scala-java-annotation-processor/mixed_scala_java/src/main/scala/org/hello/WorldScala.scala @@ -0,0 +1,7 @@ +package org.hello + +class WorldScala { + private val worldJava = new WorldJava() + + def foo() = worldJava.foo() +} diff --git a/src/functionalTest/resources/projects/scala-java-annotation-processor/mixed_scala_java/src/test/java/org/hello/WorldJavaTest.java b/src/functionalTest/resources/projects/scala-java-annotation-processor/mixed_scala_java/src/test/java/org/hello/WorldJavaTest.java new file mode 100644 index 0000000..316815c --- /dev/null +++ b/src/functionalTest/resources/projects/scala-java-annotation-processor/mixed_scala_java/src/test/java/org/hello/WorldJavaTest.java @@ -0,0 +1,11 @@ +package org.hello; + +import org.junit.Test; + +public class WorldJavaTest { + + @Test + public void foo() { + new WorldJava().foo(); + } +} diff --git a/src/functionalTest/resources/projects/scala-java-annotation-processor/mixed_scala_java/src/test/scala/org/hello/WorldScalaSuite.scala b/src/functionalTest/resources/projects/scala-java-annotation-processor/mixed_scala_java/src/test/scala/org/hello/WorldScalaSuite.scala new file mode 100644 index 0000000..08edf75 --- /dev/null +++ b/src/functionalTest/resources/projects/scala-java-annotation-processor/mixed_scala_java/src/test/scala/org/hello/WorldScalaSuite.scala @@ -0,0 +1,13 @@ +package org.hello + +import org.junit.runner.RunWith +import org.scalatest.FunSuite +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +class WorldScalaSuite extends FunSuite { + + test("foo") { + new WorldScala().foo() + } +} diff --git a/src/functionalTest/resources/projects/scala-java-annotation-processor/settings.gradle b/src/functionalTest/resources/projects/scala-java-annotation-processor/settings.gradle new file mode 100644 index 0000000..57567e8 --- /dev/null +++ b/src/functionalTest/resources/projects/scala-java-annotation-processor/settings.gradle @@ -0,0 +1 @@ +include 'java_only', 'mixed_scala_java' diff --git a/src/main/groovy/org/scoverage/ScoveragePlugin.groovy b/src/main/groovy/org/scoverage/ScoveragePlugin.groovy index 063ba04..f13ac44 100644 --- a/src/main/groovy/org/scoverage/ScoveragePlugin.groovy +++ b/src/main/groovy/org/scoverage/ScoveragePlugin.groovy @@ -87,6 +87,7 @@ class ScoveragePlugin implements Plugin { java.source(originalSourceSet.java) scala.source(originalSourceSet.scala) + annotationProcessorPath += originalSourceSet.annotationProcessorPath + project.configurations.scoverage compileClasspath += originalSourceSet.compileClasspath + project.configurations.scoverage runtimeClasspath = it.output + project.configurations.scoverage + originalSourceSet.runtimeClasspath }