-
Notifications
You must be signed in to change notification settings - Fork 26
/
build.gradle
473 lines (421 loc) · 17.2 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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
/*
*/
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.github.breadmoirai:github-release:2.5.2"
}
}
plugins {
id "de.undercouch.download" version "4.1.0"
}
apply plugin: 'java'
apply plugin: "com.github.breadmoirai.github-release"
import static groovy.io.FileType.*
//for Ant filter
import org.apache.tools.ant.filters.ReplaceTokens
import de.undercouch.gradle.tasks.download.Download
repositories {
mavenCentral()
mavenLocal()
}
ext {
version = '5.68.0'
preset_file = 'master_preset.xml'
mapped_josm_preset_file = 'mapped_josm_preset.xml'
mapped_vespucci_preset_file = 'mapped_vespucci_preset.xml'
legacy_vespucci_preset_file = 'v4.xml'
josm_preset_file = 'josm_preset.xml'
josm_preset_orig_icons_file = 'josm_preset_orig_icons.xml'
vespucci_preset_file = 'vespucci_preset.xml'
vespucci_preset_v5_file = 'vespucci_preset_v5.xml'
vespucci_preset_build_file = 'vespucci_preset_build.xml'
vespucci_preset_build_v5_file = 'vespucci_preset_build_v5.xml'
vespucci_preset_version = '1.18'
generated = 'build/gen/'
generatedDir = file(generated)
tempDir = file('build/temp/')
githubToken = System.getenv('GITHUB_TOKEN')
}
configurations {
resoveableRuntimeOnly.extendsFrom runtimeOnly {
canBeResolved = true
}
}
dependencies {
resoveableRuntimeOnly 'ch.poole:preset-utils:0.41.0'
}
def loadProperties = { filename ->
def properties = new Properties()
file(filename).withInputStream {
properties.load(it)
}
return properties
}
task copyCss(type: Copy) {
from zipTree(project.configurations.resoveableRuntimeOnly.filter{it.name.startsWith('preset-utils')}.singleFile)
include "preset.css"
into new File(projectDir.getPath() + '/website')
}
task copyResources(type: Copy) {
from zipTree(project.configurations.resoveableRuntimeOnly.filter{it.name.startsWith('preset-utils')}.singleFile)
include "josm-preset-1.0.xlmns"
include "vespucci-preset-${vespucci_preset_version}.xlmns"
include "toJOSM.xslt"
include "toVespucciOld.xslt"
include "href2wiki.xslt"
include "wiki2href.xslt"
include "expandListEntryChunks.xslt"
into new File(buildDir.getPath() + '/xml')
}
task updateWebsite(dependsOn: ["copyCss",'vespucciIcons'], type: JavaExec) {
main = "ch.poole.osm.presetutils.Preset2Html"
classpath = configurations.resoveableRuntimeOnly
args('-input', tempDir.getPath() + "/" + legacy_vespucci_preset_file,
'-output', 'index.html',
'-vespucci', 'https://github.com/simonpoole/' + project.name + '/releases/latest/download/vespucci_v5.zip',
'-josm', 'https://github.com/simonpoole/' + project.name + '/releases/latest/download/josm.zip')
}
updateWebsite.group = 'preset utils'
updateWebsite.description = 'Update the website'
// TRANSLATIONS
task updatePot(dependsOn: ['expandListEntryChunks'], type: JavaExec) {
main = "ch.poole.osm.presetutils.Preset2Pot"
classpath = configurations.resoveableRuntimeOnly
args('-input', tempDir.getPath() + "/" + legacy_vespucci_preset_file, '-output', 'i18n/preset.pot')
}
updatePot.group = 'preset utils'
updatePot.description = 'Update the translation template'
task updateTranslations(type: Exec) {
commandLine 'tx', 'pull', '-a'
}
updateTranslations.group = 'transifex'
updateTranslations.description = 'Update translations by executing the transifex tx utility'
task copyTranslations(dependsOn: ['updateTranslations'], type: Copy) {
from 'i18n'
into "$buildDir/temp/i18n/data"
rename 'preset_(.*).po', '$1.po'
rename { filename -> filename.replace '-r', '_' }
include "*.po"
include "*.pot"
}
task downloadLangScript(type: Download) {
acceptAnyCertificate true
src 'https://josm.openstreetmap.de/export/HEAD/osm/applications/editors/josm/i18n/i18n.pl'
dest tempDir.getPath() + "/" + 'i18n.pl'
}
task patchLangScript(dependsOn: ['downloadLangScript']) {
doLast {
ant.replace(token:"/\\/", value:"/") {
fileset(dir: tempDir.getPath(), includes: 'i18n.pl')
}
}
}
// generate JOSM .lang files
task generateLang(dependsOn: ['patchLangScript'], type: Exec) {
workingDir tempDir.getPath() + '/i18n/data'
commandLine 'perl', '../../i18n.pl', '--basedir=.', '--potfile=preset.pot', '*.po'
}
// VESPUCCI
// map to beautified icon set
task mapToBeautifiedIcons(type: Copy) {
inputs.file('beautified_icons.mapping')
from projectDir
include preset_file
into tempDir
filteringCharset = 'UTF-8'
rename (preset_file, mapped_vespucci_preset_file)
def map = loadProperties('beautified_icons.mapping')
filter(ReplaceTokens, beginToken : '${', endToken : '}', tokens: map)
}
// for V4 and utilities
task expandListEntryChunks(dependsOn: ["mapToBeautifiedIcons"], type: Exec) {
def input = tempDir.getPath() + "/" + mapped_vespucci_preset_file
def output = legacy_vespucci_preset_file
def xslt = 'build/xml/expandListEntryChunks.xslt'
commandLine 'xmlstarlet', 'tr', xslt, input
doFirst {
standardOutput = new FileOutputStream(new File(tempDir, output))
}
}
// copy icons and preset files for vespucci
task vespucciIcons(dependsOn: ["expandListEntryChunks"], type: Copy) {
from tempDir
include legacy_vespucci_preset_file
include mapped_vespucci_preset_file
into generatedDir
filteringCharset = 'UTF-8'
rename (legacy_vespucci_preset_file, vespucci_preset_file)
rename (mapped_vespucci_preset_file, vespucci_preset_v5_file)
filter(ReplaceTokens, beginToken : '${', endToken : '}', tokens: [ICONPATH: '', ICONTYPE: 'png'])
}
task checkPreset(dependsOn: ["vespucciIcons", "copyResources"], type: JavaExec) {
def input = generated + vespucci_preset_v5_file
main = "ch.poole.osm.presetutils.CheckPreset"
classpath = configurations.resoveableRuntimeOnly
args('-i', input)
}
task generateAndValidateVespucci(dependsOn: ["checkPreset"], type: Exec) {
def input = generated + vespucci_preset_file
// validation
commandLine 'xmlstarlet', 'val', '-s', "build/xml/vespucci-preset-${vespucci_preset_version}.xlmns", '-e', input
}
// special for building vespucci
task vespucciBuild(dependsOn: ["expandListEntryChunks", "replaceVersion"], type: Copy) {
from tempDir
include legacy_vespucci_preset_file
into generatedDir
filteringCharset = 'UTF-8'
rename (legacy_vespucci_preset_file, vespucci_preset_build_file)
filter(ReplaceTokens, beginToken : '${', endToken : '}', tokens: [ICONPATH: 'icons/png/', ICONTYPE: 'png'])
}
// special for building vespucci v5
task vespucciBuildV5(dependsOn: ["replaceVersion","mapToBeautifiedIcons"], type: Copy) {
from tempDir
include mapped_vespucci_preset_file
into generatedDir
filteringCharset = 'UTF-8'
rename (mapped_vespucci_preset_file, vespucci_preset_build_v5_file)
filter(ReplaceTokens, beginToken : '${', endToken : '}', tokens: [ICONPATH: 'icons/png/', ICONTYPE: 'png'])
}
task generateAndValidateVespucciBuild(dependsOn: ["vespucciBuild", "vespucciBuildV5", "copyResources"], type: Exec) {
def input = generated + vespucci_preset_build_v5_file
// validation
commandLine 'xmlstarlet', 'val', '-s', "build/xml/vespucci-preset-${vespucci_preset_version}.xlmns", '-e', input
}
task vespucciLegacyZip(dependsOn: ["generateAndValidateVespucci", "updateTranslations"], type: Zip) {
// this suppresses bogus errors from gradle
mustRunAfter "vespucciBuildV5", "vespucciBuild"
archiveBaseName = 'vespucci_v4_zip'
version ''
destinationDirectory = generatedDir
from ('icons/png')
from (generated + vespucci_preset_file)
from ('i18n')
exclude ('*.pot')
}
vespucciLegacyZip.group = 'preset'
vespucciLegacyZip.description = 'Generate V4 zipped preset file for vespucci'
task vespucciZip(dependsOn: ["generateAndValidateVespucci", "updateTranslations"], type: Zip) {
// this suppresses bogus errors from gradle
mustRunAfter "vespucciBuildV5", "vespucciBuild"
archiveBaseName = 'vespucci_v5'
version ''
destinationDirectory = generatedDir
from ('icons/png')
from (generated + vespucci_preset_v5_file)
from ('i18n')
exclude ('*.pot')
}
vespucciZip.group = 'preset'
vespucciZip.description = 'Generate V5 zipped preset file for vespucci'
task vespucciIconsZip(type: Zip) {
archiveBaseName = 'vespucci_icons'
version ''
destinationDirectory = generatedDir
from ('icons/png')
}
vespucciZip.group = 'preset'
vespucciZip.description = 'Generate zipped icon file for vespucci'
// JOSM
// generate josm compatible preset with our icons
task transformToJosm(dependsOn: ["mapToBeautifiedIcons", "vespucciIcons", "copyResources"], type: Exec) {
def output = josm_preset_file
mkdir(generated)
// remove extensions
commandLine 'xmlstarlet', 'tr', 'build/xml/toJOSM.xslt', 'build/gen/' + vespucci_preset_v5_file
doFirst {
standardOutput = new FileOutputStream(new File(tempDir, output))
}
}
// map to JOSM icon set
task mapToJosmIcons(type: Copy) {
// this suppresses bogus errors from gradle
mustRunAfter "vespucciBuildV5", "vespucciBuild", "vespucciIcons", "josmZip"
inputs.file('josm_icons.mapping')
from projectDir
include preset_file
into tempDir
filteringCharset = 'UTF-8'
rename (preset_file, mapped_josm_preset_file)
def map = loadProperties('josm_icons.mapping')
filter(ReplaceTokens, beginToken : '${', endToken : '}', tokens: map)
}
task transformToJosmOrigIcons(dependsOn: ["mapToJosmIcons", "copyResources"], type: Exec) {
def output = 'gen/' + josm_preset_orig_icons_file
mkdir(generated)
// remove extensions
commandLine 'xmlstarlet', 'tr', 'build/xml/toJOSM.xslt', tempDir.getPath() + "/" + mapped_josm_preset_file
doFirst {
standardOutput = new FileOutputStream(new File(buildDir, output))
}
}
task generateAndValidateJosm(dependsOn: ["transformToJosm"], type: Exec) {
def input = tempDir.getPath() + "/" + josm_preset_file
// validation
commandLine 'xmlstarlet', 'val', '-s', 'build/xml/josm-preset-1.0.xlmns', '-e', input
}
task josmZip(dependsOn: ["generateAndValidateJosm", "copyTranslations", "generateLang"], type: Zip) {
archiveBaseName ='josm'
version ''
destinationDirectory = generatedDir
from ('icons/png')
from (tempDir.getPath() + "/" + josm_preset_file)
from (tempDir.getPath() + "/" + 'i18n')
exclude ('data/*.pot', 'data/*.po')
}
josmZip.group = 'preset'
josmZip.description = 'Generate zipped preset file for JOSM'
task josmOrigIconsZip(dependsOn: ["mapToJosmIcons","transformToJosmOrigIcons", "copyTranslations", "generateLang"], type: Zip) {
archiveBaseName ='josm_orig_icons'
version ''
destinationDirectory = generatedDir
from (generated + josm_preset_orig_icons_file)
from (tempDir.getPath() + "/" + 'i18n')
exclude ('data/*.pot', 'data/*.po')
}
josmZip.group = 'preset'
josmZip.description = 'Generate zipped preset file for JOSM for use with the original icons'
task replaceVersion {
inputs.file('build.gradle')
// note that this will only replace the version if it is already a valid version string
ant.replaceregexp(match:'presets version="([0-9\\.]+)"', replace:"presets version=\"${project.ext.version}\"", flags:'g', byline:true) {
fileset(dir: '.', includes: 'master_preset.xml')
}
}
task recolour {
group "Icons"
description "recolour svg icons"
doLast {
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()
logger.info("Recolouring icons from $source $categoryName")
copy {
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 + '\"')
}
}
}
}
}
}
task generatePngs (dependsOn: ["recolour"]) {
group "Icons"
description "generate PNGs from, potentially recoloured, SVG files"
doLast {
String[] svgDirs = ["build/icons/recoloured/", "icons/svg-signs/", "icons/svg-roofs/"]
svgDirs.each { svgDir ->
logger.info("Creating PNGs for icons in $svgDir")
def size = svgDir.contains("roof") ? 56 : 48 // hack alert
fileTree(dir: svgDir).each { svg ->
String fileName = svg.getName().replace('.svg','.png');
exec {
commandLine 'rsvg-convert', '-a', '-f', 'png', '-h', size, '-o', 'icons/png/' + fileName, svg
}
}
}
}
}
githubRelease {
token project.ext.githubToken == null ? "" : project.ext.githubToken
owner = "simonpoole"
tagName = project.ext.version
releaseName = project.ext.version
targetCommitish = "master"
generateReleaseNotes = true
body = provider { """\
## Files
### Vespucci
_vespucci_v5.zip_ - current preset for Vespucci 19 and later with icons
_vespucci_preset_v5.xml_ - current preset for Vespucci 19 and later without icons
_vespucci_v4_zip.zip_ - current preset in backwards compatible format (pre-Vespucci 19) with icons
_vespucci_preset.xml_ - current preset in backwards compatible format (pre-Vespucci 19) without icons
### JOSM
_josm.zip_ - current preset for JOSM using icons from this project and translations
_josm_orig_icons.zip_ - current preset for JOSM using icons distributed with JOSM, includes translations
_josm_preset_orig_icons.xml_ - current preset for JOSM using icons distributed with JOSM, without translations
### Vespucci build
_vespucci_preset_build_v5.xml_ - current preset for building Vespucci 19 and later
_vespucci_preset_build.xml_ - current preset for building Vespucci pre version 19
_vespucci_icons.zip_ - icons from this project
## URLs
You can link to the files, for example for inclusion in JOSM, by using URLs of the form
https://github.com/simonpoole/beautified-JOSM-preset/releases/latest/download/_filename_
these will always return the current release of the specified file.
"""
}
releaseAssets new File(buildDir, 'gen').listFiles()
overwrite = true
}
build {
dependsOn "vespucciLegacyZip"
dependsOn "vespucciZip"
dependsOn "vespucciIconsZip"
dependsOn "generateAndValidateVespucciBuild"
dependsOn "transformToJosmOrigIcons"
dependsOn "josmZip"
dependsOn "josmOrigIconsZip"
dependsOn "updatePot"
dependsOn "updateWebsite"
}
check {
dependsOn "generateAndValidateVespucci"
dependsOn "generateAndValidateJosm"
}