Skip to content

Commit 48c86db

Browse files
committed
Merge remote-tracking branch 'remotes/eyalroth/issues/121/java-platform-compatibility'
2 parents 780dad5 + 7c003ce commit 48c86db

File tree

22 files changed

+235
-70
lines changed

22 files changed

+235
-70
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ You can find instructions on how to apply the plugin at: http://plugins.gradle.
2323
When applied on a project with sub-projects, the plugin will create the aggregation task `aggregateScoverage`, which
2424
will first generate reports for each project individually (including the parent project), and will then generate an
2525
aggregated result based on these reports.
26+
27+
The plugin must be applied on a sub-project for it to be included in the aggregated; applying the plugin on a
28+
project _does not_ automatically apply it on sub-projects.
2629

2730
The aggregated report will override the parent-project specific report (`parent-project/build/reports/scoverage`).
2831

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.scoverage;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
public class MultiModulePluginNotConfiguredForScalaTest extends ScoverageFunctionalTest {
7+
8+
public MultiModulePluginNotConfiguredForScalaTest() {
9+
super("multi-module-plugin-not-configured-for-scala");
10+
}
11+
12+
@Test
13+
public void checkAndAggregateScoverage() throws Exception {
14+
15+
AssertableBuildResult result = run("clean", ScoveragePlugin.getCHECK_NAME(),
16+
ScoveragePlugin.getAGGREGATE_NAME());
17+
18+
result.assertTaskSkipped(ScoveragePlugin.getREPORT_NAME());
19+
result.assertTaskSkipped("scala_only:" + ScoveragePlugin.getREPORT_NAME());
20+
result.assertTaskSkipped("java_only:" + ScoveragePlugin.getREPORT_NAME());
21+
result.assertTaskSkipped(ScoveragePlugin.getCHECK_NAME());
22+
result.assertTaskSkipped("scala_only:" + ScoveragePlugin.getCHECK_NAME());
23+
result.assertTaskSkipped("java_only:" + ScoveragePlugin.getCHECK_NAME());
24+
result.assertTaskSkipped(ScoveragePlugin.getAGGREGATE_NAME());
25+
26+
assertReportDirsEmpty();
27+
28+
Assert.assertTrue(result.getResult().getOutput().contains("Scala sub-project 'scala_only' doesn't have Scoverage applied"));
29+
Assert.assertFalse(result.getResult().getOutput().contains("Scala sub-project 'java_only' doesn't have Scoverage applied"));
30+
}
31+
32+
private void assertReportDirsEmpty() {
33+
34+
Assert.assertFalse(reportDir().exists());
35+
Assert.assertFalse(reportDir(projectDir().toPath().resolve("scala_only").toFile()).exists());
36+
Assert.assertFalse(reportDir(projectDir().toPath().resolve("java_only").toFile()).exists());
37+
}
38+
}

