Skip to content

Commit

Permalink
Add $dateTool into Velocity context
Browse files Browse the repository at this point in the history
This allows us to get the current date, and other functions as decribed
by https://velocity.apache.org/tools/3.0/apidocs/org/apache/velocity/tools/generic/DateTool.html

Note: in those examples, they refer to $date. In our implementation it
is $dateTool, because $date is already in use for a formatted date
string.
  • Loading branch information
netwolfuk committed Jul 28, 2023
1 parent 4674da7 commit 9ac3e38
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions tcwebhooks-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@
<artifactId>velocity-engine-core</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.apache.velocity.tools</groupId>
<artifactId>velocity-tools-generic</artifactId>
<version>3.0</version>
</dependency>

<!-- Use same version of slf4j as velocity 2.3 uses -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.context.Context;
import org.apache.velocity.tools.generic.DateTool;

import jetbrains.buildServer.serverSide.SProject;
import webhook.teamcity.Loggers;
Expand Down Expand Up @@ -65,10 +66,15 @@ public WebHooksBeanUtilsVelocityVariableResolver(
Loggers.SERVER.debug(e);
}

if (!velocityContext.containsKey("dateTool")) {
velocityContext.put("dateTool", new DateTool());
} else {
Loggers.SERVER.warn("WebHooksBeanUtilsVelocityVariableResolver :: Unable to add 'dateTool' to Velocity context. An item of that name already exists");
}
if (!velocityContext.containsKey("jsonTool")) {
velocityContext.put("jsonTool", new VelocityJsonTool());
velocityContext.put("jsonTool", new VelocityJsonTool());
} else {
Loggers.SERVER.warn("WebHooksBeanUtilsVelocityVariableResolver :: Unable to add 'jsonTool' to Velocity context. An item of that name already exists");
Loggers.SERVER.warn("WebHooksBeanUtilsVelocityVariableResolver :: Unable to add 'jsonTool' to Velocity context. An item of that name already exists");
}
if (!velocityContext.containsKey("nullUtils")) {
velocityContext.put("nullUtils", new VelocityNullUtils());
Expand Down

0 comments on commit 9ac3e38

Please sign in to comment.