@@ -14,18 +14,21 @@ class ScoveragePlugin(val global: Global) extends Plugin {
14
14
15
15
override val name : String = " scoverage"
16
16
override val description : String = " scoverage code coverage compiler plugin"
17
- val instrumentationComponent = new ScoverageInstrumentationComponent (global)
17
+ private val (extraAfterPhase, extraBeforePhase) = processPhaseOptions(pluginOptions)
18
+ val instrumentationComponent = new ScoverageInstrumentationComponent (global, extraAfterPhase, extraBeforePhase)
18
19
override val components : List [PluginComponent ] = List (instrumentationComponent)
19
20
20
21
override def processOptions (opts : List [String ], error : String => Unit ) {
21
22
val options = new ScoverageOptions
22
- for ( opt <- opts ) {
23
+ for (opt <- opts) {
23
24
if (opt.startsWith(" excludedPackages:" )) {
24
25
options.excludedPackages = opt.substring(" excludedPackages:" .length).split(" ;" ).map(_.trim).filterNot(_.isEmpty)
25
26
} else if (opt.startsWith(" excludedFiles:" )) {
26
27
options.excludedFiles = opt.substring(" excludedFiles:" .length).split(" ;" ).map(_.trim).filterNot(_.isEmpty)
27
28
} else if (opt.startsWith(" dataDir:" )) {
28
29
options.dataDir = opt.substring(" dataDir:" .length)
30
+ } else if (opt.startsWith(" extraAfterPhase:" ) || opt.startsWith(" extraBeforePhase:" )){
31
+ // skip here, these flags are processed elsewhere
29
32
} else {
30
33
error(" Unknown option: " + opt)
31
34
}
@@ -39,9 +42,32 @@ class ScoveragePlugin(val global: Global) extends Plugin {
39
42
" -P:scoverage:dataDir:<pathtodatadir> where the coverage files should be written\n " ,
40
43
" -P:scoverage:excludedPackages:<regex>;<regex> semicolon separated list of regexs for packages to exclude" ,
41
44
" -P:scoverage:excludedFiles:<regex>;<regex> semicolon separated list of regexs for paths to exclude" ,
45
+ " -P:scoverage:extraAfterPhase:<phaseName> phase after which scoverage phase runs (must be after typer phase)" ,
46
+ " -P:scoverage:extraBeforePhase:<phaseName> phase before which scoverage phase runs (must be before patmat phase)" ,
42
47
" Any classes whose fully qualified name matches the regex will" ,
43
48
" be excluded from coverage."
44
49
).mkString(" \n " ))
50
+
51
+ // copied from scala 2.11
52
+ private def pluginOptions : List [String ] = {
53
+ // Process plugin options of form plugin:option
54
+ def namec = name + " :"
55
+ global.settings.pluginOptions.value filter (_ startsWith namec) map (_ stripPrefix namec)
56
+ }
57
+
58
+ private def processPhaseOptions (opts : List [String ]): (Option [String ], Option [String ]) = {
59
+ var afterPhase : Option [String ] = None
60
+ var beforePhase : Option [String ] = None
61
+ for (opt <- opts) {
62
+ if (opt.startsWith(" extraAfterPhase:" )) {
63
+ afterPhase = Some (opt.substring(" extraAfterPhase:" .length))
64
+ }
65
+ if (opt.startsWith(" extraBeforePhase:" )) {
66
+ beforePhase = Some (opt.substring(" extraBeforePhase:" .length))
67
+ }
68
+ }
69
+ (afterPhase, beforePhase)
70
+ }
45
71
}
46
72
47
73
class ScoverageOptions {
@@ -50,7 +76,7 @@ class ScoverageOptions {
50
76
var dataDir : String = IOUtils .getTempPath
51
77
}
52
78
53
- class ScoverageInstrumentationComponent (val global : Global )
79
+ class ScoverageInstrumentationComponent (val global : Global , extraAfterPhase : Option [ String ], extraBeforePhase : Option [ String ] )
54
80
extends PluginComponent
55
81
with TypingTransformers
56
82
with Transform {
@@ -61,8 +87,8 @@ class ScoverageInstrumentationComponent(val global: Global)
61
87
val coverage = new Coverage
62
88
63
89
override val phaseName : String = " scoverage-instrumentation"
64
- override val runsAfter : List [String ] = List (" typer" )
65
- override val runsBefore = List [String ](" patmat" )
90
+ override val runsAfter : List [String ] = List (" typer" ) ::: extraAfterPhase.toList
91
+ override val runsBefore : List [String ] = List (" patmat" ) ::: extraBeforePhase.toList
66
92
67
93
/**
68
94
* Our options are not provided at construction time, but shortly after,
0 commit comments