Alex Volanis | 7004a61 | 2018-01-24 10:30:13 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
| 20 | // Following Gradle best practices to keep build logic organized |
| 21 | |
| 22 | // Generated code locations for Unit tests |
| 23 | ext.genSrc = file("$buildDir/gen-java") |
| 24 | ext.genBeanSrc = file("$buildDir/gen-javabean") |
| 25 | ext.genReuseSrc = file("$buildDir/gen-javareuse") |
| 26 | ext.genFullCamelSrc = file("$buildDir/gen-fullcamel") |
Ben Podgursky | 50bfc56 | 2018-04-16 23:21:46 -0700 | [diff] [blame] | 27 | ext.genUnsafeSrc = file("$buildDir/gen-unsafe") |
Alex Volanis | 7004a61 | 2018-01-24 10:30:13 -0500 | [diff] [blame] | 28 | |
| 29 | // Add the generated code directories to the test source set |
| 30 | sourceSets { |
Ben Podgursky | 50bfc56 | 2018-04-16 23:21:46 -0700 | [diff] [blame] | 31 | test.java.srcDirs genSrc, genBeanSrc, genReuseSrc, genFullCamelSrc, genUnsafeSrc |
Alex Volanis | 7004a61 | 2018-01-24 10:30:13 -0500 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | // ---------------------------------------------------------------------------- |
| 35 | // Code generation for Unit Testing |
| 36 | |
| 37 | // A callable closure to make this easier |
| 38 | ext.thriftCompile = { Task task, String thriftFileName, String generator = 'java', File outputDir = genSrc -> |
| 39 | def thriftFile = file("$thriftRoot/test/$thriftFileName") |
| 40 | assert thriftFile.exists() |
| 41 | |
| 42 | task.inputs.file thriftFile |
| 43 | task.outputs.dir outputDir |
| 44 | |
| 45 | task.doLast { |
| 46 | outputDir.mkdirs() |
| 47 | def result = exec { |
| 48 | executable file(thriftCompiler) |
| 49 | args '--gen', generator |
| 50 | args '-out', outputDir |
| 51 | args thriftFile |
| 52 | standardOutput = task.outputBuffer |
| 53 | errorOutput = task.outputBuffer |
| 54 | ignoreExitValue = true |
| 55 | } |
| 56 | if (result.exitValue != 0) { |
| 57 | // Only show the Thrift compiler output on failures, cuts down on noise! |
| 58 | println task.outputBuffer.toString() |
| 59 | result.rethrowFailure() |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | task generate(group: 'Build') { |
| 65 | description = 'Generate all unit test Thrift sources' |
| 66 | compileTestJava.dependsOn it |
| 67 | } |
| 68 | |
| 69 | task generateJava(group: 'Build') { |
| 70 | description = 'Generate the thrift gen-java source' |
| 71 | generate.dependsOn it |
| 72 | |
| 73 | ext.outputBuffer = new ByteArrayOutputStream() |
| 74 | |
| 75 | thriftCompile(it, 'ThriftTest.thrift') |
| 76 | thriftCompile(it, 'JavaTypes.thrift') |
| 77 | thriftCompile(it, 'DebugProtoTest.thrift') |
Ozan Can Altiok | e46419b | 2018-03-20 15:02:28 +0300 | [diff] [blame] | 78 | thriftCompile(it, 'DoubleConstantsTest.thrift') |
Alex Volanis | 7004a61 | 2018-01-24 10:30:13 -0500 | [diff] [blame] | 79 | thriftCompile(it, 'OptionalRequiredTest.thrift') |
| 80 | thriftCompile(it, 'ManyOptionals.thrift') |
| 81 | thriftCompile(it, 'JavaDeepCopyTest.thrift') |
| 82 | thriftCompile(it, 'EnumContainersTest.thrift') |
Ewan Higgs | b3745ee | 2019-09-20 17:15:04 +0200 | [diff] [blame] | 83 | thriftCompile(it, 'JavaBinaryDefault.thrift') |
Alex Kormukhin | c9b7bd7 | 2022-02-18 21:04:14 +0300 | [diff] [blame] | 84 | thriftCompile(it, 'VoidMethExceptionsTest.thrift') |
kpandit | 5a9d139 | 2021-11-20 00:56:17 +0100 | [diff] [blame] | 85 | thriftCompile(it, 'partial/thrift_test_schema.thrift') |
Alex Volanis | 7004a61 | 2018-01-24 10:30:13 -0500 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | task generateBeanJava(group: 'Build') { |
| 89 | description = 'Generate the thrift gen-javabean source' |
| 90 | generate.dependsOn it |
| 91 | |
| 92 | ext.outputBuffer = new ByteArrayOutputStream() |
| 93 | |
| 94 | thriftCompile(it, 'JavaBeansTest.thrift', 'java:beans,nocamel', genBeanSrc) |
| 95 | } |
| 96 | |
| 97 | task generateReuseJava(group: 'Build') { |
| 98 | description = 'Generate the thrift gen-javareuse source' |
| 99 | generate.dependsOn it |
| 100 | |
| 101 | ext.outputBuffer = new ByteArrayOutputStream() |
| 102 | |
| 103 | thriftCompile(it, 'FullCamelTest.thrift', 'java:fullcamel', genFullCamelSrc) |
| 104 | } |
| 105 | |
| 106 | task generateFullCamelJava(group: 'Build') { |
| 107 | description = 'Generate the thrift gen-fullcamel source' |
| 108 | generate.dependsOn it |
| 109 | |
| 110 | ext.outputBuffer = new ByteArrayOutputStream() |
| 111 | |
Jiayu Liu | 5a44db8 | 2022-02-22 23:17:06 +0800 | [diff] [blame^] | 112 | thriftCompile(it, 'ReuseObjects.thrift', 'java:reuse_objects', genReuseSrc) |
Alex Volanis | 7004a61 | 2018-01-24 10:30:13 -0500 | [diff] [blame] | 113 | } |
Ben Podgursky | 50bfc56 | 2018-04-16 23:21:46 -0700 | [diff] [blame] | 114 | |
| 115 | task generateUnsafeBinariesJava(group: 'Build') { |
| 116 | description = 'Generate the thrift gen-unsafebinaries source' |
| 117 | generate.dependsOn it |
| 118 | |
| 119 | ext.outputBuffer = new ByteArrayOutputStream() |
| 120 | |
| 121 | thriftCompile(it, 'UnsafeTypes.thrift', 'java:unsafe_binaries', genUnsafeSrc) |
| 122 | } |