THRIFT-5521: [java gen] use jdk8 option type in java generator code
Client: Java
Patch: Jiayu Liu
This closes #2525
diff --git a/lib/java/gradle/generateTestThrift.gradle b/lib/java/gradle/generateTestThrift.gradle
index d5bc3af..c48845e 100644
--- a/lib/java/gradle/generateTestThrift.gradle
+++ b/lib/java/gradle/generateTestThrift.gradle
@@ -24,11 +24,12 @@
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")
// Add the generated code directories to the test source set
sourceSets {
- test.java.srcDirs genSrc, genBeanSrc, genReuseSrc, genFullCamelSrc, genUnsafeSrc
+ test.java.srcDirs genSrc, genBeanSrc, genReuseSrc, genFullCamelSrc, genUnsafeSrc, genOptionTypeJdk8Src
}
// ----------------------------------------------------------------------------
@@ -37,7 +38,10 @@
// 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()
+ if (!thriftFile.exists()) {
+ thriftFile = file("$projectDir/test/resources/$thriftFileName")
+ assert thriftFile.exists(), "can't find $thriftFile"
+ }
task.inputs.file thriftFile
task.outputs.dir outputDir
@@ -85,6 +89,15 @@
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', genOptionTypeJdk8Src)
+}
+
task generateBeanJava(group: 'Build') {
description = 'Generate the thrift gen-javabean source'
generate.dependsOn it