@@ -10,6 +10,9 @@ import org.gradle.api.plugins.scala.ScalaPlugin
10
10
import org.gradle.api.tasks.JavaExec
11
11
import org.gradle.api.tasks.SourceSet
12
12
import org.gradle.api.tasks.testing.Test
13
+ import org.gradle.util.GFileUtils
14
+
15
+ import java.util.concurrent.Callable
13
16
14
17
/**
15
18
* Defines a new SourceSet for the code to be instrumented.
@@ -55,18 +58,37 @@ class ScoverageExtension {
55
58
description = ' Scoverage dependencies'
56
59
}
57
60
58
- project. sourceSets. create(ScoveragePlugin . CONFIGURATION_NAME ) {
59
- def mainSourceSet = project. sourceSets. getByName(SourceSet . MAIN_SOURCE_SET_NAME )
61
+ def mainSourceSet = project. sourceSets. create(' scoverage' ) {
62
+ def original = project. sourceSets. getByName(SourceSet . MAIN_SOURCE_SET_NAME )
63
+
64
+ java. source(original. java)
65
+ scala. source(original. scala)
66
+
67
+ compileClasspath + = original. compileClasspath + project. configurations. scoverage
68
+ runtimeClasspath = it. output + project. configurations. runtime
69
+ }
70
+
71
+ def testSourceSet = project. sourceSets. create(' testScoverage' ) {
72
+ def original = project. sourceSets. getByName(SourceSet . TEST_SOURCE_SET_NAME )
60
73
61
- java. source(mainSourceSet . java)
62
- scala. source(mainSourceSet . scala)
74
+ java. source(original . java)
75
+ scala. source(original . scala)
63
76
64
- compileClasspath + = mainSourceSet. compileClasspath
65
- runtimeClasspath + = mainSourceSet. runtimeClasspath
77
+ compileClasspath = mainSourceSet. output + project . configurations . testCompile
78
+ runtimeClasspath = it . output + mainSourceSet. output + project . configurations . scoverage + project . configurations . testRuntime
66
79
}
67
80
68
81
project. tasks. create(ScoveragePlugin . TEST_NAME , Test . class) {
69
- dependsOn(project. tasks[ScoveragePlugin . COMPILE_NAME ])
82
+ conventionMapping. map(" testClassesDir" , new Callable<Object > () {
83
+ public Object call () throws Exception {
84
+ return testSourceSet. output. classesDir;
85
+ }
86
+ })
87
+ conventionMapping. map(" classpath" , new Callable<Object > () {
88
+ public Object call () throws Exception {
89
+ return testSourceSet. runtimeClasspath;
90
+ }
91
+ })
70
92
}
71
93
72
94
project. tasks. create(ScoveragePlugin . REPORT_NAME , JavaExec . class) {
@@ -116,20 +138,21 @@ class ScoverageExtension {
116
138
if (extension. highlighting) {
117
139
parameters. add(' -Yrangepos' )
118
140
}
119
- scalaCompileOptions . additionalParameters = parameters . collect { escape(it) }
120
- // exclude the scala libraries that are added to enable scala version detection
121
- classpath + = pluginDependencies
122
- }
123
-
124
- t . tasks[ ScoveragePlugin . TEST_NAME ] . configure {
125
- def existingClasspath = classpath
126
- classpath = t . files(t . sourceSets[ ScoveragePlugin . CONFIGURATION_NAME ] . output . classesDir) +
127
- pluginDependencies +
128
- existingClasspath
141
+ if (scalaCompileOptions . useAnt) {
142
+ scalaCompileOptions . additionalParameters = parameters . collect { escape(it) }
143
+ } else {
144
+ doFirst {
145
+ GFileUtils . deleteDirectory(destinationDir)
146
+ }
147
+ scalaCompileOptions . additionalParameters = parameters
148
+ }
149
+ // the compile task creates a store of measured statements
150
+ outputs . file( new File (extension . dataDir, ' scoverage.coverage.xml ' ))
129
151
}
130
152
131
153
t. tasks[ScoveragePlugin . REPORT_NAME ]. configure {
132
- classpath = project. buildscript. configurations. classpath + configuration
154
+ def classLocation = ScoverageExtension . class. getProtectionDomain(). getCodeSource(). getLocation()
155
+ classpath = project. files(classLocation. file) + configuration
133
156
main = ' org.scoverage.ScoverageReport'
134
157
args = [
135
158
extension. sources,
0 commit comments