Search in sources :

Example 36 with Yaml

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();
}
Also used : FileWriter(java.io.FileWriter) Yaml(org.yaml.snakeyaml.Yaml)

Example 37 with Yaml

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"));
    }
}
Also used : Map(java.util.Map) Yaml(org.yaml.snakeyaml.Yaml)

Example 38 with Yaml

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

Example 39 with Yaml

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");
}
Also used : WebAppDescriptor(org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor) InputStream(java.io.InputStream) HashMap(java.util.HashMap) Map(java.util.Map) Yaml(org.yaml.snakeyaml.Yaml) Test(org.junit.Test)

Example 40 with Yaml

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;
}
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)

Aggregations

Yaml (org.yaml.snakeyaml.Yaml)253 Map (java.util.Map)92 HashMap (java.util.HashMap)73 IOException (java.io.IOException)55 FileInputStream (java.io.FileInputStream)47 InputStream (java.io.InputStream)47 File (java.io.File)43 DumperOptions (org.yaml.snakeyaml.DumperOptions)39 Constructor (org.yaml.snakeyaml.constructor.Constructor)27 ArrayList (java.util.ArrayList)25 FileNotFoundException (java.io.FileNotFoundException)21 List (java.util.List)21 Test (org.junit.Test)21 LinkedHashMap (java.util.LinkedHashMap)17 Writer (java.io.Writer)13 FileWriter (java.io.FileWriter)12 InputStreamReader (java.io.InputStreamReader)12 Path (java.nio.file.Path)12 FileReader (java.io.FileReader)10 Reader (java.io.Reader)9