Search in sources :

Example 6 with DumperOptions

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);
    }
}
Also used : HashMap(java.util.HashMap) FileWriter(java.io.FileWriter) DumperOptions(org.yaml.snakeyaml.DumperOptions) IOException(java.io.IOException) File(java.io.File) ModifiedKeyBinding(watson.gui.ModifiedKeyBinding) Yaml(org.yaml.snakeyaml.Yaml) BufferedWriter(java.io.BufferedWriter)

Example 7 with DumperOptions

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;
}
Also used : DefaultMustacheFactory(com.github.mustachejava.DefaultMustacheFactory) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) Mustache(com.github.mustachejava.Mustache) StringWriter(java.io.StringWriter) DumperOptions(org.yaml.snakeyaml.DumperOptions) Path(java.nio.file.Path) ImmutableMap(com.google.common.collect.ImmutableMap) Yaml(org.yaml.snakeyaml.Yaml) MustacheFactory(com.github.mustachejava.MustacheFactory) DefaultMustacheFactory(com.github.mustachejava.DefaultMustacheFactory) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 8 with DumperOptions

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());
    }
}
Also used : BadRequest(one.kii.summer.io.exception.BadRequest) Panic(one.kii.summer.io.exception.Panic) ReadContext(one.kii.summer.io.context.ReadContext) DumperOptions(org.yaml.snakeyaml.DumperOptions) VisitRawAssetApi(one.kii.kiimate.status.core.api.VisitRawAssetApi) Yaml(org.yaml.snakeyaml.Yaml) NotFound(one.kii.summer.io.exception.NotFound)

Example 9 with DumperOptions

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);
    }
}
Also used : DefaultMustacheFactory(com.github.mustachejava.DefaultMustacheFactory) SortedSetMultimap(com.google.common.collect.SortedSetMultimap) ImmutableMap(com.google.common.collect.ImmutableMap) StringWriter(java.io.StringWriter) Collection(java.util.Collection) Mustache(com.github.mustachejava.Mustache) Set(java.util.Set) IOException(java.io.IOException) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) Multimaps(com.google.common.collect.Multimaps) ArrayList(java.util.ArrayList) Yaml(org.yaml.snakeyaml.Yaml) DumperOptions(org.yaml.snakeyaml.DumperOptions) List(java.util.List) TreeMultimap(com.google.common.collect.TreeMultimap) Map(java.util.Map) MustacheFactory(com.github.mustachejava.MustacheFactory) AutoValue(com.google.auto.value.AutoValue) Writer(java.io.Writer) Comparator(java.util.Comparator) SeverityLevel(com.google.errorprone.BugPattern.SeverityLevel) Target(com.google.errorprone.DocGenTool.Target) HashMap(java.util.HashMap) DefaultMustacheFactory(com.github.mustachejava.DefaultMustacheFactory) Mustache(com.github.mustachejava.Mustache) Yaml(org.yaml.snakeyaml.Yaml) DefaultMustacheFactory(com.github.mustachejava.DefaultMustacheFactory) MustacheFactory(com.github.mustachejava.MustacheFactory) StringWriter(java.io.StringWriter) DumperOptions(org.yaml.snakeyaml.DumperOptions) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 10 with DumperOptions

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);
}
Also used : PropertyUtils(org.yaml.snakeyaml.introspector.PropertyUtils) DumperOptions(org.yaml.snakeyaml.DumperOptions) Yaml(org.yaml.snakeyaml.Yaml)

Aggregations

DumperOptions (org.yaml.snakeyaml.DumperOptions)11 Yaml (org.yaml.snakeyaml.Yaml)9 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 DefaultMustacheFactory (com.github.mustachejava.DefaultMustacheFactory)2 Mustache (com.github.mustachejava.Mustache)2 MustacheFactory (com.github.mustachejava.MustacheFactory)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 BufferedWriter (java.io.BufferedWriter)2 File (java.io.File)2 FileWriter (java.io.FileWriter)2 StringWriter (java.io.StringWriter)2 Writer (java.io.Writer)2 AutoValue (com.google.auto.value.AutoValue)1 Multimaps (com.google.common.collect.Multimaps)1 SortedSetMultimap (com.google.common.collect.SortedSetMultimap)1 TreeMultimap (com.google.common.collect.TreeMultimap)1 SeverityLevel (com.google.errorprone.BugPattern.SeverityLevel)1 Target (com.google.errorprone.DocGenTool.Target)1