// Copyright 2017-2020 Fitbit, Inc
// SPDX-License-Identifier: Apache-2.0

apply plugin: 'jacoco'

jacoco {
    toolVersion = '0.8.3'
}

project.afterEvaluate {
    task "testDebugCoverage" (type: JacocoReport, dependsOn: "testDebugUnitTest") {
        group = "Reporting"
        description = "Generate Jacoco coverage reports on testDebugUnitTest build"

        def javaClassTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: [
                '**/R.class',
                '**/R$*.class',
                '**/*$ViewInjector*.*',
                '**/*$ViewBinder*.*',
                '**/BuildConfig.*',
                '**/Manifest*.*'
        ] )

        def kotlinClassTree = fileTree(dir: "${buildDir}/tmp/kotlin-classes/debug")

        classDirectories.from = files([javaClassTree], [kotlinClassTree])

        def coverageSourceDirs = [
                "src/main/java",
                "src/main/kotlin",
                "src/main/cpp"
        ]
        additionalSourceDirs.from = files(coverageSourceDirs)
        sourceDirectories.from = files(coverageSourceDirs)
        executionData.from = files("${project.buildDir}/jacoco/testDebugUnitTest.exec")

        reports {
            xml.enabled = true
            html.enabled = true
        }
    }
}
