use of org.yaml.snakeyaml.DumperOptions in project watson by totemo.
the class Configuration method save.
// load
// --------------------------------------------------------------------------
/**
* Save the configuration.
*/
public void save() {
File config = new File(Controller.getModDirectory(), CONFIG_FILE);
BufferedWriter writer;
try {
writer = new BufferedWriter(new FileWriter(config));
HashMap<String, Object> dom = new HashMap<String, Object>();
dom.put("enabled", isEnabled());
dom.put("debug", isDebug());
dom.put("auto_page", isAutoPage());
dom.put("region_info_timeout", getRegionInfoTimeoutSeconds());
dom.put("vectors_shown", getVectorsShown());
dom.put("billboard_background", getBillboardBackground());
dom.put("billboard_foreground", getBillboardForeground());
dom.put("group_ores_in_creative", isGroupingOresInCreative());
dom.put("teleport_command", getTeleportCommand());
dom.put("chat_timeout", getChatTimeoutSeconds());
dom.put("max_auto_pages", getMaxAutoPages());
dom.put("pre_count", getPreCount());
dom.put("post_count", getPostCount());
dom.put("watson_prefix", getWatsonPrefix());
dom.put("ss_player_directory", _ssPlayerDirectory);
dom.put("ss_player_suffix", _ssPlayerSuffix);
dom.put("ss_date_directory", _ssDateDirectory.toPattern());
dom.put("reformat_query_results", _reformatQueryResults);
dom.put("recolour_query_results", _recolourQueryResults);
dom.put("time_ordered_deposits", _timeOrderedDeposits);
dom.put("vector_length", (double) _vectorLength);
for (Entry<String, ModifiedKeyBinding> entry : getKeyBindingsMap().entrySet()) {
dom.put(entry.getKey(), entry.getValue().toString());
}
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(options);
yaml.dump(dom, writer);
} catch (IOException ex) {
Log.exception(Level.SEVERE, "unable to save configuration file", ex);
}
}
use of org.yaml.snakeyaml.DumperOptions 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("category", pattern.category).put("severity", pattern.severity).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("category", pattern.category.toString()).put("severity", pattern.severity.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 suppression;
switch(pattern.suppressibility) {
case SUPPRESS_WARNINGS:
suppression = String.format("Suppress false positives by adding an `@SuppressWarnings(\"%s\")` " + "annotation to the enclosing element.", pattern.name);
break;
case CUSTOM_ANNOTATION:
if (pattern.customSuppressionAnnotations.length == 1) {
suppression = String.format("Suppress false positives by adding the custom suppression annotation " + "`@%s` to the enclosing element.", pattern.customSuppressionAnnotations[0]);
} else {
suppression = String.format("Suppress false positives by adding one of these custom suppression " + "annotations to the enclosing element: %s", COMMA_JOINER.join(Lists.transform(Arrays.asList(pattern.customSuppressionAnnotations), ANNOTATE_AND_CODIFY)));
}
break;
case UNSUPPRESSIBLE:
suppression = "This check may not be suppressed.";
break;
default:
throw new AssertionError(pattern.suppressibility);
}
templateData.put("suppression", suppression);
}
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;
}
use of org.yaml.snakeyaml.DumperOptions in project kiimate by SINeWang.
the class VisitRawAssetCtl method visit.
@RequestMapping(value = "/{" + GROUP + "}/{" + NAME + "}/{" + STABILITY + "}/{" + VERSION + ":.+}/raw")
public ResponseEntity<?> visit(@RequestHeader(value = ErestHeaders.REQUEST_ID, required = false) String requestId, @RequestHeader(ErestHeaders.VISITOR_ID) String visitorId, @PathVariable(OWNER_ID) String ownerId, @PathVariable(GROUP) String group, @PathVariable(NAME) String name, @PathVariable(STABILITY) String stability, @PathVariable(VERSION) String version, @RequestParam(value = FORMAT_YML, required = false) String yml) {
ReadContext context = buildContext(requestId, ownerId, visitorId);
VisitRawAssetApi.GroupNameForm form = new VisitRawAssetApi.GroupNameForm();
form.setGroup(group);
form.setName(name);
if (null != stability) {
form.setStability(stability);
}
if (null != version) {
form.setVersion(version);
}
try {
if (yml == null) {
return VisitApiCaller.sync(api, context, form);
} else {
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
try {
Yaml yaml = new Yaml(options);
return ErestResponse.ok(requestId, yaml.dump(api.visit(context, form)));
} catch (BadRequest badRequest) {
return ErestResponse.badRequest(requestId, badRequest.getKeys());
} catch (Panic panic) {
return ErestResponse.badRequest(requestId, panic.getKeys());
}
}
} catch (NotFound notFound) {
return ErestResponse.notFound(requestId, notFound.getKeys());
}
}
use of org.yaml.snakeyaml.DumperOptions in project error-prone by google.
the class BugPatternIndexWriter method dump.
void dump(Collection<BugPatternInstance> patterns, Writer w, Target target, Set<String> enabledChecks) throws IOException {
// (Default, Severity) -> [Pattern...]
SortedSetMultimap<IndexEntry, MiniDescription> sorted = TreeMultimap.create(Comparator.comparing(IndexEntry::onByDefault).reversed().thenComparing(IndexEntry::severity), Comparator.comparing(MiniDescription::name));
for (BugPatternInstance pattern : patterns) {
sorted.put(IndexEntry.create(enabledChecks.contains(pattern.name), pattern.severity), MiniDescription.create(pattern));
}
Map<String, Object> templateData = new HashMap<>();
List<Map<String, Object>> bugpatternData = Multimaps.asMap(sorted).entrySet().stream().map(e -> ImmutableMap.of("category", e.getKey().asCategoryHeader(), "checks", e.getValue())).collect(Collectors.toCollection(ArrayList::new));
templateData.put("bugpatterns", bugpatternData);
if (target == Target.EXTERNAL) {
Map<String, String> frontmatterData = ImmutableMap.<String, String>builder().put("title", "Bug Patterns").put("layout", "bugpatterns").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());
MustacheFactory mf = new DefaultMustacheFactory();
Mustache mustache = mf.compile("com/google/errorprone/resources/bugpatterns_external.mustache");
mustache.execute(w, templateData);
} else {
MustacheFactory mf = new DefaultMustacheFactory();
Mustache mustache = mf.compile("com/google/errorprone/resources/bugpatterns_internal.mustache");
mustache.execute(w, templateData);
}
}
use of org.yaml.snakeyaml.DumperOptions in project Apktool by iBotPeaches.
the class MetaInfo method getYaml.
private static Yaml getYaml() {
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
StringExRepresent representer = new StringExRepresent();
PropertyUtils propertyUtils = representer.getPropertyUtils();
propertyUtils.setSkipMissingProperties(true);
return new Yaml(new StringExConstructor(), representer, options);
}
Aggregations