use of org.yaml.snakeyaml.Yaml in project mybatis-generator-gui-extension by spawpaw.
the class SCVXGeneratorPlugin method contextGenerateAdditionalJavaFiles.
@Override
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(IntrospectedTable introspectedTable) {
log.info(">>>> generating extra files...");
// : 2018/3/22 将 introspectedTable 转化为对象
Map<String, String> map = new HashMap<>();
for (Object o : properties.keySet()) {
map.put(o.toString(), properties.getProperty(o.toString()));
}
Table table = new Table(context, introspectedTable, map);
// : 2018/3/22 初始化context
VelocityContext templateContext = new VelocityContext();
templateContext.put("table", table);
templateContext.put("projectDir.ss", projectDir);
// 输出测试数据
String content = renderTemplateAsString("test.vm", templateContext);
log.info("hierarchical table structure: {}", content);
// : 2018/3/22 保存到指定目录
List<TemplateConfig> configs = new Yaml().loadAs(Thread.currentThread().getContextClassLoader().getResourceAsStream("config.yml"), ConfigWrapper.class).getTemplateConfig();
for (TemplateConfig config : configs) {
String template = config.getTemplate();
String destDir = config.getDestDir().replaceAll("\\.", "/");
String destPackage = config.getDestPackage();
String destFileName = config.getDestFileName();
String absPath = (projectDir == null || projectDir.isEmpty() ? "" : projectDir) + destDir + "/" + destPackage.replace(".", "/") + "/" + destFileName;
absPath = absPath.replace("//", "/");
absPath = absPath.replace("${entityName}", table.getEntityName());
absPath = absPath.replace("${basePackage}", basePackage.replace(".", "/"));
log.info("generate file `{}` from template `{}`", absPath, template);
content = renderTemplateAsString(config.getTemplate(), templateContext);
// 写入文件
try {
FileUtil.writeStringToFile(absPath, content);
} catch (IOException e) {
log.error(e.getMessage());
}
log.info("content: {}", content);
}
log.info("<<< generated extra files.");
return null;
}
use of org.yaml.snakeyaml.Yaml in project cas by apereo.
the class AddPropertiesToConfigurationCommand method writeYamlConfigurationPropertiesToFile.
private void writeYamlConfigurationPropertiesToFile(final File filePath, final Map<String, ConfigurationMetadataProperty> results, final Properties yamlProps) throws Exception {
final DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.AUTO);
options.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN);
options.setPrettyFlow(true);
options.setAllowUnicode(true);
final Yaml yaml = new Yaml(options);
try (Writer writer = Files.newBufferedWriter(filePath.toPath(), StandardCharsets.UTF_8)) {
putResultsIntoProperties(results, yamlProps);
yaml.dump(yamlProps, writer);
}
}
use of org.yaml.snakeyaml.Yaml in project grakn by graknlabs.
the class MigrationCLI method extractOptionsFromConfiguration.
private static List<String[]> extractOptionsFromConfiguration(String path, String[] args) {
// check file exists
File configuration = new File(path);
if (!configuration.exists()) {
throw new IllegalArgumentException("Could not find configuration file " + path);
}
try (InputStreamReader reader = new InputStreamReader(new FileInputStream(configuration), Charset.defaultCharset())) {
List<Map<String, String>> config = (List<Map<String, String>>) new Yaml().load(reader);
List<String[]> options = new ArrayList<>();
for (Map<String, String> c : config) {
List<String> parameters = new ArrayList<>(Arrays.asList(args));
c.entrySet().stream().flatMap(m -> Stream.of("-" + m.getKey(), m.getValue())).forEach(parameters::add);
options.add(parameters.toArray(new String[parameters.size()]));
}
return options;
} catch (IOException e) {
throw new RuntimeException("Could not parse configuration file.");
}
}
use of org.yaml.snakeyaml.Yaml in project cxf by apache.
the class AbstractSwagger2ServiceDescriptionTest method testApiListingIsProperlyReturnedYAML.
@Test
@Ignore
public void testApiListingIsProperlyReturnedYAML() throws Exception {
final WebClient client = createWebClient("/swagger.yaml");
try {
final Response r = client.get();
assertEquals(Status.OK.getStatusCode(), r.getStatus());
// REVISIT find a better way of reliably comparing two yaml instances.
// I noticed that yaml.load instantiates a Map and
// for an integer valued key, an Integer or a String is arbitrarily instantiated,
// which leads to the assertion error. So, we serilialize the yamls and compare the re-serialized texts.
Yaml yaml = new Yaml();
assertEquals(yaml.load(getExpectedValue(getExpectedFileYaml(), getPort())).toString(), yaml.load(IOUtils.readStringFromStream((InputStream) r.getEntity())).toString());
} finally {
client.close();
}
}
use of org.yaml.snakeyaml.Yaml in project java by kubernetes-client.
the class KubeConfig method loadKubeConfig.
/**
* Load a Kubernetes config from a Reader
*/
public static KubeConfig loadKubeConfig(Reader input) {
Yaml yaml = new Yaml(new SafeConstructor());
Object config = yaml.load(input);
Map<String, Object> configMap = (Map<String, Object>) config;
String currentContext = (String) configMap.get("current-context");
ArrayList<Object> contexts = (ArrayList<Object>) configMap.get("contexts");
ArrayList<Object> clusters = (ArrayList<Object>) configMap.get("clusters");
ArrayList<Object> users = (ArrayList<Object>) configMap.get("users");
KubeConfig kubeConfig = new KubeConfig(contexts, clusters, users);
kubeConfig.setContext(currentContext);
return kubeConfig;
}
Aggregations