/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you 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.
 */

// Following Gradle best practices to keep build logic organized

// Generated code locations for Unit tests
ext.genSrc = file("$buildDir/gen-java")
ext.genBeanSrc = file("$buildDir/gen-javabean")
ext.genReuseSrc = file("$buildDir/gen-javareuse")
ext.genFullCamelSrc = file("$buildDir/gen-fullcamel")
ext.genOptionTypeJdk8Src = file("$buildDir/gen-option-type-jdk8")
ext.genUnsafeSrc = file("$buildDir/gen-unsafe")
ext.genStructOrderTestASrc = file("$buildDir/resources/test/struct-order-test/a")
ext.genStructOrderTestBSrc = file("$buildDir/resources/test/struct-order-test/b")

// Add the generated code directories to the test source set
sourceSets {
    test.java.srcDirs genSrc, genBeanSrc, genReuseSrc, genFullCamelSrc, genUnsafeSrc, genOptionTypeJdk8Src
}

// ----------------------------------------------------------------------------
// Code generation for Unit Testing

// A callable closure to make this easier
ext.thriftCompile = { Task task, String thriftFileName, String generator = 'java', File outputDir = genSrc ->
    def thriftFile = file("$thriftRoot/test/$thriftFileName")
    if (!thriftFile.exists()) {
        thriftFile = file("$projectDir/src/test/resources/$thriftFileName")
        assert thriftFile.exists(), "can't find $thriftFile"
    }

    task.inputs.file thriftFile
    task.outputs.dir outputDir

    task.doLast {
        outputDir.mkdirs()
        def result = exec {
            executable file(thriftCompiler)
            args '--gen', generator
            args '-out', outputDir
            args thriftFile
            standardOutput = task.outputBuffer
            errorOutput = task.outputBuffer
            ignoreExitValue = true
        }
        if (result.exitValue != 0) {
            // Only show the Thrift compiler output on failures, cuts down on noise!
            println task.outputBuffer.toString()
            result.rethrowFailure()
        }
    }
}

task generate(group: 'Build') {
    description = 'Generate all unit test Thrift sources'
    compileTestJava.dependsOn it
}

task generateJava(group: 'Build') {
    description = 'Generate the thrift gen-java source'
    generate.dependsOn it

    ext.outputBuffer = new ByteArrayOutputStream()

    thriftCompile(it, 'ThriftTest.thrift')
    thriftCompile(it, 'JavaTypes.thrift')
    thriftCompile(it, 'DebugProtoTest.thrift')
    thriftCompile(it, 'DoubleConstantsTest.thrift')
    thriftCompile(it, 'OptionalRequiredTest.thrift')
    thriftCompile(it, 'ManyOptionals.thrift')
    thriftCompile(it, 'JavaDeepCopyTest.thrift')
    thriftCompile(it, 'EnumContainersTest.thrift')
    thriftCompile(it, 'JavaBinaryDefault.thrift')
    thriftCompile(it, 'VoidMethExceptionsTest.thrift')
    thriftCompile(it, 'JavaAnnotationTest.thrift')
    thriftCompile(it, 'partial/thrift_test_schema.thrift')
}

task generateOptionalTypeJava(group: 'Build') {
    description = 'Generate the thrift gen-option-type-jdk8 source'
    generate.dependsOn it

    ext.outputBuffer = new ByteArrayOutputStream()

    thriftCompile(it, 'JavaOptionTypeJdk8Test.thrift', 'java:option_type=jdk8', genOptionTypeJdk8Src)
}

task generateBeanJava(group: 'Build') {
    description = 'Generate the thrift gen-javabean source'
    generate.dependsOn it

    ext.outputBuffer = new ByteArrayOutputStream()

    thriftCompile(it, 'JavaBeansTest.thrift', 'java:beans,nocamel,future_iface', genBeanSrc)
}

task generateReuseJava(group: 'Build') {
    description = 'Generate the thrift gen-javareuse source'
    generate.dependsOn it

    ext.outputBuffer = new ByteArrayOutputStream()

    thriftCompile(it, 'FullCamelTest.thrift', 'java:fullcamel,future_iface', genFullCamelSrc)
}

task generateFullCamelJava(group: 'Build') {
    description = 'Generate the thrift gen-fullcamel source'
    generate.dependsOn it

    ext.outputBuffer = new ByteArrayOutputStream()

    thriftCompile(it, 'ReuseObjects.thrift', 'java:reuse_objects', genReuseSrc)
}

task generateUnsafeBinariesJava(group: 'Build') {
    description = 'Generate the thrift gen-unsafebinaries source'
    generate.dependsOn it

    ext.outputBuffer = new ByteArrayOutputStream()

    thriftCompile(it, 'UnsafeTypes.thrift', 'java:unsafe_binaries', genUnsafeSrc)
}

task generateWithAnnotationMetadata(group: 'Build') {
    description = 'Generate with annotation enabled and add to the default source'
    generate.dependsOn it

    ext.outputBuffer = new ByteArrayOutputStream()

    thriftCompile(it, 'JavaAnnotationTest.thrift', 'java:annotations_as_metadata', genSrc)
}

task generateJavaStructOrderTestJava(group: 'Build') {
    description = 'Generate structs defined in different order and add to build dir so we can compare them'
    generate.dependsOn it

    ext.outputBuffer = new ByteArrayOutputStream()

    thriftCompile(it, 'JavaStructOrderA.thrift', 'java', genStructOrderTestASrc)
    thriftCompile(it, 'JavaStructOrderB.thrift', 'java', genStructOrderTestBSrc)
}
