// The versions are defined in "${project.rootDir}/buildconstants/android-sdk-versions.gradle"

apply plugin: 'jacoco'

jacoco {
    toolVersion = "0.8.12"
}

android {
    compileSdkVersion compile_sdk_version
    buildToolsVersion build_tools_version

    defaultConfig {
        minSdkVersion min_sdk_version
        targetSdkVersion target_sdk_version

        multiDexEnabled false
        multiDexKeepProguard file("${project.rootDir}/buildsystem/multidex/multidex.pro")

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled true

            // PROGUARD
            def proguardRuleFiles = collectCommonProguardRules()
            proguardRuleFiles.add(0, getDefaultProguardFile('proguard-android.txt'))
            proguardRuleFiles.add(1, 'proguard-rules.pro')
            logger.warn("Common proguard files: $proguardRuleFiles")

            proguardFiles proguardRuleFiles.toArray()
        }

        debug {
            minifyEnabled false

            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = 17
    }

    androidResources {
        noCompress 'zip'
    }
    lint {
        lintConfig file("$rootDir/buildsystem/codequality/lint.xml")
    }

    testOptions {
        execution 'ANDROIDX_TEST_ORCHESTRATOR'
        animationsDisabled = true

        unitTests {
            //returnDefaultValues = true
            includeAndroidResources = true
        }
    }

}

task jacocoTestReport2(type: JacocoReport) {

    reports {
        xml.required.set(true)
        html.required.set(true)
    }

    def fileFilter = ['jdk.internal.*',
                      'android/**/*.*',
                      '**/R.class',
                      '**/R$*.class',
                      '**/BuildConfig.*',
                      '**/Manifest*.*',
                      '**/*Test*.*',
                      '**/*$ViewInjector*.*',
                      '**/*$ViewBinder*.*',
                      // DAGGER 2
                      '**/*_*Factory*.*',
                      '**/*_MembersInjector*.*',
                      '**/*_MembersInjector.class',
                      '**/*Module*.*',
                      '**/Dagger*Component$Builder.class',
                      '**/Dagger*Component*.*']

    def mainSrc = "$project.projectDir/src/main/java"

    def javaClasses = fileTree(
            dir: "$buildDir/intermediates/classes/",
            excludes: fileFilter
    )

    def kotlinClasses = fileTree(
            dir: "$buildDir/tmp/kotlin-classes/",
            excludes: fileFilter
    )

    classDirectories.setFrom(files([javaClasses], [kotlinClasses]))
    sourceDirectories.setFrom(files(mainSrc))
    executionData.setFrom(fileTree(dir: "$buildDir",
            includes: ['jacoco/*.exec', 'connected/*.ec']
    ))

    reports {
        xml.required.set(true)
        html.required.set(true)
    }
}

tasks.withType(Test) {
    jacoco.includeNoLocationClasses = false
}
