use of org.yaml.snakeyaml.Yaml in project pom-manipulation-ext by release-engineering.
the class YamlTest method readYamlViaMap.
@Test
public void readYamlViaMap() throws ManipulationException, IOException {
Representer representer = new Representer();
representer.getPropertyUtils().setSkipMissingProperties(true);
Yaml y = new Yaml(representer);
Map config = (Map) y.load(new FileInputStream(yamlFile));
Map usersConfig = (Map) config.get("pme");
assertTrue(usersConfig.size() > 0);
}
use of org.yaml.snakeyaml.Yaml in project google-cloud-intellij by GoogleCloudPlatform.
the class DefaultAppEngineProjectService method getValueFromAppYaml.
/**
* Returns the value of a key-value pair for a given {@code key}, on the file located at {@code
* appYamlPathString}.
*
* @return a String with the value, or an empty Optional if app.yaml isn't a regular file, or if
* there is any error getting the value
* @throws MalformedYamlFileException when an app.yaml isn't syntactically well formed
*/
private Optional<String> getValueFromAppYaml(@NotNull String appYamlPathString, @NotNull String key) throws MalformedYamlFileException {
Yaml yamlParser = new Yaml();
Path appYamlPath = Paths.get(appYamlPathString);
if (!Files.isRegularFile(appYamlPath)) {
return Optional.empty();
}
try (BufferedReader reader = Files.newBufferedReader(appYamlPath, Charset.defaultCharset())) {
Object parseResult = yamlParser.load(reader);
if (!(parseResult instanceof Map)) {
return Optional.empty();
}
// It's possible to get rid of this unchecked cast using a loadAs(file,
// AppEngineYamlWebApp.class) sort of approach.
Map<String, String> yamlMap = (Map<String, String>) parseResult;
return yamlMap.containsKey(key) ? Optional.of(yamlMap.get(key)) : Optional.empty();
} catch (ScannerException se) {
throw new MalformedYamlFileException(se);
} catch (InvalidPathException | IOException ioe) {
return Optional.empty();
}
}
use of org.yaml.snakeyaml.Yaml in project pmd by pmd.
the class SidebarGeneratorTest method testSidebar.
@Test
public void testSidebar() throws IOException {
Map<Language, List<RuleSet>> rulesets = new HashMap<>();
RuleSet ruleSet1 = new RuleSetFactory().createNewRuleSet("test", "test", "bestpractices.xml", Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
RuleSet ruleSet2 = new RuleSetFactory().createNewRuleSet("test2", "test", "codestyle.xml", Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
rulesets.put(LanguageRegistry.findLanguageByTerseName("java"), Arrays.asList(ruleSet1, ruleSet2));
rulesets.put(LanguageRegistry.findLanguageByTerseName("ecmascript"), Arrays.asList(ruleSet1));
SidebarGenerator generator = new SidebarGenerator(writer, FileSystems.getDefault().getPath(".."));
List<Map<String, Object>> result = generator.generateRuleReferenceSection(rulesets);
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(FlowStyle.BLOCK);
if (SystemUtils.IS_OS_WINDOWS) {
options.setLineBreak(LineBreak.WIN);
}
String yaml = new Yaml(options).dump(result);
assertEquals(IOUtils.toString(SidebarGeneratorTest.class.getResourceAsStream("sidebar.yml")), yaml);
}
use of org.yaml.snakeyaml.Yaml in project Nukkit by Nukkit.
the class PluginBase method reloadConfig.
@Override
public void reloadConfig() {
this.config = new Config(this.configFile);
InputStream configStream = this.getResource("config.yml");
if (configStream != null) {
DumperOptions dumperOptions = new DumperOptions();
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(dumperOptions);
try {
this.config.setDefault(yaml.loadAs(Utils.readFile(this.configFile), LinkedHashMap.class));
} catch (IOException e) {
Server.getInstance().getLogger().logException(e);
}
}
}
use of org.yaml.snakeyaml.Yaml in project Nukkit by Nukkit.
the class Config method parseContent.
private void parseContent(String content) {
switch(this.type) {
case Config.PROPERTIES:
this.parseProperties(content);
break;
case Config.JSON:
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
this.config = new ConfigSection(gson.fromJson(content, new TypeToken<LinkedHashMap<String, Object>>() {
}.getType()));
break;
case Config.YAML:
DumperOptions dumperOptions = new DumperOptions();
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(dumperOptions);
this.config = new ConfigSection(yaml.loadAs(content, LinkedHashMap.class));
break;
// case Config.SERIALIZED
case Config.ENUM:
this.parseList(content);
break;
default:
this.correct = false;
}
}
Aggregations