Skip to content

Commit 5104de6

Browse files
committed
Support file and package exclusions for Scala 3.3.4+
1 parent 61b6991 commit 5104de6

25 files changed

+320
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ If you want to customize plugin's configuration parameters used by compilation s
328328
Read [SBT SCoverage Plugin documentation](https://github.com/scoverage/sbt-scoverage) for more information about
329329
[excludedPackages and excludedFiles](https://github.com/scoverage/sbt-scoverage?tab=readme-ov-file#exclude-classes-and-packages-and-files).
330330

331-
File and package exclusions are supported for Scala 2 and Scala 3 since version `3.4.2`.
331+
File and package exclusions are supported for Scala 2, Scala [`3.3.4`-`3.4.0`) and `3.4.2`+.
332332

333333
### Checking minimum test coverage level
334334

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invoker.goals=clean verify site -e -ntp
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>it.scoverage-maven-plugin</groupId>
9+
<artifactId>integration_tests_parent</artifactId>
10+
<version>1.0-SNAPSHOT</version>
11+
<relativePath>../integration_tests_parent/pom.xml</relativePath>
12+
</parent>
13+
14+
<artifactId>test_exclusion</artifactId>
15+
<version>1.0-SNAPSHOT</version>
16+
<packaging>jar</packaging>
17+
<name>Test Scoverage exclusion</name>
18+
<description>Test Scoverage exclusion</description>
19+
20+
<properties>
21+
<scala.compat.version>3</scala.compat.version>
22+
<scala.version>3.3.3</scala.version>
23+
<scala.library.artifact.id>scala3-library_3</scala.library.artifact.id>
24+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
25+
</properties>
26+
27+
<build>
28+
<plugins>
29+
<plugin>
30+
<groupId>org.apache.maven.plugins</groupId>
31+
<artifactId>maven-compiler-plugin</artifactId>
32+
</plugin>
33+
<plugin>
34+
<groupId>net.alchim31.maven</groupId>
35+
<artifactId>scala-maven-plugin</artifactId>
36+
</plugin>
37+
<plugin>
38+
<groupId>org.scalatest</groupId>
39+
<artifactId>scalatest-maven-plugin</artifactId>
40+
</plugin>
41+
<plugin>
42+
<groupId>@project.groupId@</groupId>
43+
<artifactId>@project.artifactId@</artifactId>
44+
<configuration>
45+
<excludedPackages>.*package02.*;.*package05</excludedPackages>
46+
<excludedFiles>.*Package03HelloService.*;.*Package03ByeService</excludedFiles>
47+
</configuration>
48+
</plugin>
49+
</plugins>
50+
</build>
51+
</project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.package01
2+
3+
object Package01HelloService {
4+
5+
// gonna be included in coverage report
6+
def hello: String = "Hello from package01"
7+
8+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// gonna be excluded from coverage report by package exclusion
2+
package org.package02.nested02
3+
4+
object ImGonnaBeExcludedCauseImInPackage02Nested02 {
5+
6+
def hello: String = "Hello from package02.nested02"
7+
8+
}
9+
10+
object SameStoryBro {
11+
12+
def hello: String = "Hello from package02.nested02 again"
13+
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// gonna be excluded from coverage report by package exclusion
2+
package org.package02
3+
4+
object ImGonnaBeExcludedCauseImInPackage02 {
5+
6+
def hello: String = "Hello from package02"
7+
8+
}
9+
10+
object SameStoryBro {
11+
12+
def hello: String = "Hello from package02 again"
13+
14+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.package03
2+
3+
object Package03ByeService {
4+
5+
// gonna be excluded from coverage report by file exclusion
6+
def bye: String = "Bye from package03"
7+
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.package03
2+
3+
object Package03HelloService1 {
4+
5+
// gonna be excluded from coverage report by file exclusion
6+
def hello: String = "Hello from package03 service 1"
7+
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.package03
2+
3+
object Package03HelloService2 {
4+
5+
// gonna be excluded from coverage report by file exclusion
6+
def hello: String = "Hello from package03 service 2"
7+
8+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// gonna be excluded from coverage report by package exclusion
2+
package org.package05
3+
4+
object ImGonnaBeExcludedCauseImInPackage05 {
5+
6+
def hello: String = "Hello from package05"
7+
8+
}
9+
10+
object SameStoryBro {
11+
12+
def hello: String = "Hello from package05 again"
13+
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.package01
2+
3+
import org.scalatest.wordspec.AnyWordSpec
4+
5+
class Package01HelloServiceTest extends AnyWordSpec {
6+
7+
"Package01HelloService" should {
8+
"say hello" in {
9+
assert(Package01HelloService.hello == "Hello from package01")
10+
}
11+
}
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
try {
2+
3+
def logFile = new File(basedir, "build.log")
4+
def lines = logFile.readLines()
5+
assert lines.contains("[WARNING] Package exclusion is supported for Scala [3.3.4-3.4.0) or 3.4.2+")
6+
assert lines.contains("[WARNING] File exclusion is supported for Scala [3.3.4-3.4.0) or 3.4.2+")
7+
assert lines.contains("[INFO] Statement coverage.: 10.00%")
8+
9+
return true
10+
11+
} catch (Throwable e) {
12+
e.printStackTrace()
13+
return false
14+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invoker.goals=clean verify site -e -ntp
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>it.scoverage-maven-plugin</groupId>
9+
<artifactId>integration_tests_parent</artifactId>
10+
<version>1.0-SNAPSHOT</version>
11+
<relativePath>../integration_tests_parent/pom.xml</relativePath>
12+
</parent>
13+
14+
<artifactId>test_exclusion</artifactId>
15+
<version>1.0-SNAPSHOT</version>
16+
<packaging>jar</packaging>
17+
<name>Test Scoverage exclusion</name>
18+
<description>Test Scoverage exclusion</description>
19+
20+
<properties>
21+
<scala.compat.version>3</scala.compat.version>
22+
<scala.version>3.3.4</scala.version>
23+
<scala.library.artifact.id>scala3-library_3</scala.library.artifact.id>
24+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
25+
</properties>
26+
27+
<build>
28+
<plugins>
29+
<plugin>
30+
<groupId>org.apache.maven.plugins</groupId>
31+
<artifactId>maven-compiler-plugin</artifactId>
32+
</plugin>
33+
<plugin>
34+
<groupId>net.alchim31.maven</groupId>
35+
<artifactId>scala-maven-plugin</artifactId>
36+
</plugin>
37+
<plugin>
38+
<groupId>org.scalatest</groupId>
39+
<artifactId>scalatest-maven-plugin</artifactId>
40+
</plugin>
41+
<plugin>
42+
<groupId>@project.groupId@</groupId>
43+
<artifactId>@project.artifactId@</artifactId>
44+
<configuration>
45+
<excludedPackages>.*package02.*;.*package05</excludedPackages>
46+
<excludedFiles>.*Package03HelloService.*;.*Package03ByeService</excludedFiles>
47+
</configuration>
48+
</plugin>
49+
</plugins>
50+
</build>
51+
</project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.package01
2+
3+
object Package01HelloService {
4+
5+
// gonna be included in coverage report
6+
def hello: String = "Hello from package01"
7+
8+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// gonna be excluded from coverage report by package exclusion
2+
package org.package02.nested02
3+
4+
object ImGonnaBeExcludedCauseImInPackage02Nested02 {
5+
6+
def hello: String = "Hello from package02.nested02"
7+
8+
}
9+
10+
object SameStoryBro {
11+
12+
def hello: String = "Hello from package02.nested02 again"
13+
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// gonna be excluded from coverage report by package exclusion
2+
package org.package02
3+
4+
object ImGonnaBeExcludedCauseImInPackage02 {
5+
6+
def hello: String = "Hello from package02"
7+
8+
}
9+
10+
object SameStoryBro {
11+
12+
def hello: String = "Hello from package02 again"
13+
14+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.package03
2+
3+
object Package03ByeService {
4+
5+
// gonna be excluded from coverage report by file exclusion
6+
def bye: String = "Bye from package03"
7+
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.package03
2+
3+
object Package03HelloService1 {
4+
5+
// gonna be excluded from coverage report by file exclusion
6+
def hello: String = "Hello from package03 service 1"
7+
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.package03
2+
3+
object Package03HelloService2 {
4+
5+
// gonna be excluded from coverage report by file exclusion
6+
def hello: String = "Hello from package03 service 2"
7+
8+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// gonna be excluded from coverage report by package exclusion
2+
package org.package05
3+
4+
object ImGonnaBeExcludedCauseImInPackage05 {
5+
6+
def hello: String = "Hello from package05"
7+
8+
}
9+
10+
object SameStoryBro {
11+
12+
def hello: String = "Hello from package05 again"
13+
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.package01
2+
3+
import org.scalatest.wordspec.AnyWordSpec
4+
5+
class Package01HelloServiceTest extends AnyWordSpec {
6+
7+
"Package01HelloService" should {
8+
"say hello" in {
9+
assert(Package01HelloService.hello == "Hello from package01")
10+
}
11+
}
12+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
try {
2+
3+
def logFile = new File(basedir, "build.log")
4+
def lines = logFile.readLines()
5+
assert lines.contains("[INFO] Statement coverage.: 100.00%")
6+
assert lines.contains("[INFO] Branch coverage....: 100.00%")
7+
8+
def scoverageFile = new File(basedir, "target/scoverage.xml")
9+
assert scoverageFile.exists()
10+
11+
def reportFile = new File(basedir, "target/site/scoverage/index.html")
12+
assert reportFile.exists()
13+
14+
return true
15+
16+
} catch (Throwable e) {
17+
e.printStackTrace()
18+
return false
19+
}

src/it/test_exclusion_Scala3_4_1/validate.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ try {
22

33
def logFile = new File(basedir, "build.log")
44
def lines = logFile.readLines()
5-
assert lines.contains("[WARNING] Package exclusion is supported since Scala 3.4.2")
6-
assert lines.contains("[WARNING] File exclusion is supported since Scala 3.4.2")
5+
assert lines.contains("[WARNING] Package exclusion is supported for Scala [3.3.4-3.4.0) or 3.4.2+")
6+
assert lines.contains("[WARNING] File exclusion is supported for Scala [3.3.4-3.4.0) or 3.4.2+")
77
assert lines.contains("[INFO] Statement coverage.: 10.00%")
88

99
return true

src/main/java/org/scoverage/plugin/SCoveragePreCompileMojo.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ public void execute() throws MojoExecutionException
278278
try
279279
{
280280
boolean scala2 = resolvedScalaVersion.isScala2();
281+
boolean filePackageExclusionSupportingScala3 =
282+
resolvedScalaVersion.isAtLeast( "3.4.2" ) ||
283+
// backported to Scala 3.3 LTS
284+
( resolvedScalaVersion.full.startsWith( "3.3." ) && resolvedScalaVersion.isAtLeast( "3.3.4" ) );
281285

282286
List<Artifact> pluginArtifacts = getScalaScoveragePluginArtifacts( resolvedScalaVersion );
283287
if ( scala2 ) // Scala 3 doesn't need scalac-scoverage-runtime
@@ -300,13 +304,13 @@ public void execute() throws MojoExecutionException
300304
arg = SCALA2_EXCLUDED_PACKAGES_OPTION + excludedPackages.replace( "(empty)", "<empty>" );
301305
_scalacOptions = _scalacOptions + SPACE + quoteArgument( arg );
302306
addScalacArgs = addScalacArgs + PIPE + arg;
303-
} else if ( resolvedScalaVersion.isAtLeast( "3.4.2" ) ) {
307+
} else if ( filePackageExclusionSupportingScala3 ) {
304308
String scala3FormatExcludedPackages = excludedPackages.replace( ";", "," );
305309
arg = SCALA3_EXCLUDED_PACKAGES_OPTION + scala3FormatExcludedPackages;
306310
_scalacOptions = _scalacOptions + SPACE + quoteArgument( arg );
307311
addScalacArgs = addScalacArgs + PIPE + arg;
308312
} else {
309-
getLog().warn( "Package exclusion is supported since Scala 3.4.2" );
313+
getLog().warn( "Package exclusion is supported for Scala [3.3.4-3.4.0) or 3.4.2+" );
310314
}
311315
}
312316

@@ -316,13 +320,13 @@ public void execute() throws MojoExecutionException
316320
arg = SCALA2_EXCLUDED_FILES_OPTION + excludedFiles;
317321
_scalacOptions = _scalacOptions + SPACE + quoteArgument( arg );
318322
addScalacArgs = addScalacArgs + PIPE + arg;
319-
} else if ( resolvedScalaVersion.isAtLeast( "3.4.2" ) ) {
323+
} else if ( filePackageExclusionSupportingScala3 ) {
320324
String scala3FormatExcludedFiles = excludedFiles.replace( ";", "," );
321325
arg = SCALA3_EXCLUDED_FILES_OPTION + scala3FormatExcludedFiles;
322326
_scalacOptions = _scalacOptions + SPACE + quoteArgument( arg );
323327
addScalacArgs = addScalacArgs + PIPE + arg;
324328
} else {
325-
getLog().warn( "File exclusion is supported since Scala 3.4.2" );
329+
getLog().warn( "File exclusion is supported for Scala [3.3.4-3.4.0) or 3.4.2+" );
326330
}
327331
}
328332

0 commit comments

Comments
 (0)