@@ -2,8 +2,10 @@ package org.scoverage
2
2
3
3
import org.gradle.api.Action
4
4
import org.gradle.api.Project
5
+ import org.gradle.api.artifacts.ResolvedConfiguration
5
6
import org.gradle.api.plugins.JavaPlugin
6
7
import org.gradle.api.plugins.scala.ScalaPlugin
8
+ import org.gradle.api.tasks.JavaExec
7
9
import org.gradle.api.tasks.SourceSet
8
10
import org.gradle.api.tasks.testing.Test
9
11
@@ -14,6 +16,14 @@ import org.gradle.api.tasks.testing.Test
14
16
*/
15
17
class ScoverageExtension {
16
18
19
+ /* * a directory to write working files to */
20
+ File dataDir
21
+ /* * a directory to write final output to */
22
+ File reportDir
23
+ /* * sources to highlight */
24
+ SourceSet sourceSet
25
+
26
+
17
27
ScoverageExtension (Project project ) {
18
28
19
29
project. plugins. apply(JavaPlugin . class);
@@ -22,11 +32,11 @@ class ScoverageExtension {
22
32
23
33
project. configurations. create(ScoveragePlugin . CONFIGURATION_NAME ) {
24
34
visible = false
25
- transitive = false
35
+ transitive = true
26
36
description = ' Scoverage dependencies'
27
37
}
28
38
29
- project. sourceSets. create(ScoveragePlugin . CONFIGURATION_NAME ) {
39
+ sourceSet = project. sourceSets. create(ScoveragePlugin . CONFIGURATION_NAME ) {
30
40
def mainSourceSet = project. sourceSets. getByName(SourceSet . MAIN_SOURCE_SET_NAME )
31
41
32
42
java. source(mainSourceSet. java)
@@ -44,34 +54,63 @@ class ScoverageExtension {
44
54
dependsOn(project. tasks[ScoveragePlugin . TEST_NAME ])
45
55
}
46
56
57
+ project. tasks. create(ScoveragePlugin . REPORT_NAME , JavaExec . class) {
58
+ dependsOn(project. tasks[ScoveragePlugin . TEST_NAME ])
59
+ }
60
+
61
+ dataDir = new File (project. buildDir, ' scoverage' )
62
+ reportDir = new File (project. buildDir, ' reports' + File . separatorChar + ' scoverage' )
63
+
47
64
}
48
65
49
66
private Action<Project > configureRuntimeOptions = new Action<Project > () {
50
67
51
68
@Override
52
69
void execute (Project t ) {
70
+
71
+ def extension = ScoveragePlugin . extensionIn(t)
72
+ extension. dataDir. mkdirs()
73
+ extension. reportDir. mkdirs()
74
+
75
+ ResolvedConfiguration s = t. configurations[ScoveragePlugin . CONFIGURATION_NAME ]. resolvedConfiguration
76
+ String pluginPath = s. getFirstLevelModuleDependencies(). iterator(). next(). moduleArtifacts. iterator(). next(). file. absolutePath
77
+
53
78
t. tasks[ScoveragePlugin . COMPILE_NAME ]. configure {
54
- List<String > plugin = [' -Xplugin:' + t. configurations[ScoveragePlugin . CONFIGURATION_NAME ]. singleFile]
79
+
80
+
81
+ List<String > plugin = [' -Xplugin:' + pluginPath]
55
82
List<String > parameters = scalaCompileOptions. additionalParameters
56
83
if (parameters != null ) {
57
84
plugin. addAll(parameters)
58
85
}
86
+ plugin. add(" -P:scoverage:dataDir:${ extension.dataDir.absolutePath} " . toString())
87
+ plugin. add(' -P:scoverage:excludedPackages:' )
59
88
scalaCompileOptions. additionalParameters = plugin
60
89
// exclude the scala libraries that are added to enable scala version detection
61
90
classpath + = t. configurations[ScoveragePlugin . CONFIGURATION_NAME ]
62
91
}
63
- t. tasks[ScoveragePlugin . TEST_NAME ]. configure {
64
- // TODO : fix this
65
- systemProperty ' scoverage.dataDir' , " ${ t.buildDir} /reports/${ t.extensions[ScoveragePlugin.CONFIGURATION_NAME].dataDirName} "
66
- systemProperty ' scoverage.basedir' , " ${ t.rootDir.absolutePath} " // for multi-module checking
67
92
93
+ t. tasks[ScoveragePlugin . TEST_NAME ]. configure {
68
94
def existingClasspath = classpath
69
95
classpath = t. files(t. sourceSets[ScoveragePlugin . CONFIGURATION_NAME ]. output. classesDir) +
70
- project. configurations[ScoveragePlugin . CONFIGURATION_NAME ] +
71
- existingClasspath
96
+ project. configurations[ScoveragePlugin . CONFIGURATION_NAME ] +
97
+ existingClasspath
98
+ }
99
+
100
+ t. tasks[ScoveragePlugin . REPORT_NAME ]. configure {
101
+ classpath = project. buildscript. configurations. classpath +
102
+ project. configurations[ScoveragePlugin . CONFIGURATION_NAME ]
103
+ main = ' org.scoverage.ScoverageReport'
104
+ args = [
105
+ extension. sourceSet. allSource. iterator(). next(). absolutePath,
106
+ extension. dataDir. absolutePath,
107
+ extension. reportDir. absolutePath
108
+ ]
109
+ inputs. dir(extension. dataDir)
110
+ outputs. dir(extension. reportDir)
72
111
}
112
+
73
113
}
74
114
}
75
115
76
- String dataDirName = ' scoverage'
77
116
}
0 commit comments