/*
 * Copyright 2020 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

apply plugin: 'jacoco'

tasks.withType(Test) {
    jacoco.excludes = ['jdk.internal.*']
    // Necessary for JaCoCo to work with Robolectric
    jacoco.includeNoLocationClasses = true
}

task jacocoTestReport(
        type: JacocoReport,
        dependsOn: ['testSampleV2DebugUnitTest', 'testSampleV3DebugUnitTest']) {

    // Output only the HTML report
    reports {
        xml.enabled = false
        html.enabled = true
    }

    // Add our project classes and exclude common Android classes from code coverage
    def debugV2Tree = fileTree(dir: "$project.buildDir/intermediates/javac/sampleV2Debug", excludes: [
            '**/R.class',
            '**/R$*.class',
            '**/BuildConfig.*',
            '**/Manifest*.*',
            'android/**/*.*',
    ])
    def debugV3Tree = fileTree(dir: "$project.buildDir/intermediates/javac/sampleV3Debug", excludes: [
            '**/R.class',
            '**/R$*.class',
            '**/BuildConfig.*',
            '**/Manifest*.*',
            'android/**/*.*',
    ])

    classDirectories.setFrom files([debugV2Tree, debugV3Tree])
    sourceDirectories.setFrom files(["$project.projectDir/src/main/java"])
    executionData.setFrom fileTree(dir: buildDir, includes: [
            'jacoco/testSampleDebugV2UnitTest.exec',
            'jacoco/testSampleDebugV3UnitTest.exec',
    ])
}
