blob: e26ae2e06d5a0ae0052d9ae5fb14658730624e25 [file] [log] [blame]
Jakub Josef3fc9ce32017-08-14 16:25:44 +02001package com.mirantis.mk
2
3@Grab(group='org.yaml', module='snakeyaml', version='1.17')
4import org.yaml.snakeyaml.Yaml
5import 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
18def 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
29def 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}