Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring boot 3 #630

Merged
merged 3 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ addons:

language: java
jdk:
- openjdk8
- openjdk11
- openjdk17

after_success:
- export VERSION=$(echo "cat //*[local-name()='project']/*[local-name()='version']/text()" | xmllint --nocdata --shell pom.xml | sed '1d;$d')
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ For more information please visit the [website](https://pebbletemplates.io).
As of version 3.1.0 and in order to follow this naming [recommendation](https://github.com/spring-projects/spring-boot/wiki/Building-On-Spring-Boot#naming), the artifactId of pebble-spring-boot-starter has been renamed as is:

| Old artifactId | New artifactId | spring-boot version |
| --- |--------------------------------------------------------------------| --- |
| pebble-spring-boot-starter | pebble-legacy-spring-boot-starter (No longer supported as of 3.1.6 | 1.5.x |
| pebble-spring-boot-2-starter | pebble-spring-boot-starter | 2.x.x |
| --- |--------------------------------------------------------------------|---------------------|
| pebble-spring-boot-starter | pebble-legacy-spring-boot-starter | 2.7.x |
| pebble-spring-boot-2-starter | pebble-spring-boot-starter | 3.x.x |

# New group id
Please note that the pebble's groupId has been updated as of version 2.5.0
Expand Down
2 changes: 1 addition & 1 deletion docs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.pebbletemplates</groupId>
<artifactId>pebble-project</artifactId>
<version>3.1.7-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
</parent>

<artifactId>docs</artifactId>
Expand Down
6 changes: 6 additions & 0 deletions docs/src/orchid/resources/changelog/v3_2_0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
version: '3.2.0'
---

- Add support for spring framework 6 and spring-boot 3 (#)
- Bump minimum supported java version to 17 in pebble-spring6 and pebble-spring-boot-starter in order to work with spring
62 changes: 62 additions & 0 deletions pebble-spring/pebble-legacy-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>pebble-spring</artifactId>
<groupId>io.pebbletemplates</groupId>
<version>3.2.0-SNAPSHOT</version>
</parent>

<artifactId>pebble-legacy-spring-boot-starter</artifactId>

<name>Pebble Spring Boot 2 Starter</name>
<description>Spring Boot 2 starter for Pebble Template Engine</description>
<url>http://pebbletemplates.io</url>

<properties>
<boot.version>2.7.5</boot.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${boot.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<version>${boot.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.pebbletemplates</groupId>
<artifactId>pebble-spring5</artifactId>
<version>${project.version}</version>
</dependency>

<!-- TEST -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${boot.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Automatic-Module-Name>io.pebbletemplates.spring.boot</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.mitchellbosecke.pebble.boot.autoconfigure;

abstract class AbstractPebbleConfiguration {

protected String stripLeadingSlash(String value) {
if (value == null) {
return null;
}
if (value.startsWith("/")) {
return value.substring(1);
}
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.mitchellbosecke.pebble.boot.autoconfigure;

import com.mitchellbosecke.pebble.PebbleEngine;
import com.mitchellbosecke.pebble.attributes.methodaccess.MethodAccessValidator;
import com.mitchellbosecke.pebble.extension.Extension;
import com.mitchellbosecke.pebble.loader.ClasspathLoader;
import com.mitchellbosecke.pebble.loader.Loader;
import com.mitchellbosecke.pebble.spring.extension.SpringExtension;
import java.util.List;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.lang.Nullable;

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(PebbleEngine.class)
@EnableConfigurationProperties(PebbleProperties.class)
@Import({PebbleServletWebConfiguration.class, PebbleReactiveWebConfiguration.class})
public class PebbleAutoConfiguration extends AbstractPebbleConfiguration {

@Bean
@ConditionalOnMissingBean(name = "pebbleLoader")
public Loader<?> pebbleLoader(PebbleProperties properties) {
ClasspathLoader loader = new ClasspathLoader();
loader.setCharset(properties.getCharsetName());
// classpath loader does not like leading slashes in resource paths
loader.setPrefix(this.stripLeadingSlash(properties.getPrefix()));
loader.setSuffix(properties.getSuffix());
return loader;
}

@Bean
@ConditionalOnMissingBean
public SpringExtension springExtension(MessageSource messageSource) {
return new SpringExtension(messageSource);
}

@Bean
@ConditionalOnMissingBean(name = "pebbleEngine")
public PebbleEngine pebbleEngine(PebbleProperties properties,
Loader<?> pebbleLoader,
SpringExtension springExtension,
@Nullable List<Extension> extensions,
@Nullable MethodAccessValidator methodAccessValidator) {
PebbleEngine.Builder builder = new PebbleEngine.Builder();
builder.loader(pebbleLoader);
builder.extension(springExtension);
if (extensions != null && !extensions.isEmpty()) {
builder.extension(extensions.toArray(new Extension[extensions.size()]));
}
if (!properties.isCache()) {
builder.cacheActive(false);
}
if (properties.getDefaultLocale() != null) {
builder.defaultLocale(properties.getDefaultLocale());
}
builder.strictVariables(properties.isStrictVariables());
builder.greedyMatchMethod(properties.isGreedyMatchMethod());
if (methodAccessValidator != null) {
builder.methodAccessValidator(methodAccessValidator);
}
return builder.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.mitchellbosecke.pebble.boot.autoconfigure;

import java.util.Locale;
import org.springframework.boot.autoconfigure.template.AbstractTemplateViewResolverProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties("pebble")
public class PebbleProperties extends AbstractTemplateViewResolverProperties {

public static final String DEFAULT_PREFIX = "/templates/";
public static final String DEFAULT_SUFFIX = ".pebble";

private Locale defaultLocale;
private boolean strictVariables;
private boolean greedyMatchMethod;

public PebbleProperties() {
super(DEFAULT_PREFIX, DEFAULT_SUFFIX);
this.setCache(true);
}

public Locale getDefaultLocale() {
return this.defaultLocale;
}

public void setDefaultLocale(Locale defaultLocale) {
this.defaultLocale = defaultLocale;
}

public boolean isStrictVariables() {
return this.strictVariables;
}

public void setStrictVariables(boolean strictVariables) {
this.strictVariables = strictVariables;
}

public boolean isGreedyMatchMethod() {
return this.greedyMatchMethod;
}

public void setGreedyMatchMethod(boolean greedyMatchMethod) {
this.greedyMatchMethod = greedyMatchMethod;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.mitchellbosecke.pebble.boot.autoconfigure;

import com.mitchellbosecke.pebble.PebbleEngine;
import com.mitchellbosecke.pebble.loader.ClasspathLoader;
import com.mitchellbosecke.pebble.spring.reactive.PebbleReactiveViewResolver;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
@ConditionalOnWebApplication(type = Type.REACTIVE)
class PebbleReactiveWebConfiguration extends AbstractPebbleConfiguration {

@Bean
@ConditionalOnMissingBean
PebbleReactiveViewResolver pebbleReactiveViewResolver(PebbleProperties properties,
PebbleEngine pebbleEngine) {
String prefix = properties.getPrefix();
if (pebbleEngine.getLoader() instanceof ClasspathLoader) {
// classpathloader doesn't like leading slashes in paths
prefix = this.stripLeadingSlash(properties.getPrefix());
}
PebbleReactiveViewResolver resolver = new PebbleReactiveViewResolver(pebbleEngine);
resolver.setPrefix(prefix);
resolver.setSuffix(properties.getSuffix());
resolver.setViewNames(properties.getViewNames());
resolver.setRequestContextAttribute(properties.getRequestContextAttribute());
return resolver;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.mitchellbosecke.pebble.boot.autoconfigure;

import com.mitchellbosecke.pebble.PebbleEngine;
import com.mitchellbosecke.pebble.loader.ClasspathLoader;
import com.mitchellbosecke.pebble.spring.servlet.PebbleViewResolver;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
@ConditionalOnWebApplication(type = Type.SERVLET)
class PebbleServletWebConfiguration extends AbstractPebbleConfiguration {

@Bean
@ConditionalOnMissingBean
PebbleViewResolver pebbleViewResolver(PebbleProperties properties,
PebbleEngine pebbleEngine) {
PebbleViewResolver pvr = new PebbleViewResolver(pebbleEngine);
properties.applyToMvcViewResolver(pvr);
if (pebbleEngine.getLoader() instanceof ClasspathLoader) {
// classpathloader doesn't like leading slashes in paths
pvr.setPrefix(this.stripLeadingSlash(properties.getPrefix()));
}

return pvr;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.mitchellbosecke.pebble.boot.autoconfigure;

import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.ClassUtils;

import static org.springframework.core.io.ResourceLoader.CLASSPATH_URL_PREFIX;

public class PebbleTemplateAvailabilityProvider implements TemplateAvailabilityProvider {

@Override
public boolean isTemplateAvailable(String view, Environment environment, ClassLoader classLoader,
ResourceLoader resourceLoader) {
if (ClassUtils.isPresent("com.mitchellbosecke.pebble.PebbleEngine", classLoader)) {
String prefix = environment.getProperty("pebble.prefix", PebbleProperties.DEFAULT_PREFIX);
String suffix = environment.getProperty("pebble.suffix", PebbleProperties.DEFAULT_SUFFIX);
return resourceLoader.getResource(CLASSPATH_URL_PREFIX + prefix + view + suffix).exists();
}
return false;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Auto-configuration for Pebble Template Engine.
*/
package com.mitchellbosecke.pebble.boot.autoconfigure;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.mitchellbosecke.pebble.boot.autoconfigure.PebbleAutoConfiguration
# Template availability providers
org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider=\
com.mitchellbosecke.pebble.boot.autoconfigure.PebbleTemplateAvailabilityProvider
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
provides: pebble,pebble-spring5
Loading