Search in sources :

Example 71 with Representer

use of org.yaml.snakeyaml.representer.Representer in project spring-framework-5.2.9.RELEASE by somepeopleHavingDream.

the class YamlProcessor method createYaml.

/**
 * Create the {@link Yaml} instance to use.
 * <p>The default implementation sets the "allowDuplicateKeys" flag to {@code false},
 * enabling built-in duplicate key handling in SnakeYAML 1.18+.
 * <p>As of Spring Framework 5.1.16, if custom {@linkplain #setSupportedTypes
 * supported types} have been configured, the default implementation creates
 * a {@code Yaml} instance that filters out unsupported types encountered in
 * YAML documents. If an unsupported type is encountered, an
 * {@link IllegalStateException} will be thrown when the node is processed.
 * @see LoaderOptions#setAllowDuplicateKeys(boolean)
 */
protected Yaml createYaml() {
    LoaderOptions loaderOptions = new LoaderOptions();
    loaderOptions.setAllowDuplicateKeys(false);
    if (!this.supportedTypes.isEmpty()) {
        return new Yaml(new FilteringConstructor(loaderOptions), new Representer(), new DumperOptions(), loaderOptions);
    }
    return new Yaml(loaderOptions);
}
Also used : LoaderOptions(org.yaml.snakeyaml.LoaderOptions) Representer(org.yaml.snakeyaml.representer.Representer) DumperOptions(org.yaml.snakeyaml.DumperOptions) Yaml(org.yaml.snakeyaml.Yaml)

Example 72 with Representer

use of org.yaml.snakeyaml.representer.Representer in project montithings by MontiCore.

the class DockerComposeConfig method serializeYaml.

public String serializeYaml() {
    DumperOptions opt = new DumperOptions();
    opt.setAllowReadOnlyProperties(true);
    opt.setDefaultFlowStyle(FlowStyle.BLOCK);
    // hide java class name
    Representer repr = new Representer(opt);
    repr.addClassTag(DockerComposeConfig.class, Tag.MAP);
    return new Yaml(repr, opt).dump(this);
}
Also used : Representer(org.yaml.snakeyaml.representer.Representer) DumperOptions(org.yaml.snakeyaml.DumperOptions) Yaml(org.yaml.snakeyaml.Yaml)

Example 73 with Representer

use of org.yaml.snakeyaml.representer.Representer in project spring-framework-debug by Joker-5.

the class YamlProcessor method createYaml.

/**
 * Create the {@link Yaml} instance to use.
 * <p>The default implementation sets the "allowDuplicateKeys" flag to {@code false},
 * enabling built-in duplicate key handling in SnakeYAML 1.18+.
 * <p>As of Spring Framework 5.1.16, if custom {@linkplain #setSupportedTypes
 * supported types} have been configured, the default implementation creates
 * a {@code Yaml} instance that filters out unsupported types encountered in
 * YAML documents. If an unsupported type is encountered, an
 * {@link IllegalStateException} will be thrown when the node is processed.
 * @see LoaderOptions#setAllowDuplicateKeys(boolean)
 */
protected Yaml createYaml() {
    LoaderOptions loaderOptions = new LoaderOptions();
    loaderOptions.setAllowDuplicateKeys(false);
    if (!this.supportedTypes.isEmpty()) {
        return new Yaml(new FilteringConstructor(loaderOptions), new Representer(), new DumperOptions(), loaderOptions);
    }
    return new Yaml(loaderOptions);
}
Also used : LoaderOptions(org.yaml.snakeyaml.LoaderOptions) Representer(org.yaml.snakeyaml.representer.Representer) DumperOptions(org.yaml.snakeyaml.DumperOptions) Yaml(org.yaml.snakeyaml.Yaml)

Example 74 with Representer

use of org.yaml.snakeyaml.representer.Representer in project HaE by gh0stkey.

the class SetConfig method format.

