-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmetainfo.gradle
61 lines (52 loc) · 1.6 KB
/
metainfo.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
56
57
58
59
60
61
import java.nio.file.Files
task generateMetaInfo(type: TransformTask) {
group 'codegen'
description "generate meta information class"
generateCode.dependsOn it
def outputDir = file("meta-info")
def className = "MetaInfo"
def classFile = file("$outputDir/$pckgDir/${className}.kt")
template = rootProject.file('metainfo.template.kt')
output = classFile
model.className = className
inputs.file(rootProject.file("gradle.properties"))
inputs.file(template)
outputs.file(output)
project.sourceSets.main.java.srcDirs += outputDir
doFirst {
delete(outputDir)
outputDir.mkdirs()
// get current commit SHA
try {
new ByteArrayOutputStream().withStream { os ->
exec {
standardOutput = os
commandLine = ['git', 'rev-parse', '--verify', 'HEAD']
println "getting current commit SHA..."
println "> ${commandLine.join(' ')}"
}
model.sha = new Scanner(os.toString()).nextLine()
println "model.sha: ${model.sha}"
}
} catch (e) {
println "failed to get current commit SHA: $e"
}
try {
new ByteArrayOutputStream().withStream { os ->
exec {
standardOutput = os
commandLine = ['git', 'tag', '--points-at', 'HEAD']
println "getting current tags..."
println "> ${commandLine.join(' ')}"
}
model.tags = os.toString().split('\n').findAll {!it.isAllWhitespace()}
println "model.tags: ${model.tags}"
}
} catch (e) {
println "failed to get current commit SHA: $e"
}
}
clean.doFirst {
delete(outputDir)
}
}