-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbuild.gradle
208 lines (195 loc) · 6.68 KB
/
build.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
buildscript {
repositories {
jcenter()
}
dependencies {
classpath group: 'org.kohsuke', name: 'github-api', version: '1.92'
}
}
buildDir 'installed'
version '5.2'
repositories {
jcenter()
ivy {
url 'http://mary.dfki.de/repo'
layout 'maven'
}
}
configurations.create 'marytts'
configurations.marytts.resolutionStrategy.eachDependency {
if (it.requested.group == 'de.dfki.mary' && it.requested.name.startsWith('marytts-')) {
it.useVersion version
}
}
ext {
voices = new groovy.json.JsonSlurper().parse(file('components.json'))
selectedVoices = []
}
task list(group: 'Help', description: 'List all available voices') {
doLast {
def github
if (System.env.GITHUB_API_TOKEN) {
github = org.kohsuke.github.GitHub.connectUsingOAuth(System.env.GITHUB_API_TOKEN)
} else {
github = org.kohsuke.github.GitHub.connectAnonymously()
}
github.getOrganization('marytts').repositories.findAll { it.key.startsWith('voice-') }.each { repoName, repo ->
logger.debug "$repo"
def voice = [
name : repoName,
description: repo.description,
license : repo.license?.name,
url : repo.html_url,
version : repo.latestRelease?.name,
files : repo.latestRelease?.assets?.collectEntries { asset ->
[(asset.name): [
size: asset.size,
url : asset.browserDownloadUrl
]]
}
]
logger.info new groovy.json.JsonBuilder(voice).toPrettyString()
logger.lifecycle "$voice.name\t$voice.description"
}
}
}
task info(group: 'Help', description: "Display details") {
doLast {
selectedVoices.each { voice ->
println "\nName\t$voice.name"
println "Gender\t$voice.gender"
println "Language\t$voice.language"
println "Type\t$voice.type"
println "Download size\t${voice.files.values().sum { it.size }}"
println "License\t$voice.license.name, see $voice.license.url"
println "Description\t$voice.description"
}
}
}
task payload(type: Copy) {
from configurations.marytts
into buildDir
outputs.upToDateWhen { false }
ext.files = [:]
eachFile { source ->
files[source.file] = source.name.endsWith('.zip') ?
new java.util.zip.ZipFile(source.file).entries().collect {
new File(destinationDir, it.name)
} : [new File(destinationDir, source.name)]
source.exclude()
}
}
task verify(group: 'Install') {
description "Verify SHA-1 checksum of downloaded files for selected voices"
dependsOn payload
doLast {
selectedVoices.each { voice ->
payload.files.keySet().each {
if (voice.files[it.name]) {
def expected = voice.files[it.name].sha1
def actual = it.parentFile.name.padLeft(40, '0')
logger.lifecycle "Verify\t$it.name"
assert expected == actual: "Checksum failed for $it.name"
}
}
}
}
}
task install(group: 'Install') {
description "Install selected voices"
dependsOn hasProperty('noverify') ? payload : verify
doLast {
payload.files.keySet().each { source ->
if (source.name.endsWith('.zip')) {
copy {
from zipTree(source)
into buildDir
eachFile {
def target = new File(buildDir, it.path)
if (!target.exists() || hasProperty('force')) {
logger.lifecycle "Unpack\t$it.name"
} else {
it.exclude()
}
}
}
} else {
def target = new File(buildDir, source.name)
if (!target.exists() || hasProperty('force')) {
logger.lifecycle "Copy\t$source.name"
copy {
from source
into buildDir
}
}
}
}
}
}
task uninstall(group: 'Uninstall') {
description "Uninstall selected voices"
dependsOn payload
doLast {
selectedVoices.each { voice ->
payload.files.each { source, targets ->
targets.each { target ->
if (target.isFile() && voice.files.containsKey(source.name)) {
logger.lifecycle "Delete\t$target.name"
delete target
}
}
}
}
}
}
task purge(group: 'Uninstall') {
description "Remove the selected voice files from the download cache (experimental)"
dependsOn payload
doLast {
selectedVoices.each { voice ->
payload.files.keySet().each {
if (voice.files.containsKey(it.name)) {
logger.lifecycle "Delete\t$it"
delete it
}
}
}
}
}
tasks.addRule("Pattern: <voice>") { taskName ->
(taskName =~ /^voice-(.+)/).each { match, voiceName ->
task(taskName) {
def voice = voices.find { it.name == voiceName }
if (voice) {
selectedVoices << voice
voice.files.keySet().each { name ->
def dependency = "$voice.group:$voice.artifact:$voice.version"
if (name.endsWith('.zip')) {
dependency += ":data@zip"
}
dependencies.add 'marytts', dependency
}
}
}
}
}
task server(type: JavaExec, group: 'Runtime', description: 'Start the MaryTTS server') {
defaultTasks.add it.name
if (!fileTree(buildDir).include('voice-*.jar').files) {
dependsOn install, 'voice-cmu-slt-hsmm'
}
workingDir buildDir
main 'marytts.server.Mary'
systemProperties System.properties
if (logger.isEnabled(LogLevel.INFO)) {
systemProperties << ['log4j.logger.marytts': 'INFO,stderr']
}
if (logger.isEnabled(LogLevel.DEBUG)) {
systemProperties << ['log4j.logger.marytts': 'DEBUG,stderr']
}
doFirst {
def jarFiles = buildDir.exists() ? buildDir.listFiles() : null
assert jarFiles: "No jar files found in \"$buildDir.name\" directory! Please install a MaryTTS voice first"
classpath jarFiles
}
}