Skip to content

Commit d764558

Browse files
committed
Migrate JinjavaConfig and LegacyOverrides to @Value.Immutable
Switch from hand-rolled builder POJOs to Immutables-generated interfaces. Adds JinjavaImmutableStyle, ContextConfiguration (replacing ContextConfigurationIF), ErrorHandlingStrategy, and updates all call sites to the new builder API. Also restricts checkstyle to src/main/java to exclude generated Immutables code.
1 parent 923a276 commit d764558

147 files changed

Lines changed: 2503 additions & 2567 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3.0-changes.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
- Migrated JinjavaConfig to immutable
2+
- Removed whitespaceRequiredWithinTokens LegacyOverride and converted to BuiltinFeatures
3+
- Nested interpretation disabled by default
4+
- Removed restricted methods and properties from JinjavaConfig
5+
- Turn on all current LegacyOverrides by default
6+
- Use MethodValidator and ReturnTypeValidator to enforce method invocations and objects returned by ELResolver

CHANGES.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,9 @@
11
# Jinjava Releases #
2-
### 2026-02-02 Version 2.8.3 ([Maven Central](https://search.maven.org/artifact/com.hubspot.jinjava/jinjava/2.8.3/jar)) ###
3-
* Disallow accessing properties on restricted classes while rendering through ForTag
4-
* Upgrade jackson to version 2.20
5-
* [Add performance optimization to chained filters](https://github.com/HubSpot/jinjava/pull/1274)
6-
7-
### 2026-02-02 Version 2.7.6 ([Maven Central](https://search.maven.org/artifact/com.hubspot.jinjava/jinjava/2.7.6/jar)) ###
8-
* Disallow accessing properties on restricted classes while rendering through ForTag
9-
* Upgrade jackson to version 2.20
10-
112
### 2025-10-22 Version 2.8.2 ([Maven Central](https://search.maven.org/artifact/com.hubspot.jinjava/jinjava/2.8.2/jar)) ###
123
* [Fix helper token escape handling and unescaping when unquoting strings](https://github.com/HubSpot/jinjava/pull/1263)
13-
14-
### 2025-09-30 Version 2.7.5 ([Maven Central](https://search.maven.org/artifact/com.hubspot.jinjava/jinjava/2.7.5/jar)) ###
15-
* Disallow accessing properties on restricted classes while rendering
16-
174
### 2025-09-16 Version 2.8.1 ([Maven Central](https://search.maven.org/artifact/com.hubspot.jinjava/jinjava/2.8.1/jar)) ###
185
* Disallow accessing properties on restricted classes while rendering
196
* [Make stack operations use AutoCloseable for safer usage with try-with-resources](https://github.com/HubSpot/jinjava/pull/1250)
20-
217
### 2025-05-05 Version 2.8.0 ([Maven Central](https://search.maven.org/artifact/com.hubspot.jinjava/jinjava/2.8.0/jar)) ###
228
* [Target Java 17](https://github.com/HubSpot/jinjava/pull/1238)
239
* [Implement PyMap#get with optional default](https://github.com/HubSpot/jinjava/pull/1233)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ You will likely want to provide your own implementation of
7878
`ResourceLoader` to hook into your application's template repository, and then tell jinjava about it:
7979

8080
```java
81-
JinjavaConfig config = new JinjavaConfig();
81+
JinjavaConfig config = JinjavaConfig.builder().build();
8282

8383
Jinjava jinjava = new Jinjava(config);
8484
jinjava.setResourceLocator(new MyCustomResourceLocator());
@@ -87,7 +87,7 @@ jinjava.setResourceLocator(new MyCustomResourceLocator());
8787
To use more than one `ResourceLocator`, use a `CascadingResourceLocator`.
8888

8989
```java
90-
JinjavaConfig config = new JinjavaConfig();
90+
JinjavaConfig config = JinjavaConfig.builder().build();
9191

9292
Jinjava jinjava = new Jinjava(config);
9393
jinjava.setResourceLocator(new MyCustomResourceLocator(), new FileResourceLocator());

pom.xml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@
104104
<artifactId>immutables-exceptions</artifactId>
105105
<version>${dep.hubspot-immutables.version}</version>
106106
</dependency>
107+
<dependency>
108+
<groupId>com.hubspot.immutables</groupId>
109+
<artifactId>immutable-collection-encodings</artifactId>
110+
<version>${dep.hubspot-immutables.version}</version>
111+
</dependency>
107112
<dependency>
108113
<groupId>com.hubspot</groupId>
109114
<artifactId>algebra</artifactId>
@@ -184,6 +189,7 @@
184189
<dependency>
185190
<groupId>com.google.errorprone</groupId>
186191
<artifactId>error_prone_annotations</artifactId>
192+
<scope>runtime</scope>
187193
</dependency>
188194

189195
<dependency>
@@ -217,18 +223,15 @@
217223
<scope>provided</scope>
218224
</dependency>
219225
<dependency>
220-
<groupId>com.hubspot.immutables</groupId>
221-
<artifactId>hubspot-style</artifactId>
222-
<scope>provided</scope>
226+
<groupId>com.hubspot</groupId>
227+
<artifactId>algebra</artifactId>
223228
</dependency>
224229
<dependency>
225230
<groupId>com.hubspot.immutables</groupId>
226-
<artifactId>immutables-exceptions</artifactId>
227-
</dependency>
228-
<dependency>
229-
<groupId>com.hubspot</groupId>
230-
<artifactId>algebra</artifactId>
231+
<artifactId>immutable-collection-encodings</artifactId>
232+
<scope>provided</scope>
231233
</dependency>
234+
232235
</dependencies>
233236

234237
<build>
@@ -266,6 +269,12 @@
266269
<encoding>UTF-8</encoding>
267270
<consoleOutput>true</consoleOutput>
268271
<failsOnError>true</failsOnError>
272+
<sourceDirectories>
273+
<sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
274+
</sourceDirectories>
275+
<testSourceDirectories>
276+
<testSourceDirectory>${project.build.testSourceDirectory}</testSourceDirectory>
277+
</testSourceDirectories>
269278
</configuration>
270279
</execution>
271280
</executions>

src/main/java/com/hubspot/jinjava/Jinjava.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.hubspot.jinjava.el.ExtendedSyntaxBuilder;
2121
import com.hubspot.jinjava.el.TruthyTypeConverter;
2222
import com.hubspot.jinjava.el.ext.eager.EagerExtendedSyntaxBuilder;
23-
import com.hubspot.jinjava.interpret.AutoCloseableSupplier.AutoCloseableImpl;
2423
import com.hubspot.jinjava.interpret.Context;
2524
import com.hubspot.jinjava.interpret.FatalTemplateErrorsException;
2625
import com.hubspot.jinjava.interpret.InterpretException;
@@ -74,7 +73,7 @@ public class Jinjava {
7473
* Create a new Jinjava processor instance with the default global config
7574
*/
7675
public Jinjava() {
77-
this(new JinjavaConfig());
76+
this(JinjavaConfig.newBuilder().build());
7877
}
7978

8079
/**
@@ -246,14 +245,10 @@ public RenderResult renderForResult(
246245
context = new Context(copyGlobalContext(), bindings, renderConfig.getDisabled());
247246
}
248247

249-
try (
250-
AutoCloseableImpl<JinjavaInterpreter> interpreterAutoCloseable = JinjavaInterpreter
251-
.closeablePushCurrent(
252-
globalConfig.getInterpreterFactory().newInstance(this, context, renderConfig)
253-
)
254-
.get()
255-
) {
256-
JinjavaInterpreter interpreter = interpreterAutoCloseable.value();
248+
try {
249+
JinjavaInterpreter interpreter = globalConfig
250+
.getInterpreterFactory()
251+
.newInstance(this, context, renderConfig);
257252
try {
258253
String result = interpreter.render(template);
259254
return new RenderResult(

0 commit comments

Comments
 (0)