Java Code Examples for org.yaml.snakeyaml.DumperOptions#setPrettyFlow()
The following examples show how to use
org.yaml.snakeyaml.DumperOptions#setPrettyFlow() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: YamlPipelineConfiguration.java From baleen with Apache License 2.0 | 6 votes |
@Override public String dumpOrdered(List<Object> ann, List<Object> con) { Map<String, Object> confMap; if (root instanceof Map<?, ?>) { confMap = new LinkedHashMap<>((Map<String, Object>) root); } else { confMap = new LinkedHashMap<>(); } confMap.put("annotators", ann); confMap.put("consumers", con); DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(FlowStyle.BLOCK); options.setPrettyFlow(true); org.yaml.snakeyaml.Yaml y = new org.yaml.snakeyaml.Yaml(options); return y.dump(confMap); }
Example 2
Source File: Utils.java From ballerina-message-broker with Apache License 2.0 | 6 votes |
/** * Create the CLI configuration information file. * * @param configuration instance containing the Configuration information. */ public static void createConfigurationFile(Configuration configuration) { DumperOptions options = new DumperOptions(); options.setPrettyFlow(true); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); Yaml yaml = new Yaml(options); // dump to the file try (Writer writer = new OutputStreamWriter(new FileOutputStream(getConfigFilePath()), StandardCharsets.UTF_8)) { yaml.dump(configuration, writer); } catch (IOException e) { BrokerClientException brokerClientException = new BrokerClientException(); brokerClientException.addMessage("error when creating the configuration file. " + e.getMessage()); throw brokerClientException; } }
Example 3
Source File: Main.java From rundeck-cli with Apache License 2.0 | 6 votes |
private static void configYamlFormat(final ToolBelt belt, final RdClientConfig config) { DumperOptions dumperOptions = new DumperOptions(); dumperOptions.setDefaultFlowStyle( "BLOCK".equalsIgnoreCase(config.getString("RD_YAML_FLOW", "BLOCK")) ? DumperOptions.FlowStyle.BLOCK : DumperOptions.FlowStyle.FLOW ); dumperOptions.setPrettyFlow(config.getBool("RD_YAML_PRETTY", true)); Representer representer = new Representer(); representer.addClassTag(JobItem.class, Tag.MAP); representer.addClassTag(ScheduledJobItem.class, Tag.MAP); representer.addClassTag(DateInfo.class, Tag.MAP); representer.addClassTag(Execution.class, Tag.MAP); belt.formatter(new YamlFormatter(DataOutputAsFormatable, new Yaml(representer, dumperOptions))); belt.channels().infoEnabled(false); belt.channels().warningEnabled(false); belt.channels().errorEnabled(false); }
Example 4
Source File: SaltStateGenerator.java From uyuni with GNU General Public License v2.0 | 5 votes |
/** * Generate the YAML. * * @param states the states to output * */ public void generate(SaltState... states) { DumperOptions setup = new DumperOptions(); setup.setIndent(4); setup.setAllowUnicode(true); setup.setPrettyFlow(true); setup.setLineBreak(DumperOptions.LineBreak.UNIX); setup.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); setup.setCanonical(false); Yaml yaml = new Yaml(setup); for (SaltState state : states) { yaml.dump(state.getData(), destination); } }
Example 5
Source File: HumanTest.java From snake-yaml with Apache License 2.0 | 5 votes |
public void testNoChildrenPretty() { Human father = new Human(); father.setName("Father"); father.setBirthday(new Date(1000000000)); father.setBirthPlace("Leningrad"); father.setBankAccountOwner(father); Human mother = new Human(); mother.setName("Mother"); mother.setBirthday(new Date(100000000000L)); mother.setBirthPlace("Saint-Petersburg"); father.setPartner(mother); mother.setPartner(father); mother.setBankAccountOwner(father); DumperOptions options = new DumperOptions(); options.setPrettyFlow(true); options.setDefaultFlowStyle(FlowStyle.FLOW); Yaml yaml = new Yaml(options); String output = yaml.dump(father); String etalon = Util.getLocalResource("recursive/no-children-1-pretty.yaml"); assertEquals(etalon, output); // Human father2 = (Human) yaml.load(output); assertNotNull(father2); assertEquals("Father", father2.getName()); assertEquals("Mother", father2.getPartner().getName()); assertEquals("Father", father2.getBankAccountOwner().getName()); assertSame(father2, father2.getBankAccountOwner()); }
Example 6
Source File: ManifestUtil.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
public static String getContents(Map<Object, Object> rawMap) { DumperOptions options = new DumperOptions(); options.setExplicitStart(true); options.setCanonical(false); options.setPrettyFlow(true); options.setDefaultFlowStyle(FlowStyle.BLOCK); Yaml yaml = new Yaml(options); return (yaml.dump(rawMap)); }
Example 7
Source File: YamlBuilder.java From mdw with Apache License 2.0 | 5 votes |
protected DumperOptions getDumperOptions() { DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); options.setPrettyFlow(true); options.setIndent(indent); options.setSplitLines(false); return options; }
Example 8
Source File: AbstractPluginDescriptorUpgradeOperation.java From studio with GNU General Public License v3.0 | 5 votes |
@Override public void execute(final String site) throws UpgradeException { Path descriptorFile = getRepositoryPath(site).getParent().resolve(descriptorPath); if (Files.notExists(descriptorFile)) { logger.info("Plugin descriptor file not found for site {0}", site); return; } try (Reader reader = Files.newBufferedReader(descriptorFile)) { PluginDescriptor descriptor = descriptorReader.read(reader); if (descriptor.getDescriptorVersion().equals(descriptorVersion)) { logger.info("Plugin descriptor already update for site " + site); return; } logger.info("Updating plugin descriptor for site " + site); doPluginDescriptorUpdates(descriptor); descriptor.setDescriptorVersion(descriptorVersion); DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); options.setPrettyFlow(true); Yaml yaml = new Yaml(new Representer() { @Override protected NodeTuple representJavaBeanProperty(final Object javaBean, final Property property, final Object propertyValue, final Tag customTag) { if (propertyValue != null) { return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag); } return null; } }, options); String content = yaml.dumpAsMap(descriptor); writeToRepo(site, descriptorPath, new ByteArrayInputStream(content.getBytes())); commitAllChanges(site); } catch (Exception e) { throw new UpgradeException("Plugin descriptor can't be read for site " + site); } }
Example 9
Source File: ConfigurationAsCode.java From configuration-as-code-plugin with MIT License | 5 votes |
@VisibleForTesting @Restricted(NoExternalUse.class) public static void serializeYamlNode(Node root, Writer writer) throws IOException { DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(BLOCK); options.setDefaultScalarStyle(PLAIN); options.setSplitLines(true); options.setPrettyFlow(true); Serializer serializer = new Serializer(new Emitter(writer, options), new Resolver(), options, null); serializer.open(); serializer.serialize(root); serializer.close(); }
Example 10
Source File: StringArrayTest.java From snake-yaml with Apache License 2.0 | 5 votes |
public void testStringsPretty() { A a = new A(); a.setNames(new String[] { "aaa", "bbb", "ccc" }); DumperOptions options = new DumperOptions(); options.setPrettyFlow(true); Yaml yaml = new Yaml(options); String output = yaml.dump(a); assertEquals( "!!org.yaml.snakeyaml.javabeans.StringArrayTest$A\nnames: [\n aaa,\n bbb,\n ccc]\n", output); A b = (A) yaml.load(output); assertTrue(Arrays.equals(a.getNames(), b.getNames())); }
Example 11
Source File: ConfigValueUtilsTests.java From spring-cloud-skipper with Apache License 2.0 | 5 votes |
@Test public void testYamlMerge() throws IOException { DumperOptions dumperOptions = new DumperOptions(); dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); dumperOptions.setPrettyFlow(true); Yaml yaml = new Yaml(dumperOptions); Resource resource = new ClassPathResource("/org/springframework/cloud/skipper/server/service/ticktock-1.0.0"); Package pkg = this.packageReader.read(resource.getFile()); ConfigValues configValues = new ConfigValues(); Map<String, Object> configValuesMap = new TreeMap<>(); Map<String, Object> logMap = new TreeMap<>(); logMap.put("appVersion", "1.2.1.RELEASE"); configValuesMap.put("log", logMap); configValuesMap.put("hello", "universe"); String configYaml = yaml.dump(configValuesMap); configValues.setRaw(configYaml); Map<String, Object> mergedMap = ConfigValueUtils.mergeConfigValues(pkg, configValues); String mergedYaml = yaml.dump(mergedMap); String expectedYaml = StreamUtils.copyToString( TestResourceUtils.qualifiedResource(getClass(), "merged.yaml").getInputStream(), Charset.defaultCharset()); assertThat(mergedYaml).isEqualTo(expectedYaml); }
Example 12
Source File: ConfigUtils.java From incubator-heron with Apache License 2.0 | 5 votes |
private static Yaml newYaml() { final DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); options.setPrettyFlow(true); return new Yaml(options); }
Example 13
Source File: DefaultStreamServiceIntegrationTests.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
@Test public void testInstallVersionOverride() throws IOException { Map<String, String> deploymentProperties = createSkipperDeploymentProperties(); // override log to 1.2.0.RELEASE deploymentProperties.put("version.log", "1.2.0.RELEASE"); when(skipperClient.status(eq("ticktock"))).thenThrow(new ReleaseNotFoundException("")); streamService.deployStream("ticktock", deploymentProperties); ArgumentCaptor<UploadRequest> uploadRequestCaptor = ArgumentCaptor.forClass(UploadRequest.class); verify(skipperClient).upload(uploadRequestCaptor.capture()); Package pkg = SkipperPackageUtils.loadPackageFromBytes(uploadRequestCaptor); // ExpectedYaml will have version: 1.2.0.RELEASE and not 1.1.1.RELEASE String expectedYaml = StreamUtils.copyToString( TestResourceUtils.qualifiedResource(getClass(), "install.yml").getInputStream(), Charset.defaultCharset()); Package logPackage = null; for (Package subpkg : pkg.getDependencies()) { if (subpkg.getMetadata().getName().equals("log")) { logPackage = subpkg; } } assertThat(logPackage).isNotNull(); String actualYaml = logPackage.getConfigValues().getRaw(); DumperOptions dumperOptions = new DumperOptions(); dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); dumperOptions.setPrettyFlow(true); Yaml yaml = new Yaml(dumperOptions); Object actualYamlLoaded = yaml.load(actualYaml); Object expectedYamlLoaded = yaml.load(expectedYaml); assertThat(actualYamlLoaded).isEqualTo(expectedYamlLoaded); }
Example 14
Source File: OdinConfigurationProcessor.java From baleen with Apache License 2.0 | 5 votes |
/** * Construct the processor * * @param taxonomy the taxonomy to be added * @param configuration the base configuration */ public OdinConfigurationProcessor(Collection<Object> taxonomy, String configuration) { this.taxonomy = taxonomy; this.configuration = configuration; DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(FlowStyle.BLOCK); options.setPrettyFlow(true); yaml = new org.yaml.snakeyaml.Yaml(options); }
Example 15
Source File: ReleaseReportService.java From spring-cloud-skipper with Apache License 2.0 | 5 votes |
private Release updateReplacingReleaseConfigValues(Release targetRelease, Release replacingRelease) { Map<String, Object> targetConfigValueMap = getConfigValuesAsMap(targetRelease.getConfigValues()); Map<String, Object> replacingRelaseConfigValueMap = getConfigValuesAsMap(replacingRelease.getConfigValues()); if (targetConfigValueMap != null && replacingRelaseConfigValueMap != null) { ConfigValueUtils.merge(targetConfigValueMap, replacingRelaseConfigValueMap); DumperOptions dumperOptions = new DumperOptions(); dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); dumperOptions.setPrettyFlow(true); Yaml yaml = new Yaml(dumperOptions); ConfigValues mergedConfigValues = new ConfigValues(); mergedConfigValues.setRaw(yaml.dump(targetConfigValueMap)); replacingRelease.setConfigValues(mergedConfigValues); } return replacingRelease; }
Example 16
Source File: DefaultStreamServiceUpdateTests.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
public void testCreateUpdateRequests() throws IOException { DefaultStreamService streamService = new DefaultStreamService(streamDefinitionRepository, skipperStreamDeployer, appDeploymentRequestCreator, streamValidationService, auditRecordService, new DefaultStreamDefinitionService()); StreamDefinition streamDefinition = new StreamDefinition("test", "time | log"); this.streamDefinitionRepository.save(streamDefinition); Map<String, String> updateProperties = new HashMap<>(); updateProperties.put("app.log.server.port", "9999"); updateProperties.put("app.log.endpoints.sensitive", "false"); updateProperties.put("app.log.level", "ERROR"); // this should be expanded updateProperties.put("deployer.log.memory", "4096m"); updateProperties.put("version.log", "1.1.1.RELEASE"); String yml = streamService.convertPropertiesToSkipperYaml(streamDefinition, updateProperties); String expectedYaml = StreamUtils.copyToString( TestResourceUtils.qualifiedResource(getClass(), "update.yml").getInputStream(), Charset.defaultCharset()); if (PlatformUtils.isWindows()) { expectedYaml = expectedYaml + DumperOptions.LineBreak.WIN.getString(); } DumperOptions dumperOptions = new DumperOptions(); dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); dumperOptions.setPrettyFlow(true); Yaml yaml = new Yaml(dumperOptions); Object actualYamlLoaded = yaml.load(yml); Object expectedYamlLoaded = yaml.load(expectedYaml); assertThat(actualYamlLoaded).isEqualTo(expectedYamlLoaded); }
Example 17
Source File: YamlTest.java From rpcx-java with Apache License 2.0 | 5 votes |
private String dump() { DumperOptions options = new DumperOptions(); options.setPrettyFlow(true); Yaml yaml = new Yaml(options); RpcxConfig config = new RpcxConfig(); config.setConsumerPackage("com.test.consumer"); config.setFilterPackage("com.test.filter"); return yaml.dump(config); }
Example 18
Source File: DatanodeIdYaml.java From hadoop-ozone with Apache License 2.0 | 5 votes |
/** * Creates a yaml file using DatnodeDetails. This method expects the path * validation to be performed by the caller. * * @param datanodeDetails {@link DatanodeDetails} * @param path Path to datnode.id file */ public static void createDatanodeIdFile(DatanodeDetails datanodeDetails, File path) throws IOException { DumperOptions options = new DumperOptions(); options.setPrettyFlow(true); options.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW); Yaml yaml = new Yaml(options); try (Writer writer = new OutputStreamWriter( new FileOutputStream(path), "UTF-8")) { yaml.dump(getDatanodeDetailsYaml(datanodeDetails), writer); } }
Example 19
Source File: YamlUtils.java From gocd-yaml-config-plugin with Apache License 2.0 | 4 votes |
public static String dump(Object o) { DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); options.setPrettyFlow(true); return new Yaml(options).dump(o); }
Example 20
Source File: HumanTest.java From snake-yaml with Apache License 2.0 | 4 votes |
public void testChildrenPretty() { Human father = new Human(); father.setName("Father"); father.setBirthday(new Date(1000000000)); father.setBirthPlace("Leningrad"); father.setBankAccountOwner(father); // Human mother = new Human(); mother.setName("Mother"); mother.setBirthday(new Date(100000000000L)); mother.setBirthPlace("Saint-Petersburg"); father.setPartner(mother); mother.setPartner(father); mother.setBankAccountOwner(father); // Human son = new Human(); son.setName("Son"); son.setBirthday(new Date(310000000000L)); son.setBirthPlace("Munich"); son.setBankAccountOwner(father); son.setFather(father); son.setMother(mother); // Human daughter = new Human(); daughter.setName("Daughter"); daughter.setBirthday(new Date(420000000000L)); daughter.setBirthPlace("New York"); daughter.setBankAccountOwner(father); daughter.setFather(father); daughter.setMother(mother); // Set<Human> children = new LinkedHashSet<Human>(2); children.add(son); children.add(daughter); father.setChildren(children); mother.setChildren(children); // DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(FlowStyle.FLOW); options.setPrettyFlow(true); Yaml beanDumper = new Yaml(options); String output = beanDumper.dump(son); // System.out.println(output); String etalon = Util.getLocalResource("recursive/with-children-pretty.yaml"); assertEquals(etalon, output); TypeDescription humanDescription = new TypeDescription(Human.class); humanDescription.putMapPropertyType("children", Human.class, Object.class); Yaml beanLoader = new Yaml(new Constructor(humanDescription)); // Human son2 = beanLoader.loadAs(output, Human.class); assertNotNull(son2); assertEquals("Son", son.getName()); Human father2 = son2.getFather(); assertEquals("Father", father2.getName()); assertEquals("Mother", son2.getMother().getName()); assertSame(father2, father2.getBankAccountOwner()); assertSame(father2.getPartner(), son2.getMother()); assertSame(father2, son2.getMother().getPartner()); Set<Human> children2 = father2.getChildren(); assertEquals(2, children2.size()); assertSame(father2.getPartner().getChildren(), children2); for (Object child : children2) { // check if type descriptor was correct assertSame(Human.class, child.getClass()); } // check if hashCode is correct validateSet(children2); }