@@ -11,6 +11,7 @@ import scala.reflect.internal.util.Position
11
11
*/
12
12
trait CoverageFilter {
13
13
def isClassIncluded (className : String ): Boolean
14
+ def isFileIncluded (file : SourceFile ): Boolean
14
15
def isLineIncluded (position : Position ): Boolean
15
16
def getExcludedLineNumbers (sourceFile : SourceFile ): List [Range ]
16
17
}
@@ -19,18 +20,21 @@ object AllCoverageFilter extends CoverageFilter {
19
20
override def getExcludedLineNumbers (sourceFile : SourceFile ): List [Range ] = Nil
20
21
override def isLineIncluded (position : Position ): Boolean = true
21
22
override def isClassIncluded (className : String ): Boolean = true
23
+ override def isFileIncluded (file : SourceFile ): Boolean = true
22
24
}
23
25
24
- class RegexCoverageFilter (excludedPackages : Seq [String ]) extends CoverageFilter {
26
+ class RegexCoverageFilter (excludedPackages : Seq [String ],
27
+ excludedFiles : Seq [String ]) extends CoverageFilter {
25
28
26
29
val excludedClassNamePatterns = excludedPackages.map(_.r.pattern)
30
+ val excludedFilePatterns = excludedFiles.map(_.r.pattern)
31
+
27
32
/**
28
33
* We cache the excluded ranges to avoid scanning the source code files
29
34
* repeatedly. For a large project there might be a lot of source code
30
35
* data, so we only hold a weak reference.
31
36
*/
32
- val linesExcludedByScoverageCommentsCache : mutable.Map [SourceFile , List [Range ]] =
33
- mutable.WeakHashMap .empty
37
+ val linesExcludedByScoverageCommentsCache : mutable.Map [SourceFile , List [Range ]] = mutable.WeakHashMap .empty
34
38
35
39
final val scoverageExclusionCommentsRegex =
36
40
""" (?ms)^\s*//\s*(\$COVERAGE-OFF\$).*?(^\s*//\s*\$COVERAGE-ON\$|\Z)""" .r
@@ -39,9 +43,13 @@ class RegexCoverageFilter(excludedPackages: Seq[String]) extends CoverageFilter
39
43
* True if the given className has not been excluded by the
40
44
* `excludedPackages` option.
41
45
*/
42
- def isClassIncluded (className : String ): Boolean = {
43
- excludedClassNamePatterns.isEmpty ||
44
- ! excludedClassNamePatterns.exists(_.matcher(className).matches)
46
+ override def isClassIncluded (className : String ): Boolean = {
47
+ excludedClassNamePatterns.isEmpty || ! excludedClassNamePatterns.exists(_.matcher(className).matches)
48
+ }
49
+
50
+ override def isFileIncluded (file : SourceFile ): Boolean = {
51
+ def isFileMatch (file: SourceFile ) = excludedFilePatterns.exists(_.matcher(file.path).matches)
52
+ excludedFilePatterns.isEmpty || ! isFileMatch(file)
45
53
}
46
54
47
55
/**
0 commit comments