use of org.yaml.snakeyaml.Yaml in project bboxdb by jnidzwetzki.
the class TupleStoreMetaData method exportToYamlFile.
/**
* Export the data to YAML File
* @return
* @throws IOException
*/
public void exportToYamlFile(final File outputFile) throws IOException {
final Map<String, Object> data = getPropertyMap();
final FileWriter writer = new FileWriter(outputFile);
logger.debug("Output data to: " + outputFile);
final Yaml yaml = new Yaml();
yaml.dump(data, writer);
writer.close();
}
use of org.yaml.snakeyaml.Yaml in project wildfly-swarm by wildfly-swarm.
the class FractionManifest method read.
@SuppressWarnings("unchecked")
protected void read(InputStream in) throws IOException {
Yaml yaml = new Yaml();
Map data = (Map) yaml.load(in);
setName((String) data.get("name"));
setModule((String) data.get("module"));
setGroupId((String) data.get("groupId"));
setArtifactId((String) data.get("artifactId"));
setVersion((String) data.get("version"));
setDependencies((Collection<String>) data.get("dependencies"));
Object internal = data.get("internal");
if (internal != null) {
setInternal((Boolean) internal);
}
Map stability = (Map) data.get("stability");
if (stability != null) {
setStabilityIndex((Integer) stability.get("index"));
setStabilityLevel((String) stability.get("level"));
}
}
use of org.yaml.snakeyaml.Yaml in project wildfly-swarm by wildfly-swarm.
the class WildFlySwarmManifest method toString.
@Override
public String toString() {
Map<String, Object> data = new LinkedHashMap<String, Object>() {
{
if (asset != null) {
put(ASSET, asset);
}
put(MAIN_CLASS, mainClass);
put(HOLLOW, hollow);
put(PROPERTIES, properties);
put(MODULES, bootstrapModules);
put(BOOTSTRAP_ARTIFACTS, bootstrapArtifacts);
put(BUNDLE_DEPENDENCIES, bundleDependencies);
put(DEPENDENCIES, dependencies);
}
};
DumperOptions options = new DumperOptions();
options.setPrettyFlow(true);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(options);
return yaml.dump(data);
}
use of org.yaml.snakeyaml.Yaml in project wildfly-swarm by wildfly-swarm.
the class HttpSecurityPreparerTest method yaml_parsing.
@SuppressWarnings("unchecked")
@Test
public void yaml_parsing() throws Exception {
InputStream in = getClass().getClassLoader().getResourceAsStream("security.yml");
assertThat(in).isNotNull().as("security.yml is null");
Yaml yaml = new Yaml();
Map<String, Object> httpConfig = (Map<String, Object>) yaml.load(in);
preparer.deploymentConfigs = (Map) ((Map) httpConfig.get("swarm")).get("deployment");
preparer.process();
WebAppDescriptor webXml = Descriptors.importAs(WebAppDescriptor.class).fromStream(archive.get(WebXmlAsset.NAME).getAsset().openStream());
assertThat(webXml.getAllSecurityConstraint().size()).isEqualTo(1);
assertThat(webXml.getAllSecurityConstraint().get(0).getAllWebResourceCollection().get(0).getAllUrlPattern().get(0)).isEqualTo("/protected");
}
use of org.yaml.snakeyaml.Yaml in project error-prone by google.
the class BugPatternFileGenerator method processLine.
@Override
public boolean processLine(String line) throws IOException {
BugPatternInstance pattern = new Gson().fromJson(line, BugPatternInstance.class);
result.add(pattern);
// replace spaces in filename with underscores
Path checkPath = Paths.get(pattern.name.replace(' ', '_') + ".md");
try (Writer writer = Files.newBufferedWriter(outputDir.resolve(checkPath), UTF_8)) {
// load side-car explanation file, if it exists
Path sidecarExplanation = explanationDir.resolve(checkPath);
if (Files.exists(sidecarExplanation)) {
if (!pattern.explanation.isEmpty()) {
throw new AssertionError(String.format("%s specifies an explanation via @BugPattern and side-car", pattern.name));
}
pattern.explanation = new String(Files.readAllBytes(sidecarExplanation), UTF_8).trim();
}
// Construct an appropriate page for this {@code BugPattern}. Include altNames if
// there are any, and explain the correct way to suppress.
ImmutableMap.Builder<String, Object> templateData = ImmutableMap.<String, Object>builder().put("tags", Joiner.on(", ").join(pattern.tags)).put("severity", pattern.severity).put("providesFix", pattern.providesFix.displayInfo()).put("name", pattern.name).put("summary", pattern.summary.trim()).put("altNames", Joiner.on(", ").join(pattern.altNames)).put("explanation", pattern.explanation.trim());
if (baseUrl != null) {
templateData.put("baseUrl", baseUrl);
}
if (generateFrontMatter) {
Map<String, String> frontmatterData = ImmutableMap.<String, String>builder().put("title", pattern.name).put("summary", pattern.summary).put("layout", "bugpattern").put("tags", Joiner.on(", ").join(pattern.tags)).put("severity", pattern.severity.toString()).put("providesFix", pattern.providesFix.toString()).build();
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(options);
Writer yamlWriter = new StringWriter();
yamlWriter.write("---\n");
yaml.dump(frontmatterData, yamlWriter);
yamlWriter.write("---\n");
templateData.put("frontmatter", yamlWriter.toString());
}
if (pattern.documentSuppression) {
String suppressionString;
if (pattern.suppressionAnnotations.length == 0) {
suppressionString = "This check may not be suppressed.";
} else {
suppressionString = pattern.suppressionAnnotations.length == 1 ? "Suppress false positives by adding the suppression annotation %s to the " + "enclosing element." : "Suppress false positives by adding one of these suppression annotations to " + "the enclosing element: %s";
suppressionString = String.format(suppressionString, Arrays.stream(pattern.suppressionAnnotations).map((String anno) -> standardizeAnnotation(anno, pattern.name)).collect(Collectors.joining(", ")));
}
templateData.put("suppression", suppressionString);
}
MustacheFactory mf = new DefaultMustacheFactory();
Mustache mustache = mf.compile("com/google/errorprone/resources/bugpattern.mustache");
mustache.execute(writer, templateData.build());
if (pattern.generateExamplesFromTestCases) {
// Example filename must match example pattern.
List<Path> examplePaths = new ArrayList<>();
Filter<Path> filter = new ExampleFilter(pattern.className.substring(pattern.className.lastIndexOf('.') + 1));
findExamples(examplePaths, exampleDirBase, filter);
List<ExampleInfo> exampleInfos = FluentIterable.from(examplePaths).transform(new PathToExampleInfo(pattern.className)).toSortedList(new Comparator<ExampleInfo>() {
@Override
public int compare(ExampleInfo first, ExampleInfo second) {
return first.name().compareTo(second.name());
}
});
Collection<ExampleInfo> positiveExamples = Collections2.filter(exampleInfos, IS_POSITIVE);
Collection<ExampleInfo> negativeExamples = Collections2.filter(exampleInfos, not(IS_POSITIVE));
if (!exampleInfos.isEmpty()) {
writer.write("\n----------\n\n");
if (!positiveExamples.isEmpty()) {
writer.write("### Positive examples\n");
for (ExampleInfo positiveExample : positiveExamples) {
writeExample(positiveExample, writer);
}
}
if (!negativeExamples.isEmpty()) {
writer.write("### Negative examples\n");
for (ExampleInfo negativeExample : negativeExamples) {
writeExample(negativeExample, writer);
}
}
}
}
}
return true;
}
Aggregations