plugins {
    id 'java'
    id 'io.freefair.lombok'
    id 'antlr'
}

version '1.8.0.0'

repositories {
    mavenCentral()
}

generateGrammarSource {
    arguments += ['-visitor', '-package', 'com.amazon.opendistroforelasticsearch.sql.legacy.antlr.parser']
    source = sourceSets.main.antlr
    outputDirectory = file("build/generated-src/antlr/main/com/amazon/opendistroforelasticsearch/sql/legacy/antlr/parser")
}

// Remove ANTLR plugin jars as it's specified as 'compile' dependency internally
configurations {
    compile {
        extendsFrom = extendsFrom.findAll { it != configurations.antlr }
    }
}

// TODO: fix compiler warnings
compileJava.options.warnings = false
compileJava {
    options.compilerArgs.addAll(["-processor", 'lombok.launch.AnnotationProcessorHider$AnnotationProcessor'])
    doFirst {
        // TODO: do not fail build on warnings, need to fix all compiler warnings
        options.compilerArgs.remove('-Werror')
        // TODO: need to fix all java doc format
        options.compilerArgs.remove('-Xdoclint:all')
    }
}

// TODO: Similarly, need to fix compiling errors in test source code
compileTestJava.options.warnings = false
compileTestJava {
    options.compilerArgs.addAll(["-processor", 'lombok.launch.AnnotationProcessorHider$AnnotationProcessor'])
    doFirst {
        options.compilerArgs.remove('-Werror')
        options.compilerArgs.remove('-Xdoclint:all')
    }
}

// TODO: Need to update integration test to use ElasticSearch test framework
test {
    include '**/*Test.class'
    exclude 'com/amazon/opendistroforelasticsearch/sql/intgtest/**'
    // Gradle runs unit test using a working directory other and project root
    // set 'project.projectDir' property to allow unit test classes to access test resources
    // in src/test/resources in current module
    systemProperty('project.root', project.projectDir.absolutePath)

    testLogging {
        events "passed", "skipped", "failed"
        exceptionFormat "full"
    }
}

dependencies {
    compile group: 'com.alibaba', name: 'druid', version:'1.0.15'
    compile group: 'org.locationtech.spatial4j', name: 'spatial4j', version:'0.7'
    compile group: "org.elasticsearch.plugin", name: 'parent-join-client', version: "${es_version}"
    compile group: "org.elasticsearch.plugin", name: 'reindex-client', version: "${es_version}"
    constraints {
        implementation('commons-codec:commons-codec:1.13') {
            because 'https://www.whitesourcesoftware.com/vulnerability-database/WS-2019-0379'
        }
    }
    // https://github.com/google/guava/wiki/CVE-2018-10237
    implementation group: 'com.google.guava', name: 'guava', version: '29.0-jre'
    compile group: 'org.json', name: 'json', version:'20180813'
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.10'
    compile group: 'org.elasticsearch', name: 'elasticsearch', version: "${es_version}"
    compile project(':sql')
    compile project(':common')
    compile project(':elasticsearch')

    // ANTLR gradle plugin and runtime dependency
    antlr "org.antlr:antlr4:4.7.1"
    compile "org.antlr:antlr4-runtime:4.7.1"

    //compileOnly group: 'org.locationtech.jts', name: 'jts-core', version:'1.15.0'
    // compileOnly group: 'org.elasticsearch', name: 'elasticsearch', version:'6.5.3'
    // compileOnly group: 'com.unboundid', name: 'unboundid-ldapsdk', version:'3.2.0'
    // compileOnly group: 'org.bouncycastle', name: 'bcprov-jdk15on', version:'1.58'
    // compileOnly group: 'log4j', name: 'log4j', version:'1.2.17'
    // compileOnly group: 'org.apache.logging.log4j', name: 'log4j-api', version:'2.7'
    // compileOnly group: 'org.apache.logging.log4j', name: 'log4j-core', version:'2.7'
    compileOnly group: 'javax.servlet', name: 'servlet-api', version:'2.5'

    testCompile group: 'org.hamcrest', name: 'hamcrest-core', version:'2.2'
    // testCompile group: 'com.alibaba', name: 'fastjson', version:'1.2.56'
    testCompile group: 'org.mockito', name: 'mockito-core', version:'3.5.0'
    testCompile group: 'junit', name: 'junit', version: '4.12'
    testCompile group: "org.elasticsearch.client", name: 'transport', version: "${es_version}"

}