/*
 * 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.genDefinitionOrderTestASrc = file("$buildDir/resources/test/definition-order-test/a")
ext.genDefinitionOrderTestBSrc = file("$buildDir/resources/test/definition-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:jakarta_annotations', 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,jakarta_annotations', 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,jakarta_annotations', 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,jakarta_annotations', 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,jakarta_annotations', 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,jakarta_annotations', 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,jakarta_annotations', genSrc)
}

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

    ext.outputBuffer = new ByteArrayOutputStream()

    thriftCompile(it, 'JavaDefinitionOrderA.thrift', 'java:jakarta_annotations', genDefinitionOrderTestASrc)
    thriftCompile(it, 'JavaDefinitionOrderB.thrift', 'java:jakarta_annotations', genDefinitionOrderTestBSrc)
}
