blob: c3479179b13a97449be97405bb8b1d6f6d1880c2 [file] [log] [blame]
Alex Volanis7004a612018-01-24 10:30:13 -05001/*
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
23ext.genSrc = file("$buildDir/gen-java")
24ext.genBeanSrc = file("$buildDir/gen-javabean")
25ext.genReuseSrc = file("$buildDir/gen-javareuse")
26ext.genFullCamelSrc = file("$buildDir/gen-fullcamel")
27
28// Add the generated code directories to the test source set
29sourceSets {
30 test.java.srcDirs genSrc, genBeanSrc, genReuseSrc, genFullCamelSrc
31}
32
33// ----------------------------------------------------------------------------
34// Code generation for Unit Testing
35
36// A callable closure to make this easier
37ext.thriftCompile = { Task task, String thriftFileName, String generator = 'java', File outputDir = genSrc ->
38 def thriftFile = file("$thriftRoot/test/$thriftFileName")
39 assert thriftFile.exists()
40
41 task.inputs.file thriftFile
42 task.outputs.dir outputDir
43
44 task.doLast {
45 outputDir.mkdirs()
46 def result = exec {
47 executable file(thriftCompiler)
48 args '--gen', generator
49 args '-out', outputDir
50 args thriftFile
51 standardOutput = task.outputBuffer
52 errorOutput = task.outputBuffer
53 ignoreExitValue = true
54 }
55 if (result.exitValue != 0) {
56 // Only show the Thrift compiler output on failures, cuts down on noise!
57 println task.outputBuffer.toString()
58 result.rethrowFailure()
59 }
60 }
61}
62
63task generate(group: 'Build') {
64 description = 'Generate all unit test Thrift sources'
65 compileTestJava.dependsOn it
66}
67
68task generateJava(group: 'Build') {
69 description = 'Generate the thrift gen-java source'
70 generate.dependsOn it
71
72 ext.outputBuffer = new ByteArrayOutputStream()
73
74 thriftCompile(it, 'ThriftTest.thrift')
75 thriftCompile(it, 'JavaTypes.thrift')
76 thriftCompile(it, 'DebugProtoTest.thrift')
Ozan Can Altioke46419b2018-03-20 15:02:28 +030077 thriftCompile(it, 'DoubleConstantsTest.thrift')
Alex Volanis7004a612018-01-24 10:30:13 -050078 thriftCompile(it, 'OptionalRequiredTest.thrift')
79 thriftCompile(it, 'ManyOptionals.thrift')
80 thriftCompile(it, 'JavaDeepCopyTest.thrift')
81 thriftCompile(it, 'EnumContainersTest.thrift')
82}
83
84task generateBeanJava(group: 'Build') {
85 description = 'Generate the thrift gen-javabean source'
86 generate.dependsOn it
87
88 ext.outputBuffer = new ByteArrayOutputStream()
89
90 thriftCompile(it, 'JavaBeansTest.thrift', 'java:beans,nocamel', genBeanSrc)
91}
92
93task generateReuseJava(group: 'Build') {
94 description = 'Generate the thrift gen-javareuse source'
95 generate.dependsOn it
96
97 ext.outputBuffer = new ByteArrayOutputStream()
98
99 thriftCompile(it, 'FullCamelTest.thrift', 'java:fullcamel', genFullCamelSrc)
100}
101
102task generateFullCamelJava(group: 'Build') {
103 description = 'Generate the thrift gen-fullcamel source'
104 generate.dependsOn it
105
106 ext.outputBuffer = new ByteArrayOutputStream()
107
108 thriftCompile(it, 'ReuseObjects.thrift', 'java:reuse-objects', genReuseSrc)
109}