apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {
    namespace "com.airbnb.paris.test"
    compileSdkVersion rootProject.COMPILE_SDK_VERSION

    defaultConfig {
        minSdkVersion rootProject.MIN_SDK_VERSION
        targetSdkVersion rootProject.TARGET_SDK_VERSION
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    testOptions {
        unitTests {
            includeAndroidResources = true
        }
    }

    compileOptions {
        sourceCompatibility rootProject.JAVA_SOURCE_VERSION
        targetCompatibility rootProject.JAVA_TARGET_VERSION
    }

    kotlinOptions {
        jvmTarget = '11'
    }
}

sourceCompatibility = rootProject.JAVA_SOURCE_VERSION
targetCompatibility = rootProject.JAVA_TARGET_VERSION

dependencies {
    implementation project(':paris')
    implementation project(':paris-test-lib')
    implementation "com.google.devtools.ksp:symbol-processing-api:$KSP_VERSION"

    implementation deps.appcompat

    kapt project(':paris-processor')

    testImplementation project(':paris-processor')

    testImplementation files(rootProject.file("libs/rt.jar"))
    testImplementation files(rootProject.file("libs/tools.jar"))

    testImplementation deps.junit
    testImplementation deps.testingCompile
    testImplementation deps.kotlinCompileTesting
    testImplementation "io.github.java-diff-utils:java-diff-utils:4.5"
    testImplementation "io.strikt:strikt-core:0.31.0"

    androidTestImplementation deps.espresso
}

// Java files in the "resources" folder are not included in the build for some reason (seems like source files are skipped?)
// This files are needed to test the annotation processor, so we manually copy them into the build.
task('copyDebugTestResources', type: Copy) {
    from("${projectDir}/src/test/resources")
    into("${buildDir}/intermediates/sourceFolderJavaResources/debug")
}

task('copyReleaseTestResources', type: Copy) {
    from("${projectDir}/src/test/resources")
    into("${buildDir}/intermediates/sourceFolderJavaResources/release")
}

preBuild.dependsOn copyReleaseTestResources
preBuild.dependsOn copyDebugTestResources

tasks.withType(Test) {
    jvmArgs(
        '--add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED',
        '--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED',
        '--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED',
        '--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED',
        '--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED',
        '--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED',
        '--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED',
        '--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED',
        '--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED',
        '--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED'
    )
}
