@@ -266,51 +266,53 @@ class ScoveragePlugin implements Plugin<PluginAware> {
266266 }
267267 }
268268 }
269+ }
269270
270- compileTask. configure {
271- if (! graph. hasTask(originalCompileTask)) {
272- destinationDir = originalCompileTask. destinationDir
273- } else {
274- doFirst {
275- destinationDir. deleteDir()
276- }
271+ compileTask. configure {
272+ if (! graph. hasTask(originalCompileTask)) {
273+ project. logger. info(" Making scoverage compilation the primary compilation task (instead of compileScala)" )
274+ destinationDir = originalCompileTask. destinationDir
275+ } else {
276+ doFirst {
277+ destinationDir. deleteDir()
278+ }
277279
278- // delete non-instrumented classes by comparing normally compiled classes to those compiled with scoverage
279- doLast {
280- def originalCompileTaskName = project . sourceSets . getByName( SourceSet . MAIN_SOURCE_SET_NAME )
281- .getCompileTaskName( " scala " )
282- def originalDestinationDir = project . tasks[originalCompileTaskName] . destinationDir
283-
284- def findFiles = { File dir , Closure< Boolean > condition = null ->
285- def files = []
286-
287- if (dir . exists()) {
288- dir. eachFileRecurse( FILES ) { f ->
289- if (condition == null || condition(f)) {
290- def relativePath = dir . relativePath (f)
291- files << relativePath
292- }
280+ // delete non-instrumented classes by comparing normally compiled classes to those compiled with scoverage
281+ doLast {
282+ project . logger . info( " Deleting classes compiled by scoverage but non-instrumented (identical to normal compilation) " )
283+ def originalCompileTaskName = project . sourceSets . getByName( SourceSet . MAIN_SOURCE_SET_NAME )
284+ .getCompileTaskName( " scala " )
285+ def originalDestinationDir = project . tasks[originalCompileTaskName] . destinationDir
286+
287+ def findFiles = { File dir , Closure< Boolean > condition = null ->
288+ def files = []
289+
290+ if ( dir. exists()) {
291+ dir . eachFileRecurse( FILES ) { f ->
292+ if (condition == null || condition (f)) {
293+ def relativePath = dir . relativePath(f)
294+ files << relativePath
293295 }
294296 }
295-
296- files
297297 }
298298
299- def isSameFile = { String relativePath ->
300- def fileA = new File (originalDestinationDir, relativePath)
301- def fileB = new File (destinationDir, relativePath)
302- FileUtils . contentEquals(fileA, fileB)
303- }
299+ files
300+ }
304301
305- def originalClasses = findFiles(originalDestinationDir)
306- def identicalInstrumentedClasses = findFiles(destinationDir, { f ->
307- def relativePath = destinationDir. relativePath(f )
308- originalClasses . contains(relativePath) && isSameFile(relativePath )
309- })
302+ def isSameFile = { String relativePath ->
303+ def fileA = new File (originalDestinationDir, relativePath)
304+ def fileB = new File ( destinationDir, relativePath)
305+ FileUtils . contentEquals(fileA, fileB )
306+ }
310307
311- identicalInstrumentedClasses. each { f ->
312- Files . deleteIfExists(destinationDir. toPath(). resolve(f))
313- }
308+ def originalClasses = findFiles(originalDestinationDir)
309+ def identicalInstrumentedClasses = findFiles(destinationDir, { f ->
310+ def relativePath = destinationDir. relativePath(f)
311+ originalClasses. contains(relativePath) && isSameFile(relativePath)
312+ })
313+
314+ identicalInstrumentedClasses. each { f ->
315+ Files . deleteIfExists(destinationDir. toPath(). resolve(f))
314316 }
315317 }
316318 }
0 commit comments