@@ -247,51 +247,53 @@ class ScoveragePlugin implements Plugin<PluginAware> {
247247 }
248248 }
249249 }
250+ }
250251
251- compileTask. configure {
252- if (! graph. hasTask(originalCompileTask)) {
253- destinationDir = originalCompileTask. destinationDir
254- } else {
255- doFirst {
256- destinationDir. deleteDir()
257- }
252+ compileTask. configure {
253+ if (! graph. hasTask(originalCompileTask)) {
254+ project. logger. info(" Making scoverage compilation the primary compilation task (instead of compileScala)" )
255+ destinationDir = originalCompileTask. destinationDir
256+ } else {
257+ doFirst {
258+ destinationDir. deleteDir()
259+ }
258260
259- // delete non-instrumented classes by comparing normally compiled classes to those compiled with scoverage
260- doLast {
261- def originalCompileTaskName = project . sourceSets . getByName( SourceSet . MAIN_SOURCE_SET_NAME )
262- .getCompileTaskName( " scala " )
263- def originalDestinationDir = project . tasks[originalCompileTaskName] . destinationDir
264-
265- def findFiles = { File dir , Closure< Boolean > condition = null ->
266- def files = []
267-
268- if (dir . exists()) {
269- dir. eachFileRecurse( FILES ) { f ->
270- if (condition == null || condition(f)) {
271- def relativePath = dir . relativePath (f)
272- files << relativePath
273- }
261+ // delete non-instrumented classes by comparing normally compiled classes to those compiled with scoverage
262+ doLast {
263+ project . logger . info( " Deleting classes compiled by scoverage but non-instrumented (identical to normal compilation) " )
264+ def originalCompileTaskName = project . sourceSets . getByName( SourceSet . MAIN_SOURCE_SET_NAME )
265+ .getCompileTaskName( " scala " )
266+ def originalDestinationDir = project . tasks[originalCompileTaskName] . destinationDir
267+
268+ def findFiles = { File dir , Closure< Boolean > condition = null ->
269+ def files = []
270+
271+ if ( dir. exists()) {
272+ dir . eachFileRecurse( FILES ) { f ->
273+ if (condition == null || condition (f)) {
274+ def relativePath = dir . relativePath(f)
275+ files << relativePath
274276 }
275277 }
276-
277- files
278278 }
279279
280- def isSameFile = { String relativePath ->
281- def fileA = new File (originalDestinationDir, relativePath)
282- def fileB = new File (destinationDir, relativePath)
283- FileUtils . contentEquals(fileA, fileB)
284- }
280+ files
281+ }
285282
286- def originalClasses = findFiles(originalDestinationDir)
287- def identicalInstrumentedClasses = findFiles(destinationDir, { f ->
288- def relativePath = destinationDir. relativePath(f )
289- originalClasses . contains(relativePath) && isSameFile(relativePath )
290- })
283+ def isSameFile = { String relativePath ->
284+ def fileA = new File (originalDestinationDir, relativePath)
285+ def fileB = new File ( destinationDir, relativePath)
286+ FileUtils . contentEquals(fileA, fileB )
287+ }
291288
292- identicalInstrumentedClasses. each { f ->
293- Files . deleteIfExists(destinationDir. toPath(). resolve(f))
294- }
289+ def originalClasses = findFiles(originalDestinationDir)
290+ def identicalInstrumentedClasses = findFiles(destinationDir, { f ->
291+ def relativePath = destinationDir. relativePath(f)
292+ originalClasses. contains(relativePath) && isSameFile(relativePath)
293+ })
294+
295+ identicalInstrumentedClasses. each { f ->
296+ Files . deleteIfExists(destinationDir. toPath(). resolve(f))
295297 }
296298 }
297299 }
0 commit comments