public void format() {
    DumperOptions dop = new DumperOptions();
    dop.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
    Representer representer = new Representer();
    representer.addClassTag(RulesConfig.class, Tag.MAP);
    Yaml yaml = new Yaml(new Constructor(), representer, dop);
    RulesConfig con = new RulesConfig();
    List<Rules> rls = new ArrayList<>();
    Config.ruleConfig.keySet().forEach(i -> {
        Rules rlsTmp = new Rules();
        rlsTmp.setType(i);
        List<Rule> rl = new ArrayList<>();
        for (Object[] objects : Config.ruleConfig.get(i)) {
            Rule rlTmp = new Rule();
            rlTmp.setName((String) objects[1]);
            rlTmp.setLoaded((Boolean) objects[0]);
            rlTmp.setRegex((String) objects[2]);
            rlTmp.setColor((String) objects[3]);
            rlTmp.setScope((String) objects[4]);
            rlTmp.setEngine((String) objects[5]);
            rl.add(rlTmp);
        }
        rlsTmp.setRule(rl);
        rls.add(rlsTmp);
    });
    con.setRules(rls);
    File f = new File(LoadConfig.getConfigPath());
    try {
        Writer ws = new OutputStreamWriter(new FileOutputStream(f), StandardCharsets.UTF_8);
        yaml.dump(con, ws);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : Constructor(org.yaml.snakeyaml.constructor.Constructor) Rules(burp.yaml.template.Rules) Yaml(org.yaml.snakeyaml.Yaml) Representer(org.yaml.snakeyaml.representer.Representer) FileOutputStream(java.io.FileOutputStream) DumperOptions(org.yaml.snakeyaml.DumperOptions) OutputStreamWriter(java.io.OutputStreamWriter) Rule(burp.yaml.template.Rule) File(java.io.File) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 75 with Representer

use of org.yaml.snakeyaml.representer.Representer in project spring-security by spring-projects.

the class CheckAntoraVersionTask method check.

@TaskAction
public void check() throws FileNotFoundException {
    File antoraYmlFile = getAntoraYmlFile().getAsFile().get();
    String expectedAntoraVersion = getAntoraVersion().get();
    String expectedAntoraPrerelease = getAntoraPrerelease().getOrElse(null);
    String expectedAntoraDisplayVersion = getAntoraDisplayVersion().getOrElse(null);
    Representer representer = new Representer();
    representer.getPropertyUtils().setSkipMissingProperties(true);
    Yaml yaml = new Yaml(new Constructor(AntoraYml.class), representer);
    AntoraYml antoraYml = yaml.load(new FileInputStream(antoraYmlFile));
    String actualAntoraPrerelease = antoraYml.getPrerelease();
    boolean preReleaseMatches = antoraYml.getPrerelease() == null && expectedAntoraPrerelease == null || (actualAntoraPrerelease != null && actualAntoraPrerelease.equals(expectedAntoraPrerelease));
    String actualAntoraDisplayVersion = antoraYml.getDisplay_version();
    boolean displayVersionMatches = antoraYml.getDisplay_version() == null && expectedAntoraDisplayVersion == null || (actualAntoraDisplayVersion != null && actualAntoraDisplayVersion.equals(expectedAntoraDisplayVersion));
    String actualAntoraVersion = antoraYml.getVersion();
    if (!preReleaseMatches || !displayVersionMatches || !expectedAntoraVersion.equals(actualAntoraVersion)) {
        throw new GradleException("The Gradle version of '" + getProject().getVersion() + "' should have version: '" + expectedAntoraVersion + "' prerelease: '" + expectedAntoraPrerelease + "' display_version: '" + expectedAntoraDisplayVersion + "' defined in " + antoraYmlFile + " but got version: '" + actualAntoraVersion + "' prerelease: '" + actualAntoraPrerelease + "' display_version: '" + actualAntoraDisplayVersion + "'");
    }
}
Also used : Representer(org.yaml.snakeyaml.representer.Representer) Constructor(org.yaml.snakeyaml.constructor.Constructor) GradleException(org.gradle.api.GradleException) File(java.io.File) InputFile(org.gradle.api.tasks.InputFile) Yaml(org.yaml.snakeyaml.Yaml) FileInputStream(java.io.FileInputStream) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

Representer (org.yaml.snakeyaml.representer.Representer)82 Yaml (org.yaml.snakeyaml.Yaml)77 DumperOptions (org.yaml.snakeyaml.DumperOptions)54 Constructor (org.yaml.snakeyaml.constructor.Constructor)25 LoaderOptions (org.yaml.snakeyaml.LoaderOptions)21 FileInputStream (java.io.FileInputStream)12 SafeConstructor (org.yaml.snakeyaml.constructor.SafeConstructor)11 IOException (java.io.IOException)7 Tag (org.yaml.snakeyaml.nodes.Tag)7 File (java.io.File)6 TypeDescription (org.yaml.snakeyaml.TypeDescription)6 BaseConstructor (org.yaml.snakeyaml.constructor.BaseConstructor)5 FileNotFoundException (java.io.FileNotFoundException)4 InputStream (java.io.InputStream)4 PropertyUtils (org.yaml.snakeyaml.introspector.PropertyUtils)4 FileOutputStream (java.io.FileOutputStream)3 FileReader (java.io.FileReader)3 OutputStreamWriter (java.io.OutputStreamWriter)3 PrintWriter (java.io.PrintWriter)3 Map (java.util.Map)3