src/functionalTest/java/org.scoverage/ScalaJavaMultiModuleTest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@ public void checkAndAggregateScoverage() throws Exception {
1818
AssertableBuildResult result = run("clean", ScoveragePlugin.getCHECK_NAME(),
1919
ScoveragePlugin.getAGGREGATE_NAME());
2020

21-
result.assertTaskOutcome("java_only:" + ScoveragePlugin.getCOMPILE_NAME(), TaskOutcome.NO_SOURCE);
21+
result.assertTaskSkipped("java_only:" + ScoveragePlugin.getCOMPILE_NAME());
2222

2323
result.assertTaskSkipped(ScoveragePlugin.getREPORT_NAME());
2424
result.assertTaskSucceeded("scala_only:" + ScoveragePlugin.getREPORT_NAME());
2525
result.assertTaskSucceeded("mixed_scala_java:" + ScoveragePlugin.getREPORT_NAME());
2626
result.assertTaskSkipped("java_only:" + ScoveragePlugin.getREPORT_NAME());
27+
2728
result.assertTaskSucceeded(ScoveragePlugin.getCHECK_NAME());
2829
result.assertTaskSucceeded("scala_only:" + ScoveragePlugin.getCHECK_NAME());
2930
result.assertTaskSucceeded("mixed_scala_java:" + ScoveragePlugin.getCHECK_NAME());
3031
result.assertTaskSkipped("java_only:" + ScoveragePlugin.getCHECK_NAME());
32+
3133
result.assertTaskSucceeded(ScoveragePlugin.getAGGREGATE_NAME());
3234

3335
assertAllReportFilesExist();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
plugins {
2+
id 'org.scoverage' apply false
3+
}
4+
5+
description = 'a multi-module Scala and Java project that defines scoverage only on root but not on subprojects'
6+
7+
allprojects {
8+
repositories {
9+
jcenter()
10+
}
11+
}
12+
13+
subprojects { p ->
14+
if (p.name != 'dependencies') {
15+
apply plugin: 'java'
16+
dependencies {
17+
implementation platform(project(':dependencies'))
18+
testCompile group: 'org.junit.platform', name: 'junit-platform-runner'
19+
}
20+
21+
test {
22+
useJUnitPlatform()
23+
}
24+
}
25+
}
26+
27+
apply plugin: 'org.scoverage'
28+
scoverage {
29+
minimumRate = 0.5
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
plugins {
2+
id 'java-platform'
3+
}
4+
5+
dependencies {
6+
constraints {
7+
api group: 'org.scala-lang', name: 'scala-library', version: "${scalaVersionMajor}.${scalaVersionMinor}.${scalaVersionBuild}"
8+
9+
api group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junitVersion
10+
api group: 'org.junit.platform', name: 'junit-platform-runner', version: junitPlatformVersion
11+
12+
api group: 'org.scalatest', name: "scalatest_${scalaVersionMajor}.${scalaVersionMinor}", version: scalatestVersion
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dependencies {
2+
testRuntime group: 'org.junit.vintage', name: 'junit-vintage-engine'
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.hello;
2+
3+
public class WorldJavaOnly {
4+
5+
public String foo() {
6+
String s = "java_only" + "a";
7+
return s;
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.hello;
2+
3+
import org.junit.Test;
4+
5+
public class WorldJavaOnlyTest {
6+
7+
@Test
8+
public void foo() {
9+
new WorldJavaOnly().foo();
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apply plugin: 'scala'
2+
// apply plugin: 'org.scoverage' // Oops forgot to configure scoverage
3+
4+
dependencies {
5+
compile group: 'org.scala-lang', name: 'scala-library'
6+
7+
testRuntime group: 'org.junit.vintage', name: 'junit-vintage-engine'
8+
testCompile group: 'org.scalatest', name: "scalatest_${scalaVersionMajor}.${scalaVersionMinor}"
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.hello
2+
3+
class WorldScalaOnly {
4+
5+
def foo(): String = {
6+
val s = "scala_only" + "a"
7+
s
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.hello
2+
3+
import org.junit.runner.RunWith
4+
import org.scalatest.FunSuite
5+
import org.scalatest.junit.JUnitRunner
6+
7+
@RunWith(classOf[JUnitRunner])
8+
class WorldScalaOnlySuite extends FunSuite {
9+
10+
test("foo") {
11+
new WorldScalaOnly().foo()
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include 'dependencies', 'java_only', 'scala_only'

src/functionalTest/resources/projects/scala-java-multi-module/build.gradle

+5-9
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ plugins {
22
id 'org.scoverage' apply false
33
}
44

5+
description = 'a multi-module Scala and Java project that builds successfully with 100% coverage'
6+
57
allprojects {
68
repositories {
79
jcenter()
810
}
911
}
1012

11-
description = 'a multi-module Scala and Java project that builds successfully with 100% coverage'
12-
13-
apply plugin: 'org.scoverage'
14-
15-
allprojects {
13+
subprojects {
14+
apply plugin: 'java'
1615

1716
dependencies {
1817
testCompile group: 'org.junit.platform', name: 'junit-platform-runner', version: junitPlatformVersion
@@ -21,12 +20,9 @@ allprojects {
2120
test {
2221
useJUnitPlatform()
2322
}
24-
25-
scoverage {
26-
minimumRate = 0.5
27-
}
2823
}
2924

25+
apply plugin: 'org.scoverage'
3026
scoverage {
3127
minimumRate = 0.5
3228
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
apply plugin: 'java'
2-
31
dependencies {
4-
52
testRuntime group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junitVersion
63
}

src/functionalTest/resources/projects/scala-java-multi-module/mixed_scala_java/build.gradle

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
apply plugin: 'java'
21
apply plugin: 'scala'
3-
apply plugin: 'org.scoverage'
42

53
dependencies {
64
compile group: 'org.scala-lang', name: 'scala-library', version: "${scalaVersionMajor}.${scalaVersionMinor}.${scalaVersionBuild}"
@@ -16,4 +14,9 @@ ext.configureSources = { set, name ->
1614
set.java.srcDirs = []
1715
}
1816
configureSources(sourceSets.main, 'main')
19-
configureSources(sourceSets.test, 'test')
17+
configureSources(sourceSets.test, 'test')
18+
19+
apply plugin: 'org.scoverage'
20+
scoverage {
21+
minimumRate = 0.5
22+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
apply plugin: 'scala'
2-
apply plugin: 'org.scoverage'
32

43
dependencies {
54
compile group: 'org.scala-lang', name: 'scala-library', version: "${scalaVersionMajor}.${scalaVersionMinor}.${scalaVersionBuild}"
@@ -8,3 +7,8 @@ dependencies {
87

98
testCompile group: 'org.scalatest', name: "scalatest_${scalaVersionMajor}.${scalaVersionMinor}", version: scalatestVersion
109
}
10+
11+
apply plugin: 'org.scoverage'
12+
scoverage {
13+
minimumRate = 0.5
14+
}

src/functionalTest/resources/projects/scala-multi-module-cross-version/build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id 'org.scoverage'
2+
id 'org.scoverage' apply false
33
}
44

55
allprojects {
@@ -14,6 +14,7 @@ allprojects {
1414

1515
apply plugin: 'java'
1616
apply plugin: 'scala'
17+
apply plugin: 'org.scoverage'
1718

1819
dependencies {
1920
testRuntime group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junitVersion

src/functionalTest/resources/projects/scala-multi-module-multiple-test-tasks/build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id 'org.scoverage'
2+
id 'org.scoverage' apply false
33
}
44

55
allprojects {
@@ -14,6 +14,7 @@ allprojects {
1414

1515
apply plugin: 'java'
1616
apply plugin: 'scala'
17+
apply plugin: 'org.scoverage'
1718

1819
dependencies {
1920
compile group: 'org.scala-lang', name: 'scala-library', version: "${scalaVersionMajor}.${scalaVersionMinor}.${scalaVersionBuild}"
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
11
plugins {
2-
id 'org.scoverage'
2+
id 'org.scoverage' apply false
33
}
44

5-
allprojects {
5+
description = 'a multi-module Scala project that builds successfully with 100% coverage'
6+
7+
allprojects { p ->
68
repositories {
79
jcenter()
810
}
9-
}
1011

11-
description = 'a multi-module Scala project that builds successfully with 100% coverage'
12+
if (p.name != 'dependencies') {
13+
apply plugin: 'java'
14+
apply plugin: 'scala'
15+
apply plugin: 'org.scoverage'
1216

13-
allprojects {
17+
dependencies {
18+
implementation platform(project(':dependencies'))
1419

15-
apply plugin: 'java'
16-
apply plugin: 'scala'
20+
compile group: 'org.scala-lang', name: 'scala-library'
1721

18-
dependencies {
19-
compile group: 'org.scala-lang', name: 'scala-library', version: "${scalaVersionMajor}.${scalaVersionMinor}.${scalaVersionBuild}"
22+
testRuntime group: 'org.junit.vintage', name: 'junit-vintage-engine'
23+
testCompile group: 'org.junit.platform', name: 'junit-platform-runner'
2024

21-
testRuntime group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junitVersion
22-
testCompile group: 'org.junit.platform', name: 'junit-platform-runner', version: junitPlatformVersion
25+
testCompile group: 'org.scalatest', name: "scalatest_${scalaVersionMajor}.${scalaVersionMinor}"
26+
}
2327

24-
testCompile group: 'org.scalatest', name: "scalatest_${scalaVersionMajor}.${scalaVersionMinor}", version: scalatestVersion
25-
}
26-
27-
test {
28-
useJUnitPlatform()
29-
}
28+
test {
29+
useJUnitPlatform()
30+
}
3031

31-
scoverage {
32-
minimumRate = 0.5
32+
scoverage {
33+
minimumRate = 0.5
34+
}
3335
}
3436
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
plugins {
2+
id 'java-platform'
3+
}
4+
5+
dependencies {
6+
constraints {
7+
api group: 'org.scala-lang', name: 'scala-library', version: "${scalaVersionMajor}.${scalaVersionMinor}.${scalaVersionBuild}"
8+
9+
api group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junitVersion
10+
api group: 'org.junit.platform', name: 'junit-platform-runner', version: junitPlatformVersion
11+
12+
api group: 'org.scalatest', name: "scalatest_${scalaVersionMajor}.${scalaVersionMinor}", version: scalatestVersion
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include 'a', 'b', 'common'
1+
include 'dependencies', 'a', 'b', 'common'

0 commit comments

Comments
 (0)