-
Notifications
You must be signed in to change notification settings - Fork 562
/
thrift-cli.gradle
55 lines (46 loc) · 1.15 KB
/
thrift-cli.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
apply plugin: "java"
dependencies {
compile 'org.apache.thrift:libthrift:0.20.0'
}
def genJavaDir = new File("${->buildDir}/gen-java")
task genThrift {
doLast {
if (genJavaDir.isDirectory()) {
genJavaDir.deleteDir()
}
mkdir(genJavaDir)
def thriftFiles = fileTree(dir: "$projectDir/src/main/thrift/").matching { include '*.thrift' }
thriftFiles.each() { File file ->
exec {
executable = 'thrift'
args = ['--gen', 'java', '-o', "${-> buildDir}/", file]
}
}
}
}
genThrift.doFirst {
def thrift_installed = "which thrift".execute().waitFor() == 0
if (thrift_installed) {
logger.debug "thrift command found"
} else {
throw new GradleException('The thrift command cannot be found. Check $PATH or install thrift.\n' +
'Try `brew install thrift`, or see http://thrift.apache.org/docs/install/')
}
}
sourceSets {
main {
java {
srcDir genJavaDir
}
}
}
compileJava.dependsOn genThrift
idea.module {
def build = file("${->buildDir}")
excludeDirs -= build
build.listFiles().each { f ->
if (f.name != "gen-java") {
excludeDirs += f
}
}
}