Search in sources :

Example 1 with SimpleTemplateEngine

use of groovy.text.SimpleTemplateEngine in project gradle by gradle.

the class SimpleTemplateOperation method generate.

@Override
public void generate() {
    try {
        target.getParentFile().mkdirs();
        SimpleTemplateEngine templateEngine = new SimpleTemplateEngine();
        String templateText = Resources.asCharSource(templateURL, CharsetToolkit.getDefaultSystemCharset()).read();
        Template template = templateEngine.createTemplate(templateText);
        Writer writer = Files.asCharSink(target, Charsets.UTF_8).openStream();
        try {
            template.make(bindings).writeTo(writer);
        } finally {
            writer.close();
        }
    } catch (Exception ex) {
        throw new GradleException("Could not generate file " + target + ".", ex);
    }
}
Also used : GradleException(org.gradle.api.GradleException) Writer(java.io.Writer) GradleException(org.gradle.api.GradleException) SimpleTemplateEngine(groovy.text.SimpleTemplateEngine) Template(groovy.text.Template)

Aggregations

SimpleTemplateEngine (groovy.text.SimpleTemplateEngine)1 Template (groovy.text.Template)1 Writer (java.io.Writer)1 GradleException (org.gradle.api.GradleException)1