forked from simonpoole/beautified-JOSM-preset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
379 lines (342 loc) · 13.5 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
/*
*/
version = '1.8.15'
//for Ant filter
import org.apache.tools.ant.filters.ReplaceTokens
apply plugin: 'java'
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.com.github.breadmoirai:github-release:2.2.9"
}
}
apply plugin: "com.github.breadmoirai.github-release"
repositories {
jcenter()
maven { url 'https://dl.bintray.com/content/simonpoole/osm' }
}
ext {
preset_file = 'master_preset.xml'
josm_preset_file = 'josm_preset.xml'
vespucci_preset_file = 'vespucci_preset.xml'
vespucci_preset_build_file = 'vespucci_preset_build.xml'
vespucci_preset_version = '1.9'
generated = 'build/gen/'
github_token = System.getenv('GITHUB_TOKEN')
}
dependencies {
runtime 'ch.poole:preset-utils:0.13.0'
}
task copyCss(type: Copy) {
from zipTree(project.configurations.runtime.filter{it.name.startsWith('preset-utils')}.singleFile)
include "preset.css"
into new File(projectDir.getPath() + '/website')
}
task copyResources(type: Copy) {
from zipTree(project.configurations.runtime.filter{it.name.startsWith('preset-utils')}.singleFile)
include "josm-preset-1.0.xlmns"
include "vespucci-preset-${vespucci_preset_version}.xlmns"
include "toJOSM.xslt"
include "href2wiki.xslt"
include "wiki2href.xslt"
into new File(buildDir.getPath() + '/xml')
}
task updateWebsite(dependsOn: ["copyCss"], type: JavaExec) {
main = "ch.poole.osm.presetutils.Preset2Html"
classpath = configurations.runtime
args('-input', preset_file,
'-output', 'index.html',
'-vespucci', 'https://github.com/simonpoole/' + project.name + '/releases/latest/download/vespucci_zip.zip',
'-josm', 'https://github.com/simonpoole/' + project.name + '/releases/latest/download/josm.zip')
}
updateWebsite.group = 'preset utils'
updateWebsite.description = 'Update the website'
task updatePot(type: JavaExec) {
main = "ch.poole.osm.presetutils.Preset2Pot"
classpath = configurations.runtime
args('-input', preset_file,
'-output', 'i18n/preset.pot')
}
updatePot.group = 'preset utils'
updatePot.description = 'Update the translation template'
task updateTranslations(type: Exec) {
if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
commandLine 'cmd', '/c', 'tx.exe', 'pull', '-a'
} else {
commandLine 'tx', 'pull', '-a'
}
}
updateTranslations.group = 'transifex'
updateTranslations.description = 'Update translations by executing the transifex tx utility'
// one time transformation to new format
task transformHrefToWiki(type: Exec) {
def output = 'build/temp/no_href.xml'
if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
// remove extensions
commandLine 'cmd', '/c', 'xmlstarlet', 'tr', 'build/xml/href2wiki.xslt', 'master_preset.xml'
} else {
// remove extensions
commandLine 'xmlstarlet', 'tr', 'build/xml/href2wiki.xslt', 'master_preset.xml'
}
doFirst {
standardOutput = new FileOutputStream(new File(projectDir, output))
}
}
// tasks to generate a zipped preset for JOSM
task josmIcons(dependsOn: ["replaceVersion"], type: Copy) {
from projectDir
include preset_file
into 'build/temp'
filteringCharset = 'UTF-8'
rename preset_file, josm_preset_file
filter(ReplaceTokens, beginToken : '${', endToken : '}', tokens: [ICONPATH: '', ICONTYPE: 'png'])
}
task transformToJosm(dependsOn: ["josmIcons", "copyResources"], type: Exec) {
def output = 'gen/new_' + josm_preset_file
mkdir('build/gen')
if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
// remove extensions
commandLine 'cmd', '/c', 'xmlstarlet', 'tr', 'build/xml/toJOSM.xslt', 'build/temp/' + josm_preset_file
} else {
// remove extensions
commandLine 'xmlstarlet', 'tr', 'build/xml/toJOSM.xslt', 'build/temp/' + josm_preset_file
}
doFirst {
standardOutput = new FileOutputStream(new File(buildDir, output))
}
}
task transformToOldJosm(dependsOn: ["josmIcons", "copyResources"], type: Exec) {
def output = 'gen/' + josm_preset_file
mkdir('build/gen')
if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
// remove extensions
commandLine 'cmd', '/c', 'xmlstarlet', 'tr', 'build/xml/wiki2href.xslt', generated + 'new_' + josm_preset_file
} else {
// remove extensions
commandLine 'xmlstarlet', 'tr', 'build/xml/wiki2href.xslt', generated + 'new_' + josm_preset_file
}
doFirst {
standardOutput = new FileOutputStream(new File(buildDir, output))
}
}
task generateAndValidateJosm(dependsOn: ["transformToJosm", "transformToOldJosm"], type: Exec) {
def input = generated + josm_preset_file
if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
// validation
commandLine 'cmd', '/c', 'xmlstarlet', 'val', '-s', 'build/xml/josm-preset-1.0.xlmns', '-e', input
} else {
// validation
commandLine 'xmlstarlet', 'val', '-s', 'build/xml/josm-preset-1.0.xlmns', '-e', input
}
}
task josmZip(dependsOn: ["generateAndValidateJosm"], type: Zip) {
baseName 'josm'
version ''
destinationDir = new File(buildDir, 'gen')
from ('icons/png')
from (generated + josm_preset_file)
}
josmZip.group = 'preset'
josmZip.description = 'Generate zipped preset file for JOSM'
// tasks to generate a zipped preset for vespucci
task vespucciIcons(type: Copy) {
from projectDir
include preset_file
into 'build/gen'
filteringCharset = 'UTF-8'
rename (preset_file, vespucci_preset_file)
filter(ReplaceTokens, beginToken : '${', endToken : '}', tokens: [ICONPATH: '', ICONTYPE: 'png'])
}
task generateAndValidateVespucci(dependsOn: ["vespucciIcons", "copyResources"], type: Exec) {
def input = generated + vespucci_preset_file
if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
// validation
commandLine 'cmd', '/c', 'xmlstarlet', 'val', '-s', "build/xml/vespucci-preset-${vespucci_preset_version}.xlmns", '-e', input
} else {
// validation
commandLine 'xmlstarlet', 'val', '-s', "build/xml/vespucci-preset-${vespucci_preset_version}.xlmns", '-e', input
}
}
// special for building vespucci
task vespucciBuild(dependsOn: ["replaceVersion"], type: Copy) {
from projectDir
include preset_file
into 'build/gen'
filteringCharset = 'UTF-8'
rename (preset_file, vespucci_preset_build_file)
filter(ReplaceTokens, beginToken : '${', endToken : '}', tokens: [ICONPATH: 'icons/png/', ICONTYPE: 'png'])
}
task generateAndValidateVespucciBuild(dependsOn: ["vespucciBuild", "copyResources"], type: Exec) {
def input = generated + vespucci_preset_build_file
if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
// validation
commandLine 'cmd', '/c', 'xmlstarlet', 'val', '-s', "build/xml/vespucci-preset-${vespucci_preset_version}.xlmns", '-e', input
} else {
// validation
commandLine 'xmlstarlet', 'val', '-s', "build/xml/vespucci-preset-${vespucci_preset_version}.xlmns", '-e', input
}
}
task vespucciZip(dependsOn: ["generateAndValidateVespucci", "updateTranslations"], type: Zip) {
baseName 'vespucci_zip'
version ''
destinationDir = new File(buildDir, 'gen')
from ('icons/png')
from (generated + vespucci_preset_file)
from ('i18n')
exclude ('*.pot')
}
vespucciZip.group = 'preset'
vespucciZip.description = 'Generate zipped preset file for vespucci'
vespucciZip.group = 'preset'
vespucciZip.description = 'Generate zipped preset file for vespucci'
task vespucciIconsZip(type: Zip) {
baseName 'vespucci_icons'
version ''
destinationDir = new File(buildDir, 'gen')
from ('icons/png')
}
vespucciZip.group = 'preset'
vespucciZip.description = 'Generate zipped icon file for vespucci'
task vespucciNoTranslationsZip(dependsOn: ["generateAndValidateVespucci"], type: Zip) {
baseName 'vespucci_zip_no_translations'
version ''
destinationDir = new File(buildDir, 'gen')
from ('icons/png')
from (generated + vespucci_preset_file)
}
vespucciNoTranslationsZip.group = 'preset'
vespucciNoTranslationsZip.description = 'Generate zipped preset file for vespucci without translations'
// this copies the zip files to their legacy location
task copyToGen(dependsOn: ["vespucciNoTranslationsZip", "vespucciZip"]) {
mkdir('gen')
copy {
from new File(buildDir, 'gen')
include 'vespucci_zip_no_translations.zip', 'vespucci_zip.zip'
into 'gen'
}
}
task replaceVersion {
inputs.file('build.gradle')
ant.replaceregexp(match:'presets version="([0-9\\.]+)"', replace:"presets version=\"${version}\"", flags:'g', byline:true) {
fileset(dir: '.', includes: 'master_preset.xml')
}
}
task recolour {
group "Icons"
}
task generatePngs { //(dependsOn: ["recolour"]) {
group "Icons"
}
afterEvaluate{
Map<String, String> colours = [
accommodation: '#0092DA',
amenity: '#734A08',
barrier: '#666666',
craft: '#ff9933',
education: '#39AC39',
emergency: '#CE2029',
food: '#734A08',
health: '#DA0092',
highway: '#666666',
indoor: '#000000',
landuse: '#999999',
money: '#000000',
natural: '#999999',
man_made: '#8e7409',
military: '#556B2F',
office: '#ff3333',
osm: '#000000',
place_of_worship: '#000000',
poi: '#000000',
power: '#8e7409',
shopping: '#AC39AC',
sport: '#39AC39',
tourist: '#734A08',
transport: '#0092DA',
water: '#0092DA'
]
String[] sources = ["svg-osmic","svg-sjjb","svg-osm-icons"]
sources.each { source ->
new File("$projectDir/icons/$source").eachDir { category ->
def categoryName = category.getName()
def name="recolour${source.capitalize()}${categoryName.capitalize()}"
task(name, type: Copy) {
description "recolour svg icons in $source $category"
from "$category"
into 'build/icons/recoloured'
filteringCharset = 'UTF-8'
rename '(.*)', categoryName+'_$0'
String colour = colours.get(categoryName)
String c1 = colour;
String c2 = colour;
String c3 = '#ffffff';
filter {
String line ->
line = line.replaceAll('(?i)fill:#111111', 'fill:' + c1)
line = line.replaceAll('(?i)fill:#111;', 'fill:' + c1 + ';')
line = line.replaceAll('(?i)stroke:#eeeeee', 'stroke:' + c2)
line = line.replaceAll('(?i)stroke:#eee;', 'stroke:' + c2 + ';')
line = line.replaceAll('(?i)fill:white', 'fill:' + c3)
line = line.replaceAll('(?i)stroke:white', 'stroke:' + c3)
line = line.replaceAll('(?i)fill:#ffffff', 'fill:' + c3)
line = line.replaceAll('(?i)stroke:#ffffff', 'stroke:' + c3)
line = line.replaceAll('(?i)fill=\"#111111\"', 'fill=\"' + c1 + '\"')
line = line.replaceAll('(?i)fill=\"#111\"', 'fill=\"' + c1 + ' \"')
line = line.replaceAll('(?i)stroke=\"#eeeeee\"', 'stroke=\"' + c2 + '\"')
line = line.replaceAll('(?i)stroke=\"#eee\"', 'stroke=\"' + c2 + '\"')
line = line.replaceAll('(?i)fill=\"white\"', 'fill=\"' + c3 + '\"')
line = line.replaceAll('(?i)stroke=\"white\"', 'stroke=\"' + c3 + '\"')
line = line.replaceAll('(?i)fill=\"#ffffff\"', 'fill=\"' + c3 + '\"')
line = line.replaceAll('(?i)stroke=\"#ffffff\"', 'stroke=\"' + c3 + '\"')
}
}
recolour.dependsOn name
}
}
String[] svgDirs = ["build/icons/recoloured/", "icons/svg-signs/", "icons/svg-roofs/"]
svgDirs.each { svgDir ->
def name="generatePng${svgDir.capitalize().replace("/","_")}"
def size = svgDir.contains("roof") ? 56 : 48 // hack alert
task(name) {
def windows = System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')
fileTree(dir: svgDir).each { svg ->
String fileName = svg.getName().replace('.svg','.png');
exec {
if (windows) {
commandLine 'cmd', '/c', 'rsvg-convert', '-a', '-f', 'png', '-h', size, '-w', size, '-o', 'icons/png/' + fileName, svg
} else {
commandLine 'rsvg-convert', '-a', '-f', 'png', '-h', size, '-w', size, '-o', 'icons/png/' + fileName, svg
}
}
}
}
generatePngs.dependsOn name
}
}
githubRelease {
token "${github_token}"
owner "simonpoole"
tagName "${version}"
releaseName "${version}"
body ""
releaseAssets new File(buildDir, 'gen').listFiles()
overwrite true
}
build {
dependsOn "vespucciNoTranslationsZip"
dependsOn "vespucciZip"
dependsOn "vespucciIconsZip"
dependsOn "generateAndValidateVespucciBuild"
dependsOn "josmZip"
dependsOn "updatePot"
dependsOn "updateWebsite"
dependsOn "copyToGen"
}
check {
dependsOn "generateAndValidateVespucci"
dependsOn "generateAndValidateJosm"
}