/*
 * Copyright 2021 DataCanvas
 *
 * 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
 *
 *     http://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.
 */

plugins {
    id 'java-conventions'
    id 'java-library'
    id "org.javacc.javacc" version "3.0.0"
}

configurations {
    fmppTask
}


dependencies {
    annotationProcessor group: 'org.immutables', name: 'value', version: 'immutables'.v()
    implementation group: 'io.dingodb', name: 'calcite-core', version: 'calcite'.v()
    api project(':dingo-exec')
    implementation project(':dingo-partition-api')
    implementation project(':dingo-codec-api')
    compileOnly group: 'org.immutables', name: 'value', version: 'immutables'.v()
    implementation project(':dingo-store-api')
    implementation project(':dingo-verify')
    implementation project(':dingo-transaction-api')
    implementation group: 'org.apache.commons', name: 'commons-lang3', version: 'commons-lang3'.v()
    implementation group: 'net.agkn', name: 'hll', version: 'hll'.v()
    implementation group: 'io.dingodb.expr', name: 'dingo-expr-coding', version: 'dingo-expr'.v()
    implementation group: 'io.dingodb.expr', name: 'dingo-expr-common', version: 'dingo-expr'.v()
    implementation group: 'io.dropwizard.metrics', name: 'metrics-core', version: 'metrics-core'.v()
    implementation group: 'org.codehaus.janino', name:'janino', version: '3.1.8'
    implementation group: 'org.codehaus.janino', name:'commons-compiler', version: '3.1.8'

    api group: 'io.dingodb.expr', name: 'dingo-expr-parser', version: 'dingo-expr'.v()
    api group: 'io.dingodb.expr', name: 'dingo-expr-rel', version: 'dingo-expr'.v()

    testAnnotationProcessor group: 'com.google.auto.service', name: 'auto-service', version: 'auto-service'.v()
    testCompileOnly group: 'com.google.auto.service', name: 'auto-service', version: 'auto-service'.v()
    testImplementation group: 'org.mockito', name: 'mockito-core', version: 'mockito'.v()
    testImplementation project(':dingo-test')
    testImplementation project(':dingo-test:dingo-meta-local')
    testImplementation project(':dingo-codec-serial')
    testImplementation project(':dingo-partition-base')
    fmppTask "com.googlecode.fmpp-maven-plugin:fmpp-maven-plugin:1.0"
    fmppTask "org.freemarker:freemarker:2.3.31"
}

sourceSets {
    main {
        java {
            srcDir compileJavacc.outputDirectory
        }
    }
}

task copyFmppTemplatesFromSrc(type: Copy) {
    from "src/main/codegen"
    into "${project.buildDir}/templates-fmpp/codegen"
}

def generateFmppOutputDir = "${project.buildDir}/generated/fmpp"
task generateFmppSources {
    dependsOn configurations.fmppTask
    dependsOn copyFmppTemplatesFromSrc
    doLast {
        ant.taskdef(name: "fmpp", classname: "fmpp.tools.AntTask", classpath: configurations.fmppTask.asPath)
        ant.fmpp(configuration: "${project.buildDir}/templates-fmpp/codegen/config.fmpp", sourceRoot: "${project.buildDir}/templates-fmpp/codegen/templates", outputRoot: generateFmppOutputDir)
    }
}

compileJavacc {
    dependsOn generateFmppSources
    inputDirectory = file(project.buildDir.absolutePath + '/generated/fmpp/javacc')
    outputDirectory = file(project.buildDir.absolutePath + '/generated/javacc/org/apache/calcite/sql/parser/dingo')
}

javadoc {
    exclude "org/apache/calcite/**"
    source = sourceSets.main.allJava
}
