diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2021-03-05 13:06:53 +0100 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2021-03-05 13:06:53 +0100 |
commit | 9d1f559cc097f71e8e5af95c81ca5fb43aa4e707 (patch) | |
tree | 1f64c6b27eed4fc86eca8c3a597a2563f8553464 /node-admin | |
parent | cf288e59fddb5a1a8ad2430a10f820068a61d120 (diff) |
Avoid duplicating VelocityRuntime for each template
Diffstat (limited to 'node-admin')
-rw-r--r-- | node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/Template.java | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/Template.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/Template.java index cef35803e98..1ab4a30dc58 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/Template.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/Template.java @@ -3,7 +3,6 @@ package com.yahoo.vespa.hosted.node.admin.task.util.file; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.Velocity; -import org.apache.velocity.app.VelocityEngine; import java.io.StringWriter; import java.nio.file.Files; @@ -19,16 +18,16 @@ import static com.yahoo.yolean.Exceptions.uncheck; */ public class Template { - private final VelocityEngine velocityEngine = new VelocityEngine(); + static { + Velocity.addProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.NullLogSystem"); + Velocity.init(); + } + private final VelocityContext velocityContext = new VelocityContext(); private final String template; private Template(String template) { this.template = template; - - velocityEngine.addProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, - "org.apache.velocity.runtime.log.NullLogSystem"); - velocityEngine.init(); } public static Template at(Path templatePath) { @@ -50,7 +49,7 @@ public class Template { public String render() { StringWriter writer = new StringWriter(); - velocityEngine.evaluate(velocityContext, writer, "Template", template); + Velocity.evaluate(velocityContext, writer, "Template", template); return writer.toString(); } |