| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | /**
|
|---|
| 3 | * Extracts tag information for the taginfo project.
|
|---|
| 4 | *
|
|---|
| 5 | * Run from the base directory of a JOSM checkout:
|
|---|
| 6 | *
|
|---|
| 7 | * groovy -cp dist/josm-custom.jar scripts/taginfoextract.groovy -t mappaint
|
|---|
| 8 | * groovy -cp dist/josm-custom.jar scripts/taginfoextract.groovy -t presets
|
|---|
| 9 | * groovy -cp dist/josm-custom.jar scripts/taginfoextract.groovy -t external_presets
|
|---|
| 10 | */
|
|---|
| 11 | import groovy.json.JsonBuilder
|
|---|
| 12 |
|
|---|
| 13 | import java.awt.image.BufferedImage
|
|---|
| 14 | import java.nio.file.FileSystems
|
|---|
| 15 | import java.nio.file.Files
|
|---|
| 16 | import java.nio.file.Path
|
|---|
| 17 |
|
|---|
| 18 | import javax.imageio.ImageIO
|
|---|
| 19 |
|
|---|
| 20 | import org.openstreetmap.josm.Main
|
|---|
| 21 | import org.openstreetmap.josm.data.Version
|
|---|
| 22 | import org.openstreetmap.josm.data.coor.LatLon
|
|---|
| 23 | import org.openstreetmap.josm.data.osm.Node
|
|---|
| 24 | import org.openstreetmap.josm.data.osm.OsmPrimitive
|
|---|
| 25 | import org.openstreetmap.josm.data.osm.Way
|
|---|
| 26 | import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings
|
|---|
| 27 | import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer
|
|---|
| 28 | import org.openstreetmap.josm.data.projection.Projections
|
|---|
| 29 | import org.openstreetmap.josm.gui.NavigatableComponent
|
|---|
| 30 | import org.openstreetmap.josm.gui.mappaint.Environment
|
|---|
| 31 | import org.openstreetmap.josm.gui.mappaint.MultiCascade
|
|---|
| 32 | import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference
|
|---|
| 33 | import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource
|
|---|
| 34 | import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.SimpleKeyValueCondition
|
|---|
| 35 | import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector
|
|---|
| 36 | import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser
|
|---|
| 37 | import org.openstreetmap.josm.gui.mappaint.styleelement.AreaElement
|
|---|
| 38 | import org.openstreetmap.josm.gui.mappaint.styleelement.LineElement
|
|---|
| 39 | import org.openstreetmap.josm.gui.mappaint.styleelement.StyleElement
|
|---|
| 40 | import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference
|
|---|
| 41 | import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset
|
|---|
| 42 | import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetReader
|
|---|
| 43 | import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetType
|
|---|
| 44 | import org.openstreetmap.josm.gui.tagging.presets.items.KeyedItem
|
|---|
| 45 | import org.openstreetmap.josm.gui.tagging.presets.items.KeyedItem.MatchType
|
|---|
| 46 | import org.openstreetmap.josm.io.CachedFile
|
|---|
| 47 | import org.openstreetmap.josm.tools.Utils
|
|---|
| 48 |
|
|---|
| 49 | class TagInfoExtract {
|
|---|
| 50 |
|
|---|
| 51 | static def options
|
|---|
| 52 | static String image_dir
|
|---|
| 53 | int josm_svn_revision
|
|---|
| 54 | String input_file
|
|---|
| 55 | MapCSSStyleSource style_source
|
|---|
| 56 | FileWriter output_file
|
|---|
| 57 | String base_dir = "."
|
|---|
| 58 | Set tags = []
|
|---|
| 59 |
|
|---|
| 60 | private def cached_svnrev
|
|---|
| 61 |
|
|---|
| 62 | /**
|
|---|
| 63 | * Check if a certain tag is supported by the style as node / way / area.
|
|---|
| 64 | */
|
|---|
| 65 | abstract class Checker {
|
|---|
| 66 |
|
|---|
| 67 | def tag
|
|---|
| 68 | OsmPrimitive osm
|
|---|
| 69 |
|
|---|
| 70 | Checker(tag) {
|
|---|
| 71 | this.tag = tag
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | Environment apply_stylesheet(OsmPrimitive osm) {
|
|---|
| 75 | osm.put(tag[0], tag[1])
|
|---|
| 76 | MultiCascade mc = new MultiCascade()
|
|---|
| 77 |
|
|---|
| 78 | Environment env = new Environment(osm, mc, null, style_source)
|
|---|
| 79 | for (def r in style_source.rules) {
|
|---|
| 80 | env.clearSelectorMatchingInformation()
|
|---|
| 81 | if (r.selector.matches(env)) {
|
|---|
| 82 | // ignore selector range
|
|---|
| 83 | if (env.layer == null) {
|
|---|
| 84 | env.layer = "default"
|
|---|
| 85 | }
|
|---|
| 86 | r.execute(env)
|
|---|
| 87 | }
|
|---|
| 88 | }
|
|---|
| 89 | env.layer = "default"
|
|---|
| 90 | return env
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | /**
|
|---|
| 94 | * Create image file from StyleElement.
|
|---|
| 95 | * @return the URL
|
|---|
| 96 | */
|
|---|
| 97 | def create_image(StyleElement elem_style, type, nc) {
|
|---|
| 98 | def img = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)
|
|---|
| 99 | def g = img.createGraphics()
|
|---|
| 100 | g.setClip(0, 0, 16, 16)
|
|---|
| 101 | def renderer = new StyledMapRenderer(g, nc, false)
|
|---|
| 102 | renderer.getSettings(false)
|
|---|
| 103 | elem_style.paintPrimitive(osm, MapPaintSettings.INSTANCE, renderer, false, false, false)
|
|---|
| 104 | def base_url = options.imgurlprefix ? options.imgurlprefix : image_dir
|
|---|
| 105 | def image_name = "${type}_${tag[0]}=${tag[1]}.png"
|
|---|
| 106 | ImageIO.write(img, "png", new File("${image_dir}/${image_name}"))
|
|---|
| 107 | return "${base_url}/${image_name}"
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | /**
|
|---|
| 111 | * Checks, if tag is supported and find URL for image icon in this case.
|
|---|
| 112 | * @param generate_image if true, create or find a suitable image icon and return URL,
|
|---|
| 113 | * if false, just check if tag is supported and return true or false
|
|---|
| 114 | */
|
|---|
| 115 | abstract def find_url(boolean generate_image)
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | class NodeChecker extends Checker {
|
|---|
| 119 | NodeChecker(tag) {
|
|---|
| 120 | super(tag)
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | @Override
|
|---|
| 124 | def find_url(boolean generate_image) {
|
|---|
| 125 | osm = new Node(LatLon.ZERO)
|
|---|
| 126 | def env = apply_stylesheet(osm)
|
|---|
| 127 | def c = env.mc.getCascade("default")
|
|---|
| 128 | def image = c.get("icon-image")
|
|---|
| 129 | if (image) {
|
|---|
| 130 | if (image instanceof IconReference) {
|
|---|
| 131 | if (image.iconName != "misc/deprecated.svg")
|
|---|
| 132 | return find_image_url(image.iconName)
|
|---|
| 133 | }
|
|---|
| 134 | }
|
|---|
| 135 | }
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | class WayChecker extends Checker {
|
|---|
| 139 | WayChecker(tag) {
|
|---|
| 140 | super(tag)
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | @Override
|
|---|
| 144 | def find_url(boolean generate_image) {
|
|---|
| 145 | osm = new Way()
|
|---|
| 146 | def nc = new NavigatableComponent()
|
|---|
| 147 | def n1 = new Node(nc.getLatLon(2,8))
|
|---|
| 148 | def n2 = new Node(nc.getLatLon(14,8))
|
|---|
| 149 | ((Way)osm).addNode(n1)
|
|---|
| 150 | ((Way)osm).addNode(n2)
|
|---|
| 151 | def env = apply_stylesheet(osm)
|
|---|
| 152 | def les = LineElement.createLine(env)
|
|---|
| 153 | if (les != null) {
|
|---|
| 154 | if (!generate_image) return true
|
|---|
| 155 | return create_image(les, 'way', nc)
|
|---|
| 156 | }
|
|---|
| 157 | }
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | class AreaChecker extends Checker {
|
|---|
| 161 | AreaChecker(tag) {
|
|---|
| 162 | super(tag)
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 | @Override
|
|---|
| 166 | def find_url(boolean generate_image) {
|
|---|
| 167 | osm = new Way()
|
|---|
| 168 | def nc = new NavigatableComponent()
|
|---|
| 169 | def n1 = new Node(nc.getLatLon(2,2))
|
|---|
| 170 | def n2 = new Node(nc.getLatLon(14,2))
|
|---|
| 171 | def n3 = new Node(nc.getLatLon(14,14))
|
|---|
| 172 | def n4 = new Node(nc.getLatLon(2,14))
|
|---|
| 173 | ((Way)osm).addNode(n1)
|
|---|
| 174 | ((Way)osm).addNode(n2)
|
|---|
| 175 | ((Way)osm).addNode(n3)
|
|---|
| 176 | ((Way)osm).addNode(n4)
|
|---|
| 177 | ((Way)osm).addNode(n1)
|
|---|
| 178 | def env = apply_stylesheet(osm)
|
|---|
| 179 | def aes = AreaElement.create(env)
|
|---|
| 180 | if (aes != null) {
|
|---|
| 181 | if (!generate_image) return true
|
|---|
| 182 | return create_image(aes, 'area', nc)
|
|---|
| 183 | }
|
|---|
| 184 | }
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | /**
|
|---|
| 188 | * Main method.
|
|---|
| 189 | */
|
|---|
| 190 | static main(def args) {
|
|---|
| 191 | parse_command_line_arguments(args)
|
|---|
| 192 | def script = new TagInfoExtract()
|
|---|
| 193 | if (!options.t || options.t == 'mappaint') {
|
|---|
| 194 | script.run()
|
|---|
| 195 | } else if (options.t == 'presets') {
|
|---|
| 196 | script.run_presets()
|
|---|
| 197 | } else if (options.t == 'external_presets') {
|
|---|
| 198 | script.run_external_presets()
|
|---|
| 199 | } else {
|
|---|
| 200 | System.err.println 'Invalid type ' + options.t
|
|---|
| 201 | if (!options.noexit) {
|
|---|
| 202 | System.exit(1)
|
|---|
| 203 | }
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | if (!options.noexit) {
|
|---|
| 207 | System.exit(0)
|
|---|
| 208 | }
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | /**
|
|---|
| 212 | * Parse command line arguments.
|
|---|
| 213 | */
|
|---|
| 214 | static void parse_command_line_arguments(args) {
|
|---|
| 215 | def cli = new CliBuilder(usage:'taginfoextract.groovy [options] [inputfile]',
|
|---|
| 216 | header:"Options:",
|
|---|
| 217 | footer:"[inputfile] the file to process (optional, default is 'resource://styles/standard/elemstyles.mapcss')")
|
|---|
| 218 | cli.o(args:1, argName: "file", "output file (json), - prints to stdout (default: -)")
|
|---|
| 219 | cli.t(args:1, argName: "type", "the project type to be generated")
|
|---|
| 220 | cli._(longOpt:'svnrev', args:1, argName:"revision", "corresponding revision of the repository https://svn.openstreetmap.org/ (optional, current revision is read from the local checkout or from the web if not given, see --svnweb)")
|
|---|
| 221 | cli._(longOpt:'imgdir', args:1, argName:"directory", "directory to put the generated images in (default: ./taginfo-img)")
|
|---|
| 222 | cli._(longOpt:'noexit', "don't call System.exit(), for use from Ant script")
|
|---|
| 223 | cli._(longOpt:'svnweb', 'fetch revision of the repository https://svn.openstreetmap.org/ from web and not from the local repository')
|
|---|
| 224 | cli._(longOpt:'imgurlprefix', args:1, argName:'prefix', 'image URLs prefix for generated image files')
|
|---|
| 225 | cli.h(longOpt:'help', "show this help")
|
|---|
| 226 | options = cli.parse(args)
|
|---|
| 227 |
|
|---|
| 228 | if (options.h) {
|
|---|
| 229 | cli.usage()
|
|---|
| 230 | System.exit(0)
|
|---|
| 231 | }
|
|---|
| 232 | if (options.arguments().size() > 1) {
|
|---|
| 233 | System.err.println "Error: More than one input file given!"
|
|---|
| 234 | cli.usage()
|
|---|
| 235 | System.exit(-1)
|
|---|
| 236 | }
|
|---|
| 237 | if (options.svnrev) {
|
|---|
| 238 | assert Integer.parseInt(options.svnrev) > 0
|
|---|
| 239 | }
|
|---|
| 240 | image_dir = 'taginfo-img'
|
|---|
| 241 | if (options.imgdir) {
|
|---|
| 242 | image_dir = options.imgdir
|
|---|
| 243 | }
|
|---|
| 244 | def image_dir_file = new File(image_dir)
|
|---|
| 245 | if (!image_dir_file.exists()) {
|
|---|
| 246 | image_dir_file.mkdirs()
|
|---|
| 247 | }
|
|---|
| 248 | }
|
|---|
| 249 |
|
|---|
| 250 | void run_presets() {
|
|---|
| 251 | init()
|
|---|
| 252 | def presets = TaggingPresetReader.readAll(input_file, true)
|
|---|
| 253 | def tags = convert_presets(presets, "", true)
|
|---|
| 254 | write_json("JOSM main presets", "Tags supported by the default presets in the OSM editor JOSM", tags)
|
|---|
| 255 | }
|
|---|
| 256 |
|
|---|
| 257 | def convert_presets(Iterable<TaggingPreset> presets, String descriptionPrefix, boolean addImages) {
|
|---|
| 258 | def tags = []
|
|---|
| 259 | for (TaggingPreset preset : presets) {
|
|---|
| 260 | for (KeyedItem item : Utils.filteredCollection(preset.data, KeyedItem.class)) {
|
|---|
| 261 | def values
|
|---|
| 262 | switch (MatchType.ofString(item.match)) {
|
|---|
| 263 | case MatchType.KEY_REQUIRED: values = item.getValues(); break;
|
|---|
| 264 | case MatchType.KEY_VALUE_REQUIRED: values = item.getValues(); break;
|
|---|
| 265 | default: values = [];
|
|---|
| 266 | }
|
|---|
| 267 | for (String value : values) {
|
|---|
| 268 | def tag = [
|
|---|
| 269 | description: descriptionPrefix + preset.name,
|
|---|
| 270 | key: item.key,
|
|---|
| 271 | value: value,
|
|---|
| 272 | ]
|
|---|
| 273 | def otypes = preset.types.collect {
|
|---|
| 274 | it == TaggingPresetType.CLOSEDWAY ? "area" :
|
|---|
| 275 | (it == TaggingPresetType.MULTIPOLYGON ? "relation" : it.toString().toLowerCase(Locale.ENGLISH))
|
|---|
| 276 | }
|
|---|
| 277 | if (!otypes.isEmpty()) tag += [object_types: otypes]
|
|---|
| 278 | if (addImages && preset.iconName) tag += [icon_url: find_image_url(preset.iconName)]
|
|---|
| 279 | tags += tag
|
|---|
| 280 | }
|
|---|
| 281 | }
|
|---|
| 282 | }
|
|---|
| 283 | return tags
|
|---|
| 284 | }
|
|---|
| 285 |
|
|---|
| 286 | void run_external_presets() {
|
|---|
| 287 | init()
|
|---|
| 288 | TaggingPresetReader.setLoadIcons(false)
|
|---|
| 289 | def sources = new TaggingPresetPreference.TaggingPresetSourceEditor().loadAndGetAvailableSources()
|
|---|
| 290 | def tags = []
|
|---|
| 291 | for (def source : sources) {
|
|---|
| 292 | if (source.url.startsWith("resource")) {
|
|---|
| 293 | // default presets
|
|---|
| 294 | continue;
|
|---|
| 295 | }
|
|---|
| 296 | try {
|
|---|
| 297 | println "Loading ${source.url}"
|
|---|
| 298 | def presets = TaggingPresetReader.readAll(source.url, false)
|
|---|
| 299 | def t = convert_presets(presets, source.title + " ", false)
|
|---|
| 300 | println "Converting ${t.size()} presets of ${source.title}"
|
|---|
| 301 | tags += t
|
|---|
| 302 | } catch (Exception ex) {
|
|---|
| 303 | System.err.println("Skipping ${source.url} due to error")
|
|---|
| 304 | ex.printStackTrace()
|
|---|
| 305 | }
|
|---|
| 306 | }
|
|---|
| 307 | write_json("JOSM user presets", "Tags supported by the user contributed presets in the OSM editor JOSM", tags)
|
|---|
| 308 | }
|
|---|
| 309 |
|
|---|
| 310 | void run() {
|
|---|
| 311 | init()
|
|---|
| 312 | parse_style_sheet()
|
|---|
| 313 | collect_tags()
|
|---|
| 314 |
|
|---|
| 315 | def tags = tags.collect {
|
|---|
| 316 | def tag = it
|
|---|
| 317 | def types = []
|
|---|
| 318 | def final_url = null
|
|---|
| 319 |
|
|---|
| 320 | def node_url = new NodeChecker(tag).find_url(true)
|
|---|
| 321 | if (node_url) {
|
|---|
| 322 | types += 'node'
|
|---|
| 323 | final_url = node_url
|
|---|
| 324 | }
|
|---|
| 325 | def way_url = new WayChecker(tag).find_url(final_url == null)
|
|---|
| 326 | if (way_url) {
|
|---|
| 327 | types += 'way'
|
|---|
| 328 | if (!final_url) {
|
|---|
| 329 | final_url = way_url
|
|---|
| 330 | }
|
|---|
| 331 | }
|
|---|
| 332 | def area_url = new AreaChecker(tag).find_url(final_url == null)
|
|---|
| 333 | if (area_url) {
|
|---|
| 334 | types += 'area'
|
|---|
| 335 | if (!final_url) {
|
|---|
| 336 | final_url = area_url
|
|---|
| 337 | }
|
|---|
| 338 | }
|
|---|
| 339 |
|
|---|
| 340 | def obj = [key: tag[0], value: tag[1]]
|
|---|
| 341 | if (types) obj += [object_types: types]
|
|---|
| 342 | if (final_url) obj += [icon_url: final_url]
|
|---|
| 343 | obj
|
|---|
| 344 | }
|
|---|
| 345 |
|
|---|
| 346 | write_json("JOSM main mappaint style", "Tags supported by the main mappaint style in the OSM editor JOSM", tags)
|
|---|
| 347 | }
|
|---|
| 348 |
|
|---|
| 349 | void write_json(name, description, tags) {
|
|---|
| 350 | def json = new JsonBuilder()
|
|---|
| 351 | def project = [
|
|---|
| 352 | name: name,
|
|---|
| 353 | description: description,
|
|---|
| 354 | project_url: "https://josm.openstreetmap.de/",
|
|---|
| 355 | icon_url: "https://josm.openstreetmap.de/export/7770/josm/trunk/images/logo_16x16x8.png",
|
|---|
| 356 | contact_name: "JOSM developer team",
|
|---|
| 357 | contact_email: "josm-dev@openstreetmap.org",
|
|---|
| 358 | ]
|
|---|
| 359 | json data_format: 1, data_updated: new Date().format("yyyyMMdd'T'hhmmss'Z'", TimeZone.getTimeZone('UTC')), project: project, tags: tags
|
|---|
| 360 |
|
|---|
| 361 | if (output_file != null) {
|
|---|
| 362 | json.writeTo(output_file)
|
|---|
| 363 | output_file.close()
|
|---|
| 364 | } else {
|
|---|
| 365 | print json.toPrettyString()
|
|---|
| 366 | }
|
|---|
| 367 | }
|
|---|
| 368 |
|
|---|
| 369 | /**
|
|---|
| 370 | * Initialize the script.
|
|---|
| 371 | */
|
|---|
| 372 | def init() {
|
|---|
| 373 | Main.determinePlatformHook()
|
|---|
| 374 | Main.pref.enableSaveOnPut(false)
|
|---|
| 375 | Main.setProjection(Projections.getProjectionByCode("EPSG:3857"))
|
|---|
| 376 | Path tmpdir = Files.createTempDirectory(FileSystems.getDefault().getPath(base_dir), "pref")
|
|---|
| 377 | tmpdir.toFile().deleteOnExit()
|
|---|
| 378 | System.setProperty("josm.home", tmpdir.toString())
|
|---|
| 379 |
|
|---|
| 380 | josm_svn_revision = Version.getInstance().getVersion()
|
|---|
| 381 | assert josm_svn_revision != Version.JOSM_UNKNOWN_VERSION
|
|---|
| 382 |
|
|---|
| 383 | if (options.arguments().size() == 0 && (!options.t || options.t == 'mappaint')) {
|
|---|
| 384 | input_file = "resource://styles/standard/elemstyles.mapcss"
|
|---|
| 385 | } else if (options.arguments().size() == 0 && options.t == 'presets') {
|
|---|
| 386 | input_file = "resource://data/defaultpresets.xml"
|
|---|
| 387 | } else {
|
|---|
| 388 | input_file = options.arguments()[0]
|
|---|
| 389 | }
|
|---|
| 390 |
|
|---|
| 391 | output_file = null
|
|---|
| 392 | if (options.o && options.o != "-") {
|
|---|
| 393 | output_file = new FileWriter(options.o)
|
|---|
| 394 | }
|
|---|
| 395 | }
|
|---|
| 396 |
|
|---|
| 397 | /**
|
|---|
| 398 | * Determine full image url (can refer to JOSM or OSM repository).
|
|---|
| 399 | */
|
|---|
| 400 | def find_image_url(String path) {
|
|---|
| 401 | def f = new File("${base_dir}/images/styles/standard/${path}")
|
|---|
| 402 | if (f.exists()) {
|
|---|
| 403 | def rev = osm_svn_revision()
|
|---|
| 404 | return "https://trac.openstreetmap.org/export/${rev}/subversion/applications/share/map-icons/classic.small/${path}"
|
|---|
| 405 | }
|
|---|
| 406 | f = new File("${base_dir}/images/${path}")
|
|---|
| 407 | if (f.exists()) {
|
|---|
| 408 | if (path.startsWith("images/styles/standard/")) {
|
|---|
| 409 | path = path.substring("images/styles/standard/".length())
|
|---|
| 410 | def rev = osm_svn_revision()
|
|---|
| 411 | return "https://trac.openstreetmap.org/export/${rev}/subversion/applications/share/map-icons/classic.small/${path}"
|
|---|
| 412 | } else if (path.startsWith("styles/standard/")) {
|
|---|
| 413 | path = path.substring("styles/standard/".length())
|
|---|
| 414 | def rev = osm_svn_revision()
|
|---|
| 415 | return "https://trac.openstreetmap.org/export/${rev}/subversion/applications/share/map-icons/classic.small/${path}"
|
|---|
| 416 | } else {
|
|---|
| 417 | return "https://josm.openstreetmap.de/export/${josm_svn_revision}/josm/trunk/images/${path}"
|
|---|
| 418 | }
|
|---|
| 419 | }
|
|---|
| 420 | assert false, "Cannot find image url for ${path}"
|
|---|
| 421 | }
|
|---|
| 422 |
|
|---|
| 423 | /**
|
|---|
| 424 | * Get revision for the repository https://svn.openstreetmap.org.
|
|---|
| 425 | */
|
|---|
| 426 | def osm_svn_revision() {
|
|---|
| 427 | if (cached_svnrev != null) return cached_svnrev
|
|---|
| 428 | if (options.svnrev) {
|
|---|
| 429 | cached_svnrev = Integer.parseInt(options.svnrev)
|
|---|
| 430 | return cached_svnrev
|
|---|
| 431 | }
|
|---|
| 432 | def xml
|
|---|
| 433 | if (options.svnweb) {
|
|---|
| 434 | xml = "svn info --xml https://svn.openstreetmap.org/applications/share/map-icons/classic.small".execute().text
|
|---|
| 435 | } else {
|
|---|
| 436 | xml = "svn info --xml ${base_dir}/images/styles/standard/".execute().text
|
|---|
| 437 | }
|
|---|
| 438 |
|
|---|
| 439 | def svninfo = new XmlParser().parseText(xml)
|
|---|
| 440 | def rev = svninfo.entry.'@revision'[0]
|
|---|
| 441 | cached_svnrev = Integer.parseInt(rev)
|
|---|
| 442 | assert cached_svnrev > 0
|
|---|
| 443 | return cached_svnrev
|
|---|
| 444 | }
|
|---|
| 445 |
|
|---|
| 446 | /**
|
|---|
| 447 | * Read the style sheet file and parse the MapCSS code.
|
|---|
| 448 | */
|
|---|
| 449 | def parse_style_sheet() {
|
|---|
| 450 | def file = new CachedFile(input_file)
|
|---|
| 451 | def stream = file.getInputStream()
|
|---|
| 452 | def parser = new MapCSSParser(stream, "UTF-8", MapCSSParser.LexicalState.DEFAULT)
|
|---|
| 453 | style_source = new MapCSSStyleSource("")
|
|---|
| 454 | style_source.url = ""
|
|---|
| 455 | parser.sheet(style_source)
|
|---|
| 456 | }
|
|---|
| 457 |
|
|---|
| 458 | /**
|
|---|
| 459 | * Collect all the tag from the style sheet.
|
|---|
| 460 | */
|
|---|
| 461 | def collect_tags() {
|
|---|
| 462 | for (rule in style_source.rules) {
|
|---|
| 463 | def selector = rule.selector
|
|---|
| 464 | if (selector instanceof GeneralSelector) {
|
|---|
| 465 | def conditions = selector.getConditions()
|
|---|
| 466 | for (cond in conditions) {
|
|---|
| 467 | if (cond instanceof SimpleKeyValueCondition) {
|
|---|
| 468 | tags.add([cond.k, cond.v])
|
|---|
| 469 | }
|
|---|
| 470 | }
|
|---|
| 471 | }
|
|---|
| 472 | }
|
|---|
| 473 | }
|
|---|
| 474 | }
|
|---|