-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #159 from grollinger/annotation-processors
Support mixed Java/Scala modules using Java annotation processors
- Loading branch information
Showing
14 changed files
with
185 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/functionalTest/java/org/scoverage/ScalaJavaAnnotationProcessorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/functionalTest/resources/projects/scala-java-annotation-processor/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
3 changes: 3 additions & 0 deletions
3
src/functionalTest/resources/projects/scala-java-annotation-processor/java_only/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dependencies { | ||
testRuntimeOnly group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junitVersion | ||
} |
8 changes: 8 additions & 0 deletions
8
...ects/scala-java-annotation-processor/java_only/src/main/java/org/hello/WorldJavaOnly.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.hello; | ||
|
||
import lombok.Value; | ||
|
||
@Value | ||
public class WorldJavaOnly { | ||
private final String foo = "java_only"; | ||
} |
11 changes: 11 additions & 0 deletions
11
.../scala-java-annotation-processor/java_only/src/test/java/org/hello/WorldJavaOnlyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.hello; | ||
|
||
import org.junit.Test; | ||
|
||
public class WorldJavaOnlyTest { | ||
|
||
@Test | ||
public void foo() { | ||
new WorldJavaOnly().foo(); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/functionalTest/resources/projects/scala-java-annotation-processor/lombok.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lombok.accessors.fluent=true |
14 changes: 14 additions & 0 deletions
14
...onalTest/resources/projects/scala-java-annotation-processor/mixed_scala_java/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
8 changes: 8 additions & 0 deletions
8
...s/scala-java-annotation-processor/mixed_scala_java/src/main/java/org/hello/WorldJava.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.hello; | ||
|
||
import lombok.Value; | ||
|
||
@Value | ||
public class WorldJava { | ||
private final String foo = "java"; | ||
} |
7 changes: 7 additions & 0 deletions
7
...cala-java-annotation-processor/mixed_scala_java/src/main/scala/org/hello/WorldScala.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.hello | ||
|
||
class WorldScala { | ||
private val worldJava = new WorldJava() | ||
|
||
def foo() = worldJava.foo() | ||
} |
11 changes: 11 additions & 0 deletions
11
...ala-java-annotation-processor/mixed_scala_java/src/test/java/org/hello/WorldJavaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.hello; | ||
|
||
import org.junit.Test; | ||
|
||
public class WorldJavaTest { | ||
|
||
@Test | ||
public void foo() { | ||
new WorldJava().foo(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...java-annotation-processor/mixed_scala_java/src/test/scala/org/hello/WorldScalaSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/functionalTest/resources/projects/scala-java-annotation-processor/settings.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include 'java_only', 'mixed_scala_java' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters