@@ -6,7 +6,6 @@ import org.gradle.api.Project
6
6
import org.gradle.api.invocation.Gradle
7
7
import org.gradle.api.plugins.PluginAware
8
8
import org.gradle.api.tasks.SourceSet
9
- import org.gradle.api.tasks.bundling.Jar
10
9
11
10
import java.nio.file.Files
12
11
@@ -97,19 +96,13 @@ class ScoveragePlugin implements Plugin<PluginAware> {
97
96
runtimeClasspath = it. output + project. configurations. scoverage + originalSourceSet. runtimeClasspath
98
97
}
99
98
99
+ def originalCompileTask = project. tasks[originalSourceSet. getCompileTaskName(" scala" )]
100
+ originalCompileTask. onlyIf { extension. runNormalCompilation. get() }
101
+
100
102
def compileTask = project. tasks[instrumentedSourceSet. getCompileTaskName(" scala" )]
101
- compileTask. mustRunAfter(originalSourceSet . getCompileTaskName( " scala " ) )
103
+ compileTask. mustRunAfter(originalCompileTask )
102
104
project. test. mustRunAfter(compileTask)
103
105
104
- def scoverageJar = project. tasks. create(' jarScoverage' , Jar . class) {
105
- dependsOn(instrumentedSourceSet. classesTaskName)
106
- classifier = CONFIGURATION_NAME
107
- from instrumentedSourceSet. output
108
- }
109
- project. artifacts {
110
- scoverage scoverageJar
111
- }
112
-
113
106
def reportTask = project. tasks. create(REPORT_NAME , ScoverageReport . class) {
114
107
dependsOn compileTask, project. test
115
108
onlyIf { extension. dataDir. get(). list() }
@@ -146,6 +139,12 @@ class ScoveragePlugin implements Plugin<PluginAware> {
146
139
})
147
140
}
148
141
}
142
+
143
+ if (! extension. runNormalCompilation. get()) {
144
+ project. sourceSets. getByName(SourceSet . TEST_SOURCE_SET_NAME ) {
145
+ compileClasspath = instrumentedSourceSet. output + compileClasspath
146
+ }
147
+ }
149
148
}
150
149
}
151
150
@@ -168,8 +167,12 @@ class ScoveragePlugin implements Plugin<PluginAware> {
168
167
}
169
168
170
169
compileTask. configure {
171
- doFirst {
172
- destinationDir. deleteDir()
170
+ if (extension. runNormalCompilation. get()) {
171
+ doFirst {
172
+ destinationDir. deleteDir()
173
+ }
174
+ } else {
175
+ destinationDir = originalCompileTask. destinationDir
173
176
}
174
177
175
178
File pluginFile = project. configurations[CONFIGURATION_NAME ]. find {
@@ -196,40 +199,43 @@ class ScoveragePlugin implements Plugin<PluginAware> {
196
199
// the compile task creates a store of measured statements
197
200
outputs. file(new File (extension. dataDir. get(), ' scoverage.coverage.xml' ))
198
201
199
- doLast {
200
- def originalCompileTaskName = project. sourceSets. getByName(SourceSet . MAIN_SOURCE_SET_NAME )
201
- .getCompileTaskName(" scala" )
202
- def originalDestinationDir = project. tasks[originalCompileTaskName]. destinationDir
203
-
204
- def findFiles = { File dir , Closure<Boolean > condition = null ->
205
- def files = []
206
-
207
- if (dir. exists()) {
208
- dir. eachFileRecurse(FILES ) { f ->
209
- if (condition == null || condition(f)) {
210
- def relativePath = dir. relativePath(f)
211
- files << relativePath
202
+ if (extension. runNormalCompilation. get()) {
203
+ // delete non-instrumented classes by comparing normally compiled classes to those compiled with scoverage
204
+ doLast {
205
+ def originalCompileTaskName = project. sourceSets. getByName(SourceSet . MAIN_SOURCE_SET_NAME )
206
+ .getCompileTaskName(" scala" )
207
+ def originalDestinationDir = project. tasks[originalCompileTaskName]. destinationDir
208
+
209
+ def findFiles = { File dir , Closure<Boolean > condition = null ->
210
+ def files = []
211
+
212
+ if (dir. exists()) {
213
+ dir. eachFileRecurse(FILES ) { f ->
214
+ if (condition == null || condition(f)) {
215
+ def relativePath = dir. relativePath(f)
216
+ files << relativePath
217
+ }
212
218
}
213
219
}
214
- }
215
220
216
- return files
217
- }
221
+ return files
222
+ }
218
223
219
- def isSameFile = { String relativePath ->
220
- def fileA = new File (originalDestinationDir, relativePath)
221
- def fileB = new File (destinationDir, relativePath)
222
- return FileUtils . contentEquals(fileA, fileB)
223
- }
224
+ def isSameFile = { String relativePath ->
225
+ def fileA = new File (originalDestinationDir, relativePath)
226
+ def fileB = new File (destinationDir, relativePath)
227
+ return FileUtils . contentEquals(fileA, fileB)
228
+ }
224
229
225
- def originalClasses = findFiles(originalDestinationDir)
226
- def identicalInstrumentedClasses = findFiles(destinationDir, { f ->
227
- def relativePath = destinationDir. relativePath(f)
228
- return originalClasses. contains(relativePath) && isSameFile(relativePath)
229
- })
230
+ def originalClasses = findFiles(originalDestinationDir)
231
+ def identicalInstrumentedClasses = findFiles(destinationDir, { f ->
232
+ def relativePath = destinationDir. relativePath(f)
233
+ return originalClasses. contains(relativePath) && isSameFile(relativePath)
234
+ })
230
235
231
- identicalInstrumentedClasses. each { f ->
232
- Files . deleteIfExists(destinationDir. toPath(). resolve(f))
236
+ identicalInstrumentedClasses. each { f ->
237
+ Files . deleteIfExists(destinationDir. toPath(). resolve(f))
238
+ }
233
239
}
234
240
}
235
241
}
0 commit comments