Jakub Josef | 3fc9ce3 | 2017-08-14 16:25:44 +0200 | [diff] [blame] | 1 | package com.mirantis.mk |
| 2 | |
| 3 | @Grab(group='org.yaml', module='snakeyaml', version='1.17') |
| 4 | import org.yaml.snakeyaml.Yaml |
| 5 | import org.yaml.snakeyaml.DumperOptions |
| 6 | |
| 7 | /** |
| 8 | * Helper class for YAML operations |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | |
| 13 | /** |
| 14 | * Convert YAML document to Map object |
| 15 | * @param data YAML string |
| 16 | */ |
| 17 | @NonCPS |
| 18 | def loadYAML(String data) { |
| 19 | def yaml = new Yaml() |
| 20 | return yaml.load(data) |
| 21 | } |
| 22 | |
| 23 | |
| 24 | /** |
| 25 | * Convert Map object to YAML string |
| 26 | * @param map Map object |
| 27 | */ |
| 28 | @NonCPS |
| 29 | def dumpYAML(Map map) { |
| 30 | def dumperOptions = new DumperOptions() |
| 31 | dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK) |
| 32 | def yaml = new Yaml(dumperOptions) |
| 33 | return yaml.dump(map) |
| 34 | } |