Search in sources :

Example 1 with StringSubstitutorReader

use of org.apache.commons.text.io.StringSubstitutorReader in project jib by google.

the class BuildFiles method toBuildFileSpec.

/**
 * Read a build file from disk and apply templating parameters.
 */
private static BuildFileSpec toBuildFileSpec(Path buildFilePath, Map<String, String> templateParameters) throws IOException {
    ObjectMapper yamlObjectMapper = new ObjectMapper(new YAMLFactory());
    StringSubstitutor templater = new StringSubstitutor(templateParameters).setEnableUndefinedVariableException(true);
    try (StringSubstitutorReader reader = new StringSubstitutorReader(Files.newBufferedReader(buildFilePath, Charsets.UTF_8), templater)) {
        return yamlObjectMapper.readValue(reader, BuildFileSpec.class);
    }
}
Also used : StringSubstitutorReader(org.apache.commons.text.io.StringSubstitutorReader) StringSubstitutor(org.apache.commons.text.StringSubstitutor) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 StringSubstitutor (org.apache.commons.text.StringSubstitutor)1 StringSubstitutorReader (org.apache.commons.text.io.StringSubstitutorReader)1