/*
 * 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")

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

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

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