com.netflix.gradle.plugins.deb.TemplateHelper.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-ospackage-plugin Show documentation
Show all versions of gradle-ospackage-plugin Show documentation
Provides a task similar to Tar and Zip for constructing RPM and DEB package files.
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
}
}