|
| 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 | +} |
0 commit comments