Skip to content

Commit 756a841

Browse files
committed
#171 Migrate ScoverageAggregate from Groovy to Kotlin
1 parent 90f14b1 commit 756a841

File tree

3 files changed

+73
-81
lines changed

3 files changed

+73
-81
lines changed

Diff for: src/main/groovy/org/scoverage/ScoverageAggregate.groovy

-76
This file was deleted.

Diff for: src/main/kotlin/org/scoverage/ScoverageAggregate.kt

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package org.scoverage
2+
3+
import org.gradle.api.DefaultTask
4+
import org.gradle.api.file.FileCollection
5+
import org.gradle.api.provider.ListProperty
6+
import org.gradle.api.provider.Property
7+
import org.gradle.api.tasks.Input
8+
import org.gradle.api.tasks.InputFiles
9+
import org.gradle.api.tasks.Nested
10+
import org.gradle.api.tasks.OutputDirectory
11+
import org.gradle.api.tasks.PathSensitive
12+
import org.gradle.api.tasks.TaskAction
13+
import scoverage.report.CoverageAggregator
14+
15+
import org.gradle.api.tasks.PathSensitivity.RELATIVE
16+
import java.io.File
17+
18+
abstract class ScoverageAggregate: DefaultTask() {
19+
20+
@Nested
21+
var runner: ScoverageRunner? = null
22+
23+
@InputFiles
24+
@PathSensitive(RELATIVE)
25+
val sources: Property<FileCollection> = project.objects.property(FileCollection::class.java)
26+
27+
@OutputDirectory
28+
val reportDir: Property<File> = project.objects.property(File::class.java)
29+
30+
@Input
31+
val dirsToAggregateFrom: ListProperty<File> = project.objects.listProperty(File::class.java)
32+
33+
@Input
34+
val deleteReportsOnAggregation: Property<Boolean> = project.objects.property(Boolean::class.java)
35+
36+
@Input
37+
val sourceEncoding: Property<String> = project.objects.property(String::class.java)
38+
39+
// TODO - consider separate options for `report` and `aggregate` tasks
40+
@Input
41+
val coverageOutputCobertura: Property<Boolean> = project.objects.property(Boolean::class.java)
42+
@Input
43+
val coverageOutputXML: Property<Boolean> = project.objects.property(Boolean::class.java)
44+
@Input
45+
val coverageOutputHTML: Property<Boolean> = project.objects.property(Boolean::class.java)
46+
@Input
47+
val coverageDebug: Property<Boolean> = project.objects.property(Boolean::class.java)
48+
49+
@TaskAction
50+
fun aggregate() {
51+
runner?.run {
52+
reportDir.get().deleteRecursively()
53+
reportDir.get().mkdirs()
54+
55+
val dirs = dirsToAggregateFrom.get()
56+
val uniqueDirs = dirs.toSet()
57+
val coverage = CoverageAggregator.aggregate(uniqueDirs.toTypedArray())
58+
59+
if (coverage.nonEmpty()) {
60+
ScoverageWriter(project.logger).write(
61+
sources.get().getFiles(),
62+
reportDir.get(),
63+
coverage.get(),
64+
sourceEncoding.get(),
65+
coverageOutputCobertura.get(),
66+
coverageOutputXML.get(),
67+
coverageOutputHTML.get(),
68+
coverageDebug.get()
69+
)
70+
}
71+
}
72+
}
73+
}

Diff for: src/main/kotlin/org/scoverage/ScoverageRunner.kt

-5
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,4 @@ class ScoverageRunner(@Classpath val runtimeClasspath: FileCollection) {
2323

2424
action()
2525
}
26-
27-
// TODO delete when no longer used by groovy code
28-
fun runGroovy(action: Closure<*>) {
29-
run { action.call() }
30-
}
3126
}

0 commit comments

Comments
 (0)