2
0
mirror of https://github.com/rehlds/revoice.git synced 2025-04-14 05:20:15 +03:00
revoice/buildSrc/src/main/groovy/gradlecpp/VelocityUtils.groovy
s1lentq 32ed0c8924 Fix warnings in speex library
Implemented gradle build
2015-12-14 22:07:55 +06:00

54 lines
1.4 KiB
Groovy

package gradlecpp
import org.apache.velocity.Template
import org.apache.velocity.VelocityContext
import org.apache.velocity.app.Velocity
import org.joda.time.format.DateTimeFormat
import versioning.RevoiceVersionInfo
class VelocityUtils {
static {
Properties p = new Properties();
p.setProperty("resource.loader", "class");
p.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader");
p.setProperty("class.resource.loader.path", "");
p.setProperty("input.encoding", "UTF-8");
p.setProperty("output.encoding", "UTF-8");
Velocity.init(p);
}
static String renderTemplate(File tplFile, RevoiceVersionInfo ctx) {
Template tpl = Velocity.getTemplate(tplFile.absolutePath)
if (!tpl) {
throw new RuntimeException("Failed to load velocity template ${tplFile.absolutePath}: not found")
}
def templateCtx = [
verInfo: ctx
]
def velocityContext = new VelocityContext(templateCtx)
if (ctx.specialVersion.length() > 0) {
velocityContext.put("appFlags", 0x0L)
velocityContext.put("formatSpecialVersion", "-" + ctx.specialVersion)
} else {
velocityContext.put("appFlags", "VS_FF_SPECIALBUILD")
velocityContext.put("formatSpecialVersion", "")
}
velocityContext.put("current_version", ctx.asVersion())
velocityContext.put("_DateTimeFormat", DateTimeFormat)
def sw = new StringWriter()
tpl.merge(velocityContext, sw)
return sw.toString()
}
}