All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.netflix.gradle.plugins.deb.TemplateHelper.groovy Maven / Gradle / Ivy

The newest version!
package com.netflix.gradle.plugins.deb

import groovy.text.GStringTemplateEngine
import org.slf4j.Logger
import org.slf4j.LoggerFactory

class TemplateHelper {
    static final Logger logger = LoggerFactory.getLogger(DebCopyAction.class)

    private final GStringTemplateEngine engine = new GStringTemplateEngine()

    File destDir
    String templatePrefix

    TemplateHelper(File destDir, String templatePrefix) {
        this.destDir = destDir
        this.templatePrefix = templatePrefix
    }

    File generateFile(String templateName, Map context) {
        logger.info("Generating ${templateName} file...")
        BufferedReader template = getClass().getResourceAsStream("${templatePrefix}/${templateName}.ftl").newReader()
        String content = engine.createTemplate(template).make(context).toString()
        File contentFile = new File(destDir, templateName)
        destDir.mkdirs()
        contentFile.text = content
        return contentFile
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy