plugins {
    id 'java'
    id 'jacoco'
    id 'com.github.johnrengelman.shadow' version '7.1.0'
}

jacoco {
    toolVersion "0.8.12"
    reportsDirectory = layout.buildDirectory.dir('jacoco')
}

dependencies {
    implementation 'com.github.seancfoley:ipaddress:5.5.1'
    implementation 'com.google.code.gson:gson:2.11.0'
    implementation 'com.github.jnr:jnr-ffi:2.2.17'
    // Junixsocket imports :
    implementation 'com.kohlschutter.junixsocket:junixsocket-core:2.10.1'
    implementation 'com.kohlschutter.junixsocket:junixsocket-server:2.10.1'
    // Subnets :
    implementation 'com.github.seancfoley:ipaddress:5.3.3'

    // For middleware :
    compileOnly 'io.javalin:javalin:6.3.0'

    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
    testImplementation 'org.junit.jupiter:junit-jupiter:5.9.2'
    testImplementation 'org.mockito:mockito-core:5.0.0'
    testImplementation 'org.mockito:mockito-junit-jupiter:5.0.0'
    testImplementation 'org.junit-pioneer:junit-pioneer:2.2.0'
    // Sink tests :
    testImplementation 'org.postgresql:postgresql:42.2.23'
    testImplementation 'mysql:mysql-connector-java:8.0.33'
    testImplementation 'org.mariadb.jdbc:mariadb-java-client:3.0.5'
    testImplementation 'com.microsoft.sqlserver:mssql-jdbc:10.2.0.jre8'
    testImplementation 'com.squareup.okhttp3:okhttp:4.10.0'
    testImplementation 'org.apache.httpcomponents:httpclient:4.5.13'

    // Spring Web for RestTemplate
    testImplementation 'org.springframework:spring-web:5.3.20'
    testImplementation 'org.springframework:spring-webmvc:5.3.20'
    testImplementation 'org.springframework:spring-test:5.3.20'

    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
}

test {
    jvmArgs '--add-opens', 'java.base/java.util=ALL-UNNAMED'
    jvmArgs '--add-opens', 'java.base/java.lang=ALL-UNNAMED'
    jvmArgs "-javaagent:${project.rootDir}/dist/agent.jar=mode=daemon-disabled"
    jvmArgs '-Dnet.bytebuddy.experimental=true' // Mockito support.

    systemProperty 'AIK_agent_dir', "${project.rootDir}/dist"
    if (project.hasProperty('coverageRun')) {
        systemProperty 'AIK_INTERNAL_coverage_run', '1'
    }

    useJUnitPlatform()
    finalizedBy jacocoTestReport

    testLogging {
        events "passed", "skipped", "failed"
        exceptionFormat "full"
    }
    jacoco {
        enabled = true
    }
}

jacocoTestReport {
    reports {
        xml.required = true
        csv.required = false
        html.required = false
    }
    dependsOn test
}

shadowJar {
    mergeServiceFiles()
    manifest {
    }
}