1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package io.wcm.devops.conga.plugins.aem.maven.model;
21
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24 import org.yaml.snakeyaml.Yaml;
25 import org.yaml.snakeyaml.constructor.Constructor;
26
27 import io.wcm.devops.conga.generator.spi.context.PluginContextOptions;
28 import io.wcm.devops.conga.generator.spi.yaml.YamlConstructorPlugin;
29 import io.wcm.devops.conga.generator.spi.yaml.context.YamlConstructorContext;
30 import io.wcm.devops.conga.generator.util.PluginManager;
31 import io.wcm.devops.conga.generator.util.PluginManagerImpl;
32
33 final class YamlUtil {
34
35 private YamlUtil() {
36
37 }
38
39 private static final Logger log = LoggerFactory.getLogger(YamlUtil.class);
40
41 public static Yaml createYaml() {
42
43 PluginManager pluginManager = new PluginManagerImpl();
44 PluginContextOptions options = new PluginContextOptions()
45 .pluginManager(pluginManager)
46 .logger(log);
47
48
49 Constructor constructor = new Constructor(io.wcm.devops.conga.model.util.YamlUtil.createLoaderOptions());
50 YamlConstructorContext context = new YamlConstructorContext()
51 .pluginContextOptions(options)
52 .yamlConstructor(constructor);
53 for (YamlConstructorPlugin plugin : pluginManager.getAll(YamlConstructorPlugin.class)) {
54 plugin.register(context);
55 }
56
57 return new Yaml(constructor);
58 }
59
60 }