/*
 * 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.genUnsafeSrc = file("$buildDir/gen-unsafe")

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

// ----------------------------------------------------------------------------
// 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")
    assert thriftFile.exists()

    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')
}

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', 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', 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)
}
