From 9b9217a7768e401ba002dd1efecbe48324fed8fd Mon Sep 17 00:00:00 2001 From: Eric Bussieres Date: Thu, 8 Aug 2019 14:17:56 -0400 Subject: [PATCH] #459 and #460: Avoid feature version in spring boot starter name and upgrade to latest spring boot version (#461) --- .travis.yml | 2 +- docs/pom.xml | 2 +- docs/src/orchid/resources/changelog/v3_1_0.md | 12 + .../wiki/guide/spring-boot-integration.md | 8 +- .../CHANGELOG.md | 0 .../pom.xml | 20 +- .../PebbleAutoConfiguration.java | 8 +- .../boot/autoconfigure/PebbleProperties.java | 0 .../PebbleTemplateAvailabilityProvider.java | 7 +- .../boot/autoconfigure/package-info.java | 0 .../main/resources/META-INF/spring.factories | 0 .../main/resources/META-INF/spring.provides | 1 + .../pebble/boot/Application.java | 8 - .../pebble/boot/ControllerTest.java | 8 +- .../pebble/boot/Controllers.java | 0 .../pebble/boot/CoreTests.java | 4 +- .../pebble/boot/NonWebApplication.java | 5 +- ...rvletComponenRegisteringPostProcessor.java | 7 +- .../pebble/boot/ServletComponentHandler.java | 0 .../pebble/boot/ServletComponentScan.java | 0 .../boot/ServletComponentScanRegistrar.java | 0 .../pebble/boot/WebFilterHandler.java | 0 .../pebble/boot/WebListenerHandler.java | 0 .../pebble/boot/WebServletHandler.java | 0 .../src/test/resources/messages.properties | 0 .../src/test/resources/messages_es.properties | 0 .../resources/templates/contextPath.pebble | 0 .../resources/templates/extensions.pebble | 0 .../src/test/resources/templates/hello.pebble | 0 .../src/test/resources/templates/index.pebble | 0 .../main/resources/META-INF/spring.provides | 1 - .../pebble-spring-boot-starter/pom.xml | 18 +- .../PebbleAutoConfiguration.java | 8 +- .../PebbleTemplateAvailabilityProvider.java | 7 +- .../main/resources/META-INF/spring.provides | 2 +- .../pebble/boot/Application.java | 8 - .../pebble/boot/ControllerTest.java | 8 +- .../pebble/boot/CoreTests.java | 4 +- .../pebble/boot/NonWebApplication.java | 5 +- ...rvletComponenRegisteringPostProcessor.java | 7 +- pebble-spring/pebble-spring3/pom.xml | 82 ------- .../pebble/spring/PebbleView.java | 113 ---------- .../pebble/spring/PebbleViewResolver.java | 55 ----- .../pebble/spring/context/Beans.java | 97 -------- .../spring/extension/SpringExtension.java | 52 ----- .../extension/function/HrefFunction.java | 74 ------ .../function/MessageSourceFunction.java | 65 ------ .../BaseBindingResultFunction.java | 51 ----- .../bindingresult/GetAllErrorsFunction.java | 59 ----- .../bindingresult/GetFieldErrorsFunction.java | 65 ------ .../GetGlobalErrorsFunction.java | 59 ----- .../bindingresult/HasErrorsFunction.java | 38 ---- .../bindingresult/HasFieldErrorsFunction.java | 48 ---- .../HasGlobalErrorsFunction.java | 38 ---- .../pebble/spring/util/ViewUtils.java | 20 -- .../pebble/spring/PebbleViewResolverTest.java | 211 ------------------ .../pebble/spring/bean/SomeBean.java | 19 -- .../pebble/spring/config/MVCConfig.java | 70 ------ .../spring/expectedResponse/beansTest.html | 10 - .../expectedResponse/bindingResultTest.html | 21 -- .../bindingResultWithMacroTest.html | 21 -- .../expectedResponse/hrefFunctionTest.html | 13 -- .../expectedResponse/messageEnTest.html | 12 - .../expectedResponse/messageFrTest.html | 12 - .../spring/expectedResponse/requestTest.html | 11 - .../spring/expectedResponse/responseTest.html | 12 - .../spring/expectedResponse/sessionTest.html | 11 - .../pebble/spring/messages_en.properties | 5 - .../pebble/spring/messages_fr.properties | 5 - .../pebble/spring/template/beansTest.html | 10 - .../spring/template/bindingResultTest.html | 26 --- .../template/bindingResultWithMacroTest.html | 29 --- .../spring/template/hrefFunctionTest.html | 13 -- .../pebble/spring/template/messageEnTest.html | 12 - .../pebble/spring/template/messageFrTest.html | 12 - .../pebble/spring/template/requestTest.html | 11 - .../pebble/spring/template/responseTest.html | 12 - .../pebble/spring/template/sessionTest.html | 11 - pebble-spring/pebble-spring4/pom.xml | 4 +- pebble-spring/pebble-spring5/pom.xml | 4 +- pebble-spring/pom.xml | 5 +- pebble/pom.xml | 2 +- pom.xml | 2 +- 83 files changed, 86 insertions(+), 1576 deletions(-) create mode 100644 docs/src/orchid/resources/changelog/v3_1_0.md rename pebble-spring/{pebble-spring-boot-starter => pebble-legacy-spring-boot-starter}/CHANGELOG.md (100%) rename pebble-spring/{pebble-spring-boot-2-starter => pebble-legacy-spring-boot-starter}/pom.xml (79%) rename pebble-spring/{pebble-spring-boot-2-starter => pebble-legacy-spring-boot-starter}/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleAutoConfiguration.java (93%) rename pebble-spring/{pebble-spring-boot-2-starter => pebble-legacy-spring-boot-starter}/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleProperties.java (100%) rename pebble-spring/{pebble-spring-boot-2-starter => pebble-legacy-spring-boot-starter}/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleTemplateAvailabilityProvider.java (65%) rename pebble-spring/{pebble-spring-boot-2-starter => pebble-legacy-spring-boot-starter}/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/package-info.java (100%) rename pebble-spring/{pebble-spring-boot-2-starter => pebble-legacy-spring-boot-starter}/src/main/resources/META-INF/spring.factories (100%) create mode 100644 pebble-spring/pebble-legacy-spring-boot-starter/src/main/resources/META-INF/spring.provides rename pebble-spring/{pebble-spring-boot-2-starter => pebble-legacy-spring-boot-starter}/src/test/java/com/mitchellbosecke/pebble/boot/Application.java (87%) rename pebble-spring/{pebble-spring-boot-2-starter => pebble-legacy-spring-boot-starter}/src/test/java/com/mitchellbosecke/pebble/boot/ControllerTest.java (90%) rename pebble-spring/{pebble-spring-boot-2-starter => pebble-legacy-spring-boot-starter}/src/test/java/com/mitchellbosecke/pebble/boot/Controllers.java (100%) rename pebble-spring/{pebble-spring-boot-2-starter => pebble-legacy-spring-boot-starter}/src/test/java/com/mitchellbosecke/pebble/boot/CoreTests.java (85%) rename pebble-spring/{pebble-spring-boot-2-starter => pebble-legacy-spring-boot-starter}/src/test/java/com/mitchellbosecke/pebble/boot/NonWebApplication.java (87%) rename pebble-spring/{pebble-spring-boot-2-starter => pebble-legacy-spring-boot-starter}/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponenRegisteringPostProcessor.java (91%) rename pebble-spring/{pebble-spring-boot-2-starter => pebble-legacy-spring-boot-starter}/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponentHandler.java (100%) rename pebble-spring/{pebble-spring-boot-2-starter => pebble-legacy-spring-boot-starter}/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponentScan.java (100%) rename pebble-spring/{pebble-spring-boot-2-starter => pebble-legacy-spring-boot-starter}/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponentScanRegistrar.java (100%) rename pebble-spring/{pebble-spring-boot-2-starter => pebble-legacy-spring-boot-starter}/src/test/java/com/mitchellbosecke/pebble/boot/WebFilterHandler.java (100%) rename pebble-spring/{pebble-spring-boot-2-starter => pebble-legacy-spring-boot-starter}/src/test/java/com/mitchellbosecke/pebble/boot/WebListenerHandler.java (100%) rename pebble-spring/{pebble-spring-boot-2-starter => pebble-legacy-spring-boot-starter}/src/test/java/com/mitchellbosecke/pebble/boot/WebServletHandler.java (100%) rename pebble-spring/{pebble-spring-boot-2-starter => pebble-legacy-spring-boot-starter}/src/test/resources/messages.properties (100%) rename pebble-spring/{pebble-spring-boot-2-starter => pebble-legacy-spring-boot-starter}/src/test/resources/messages_es.properties (100%) rename pebble-spring/{pebble-spring-boot-2-starter => pebble-legacy-spring-boot-starter}/src/test/resources/templates/contextPath.pebble (100%) rename pebble-spring/{pebble-spring-boot-2-starter => pebble-legacy-spring-boot-starter}/src/test/resources/templates/extensions.pebble (100%) rename pebble-spring/{pebble-spring-boot-2-starter => pebble-legacy-spring-boot-starter}/src/test/resources/templates/hello.pebble (100%) rename pebble-spring/{pebble-spring-boot-2-starter => pebble-legacy-spring-boot-starter}/src/test/resources/templates/index.pebble (100%) delete mode 100644 pebble-spring/pebble-spring-boot-2-starter/src/main/resources/META-INF/spring.provides delete mode 100644 pebble-spring/pebble-spring3/pom.xml delete mode 100644 pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/PebbleView.java delete mode 100644 pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/PebbleViewResolver.java delete mode 100644 pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/context/Beans.java delete mode 100644 pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/SpringExtension.java delete mode 100644 pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/HrefFunction.java delete mode 100644 pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/MessageSourceFunction.java delete mode 100644 pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/BaseBindingResultFunction.java delete mode 100644 pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/GetAllErrorsFunction.java delete mode 100644 pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/GetFieldErrorsFunction.java delete mode 100644 pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/GetGlobalErrorsFunction.java delete mode 100644 pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/HasErrorsFunction.java delete mode 100644 pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/HasFieldErrorsFunction.java delete mode 100644 pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/HasGlobalErrorsFunction.java delete mode 100644 pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/util/ViewUtils.java delete mode 100644 pebble-spring/pebble-spring3/src/test/java/com/mitchellbosecke/pebble/spring/PebbleViewResolverTest.java delete mode 100644 pebble-spring/pebble-spring3/src/test/java/com/mitchellbosecke/pebble/spring/bean/SomeBean.java delete mode 100644 pebble-spring/pebble-spring3/src/test/java/com/mitchellbosecke/pebble/spring/config/MVCConfig.java delete mode 100644 pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/beansTest.html delete mode 100644 pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/bindingResultTest.html delete mode 100644 pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/bindingResultWithMacroTest.html delete mode 100644 pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/hrefFunctionTest.html delete mode 100644 pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/messageEnTest.html delete mode 100644 pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/messageFrTest.html delete mode 100644 pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/requestTest.html delete mode 100644 pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/responseTest.html delete mode 100644 pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/sessionTest.html delete mode 100644 pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/messages_en.properties delete mode 100644 pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/messages_fr.properties delete mode 100644 pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/beansTest.html delete mode 100644 pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/bindingResultTest.html delete mode 100644 pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/bindingResultWithMacroTest.html delete mode 100644 pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/hrefFunctionTest.html delete mode 100644 pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/messageEnTest.html delete mode 100644 pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/messageFrTest.html delete mode 100644 pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/requestTest.html delete mode 100644 pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/responseTest.html delete mode 100644 pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/sessionTest.html diff --git a/.travis.yml b/.travis.yml index 0c67e8166..9392ffc75 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ addons: language: java jdk: - - oraclejdk8 + - openjdk8 - openjdk11 - openjdk12 diff --git a/docs/pom.xml b/docs/pom.xml index 290b5f0af..1bcdb0146 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -5,7 +5,7 @@ io.pebbletemplates pebble-project - 3.0.11-SNAPSHOT + 3.1.0-SNAPSHOT docs diff --git a/docs/src/orchid/resources/changelog/v3_1_0.md b/docs/src/orchid/resources/changelog/v3_1_0.md new file mode 100644 index 000000000..355ac406f --- /dev/null +++ b/docs/src/orchid/resources/changelog/v3_1_0.md @@ -0,0 +1,12 @@ +--- +version: '3.1.0' +--- + +- **BREAKING CHANGES**: Consider avoiding feature version in spring boot starter name (#459) +- Upgrade spring boot integration to Spring Boot 2.1 (#460) +- Allow override core operators (#455, #456) +- Allows variables to be set in templates when provided context is an immutable map (#453) +- Fixed a few typos in the docs (#452) +- Remove unnecessary variable 'state' in LexerImpl by using Stack (#450) +- Updates Orchid to 0.17.1 and fixes its breaking changes (#448) +- Null value in a Map should not throw AttributeNotFoundException (#447, #446) diff --git a/docs/src/orchid/resources/wiki/guide/spring-boot-integration.md b/docs/src/orchid/resources/wiki/guide/spring-boot-integration.md index 78cb1672c..0ed841dab 100644 --- a/docs/src/orchid/resources/wiki/guide/spring-boot-integration.md +++ b/docs/src/orchid/resources/wiki/guide/spring-boot-integration.md @@ -7,7 +7,7 @@ Spring Boot starter for autoconfiguring Pebble as an MVC ViewResolver. ## Basic Usage Add the starter dependency to your pom.xml: -### spring-boot v1 +### spring-boot v2 ```XML io.pebbletemplates @@ -20,17 +20,17 @@ Or build.gradle: compile "io.pebbletemplates:pebble-spring-boot-starter:{{ site.version }}" ``` -### spring-boot v2 +### spring-boot v1 ```XML io.pebbletemplates - pebble-spring-boot-2-starter + pebble-legacy-spring-boot-starter {{ site.version }} ``` Or build.gradle: ```groovy -compile "io.pebbletemplates:pebble-spring-boot-2-starter:{{ site.version }}" +compile "io.pebbletemplates:pebble-legacy-spring-boot-starter:{{ site.version }}" ``` This is enough for autoconfiguration to kick in. This includes: diff --git a/pebble-spring/pebble-spring-boot-starter/CHANGELOG.md b/pebble-spring/pebble-legacy-spring-boot-starter/CHANGELOG.md similarity index 100% rename from pebble-spring/pebble-spring-boot-starter/CHANGELOG.md rename to pebble-spring/pebble-legacy-spring-boot-starter/CHANGELOG.md diff --git a/pebble-spring/pebble-spring-boot-2-starter/pom.xml b/pebble-spring/pebble-legacy-spring-boot-starter/pom.xml similarity index 79% rename from pebble-spring/pebble-spring-boot-2-starter/pom.xml rename to pebble-spring/pebble-legacy-spring-boot-starter/pom.xml index 7fd92aadb..83d624da9 100644 --- a/pebble-spring/pebble-spring-boot-2-starter/pom.xml +++ b/pebble-spring/pebble-legacy-spring-boot-starter/pom.xml @@ -1,20 +1,20 @@ - + 4.0.0 - pebble-spring io.pebbletemplates - 3.0.11-SNAPSHOT + pebble-spring + 3.1.0-SNAPSHOT - pebble-spring-boot-2-starter + pebble-legacy-spring-boot-starter - Pebble Spring Boot 2 Starter - Spring Boot 2 starter or Pebble Template Engine + Pebble Spring Boot Starter + Spring Boot starter for Pebble Template Engine http://pebbletemplates.io - 2.0.1.RELEASE + 1.5.21.RELEASE @@ -26,7 +26,7 @@ io.pebbletemplates - pebble-spring5 + pebble-spring4 ${project.version} @@ -38,7 +38,7 @@ test - + @@ -53,4 +53,4 @@ - \ No newline at end of file + diff --git a/pebble-spring/pebble-spring-boot-2-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleAutoConfiguration.java b/pebble-spring/pebble-legacy-spring-boot-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleAutoConfiguration.java similarity index 93% rename from pebble-spring/pebble-spring-boot-2-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleAutoConfiguration.java rename to pebble-spring/pebble-legacy-spring-boot-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleAutoConfiguration.java index 57ecbbc7a..c39977697 100644 --- a/pebble-spring/pebble-spring-boot-2-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleAutoConfiguration.java +++ b/pebble-spring/pebble-legacy-spring-boot-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleAutoConfiguration.java @@ -4,8 +4,8 @@ import com.mitchellbosecke.pebble.extension.Extension; import com.mitchellbosecke.pebble.loader.ClasspathLoader; import com.mitchellbosecke.pebble.loader.Loader; -import com.mitchellbosecke.pebble.spring.PebbleViewResolver; -import com.mitchellbosecke.pebble.spring.extension.SpringExtension; +import com.mitchellbosecke.pebble.spring4.PebbleViewResolver; +import com.mitchellbosecke.pebble.spring4.extension.SpringExtension; import java.util.List; import javax.servlet.Servlet; import org.springframework.beans.factory.annotation.Autowired; @@ -13,7 +13,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; -import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration; +import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -96,7 +96,7 @@ public static class PebbleViewResolverConfiguration { @ConditionalOnMissingBean(name = "pebbleViewResolver") public PebbleViewResolver pebbleViewResolver() { PebbleViewResolver pvr = new PebbleViewResolver(); - this.properties.applyToMvcViewResolver(pvr); + this.properties.applyToViewResolver(pvr); pvr.setPebbleEngine(this.pebbleEngine); if (this.pebbleEngine.getLoader() instanceof ClasspathLoader) { diff --git a/pebble-spring/pebble-spring-boot-2-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleProperties.java b/pebble-spring/pebble-legacy-spring-boot-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleProperties.java similarity index 100% rename from pebble-spring/pebble-spring-boot-2-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleProperties.java rename to pebble-spring/pebble-legacy-spring-boot-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleProperties.java diff --git a/pebble-spring/pebble-spring-boot-2-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleTemplateAvailabilityProvider.java b/pebble-spring/pebble-legacy-spring-boot-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleTemplateAvailabilityProvider.java similarity index 65% rename from pebble-spring/pebble-spring-boot-2-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleTemplateAvailabilityProvider.java rename to pebble-spring/pebble-legacy-spring-boot-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleTemplateAvailabilityProvider.java index 379a2d6b8..1435641f0 100644 --- a/pebble-spring/pebble-spring-boot-2-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleTemplateAvailabilityProvider.java +++ b/pebble-spring/pebble-legacy-spring-boot-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleTemplateAvailabilityProvider.java @@ -1,7 +1,9 @@ package com.mitchellbosecke.pebble.boot.autoconfigure; import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider; +import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.core.env.Environment; +import org.springframework.core.env.PropertyResolver; import org.springframework.core.io.ResourceLoader; import org.springframework.util.ClassUtils; @@ -11,8 +13,9 @@ public class PebbleTemplateAvailabilityProvider implements TemplateAvailabilityP 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); + PropertyResolver resolver = new RelaxedPropertyResolver(environment, "pebble."); + String prefix = resolver.getProperty("prefix", PebbleProperties.DEFAULT_PREFIX); + String suffix = resolver.getProperty("suffix", PebbleProperties.DEFAULT_SUFFIX); return resourceLoader.getResource(prefix + view + suffix).exists(); } return false; diff --git a/pebble-spring/pebble-spring-boot-2-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/package-info.java b/pebble-spring/pebble-legacy-spring-boot-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/package-info.java similarity index 100% rename from pebble-spring/pebble-spring-boot-2-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/package-info.java rename to pebble-spring/pebble-legacy-spring-boot-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/package-info.java diff --git a/pebble-spring/pebble-spring-boot-2-starter/src/main/resources/META-INF/spring.factories b/pebble-spring/pebble-legacy-spring-boot-starter/src/main/resources/META-INF/spring.factories similarity index 100% rename from pebble-spring/pebble-spring-boot-2-starter/src/main/resources/META-INF/spring.factories rename to pebble-spring/pebble-legacy-spring-boot-starter/src/main/resources/META-INF/spring.factories diff --git a/pebble-spring/pebble-legacy-spring-boot-starter/src/main/resources/META-INF/spring.provides b/pebble-spring/pebble-legacy-spring-boot-starter/src/main/resources/META-INF/spring.provides new file mode 100644 index 000000000..65aecbb1d --- /dev/null +++ b/pebble-spring/pebble-legacy-spring-boot-starter/src/main/resources/META-INF/spring.provides @@ -0,0 +1 @@ +provides: pebble,pebble-spring4 diff --git a/pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/Application.java b/pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/Application.java similarity index 87% rename from pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/Application.java rename to pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/Application.java index 699b801b6..a02caf2cf 100644 --- a/pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/Application.java +++ b/pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/Application.java @@ -30,14 +30,6 @@ public LocaleResolver localeResolver() { return new AcceptHeaderLocaleResolver(); } - @Bean - public MessageSource messageSource() { - ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); - messageSource.setBasename("messages"); - messageSource.setFallbackToSystemLocale(false); - return messageSource; - } - @Bean public Extension testExtension() { return new TestExtension(); diff --git a/pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/ControllerTest.java b/pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/ControllerTest.java similarity index 90% rename from pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/ControllerTest.java rename to pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/ControllerTest.java index 672b3782a..08792e1e2 100644 --- a/pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/ControllerTest.java +++ b/pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/ControllerTest.java @@ -1,6 +1,5 @@ package com.mitchellbosecke.pebble.boot; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -12,15 +11,16 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = Application.class, webEnvironment = WebEnvironment.RANDOM_PORT) +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Application.class, webEnvironment=WebEnvironment.RANDOM_PORT) public class ControllerTest { @Autowired diff --git a/pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/Controllers.java b/pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/Controllers.java similarity index 100% rename from pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/Controllers.java rename to pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/Controllers.java diff --git a/pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/CoreTests.java b/pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/CoreTests.java similarity index 85% rename from pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/CoreTests.java rename to pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/CoreTests.java index 9ea36f50f..4f4ef0a27 100644 --- a/pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/CoreTests.java +++ b/pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/CoreTests.java @@ -7,9 +7,9 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @SpringBootTest(classes = NonWebApplication.class) public class CoreTests { diff --git a/pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/NonWebApplication.java b/pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/NonWebApplication.java similarity index 87% rename from pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/NonWebApplication.java rename to pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/NonWebApplication.java index 6b4216d00..bbfc12225 100644 --- a/pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/NonWebApplication.java +++ b/pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/NonWebApplication.java @@ -1,7 +1,6 @@ package com.mitchellbosecke.pebble.boot; import org.springframework.boot.SpringApplication; -import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.context.MessageSource; @@ -12,9 +11,7 @@ public class NonWebApplication { public static void main(String[] args) { - SpringApplication sa = new SpringApplicationBuilder(NonWebApplication.class) - .web(WebApplicationType.NONE) - .build(); + SpringApplication sa = new SpringApplicationBuilder(NonWebApplication.class).web(false).build(); sa.run(args); } diff --git a/pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponenRegisteringPostProcessor.java b/pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponenRegisteringPostProcessor.java similarity index 91% rename from pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponenRegisteringPostProcessor.java rename to pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponenRegisteringPostProcessor.java index 3bf919dd8..54d229963 100644 --- a/pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponenRegisteringPostProcessor.java +++ b/pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponenRegisteringPostProcessor.java @@ -9,7 +9,7 @@ import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; +import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; @@ -60,9 +60,8 @@ private void scanPackage(ClassPathScanningCandidateComponentProvider componentPr } private boolean isRunningInEmbeddedContainer() { - return this.applicationContext instanceof ServletWebServerApplicationContext - && ((ServletWebServerApplicationContext) this.applicationContext).getServletContext() - == null; + return this.applicationContext instanceof EmbeddedWebApplicationContext + && ((EmbeddedWebApplicationContext) this.applicationContext).getServletContext() == null; } private ClassPathScanningCandidateComponentProvider createComponentProvider() { diff --git a/pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponentHandler.java b/pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponentHandler.java similarity index 100% rename from pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponentHandler.java rename to pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponentHandler.java diff --git a/pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponentScan.java b/pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponentScan.java similarity index 100% rename from pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponentScan.java rename to pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponentScan.java diff --git a/pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponentScanRegistrar.java b/pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponentScanRegistrar.java similarity index 100% rename from pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponentScanRegistrar.java rename to pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponentScanRegistrar.java diff --git a/pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/WebFilterHandler.java b/pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/WebFilterHandler.java similarity index 100% rename from pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/WebFilterHandler.java rename to pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/WebFilterHandler.java diff --git a/pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/WebListenerHandler.java b/pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/WebListenerHandler.java similarity index 100% rename from pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/WebListenerHandler.java rename to pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/WebListenerHandler.java diff --git a/pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/WebServletHandler.java b/pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/WebServletHandler.java similarity index 100% rename from pebble-spring/pebble-spring-boot-2-starter/src/test/java/com/mitchellbosecke/pebble/boot/WebServletHandler.java rename to pebble-spring/pebble-legacy-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/WebServletHandler.java diff --git a/pebble-spring/pebble-spring-boot-2-starter/src/test/resources/messages.properties b/pebble-spring/pebble-legacy-spring-boot-starter/src/test/resources/messages.properties similarity index 100% rename from pebble-spring/pebble-spring-boot-2-starter/src/test/resources/messages.properties rename to pebble-spring/pebble-legacy-spring-boot-starter/src/test/resources/messages.properties diff --git a/pebble-spring/pebble-spring-boot-2-starter/src/test/resources/messages_es.properties b/pebble-spring/pebble-legacy-spring-boot-starter/src/test/resources/messages_es.properties similarity index 100% rename from pebble-spring/pebble-spring-boot-2-starter/src/test/resources/messages_es.properties rename to pebble-spring/pebble-legacy-spring-boot-starter/src/test/resources/messages_es.properties diff --git a/pebble-spring/pebble-spring-boot-2-starter/src/test/resources/templates/contextPath.pebble b/pebble-spring/pebble-legacy-spring-boot-starter/src/test/resources/templates/contextPath.pebble similarity index 100% rename from pebble-spring/pebble-spring-boot-2-starter/src/test/resources/templates/contextPath.pebble rename to pebble-spring/pebble-legacy-spring-boot-starter/src/test/resources/templates/contextPath.pebble diff --git a/pebble-spring/pebble-spring-boot-2-starter/src/test/resources/templates/extensions.pebble b/pebble-spring/pebble-legacy-spring-boot-starter/src/test/resources/templates/extensions.pebble similarity index 100% rename from pebble-spring/pebble-spring-boot-2-starter/src/test/resources/templates/extensions.pebble rename to pebble-spring/pebble-legacy-spring-boot-starter/src/test/resources/templates/extensions.pebble diff --git a/pebble-spring/pebble-spring-boot-2-starter/src/test/resources/templates/hello.pebble b/pebble-spring/pebble-legacy-spring-boot-starter/src/test/resources/templates/hello.pebble similarity index 100% rename from pebble-spring/pebble-spring-boot-2-starter/src/test/resources/templates/hello.pebble rename to pebble-spring/pebble-legacy-spring-boot-starter/src/test/resources/templates/hello.pebble diff --git a/pebble-spring/pebble-spring-boot-2-starter/src/test/resources/templates/index.pebble b/pebble-spring/pebble-legacy-spring-boot-starter/src/test/resources/templates/index.pebble similarity index 100% rename from pebble-spring/pebble-spring-boot-2-starter/src/test/resources/templates/index.pebble rename to pebble-spring/pebble-legacy-spring-boot-starter/src/test/resources/templates/index.pebble diff --git a/pebble-spring/pebble-spring-boot-2-starter/src/main/resources/META-INF/spring.provides b/pebble-spring/pebble-spring-boot-2-starter/src/main/resources/META-INF/spring.provides deleted file mode 100644 index fa6b11812..000000000 --- a/pebble-spring/pebble-spring-boot-2-starter/src/main/resources/META-INF/spring.provides +++ /dev/null @@ -1 +0,0 @@ -provides: pebble,pebble-spring5 diff --git a/pebble-spring/pebble-spring-boot-starter/pom.xml b/pebble-spring/pebble-spring-boot-starter/pom.xml index 15b3fbe11..552e29a8c 100644 --- a/pebble-spring/pebble-spring-boot-starter/pom.xml +++ b/pebble-spring/pebble-spring-boot-starter/pom.xml @@ -1,20 +1,20 @@ + - 4.0.0 - io.pebbletemplates pebble-spring - 3.0.11-SNAPSHOT + io.pebbletemplates + 3.1.0-SNAPSHOT pebble-spring-boot-starter - Pebble Spring Boot Starter - Spring Boot starter for Pebble Template Engine + Pebble Spring Boot 2 Starter + Spring Boot 2 starter or Pebble Template Engine http://pebbletemplates.io - 1.5.21.RELEASE + 2.1.7.RELEASE @@ -26,7 +26,7 @@ io.pebbletemplates - pebble-spring4 + pebble-spring5 ${project.version} @@ -38,7 +38,7 @@ test - + @@ -53,4 +53,4 @@ - + \ No newline at end of file diff --git a/pebble-spring/pebble-spring-boot-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleAutoConfiguration.java b/pebble-spring/pebble-spring-boot-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleAutoConfiguration.java index c39977697..57ecbbc7a 100644 --- a/pebble-spring/pebble-spring-boot-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleAutoConfiguration.java +++ b/pebble-spring/pebble-spring-boot-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleAutoConfiguration.java @@ -4,8 +4,8 @@ import com.mitchellbosecke.pebble.extension.Extension; import com.mitchellbosecke.pebble.loader.ClasspathLoader; import com.mitchellbosecke.pebble.loader.Loader; -import com.mitchellbosecke.pebble.spring4.PebbleViewResolver; -import com.mitchellbosecke.pebble.spring4.extension.SpringExtension; +import com.mitchellbosecke.pebble.spring.PebbleViewResolver; +import com.mitchellbosecke.pebble.spring.extension.SpringExtension; import java.util.List; import javax.servlet.Servlet; import org.springframework.beans.factory.annotation.Autowired; @@ -13,7 +13,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; -import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; +import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -96,7 +96,7 @@ public static class PebbleViewResolverConfiguration { @ConditionalOnMissingBean(name = "pebbleViewResolver") public PebbleViewResolver pebbleViewResolver() { PebbleViewResolver pvr = new PebbleViewResolver(); - this.properties.applyToViewResolver(pvr); + this.properties.applyToMvcViewResolver(pvr); pvr.setPebbleEngine(this.pebbleEngine); if (this.pebbleEngine.getLoader() instanceof ClasspathLoader) { diff --git a/pebble-spring/pebble-spring-boot-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleTemplateAvailabilityProvider.java b/pebble-spring/pebble-spring-boot-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleTemplateAvailabilityProvider.java index 1435641f0..379a2d6b8 100644 --- a/pebble-spring/pebble-spring-boot-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleTemplateAvailabilityProvider.java +++ b/pebble-spring/pebble-spring-boot-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleTemplateAvailabilityProvider.java @@ -1,9 +1,7 @@ package com.mitchellbosecke.pebble.boot.autoconfigure; import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider; -import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.core.env.Environment; -import org.springframework.core.env.PropertyResolver; import org.springframework.core.io.ResourceLoader; import org.springframework.util.ClassUtils; @@ -13,9 +11,8 @@ public class PebbleTemplateAvailabilityProvider implements TemplateAvailabilityP public boolean isTemplateAvailable(String view, Environment environment, ClassLoader classLoader, ResourceLoader resourceLoader) { if (ClassUtils.isPresent("com.mitchellbosecke.pebble.PebbleEngine", classLoader)) { - PropertyResolver resolver = new RelaxedPropertyResolver(environment, "pebble."); - String prefix = resolver.getProperty("prefix", PebbleProperties.DEFAULT_PREFIX); - String suffix = resolver.getProperty("suffix", PebbleProperties.DEFAULT_SUFFIX); + String prefix = environment.getProperty("pebble.prefix", PebbleProperties.DEFAULT_PREFIX); + String suffix = environment.getProperty("pebble.suffix", PebbleProperties.DEFAULT_SUFFIX); return resourceLoader.getResource(prefix + view + suffix).exists(); } return false; diff --git a/pebble-spring/pebble-spring-boot-starter/src/main/resources/META-INF/spring.provides b/pebble-spring/pebble-spring-boot-starter/src/main/resources/META-INF/spring.provides index 65aecbb1d..fa6b11812 100644 --- a/pebble-spring/pebble-spring-boot-starter/src/main/resources/META-INF/spring.provides +++ b/pebble-spring/pebble-spring-boot-starter/src/main/resources/META-INF/spring.provides @@ -1 +1 @@ -provides: pebble,pebble-spring4 +provides: pebble,pebble-spring5 diff --git a/pebble-spring/pebble-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/Application.java b/pebble-spring/pebble-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/Application.java index 699b801b6..a02caf2cf 100644 --- a/pebble-spring/pebble-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/Application.java +++ b/pebble-spring/pebble-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/Application.java @@ -30,14 +30,6 @@ public LocaleResolver localeResolver() { return new AcceptHeaderLocaleResolver(); } - @Bean - public MessageSource messageSource() { - ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); - messageSource.setBasename("messages"); - messageSource.setFallbackToSystemLocale(false); - return messageSource; - } - @Bean public Extension testExtension() { return new TestExtension(); diff --git a/pebble-spring/pebble-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/ControllerTest.java b/pebble-spring/pebble-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/ControllerTest.java index 08792e1e2..672b3782a 100644 --- a/pebble-spring/pebble-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/ControllerTest.java +++ b/pebble-spring/pebble-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/ControllerTest.java @@ -1,5 +1,6 @@ package com.mitchellbosecke.pebble.boot; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -11,16 +12,15 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; -@RunWith(SpringRunner.class) -@SpringBootTest(classes = Application.class, webEnvironment=WebEnvironment.RANDOM_PORT) +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = Application.class, webEnvironment = WebEnvironment.RANDOM_PORT) public class ControllerTest { @Autowired diff --git a/pebble-spring/pebble-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/CoreTests.java b/pebble-spring/pebble-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/CoreTests.java index 4f4ef0a27..9ea36f50f 100644 --- a/pebble-spring/pebble-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/CoreTests.java +++ b/pebble-spring/pebble-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/CoreTests.java @@ -7,9 +7,9 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -@RunWith(SpringRunner.class) +@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = NonWebApplication.class) public class CoreTests { diff --git a/pebble-spring/pebble-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/NonWebApplication.java b/pebble-spring/pebble-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/NonWebApplication.java index bbfc12225..6b4216d00 100644 --- a/pebble-spring/pebble-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/NonWebApplication.java +++ b/pebble-spring/pebble-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/NonWebApplication.java @@ -1,6 +1,7 @@ package com.mitchellbosecke.pebble.boot; import org.springframework.boot.SpringApplication; +import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.context.MessageSource; @@ -11,7 +12,9 @@ public class NonWebApplication { public static void main(String[] args) { - SpringApplication sa = new SpringApplicationBuilder(NonWebApplication.class).web(false).build(); + SpringApplication sa = new SpringApplicationBuilder(NonWebApplication.class) + .web(WebApplicationType.NONE) + .build(); sa.run(args); } diff --git a/pebble-spring/pebble-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponenRegisteringPostProcessor.java b/pebble-spring/pebble-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponenRegisteringPostProcessor.java index 54d229963..3bf919dd8 100644 --- a/pebble-spring/pebble-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponenRegisteringPostProcessor.java +++ b/pebble-spring/pebble-spring-boot-starter/src/test/java/com/mitchellbosecke/pebble/boot/ServletComponenRegisteringPostProcessor.java @@ -9,7 +9,7 @@ import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; +import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; @@ -60,8 +60,9 @@ private void scanPackage(ClassPathScanningCandidateComponentProvider componentPr } private boolean isRunningInEmbeddedContainer() { - return this.applicationContext instanceof EmbeddedWebApplicationContext - && ((EmbeddedWebApplicationContext) this.applicationContext).getServletContext() == null; + return this.applicationContext instanceof ServletWebServerApplicationContext + && ((ServletWebServerApplicationContext) this.applicationContext).getServletContext() + == null; } private ClassPathScanningCandidateComponentProvider createComponentProvider() { diff --git a/pebble-spring/pebble-spring3/pom.xml b/pebble-spring/pebble-spring3/pom.xml deleted file mode 100644 index 9824dd6f4..000000000 --- a/pebble-spring/pebble-spring3/pom.xml +++ /dev/null @@ -1,82 +0,0 @@ - - - 4.0.0 - - io.pebbletemplates - pebble-spring - 3.0.11-SNAPSHOT - - - pebble-spring3 - - Pebble Integration with Spring 3 - Pebble Integration with Spring 3 - http://pebbletemplates.io - - - 3.0.1 - 3.2.13.RELEASE - - - - - - org.springframework - spring-framework-bom - ${spring-framework.version} - pom - import - - - - - - - io.pebbletemplates - pebble - - - javax.servlet - javax.servlet-api - ${servlet-api.version} - provided - - - org.springframework - spring-webmvc - provided - - - - - org.springframework - spring-test - test - - - org.mockito - mockito-core - test - - - junit - junit - test - - - - - - - maven-jar-plugin - - - - io.pebbletemplates.spring - - - - - - - diff --git a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/PebbleView.java b/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/PebbleView.java deleted file mode 100644 index f9eb6431a..000000000 --- a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/PebbleView.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2013 by Mitchell Bösecke - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -package com.mitchellbosecke.pebble.spring; - -import com.mitchellbosecke.pebble.PebbleEngine; -import com.mitchellbosecke.pebble.error.PebbleException; -import com.mitchellbosecke.pebble.spring.context.Beans; -import com.mitchellbosecke.pebble.template.PebbleTemplate; -import java.io.IOException; -import java.io.Writer; -import java.util.Locale; -import java.util.Map; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.web.servlet.support.RequestContextUtils; -import org.springframework.web.servlet.view.AbstractTemplateView; - -public class PebbleView extends AbstractTemplateView { - - public static final String REQUEST_VARIABLE_NAME = "request"; - public static final String RESPONSE_VARIABLE_NAME = "response"; - public static final String SESSION_VARIABLE_NAME = "session"; - - private static final String BEANS_VARIABLE_NAME = "beans"; - private static final int NANO_PER_SECOND = 1000000; - /** - *

- * TIMER logger. This logger will output the time required for executing each template processing - * operation. - *

- *

- * The value of this constant is - * com.mitchellbosecke.pebble.spring.PebbleView.timer. This allows - * you to set a specific configuration and/or appenders for timing info at your logging system - * configuration. - *

- */ - private static final Logger TIMER_LOGGER = LoggerFactory - .getLogger(PebbleView.class.getName() + ".timer"); - - private String characterEncoding = "UTF-8"; - private PebbleEngine pebbleEngine; - private String templateName; - - @Override - protected void renderMergedTemplateModel(Map model, HttpServletRequest request, - HttpServletResponse response) throws Exception { - long startNanoTime = System.nanoTime(); - - this.setCharacterEncoding(response); - this.addVariablesToModel(model, request, response); - this.evaluateTemplate(model, request, response); - this.logElapsedTime(startNanoTime, request); - } - - private void setCharacterEncoding(HttpServletResponse response) { - if (this.characterEncoding != null) { - response.setCharacterEncoding(this.characterEncoding); - } - } - - private void addVariablesToModel(Map model, HttpServletRequest request, - HttpServletResponse response) { - model.put(BEANS_VARIABLE_NAME, new Beans(this.getApplicationContext())); - model.put(REQUEST_VARIABLE_NAME, request); - model.put(RESPONSE_VARIABLE_NAME, response); - model.put(SESSION_VARIABLE_NAME, request.getSession(false)); - } - - private void evaluateTemplate(Map model, HttpServletRequest request, - HttpServletResponse response) throws IOException, PebbleException { - Locale locale = RequestContextUtils.getLocale(request); - - Writer writer = response.getWriter(); - try { - PebbleTemplate template = this.pebbleEngine.getTemplate(this.templateName); - template.evaluate(writer, model, locale); - } finally { - writer.flush(); - } - } - - private void logElapsedTime(long startNanoTime, HttpServletRequest request) { - if (TIMER_LOGGER.isDebugEnabled()) { - Locale locale = RequestContextUtils.getLocale(request); - long endNanoTime = System.nanoTime(); - - long elapsed = endNanoTime - startNanoTime; - long elapsedMs = elapsed / NANO_PER_SECOND; - TIMER_LOGGER - .debug("Pebble template \"{}\" with locale {} processed in {} nanoseconds (approx. {}ms)", - this.templateName, locale, elapsed, elapsedMs); - } - } - - public void setCharacterEncoding(String characterEncoding) { - this.characterEncoding = characterEncoding; - } - - public void setPebbleEngine(PebbleEngine pebbleEngine) { - this.pebbleEngine = pebbleEngine; - } - - public void setTemplateName(String name) { - this.templateName = name; - } -} \ No newline at end of file diff --git a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/PebbleViewResolver.java b/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/PebbleViewResolver.java deleted file mode 100644 index 96f3b7f12..000000000 --- a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/PebbleViewResolver.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2013 by Mitchell Bösecke - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -package com.mitchellbosecke.pebble.spring; - -import com.mitchellbosecke.pebble.PebbleEngine; -import com.mitchellbosecke.pebble.loader.Loader; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.annotation.Required; -import org.springframework.web.servlet.view.AbstractTemplateViewResolver; -import org.springframework.web.servlet.view.AbstractUrlBasedView; - -public class PebbleViewResolver extends AbstractTemplateViewResolver implements InitializingBean { - - private String characterEncoding = "UTF-8"; - private PebbleEngine pebbleEngine; - - public PebbleViewResolver() { - this.setViewClass(this.requiredViewClass()); - } - - @Override - public void afterPropertiesSet() { - Loader templateLoader = this.pebbleEngine.getLoader(); - templateLoader.setPrefix(this.getPrefix()); - templateLoader.setSuffix(this.getSuffix()); - } - - public void setCharacterEncoding(String characterEncoding) { - this.characterEncoding = characterEncoding; - } - - @Required - public void setPebbleEngine(PebbleEngine pebbleEngine) { - this.pebbleEngine = pebbleEngine; - } - - @Override - protected AbstractUrlBasedView buildView(String viewName) throws Exception { - PebbleView view = (PebbleView) super.buildView(viewName); - view.setTemplateName(viewName); - view.setPebbleEngine(this.pebbleEngine); - view.setCharacterEncoding(this.characterEncoding); - - return view; - } - - @Override - protected Class requiredViewClass() { - return PebbleView.class; - } -} diff --git a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/context/Beans.java b/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/context/Beans.java deleted file mode 100644 index 366645cf0..000000000 --- a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/context/Beans.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2013 by Mitchell Bösecke - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -package com.mitchellbosecke.pebble.spring.context; - -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Set; -import org.springframework.context.ApplicationContext; -import org.springframework.util.Assert; - -/** - *

- * Special object made available to templates in Spring MVC applications in order to access beans in - * the Application Context. - *

- * - * @author Eric Bussieres - */ -public class Beans implements Map { - - private final ApplicationContext ctx; - - public Beans(ApplicationContext ctx) { - Assert.notNull(ctx, "Application Context cannot be null"); - this.ctx = ctx; - } - - @Override - public void clear() { - throw new UnsupportedOperationException("Method \"clear\" not supported in Beans object"); - } - - @Override - public boolean containsKey(Object key) { - Assert.notNull(key, "Key cannot be null"); - return this.ctx.containsBean(key.toString()); - } - - @Override - public boolean containsValue(Object value) { - throw new UnsupportedOperationException( - "Method \"containsValue\" not supported in Beans object"); - } - - @Override - public Set> entrySet() { - throw new UnsupportedOperationException("Method \"entrySet\" not supported in Beans object"); - } - - @Override - public Object get(Object key) { - Assert.notNull(key, "Key cannot be null"); - return this.ctx.getBean(key.toString()); - } - - @Override - public boolean isEmpty() { - return this.size() <= 0; - } - - @Override - public Set keySet() { - return new LinkedHashSet<>(Arrays.asList(this.ctx.getBeanDefinitionNames())); - } - - @Override - public Object put(String key, Object value) { - throw new UnsupportedOperationException("Method \"put\" not supported in Beans object"); - } - - @Override - public void putAll(Map m) { - throw new UnsupportedOperationException("Method \"putAll\" not supported in Beans object"); - } - - @Override - public Object remove(Object key) { - throw new UnsupportedOperationException("Method \"remove\" not supported in Beans object"); - } - - @Override - public int size() { - return this.ctx.getBeanDefinitionCount(); - } - - @Override - public Collection values() { - throw new UnsupportedOperationException("Method \"values\" not supported in Beans object"); - } - -} diff --git a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/SpringExtension.java b/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/SpringExtension.java deleted file mode 100644 index 14f0e09e9..000000000 --- a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/SpringExtension.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2013 by Mitchell Bösecke - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -package com.mitchellbosecke.pebble.spring.extension; - -import com.mitchellbosecke.pebble.extension.AbstractExtension; -import com.mitchellbosecke.pebble.extension.Function; -import com.mitchellbosecke.pebble.spring.extension.function.HrefFunction; -import com.mitchellbosecke.pebble.spring.extension.function.MessageSourceFunction; -import com.mitchellbosecke.pebble.spring.extension.function.bindingresult.GetAllErrorsFunction; -import com.mitchellbosecke.pebble.spring.extension.function.bindingresult.GetFieldErrorsFunction; -import com.mitchellbosecke.pebble.spring.extension.function.bindingresult.GetGlobalErrorsFunction; -import com.mitchellbosecke.pebble.spring.extension.function.bindingresult.HasErrorsFunction; -import com.mitchellbosecke.pebble.spring.extension.function.bindingresult.HasFieldErrorsFunction; -import com.mitchellbosecke.pebble.spring.extension.function.bindingresult.HasGlobalErrorsFunction; -import java.util.HashMap; -import java.util.Map; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.MessageSource; - -/** - *

- * Extension for PebbleEngine to add spring functionality - *

- * - * @author Eric Bussieres - */ -public class SpringExtension extends AbstractExtension { - - @Autowired - private MessageSource messageSource; - - @Override - public Map getFunctions() { - Map functions = new HashMap<>(); - functions - .put(MessageSourceFunction.FUNCTION_NAME, new MessageSourceFunction(this.messageSource)); - functions.put(HasErrorsFunction.FUNCTION_NAME, new HasErrorsFunction()); - functions.put(HasGlobalErrorsFunction.FUNCTION_NAME, new HasGlobalErrorsFunction()); - functions.put(HasFieldErrorsFunction.FUNCTION_NAME, new HasFieldErrorsFunction()); - functions.put(GetAllErrorsFunction.FUNCTION_NAME, new GetAllErrorsFunction(this.messageSource)); - functions.put(GetGlobalErrorsFunction.FUNCTION_NAME, - new GetGlobalErrorsFunction(this.messageSource)); - functions - .put(GetFieldErrorsFunction.FUNCTION_NAME, new GetFieldErrorsFunction(this.messageSource)); - functions.put(HrefFunction.FUNCTION_NAME, new HrefFunction()); - return functions; - } -} diff --git a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/HrefFunction.java b/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/HrefFunction.java deleted file mode 100644 index 7e6393173..000000000 --- a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/HrefFunction.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.mitchellbosecke.pebble.spring.extension.function; - -import com.mitchellbosecke.pebble.extension.Function; -import com.mitchellbosecke.pebble.spring.util.ViewUtils; -import com.mitchellbosecke.pebble.template.EvaluationContext; -import com.mitchellbosecke.pebble.template.PebbleTemplate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import org.springframework.util.StringUtils; - -/** - * Pebble function which adds the context path to the given url - * - * @author Eric Bussieres - */ -public class HrefFunction implements Function { - - public static final String FUNCTION_NAME = "href"; - - protected static final String PARAM_URL = "url"; - - protected List argumentNames; - private String contextPath; - - /** - * Constructor - */ - public HrefFunction() { - this.argumentNames = new ArrayList<>(); - this.argumentNames.add(PARAM_URL); - } - - /** - * {@inheritDoc} - * - * @see com.mitchellbosecke.pebble.extension.Function#execute(Map, PebbleTemplate, - * EvaluationContext, int) - */ - @Override - public Object execute(Map args, PebbleTemplate self, EvaluationContext context, - int lineNumber) { - StringBuffer result = new StringBuffer(); - - result.append(this.getContextPath()); - this.addUrlParameter(args, result); - - return result.toString(); - } - - private void addUrlParameter(Map args, StringBuffer result) { - String url = (String) args.get(PARAM_URL); - if (StringUtils.hasText(url)) { - result.append(url); - } - } - - private String getContextPath() { - if (this.contextPath == null) { - this.contextPath = ViewUtils.getRequest().getContextPath(); - } - return this.contextPath; - } - - /** - * {@inheritDoc} - * - * @see com.mitchellbosecke.pebble.extension.NamedArguments#getArgumentNames() - */ - @Override - public List getArgumentNames() { - return this.argumentNames; - } -} diff --git a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/MessageSourceFunction.java b/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/MessageSourceFunction.java deleted file mode 100644 index e24b3b51d..000000000 --- a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/MessageSourceFunction.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2013 by Mitchell Bösecke - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -package com.mitchellbosecke.pebble.spring.extension.function; - -import com.mitchellbosecke.pebble.extension.Function; -import com.mitchellbosecke.pebble.template.EvaluationContext; -import com.mitchellbosecke.pebble.template.PebbleTemplate; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import org.springframework.context.MessageSource; - -/** - *

- * Function available to templates in Spring MVC applications in order to resolve message in the - * application context - *

- * - * @author Eric Bussieres - */ -public class MessageSourceFunction implements Function { - - public static final String FUNCTION_NAME = "message"; - - private final MessageSource messageSource; - - public MessageSourceFunction(MessageSource messageSource) { - this.messageSource = messageSource; - } - - @Override - public Object execute(Map args, PebbleTemplate self, EvaluationContext context, - int lineNumber) { - String key = this.extractKey(args); - List arguments = this.extractArguments(args); - Locale locale = context.getLocale(); - - return this.messageSource.getMessage(key, arguments.toArray(), "???" + key + "???", locale); - } - - private List extractArguments(Map args) { - int i = 1; - List arguments = new ArrayList<>(); - while (args.containsKey(String.valueOf(i))) { - Object param = args.get(String.valueOf(i)); - arguments.add(param); - i++; - } - return arguments; - } - - private String extractKey(Map args) { - return (String) args.get("0"); - } - - @Override - public List getArgumentNames() { - return null; - } -} diff --git a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/BaseBindingResultFunction.java b/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/BaseBindingResultFunction.java deleted file mode 100644 index 4a42f71d0..000000000 --- a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/BaseBindingResultFunction.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2013 by Mitchell Bösecke - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -package com.mitchellbosecke.pebble.spring.extension.function.bindingresult; - -import com.mitchellbosecke.pebble.extension.Function; -import com.mitchellbosecke.pebble.template.EvaluationContext; -import com.mitchellbosecke.pebble.template.GlobalContext; - -import org.springframework.validation.BindingResult; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * Base class of the function interacting with the BindingResult - * - * @author Eric Bussieres - */ -public abstract class BaseBindingResultFunction implements Function { - - protected static final String PARAM_FIELD_NAME = "fieldName"; - protected static final String PARAM_FORM_NAME = "formName"; - - private final List argumentNames = new ArrayList<>(); - - protected BaseBindingResultFunction(String... argumentsName) { - Collections.addAll(this.argumentNames, argumentsName); - } - - @Override - public List getArgumentNames() { - return this.argumentNames; - } - - protected BindingResult getBindingResult(String formName, EvaluationContext context) { - String attribute = BindingResult.MODEL_KEY_PREFIX + formName; - BindingResult bindingResult = (BindingResult) context.getVariable(attribute); - if (bindingResult == null) { - GlobalContext globalContext = (GlobalContext) context.getVariable("_context"); - if (globalContext != null) { - return (BindingResult) globalContext.get(attribute); - } - } - return bindingResult; - } -} diff --git a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/GetAllErrorsFunction.java b/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/GetAllErrorsFunction.java deleted file mode 100644 index cb7d7881b..000000000 --- a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/GetAllErrorsFunction.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2013 by Mitchell Bösecke - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -package com.mitchellbosecke.pebble.spring.extension.function.bindingresult; - -import com.mitchellbosecke.pebble.template.EvaluationContext; -import com.mitchellbosecke.pebble.template.PebbleTemplate; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import org.springframework.context.MessageSource; -import org.springframework.validation.BindingResult; -import org.springframework.validation.ObjectError; - -/** - *

- * Function available to templates in Spring MVC applications in order to access the BindingResult - * of a form - *

- * - * @author Eric Bussieres - */ -public class GetAllErrorsFunction extends BaseBindingResultFunction { - - public static final String FUNCTION_NAME = "getAllErrors"; - - private final MessageSource messageSource; - - public GetAllErrorsFunction(MessageSource messageSource) { - super(PARAM_FORM_NAME); - this.messageSource = messageSource; - } - - @Override - public Object execute(Map args, PebbleTemplate self, EvaluationContext context, - int lineNumber) { - String formName = (String) args.get(PARAM_FORM_NAME); - - Locale locale = context.getLocale(); - BindingResult bindingResult = this.getBindingResult(formName, context); - - return this.constructErrorMessage(locale, bindingResult); - } - - private List constructErrorMessage(Locale locale, BindingResult bindingResult) { - List errorMessages = new ArrayList<>(); - if (bindingResult != null) { - for (ObjectError error : bindingResult.getAllErrors()) { - String msg = this.messageSource.getMessage(error, locale); - errorMessages.add(msg); - } - } - return errorMessages; - } -} diff --git a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/GetFieldErrorsFunction.java b/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/GetFieldErrorsFunction.java deleted file mode 100644 index e29e0291e..000000000 --- a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/GetFieldErrorsFunction.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2013 by Mitchell Bösecke - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -package com.mitchellbosecke.pebble.spring.extension.function.bindingresult; - -import com.mitchellbosecke.pebble.template.EvaluationContext; -import com.mitchellbosecke.pebble.template.PebbleTemplate; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import org.springframework.context.MessageSource; -import org.springframework.validation.BindingResult; -import org.springframework.validation.FieldError; - -/** - *

- * Function available to templates in Spring MVC applications in order to access the BindingResult - * of a form - *

- * - * @author Eric Bussieres - */ -public class GetFieldErrorsFunction extends BaseBindingResultFunction { - - public static final String FUNCTION_NAME = "getFieldErrors"; - - private final MessageSource messageSource; - - public GetFieldErrorsFunction(MessageSource messageSource) { - super(PARAM_FORM_NAME, PARAM_FIELD_NAME); - this.messageSource = messageSource; - } - - @Override - public Object execute(Map args, PebbleTemplate self, EvaluationContext context, - int lineNumber) { - String formName = (String) args.get(PARAM_FORM_NAME); - String field = (String) args.get(PARAM_FIELD_NAME); - - if (field == null) { - throw new IllegalArgumentException("Field parameter is required in GetFieldErrorsFunction"); - } - - Locale locale = context.getLocale(); - BindingResult bindingResult = this.getBindingResult(formName, context); - - return this.constructErrorMessages(field, locale, bindingResult); - } - - private List constructErrorMessages(String field, Locale locale, - BindingResult bindingResult) { - List errorMessages = new ArrayList<>(); - if (bindingResult != null) { - for (FieldError error : bindingResult.getFieldErrors(field)) { - String msg = this.messageSource.getMessage(error, locale); - errorMessages.add(msg); - } - } - return errorMessages; - } -} diff --git a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/GetGlobalErrorsFunction.java b/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/GetGlobalErrorsFunction.java deleted file mode 100644 index 2baee6a73..000000000 --- a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/GetGlobalErrorsFunction.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2013 by Mitchell Bösecke - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -package com.mitchellbosecke.pebble.spring.extension.function.bindingresult; - -import com.mitchellbosecke.pebble.template.EvaluationContext; -import com.mitchellbosecke.pebble.template.PebbleTemplate; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import org.springframework.context.MessageSource; -import org.springframework.validation.BindingResult; -import org.springframework.validation.ObjectError; - -/** - *

- * Function available to templates in Spring MVC applications in order to access the BindingResult - * of a form - *

- * - * @author Eric Bussieres - */ -public class GetGlobalErrorsFunction extends BaseBindingResultFunction { - - public static final String FUNCTION_NAME = "getGlobalErrors"; - - private final MessageSource messageSource; - - public GetGlobalErrorsFunction(MessageSource messageSource) { - super(PARAM_FORM_NAME); - this.messageSource = messageSource; - } - - @Override - public Object execute(Map args, PebbleTemplate self, EvaluationContext context, - int lineNumber) { - String formName = (String) args.get(PARAM_FORM_NAME); - - Locale locale = context.getLocale(); - BindingResult bindingResult = this.getBindingResult(formName, context); - - return this.constructErrorMessages(locale, bindingResult); - } - - private List constructErrorMessages(Locale locale, BindingResult bindingResult) { - List errorMessages = new ArrayList<>(); - if (bindingResult != null) { - for (ObjectError error : bindingResult.getGlobalErrors()) { - String msg = this.messageSource.getMessage(error, locale); - errorMessages.add(msg); - } - } - return errorMessages; - } -} diff --git a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/HasErrorsFunction.java b/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/HasErrorsFunction.java deleted file mode 100644 index 9ed0016e3..000000000 --- a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/HasErrorsFunction.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2013 by Mitchell Bösecke - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -package com.mitchellbosecke.pebble.spring.extension.function.bindingresult; - -import com.mitchellbosecke.pebble.template.EvaluationContext; -import com.mitchellbosecke.pebble.template.PebbleTemplate; -import java.util.Map; -import org.springframework.validation.BindingResult; - -/** - *

- * Function available to templates in Spring MVC applications in order to access the BindingResult - * of a form - *

- * - * @author Eric Bussieres - */ -public class HasErrorsFunction extends BaseBindingResultFunction { - - public static final String FUNCTION_NAME = "hasErrors"; - - public HasErrorsFunction() { - super(PARAM_FORM_NAME); - } - - @Override - public Object execute(Map args, PebbleTemplate self, EvaluationContext context, - int lineNumber) { - String formName = (String) args.get(PARAM_FORM_NAME); - - BindingResult bindingResult = this.getBindingResult(formName, context); - return bindingResult != null && bindingResult.hasErrors(); - } -} diff --git a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/HasFieldErrorsFunction.java b/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/HasFieldErrorsFunction.java deleted file mode 100644 index 894960ea8..000000000 --- a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/HasFieldErrorsFunction.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2013 by Mitchell Bösecke - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -package com.mitchellbosecke.pebble.spring.extension.function.bindingresult; - -import com.mitchellbosecke.pebble.template.EvaluationContext; -import com.mitchellbosecke.pebble.template.PebbleTemplate; -import java.util.Map; -import org.springframework.validation.BindingResult; - -/** - *

- * Function available to templates in Spring MVC applications in order to access the BindingResult - * of a form - *

- * - * @author Eric Bussieres - */ -public class HasFieldErrorsFunction extends BaseBindingResultFunction { - - public static final String FUNCTION_NAME = "hasFieldErrors"; - - public HasFieldErrorsFunction() { - super(PARAM_FORM_NAME, PARAM_FIELD_NAME); - } - - @Override - public Object execute(Map args, PebbleTemplate self, EvaluationContext context, - int lineNumber) { - String formName = (String) args.get(PARAM_FORM_NAME); - String fieldName = (String) args.get(PARAM_FIELD_NAME); - - BindingResult bindingResult = this.getBindingResult(formName, context); - - if (bindingResult != null) { - if (fieldName == null) { - return bindingResult.hasFieldErrors(); - } else { - return bindingResult.hasFieldErrors(fieldName); - } - } else { - return false; - } - } -} diff --git a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/HasGlobalErrorsFunction.java b/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/HasGlobalErrorsFunction.java deleted file mode 100644 index bc9253aa3..000000000 --- a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/extension/function/bindingresult/HasGlobalErrorsFunction.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2013 by Mitchell Bösecke - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -package com.mitchellbosecke.pebble.spring.extension.function.bindingresult; - -import com.mitchellbosecke.pebble.template.EvaluationContext; -import com.mitchellbosecke.pebble.template.PebbleTemplate; -import java.util.Map; -import org.springframework.validation.BindingResult; - -/** - *

- * Function available to templates in Spring MVC applications in order to access the BindingResult - * of a form - *

- * - * @author Eric Bussieres - */ -public class HasGlobalErrorsFunction extends BaseBindingResultFunction { - - public static final String FUNCTION_NAME = "hasGlobalErrors"; - - public HasGlobalErrorsFunction() { - super(PARAM_FORM_NAME); - } - - @Override - public Object execute(Map args, PebbleTemplate self, EvaluationContext context, - int lineNumber) { - String formName = (String) args.get(PARAM_FORM_NAME); - - BindingResult bindingResult = this.getBindingResult(formName, context); - return bindingResult != null && bindingResult.hasGlobalErrors(); - } -} diff --git a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/util/ViewUtils.java b/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/util/ViewUtils.java deleted file mode 100644 index 1a465612b..000000000 --- a/pebble-spring/pebble-spring3/src/main/java/com/mitchellbosecke/pebble/spring/util/ViewUtils.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * - */ -package com.mitchellbosecke.pebble.spring.util; - -import javax.servlet.http.HttpServletRequest; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; - -public class ViewUtils { - - private ViewUtils() { - } - - public static HttpServletRequest getRequest() { - ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder - .currentRequestAttributes(); - return attr.getRequest(); - } -} diff --git a/pebble-spring/pebble-spring3/src/test/java/com/mitchellbosecke/pebble/spring/PebbleViewResolverTest.java b/pebble-spring/pebble-spring3/src/test/java/com/mitchellbosecke/pebble/spring/PebbleViewResolverTest.java deleted file mode 100644 index 563f1e70d..000000000 --- a/pebble-spring/pebble-spring3/src/test/java/com/mitchellbosecke/pebble/spring/PebbleViewResolverTest.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright (c) 2013 by Mitchell Bösecke - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -package com.mitchellbosecke.pebble.spring; - -import com.mitchellbosecke.pebble.spring.config.MVCConfig; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.mock.web.MockHttpServletRequest; -import org.springframework.mock.web.MockHttpServletResponse; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.validation.BindingResult; -import org.springframework.validation.FieldError; -import org.springframework.validation.ObjectError; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; -import org.springframework.web.servlet.ViewResolver; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -/** - * Unit test for the PebbleViewResolver - * - * @author Eric Bussieres - */ -@RunWith(SpringJUnit4ClassRunner.class) -@WebAppConfiguration -@ContextConfiguration(classes = {MVCConfig.class}) -public class PebbleViewResolverTest { - - private static final String CONTEXT_PATH = "/testContextPath"; - private static final Locale DEFAULT_LOCALE = Locale.CANADA; - private static final String EXPECTED_RESPONSE_PATH = "/com/mitchellbosecke/pebble/spring/expectedResponse"; - private static final String FORM_NAME = "formName"; - - private BindingResult mockBindingResult = mock(BindingResult.class); - private MockHttpServletRequest mockRequest = new MockHttpServletRequest(); - private MockHttpServletResponse mockResponse = new MockHttpServletResponse(); - - @Autowired - private ViewResolver viewResolver; - - @Before - public void initRequest() { - this.mockRequest.setContextPath(CONTEXT_PATH); - this.mockRequest.getSession().setMaxInactiveInterval(600); - - RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(this.mockRequest)); - } - - @Before - public void initBindingResult() { - this.initBindingResultAllErrors(); - this.initBindingResultGlobalErrors(); - this.initBindingResultFieldErrors(); - } - - private void initBindingResultAllErrors() { - when(this.mockBindingResult.hasErrors()).thenReturn(true); - - List allErrors = new ArrayList<>(); - allErrors.add( - new ObjectError(FORM_NAME, new String[]{"error.test"}, new String[]{}, "???error.test???")); - when(this.mockBindingResult.getAllErrors()).thenReturn(allErrors); - } - - private void initBindingResultGlobalErrors() { - when(this.mockBindingResult.hasGlobalErrors()).thenReturn(true); - - List globalErrors = new ArrayList<>(); - globalErrors.add(new ObjectError(FORM_NAME, new String[]{"error.global.test.params"}, - new String[]{"param1", "param2"}, "???error.global.test.params???")); - when(this.mockBindingResult.getGlobalErrors()).thenReturn(globalErrors); - } - - private void initBindingResultFieldErrors() { - when(this.mockBindingResult.hasFieldErrors("testField")).thenReturn(true); - - List fieldErrors = new ArrayList<>(); - fieldErrors.add( - new FieldError(FORM_NAME, "testField", null, false, new String[]{"error.field.test.params"}, - new String[]{"param1", "param2"}, "???error.field.test.params???")); - when(this.mockBindingResult.getFieldErrors("testField")).thenReturn(fieldErrors); - } - - @Test - public void whenRenderingAPage_givenPageWithBeanVariable_thenRenderingIsOK() throws Exception { - String result = this.render("beansTest", new HashMap()); - - this.assertOutput(result, EXPECTED_RESPONSE_PATH + "/beansTest.html"); - } - - @Test - public void whenRenderingAPage_givenPageWithBindingResult_thenRenderingIsOK() throws Exception { - Map model = this.givenBindingResult(); - - String result = this.render("bindingResultTest", model); - - this.assertOutput(result, EXPECTED_RESPONSE_PATH + "/bindingResultTest.html"); - } - - private Map givenBindingResult() { - Map model = new HashMap<>(); - model.put(BindingResult.MODEL_KEY_PREFIX + FORM_NAME, this.mockBindingResult); - return model; - } - - @Test - public void whenRenderingAPage_givenPageWithBindingResultAndMacro_thenRenderingIsOK() throws Exception { - Map model = this.givenBindingResult(); - - String result = this.render("bindingResultWithMacroTest", model); - - this.assertOutput(result, EXPECTED_RESPONSE_PATH + "/bindingResultWithMacroTest.html"); - } - - @Test - public void whenRenderingAPage_givenPageWithHrefFunction_thenRenderingIsOK() throws Exception { - String result = this.render("hrefFunctionTest", new HashMap()); - - this.assertOutput(result, EXPECTED_RESPONSE_PATH + "/hrefFunctionTest.html"); - } - - @Test - public void whenRenderingAPageInEnglish_givenPageWithResourceBundleMessage_thenRenderingIsOK() - throws Exception { - String result = this.render("messageEnTest", new HashMap()); - - this.assertOutput(result, EXPECTED_RESPONSE_PATH + "/messageEnTest.html"); - } - - @Test - public void whenRenderingAPageInFrench_givenPageWithResourceBundleMessage_thenRenderingIsOK() - throws Exception { - this.mockRequest.addPreferredLocale(Locale.CANADA_FRENCH); - - String result = this.render("messageFrTest", new HashMap()); - - this.assertOutput(result, EXPECTED_RESPONSE_PATH + "/messageFrTest.html"); - } - - @Test - public void whenRenderingAPage_givenPageWithHttpRequestVariable_thenRenderingIsOK() - throws Exception { - String result = this.render("requestTest", new HashMap()); - - this.assertOutput(result, EXPECTED_RESPONSE_PATH + "/requestTest.html"); - } - - @Test - public void whenRenderingAPage_givenPageWithHttpResponseVariable_thenRenderingIsOK() - throws Exception { - String result = this.render("responseTest", new HashMap()); - - this.assertOutput(result, EXPECTED_RESPONSE_PATH + "/responseTest.html"); - } - - @Test - public void whenRenderingAPage_givenPageWithHttpSessionVariable_thenRenderingIsOK() - throws Exception { - String result = this.render("sessionTest", new HashMap()); - - this.assertOutput(result, EXPECTED_RESPONSE_PATH + "/sessionTest.html"); - } - - private void assertOutput(String output, String expectedOutput) throws IOException { - assertEquals(this.readExpectedOutputResource(expectedOutput), output.replaceAll("\\s", "")); - } - - private String readExpectedOutputResource(String expectedOutput) throws IOException { - BufferedReader reader = new BufferedReader( - new InputStreamReader(this.getClass().getResourceAsStream(expectedOutput))); - - StringBuilder builder = new StringBuilder(); - for (String currentLine = reader.readLine(); currentLine != null; - currentLine = reader.readLine()) { - builder.append(currentLine); - } - - return this.removeAllWhitespaces(builder.toString()); - } - - private String removeAllWhitespaces(String source) { - return source.replaceAll("\\s", ""); - } - - private String render(String location, Map model) throws Exception { - this.viewResolver.resolveViewName(location, DEFAULT_LOCALE) - .render(model, this.mockRequest, this.mockResponse); - return this.mockResponse.getContentAsString(); - } -} diff --git a/pebble-spring/pebble-spring3/src/test/java/com/mitchellbosecke/pebble/spring/bean/SomeBean.java b/pebble-spring/pebble-spring3/src/test/java/com/mitchellbosecke/pebble/spring/bean/SomeBean.java deleted file mode 100644 index 21bce7b34..000000000 --- a/pebble-spring/pebble-spring3/src/test/java/com/mitchellbosecke/pebble/spring/bean/SomeBean.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2013 by Mitchell Bösecke - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -package com.mitchellbosecke.pebble.spring.bean; - -/** - * Spring bean for unit test - * - * @author Eric Bussieres - */ -public class SomeBean { - - public String foo() { - return "foo"; - } -} diff --git a/pebble-spring/pebble-spring3/src/test/java/com/mitchellbosecke/pebble/spring/config/MVCConfig.java b/pebble-spring/pebble-spring3/src/test/java/com/mitchellbosecke/pebble/spring/config/MVCConfig.java deleted file mode 100644 index e6d12f311..000000000 --- a/pebble-spring/pebble-spring3/src/test/java/com/mitchellbosecke/pebble/spring/config/MVCConfig.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2013 by Mitchell Bösecke - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -package com.mitchellbosecke.pebble.spring.config; - -import com.mitchellbosecke.pebble.PebbleEngine; -import com.mitchellbosecke.pebble.loader.ClasspathLoader; -import com.mitchellbosecke.pebble.loader.Loader; -import com.mitchellbosecke.pebble.spring.PebbleViewResolver; -import com.mitchellbosecke.pebble.spring.bean.SomeBean; -import com.mitchellbosecke.pebble.spring.extension.SpringExtension; -import org.springframework.context.MessageSource; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.support.ResourceBundleMessageSource; -import org.springframework.web.servlet.ViewResolver; - -/** - * Spring configuration for unit test - * - * @author Eric Bussieres - */ -@Configuration -public class MVCConfig { - - @Bean - public SomeBean foo() { - return new SomeBean(); - } - - @Bean - public MessageSource messageSource() { - ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); - messageSource.setBasename("com.mitchellbosecke.pebble.spring.messages"); - - return messageSource; - } - - @Bean - public PebbleEngine pebbleEngine(SpringExtension springExtension) { - return new PebbleEngine.Builder() - .loader(this.templateLoader()) - .strictVariables(false) - .extension(springExtension) - .build(); - } - - @Bean - public SpringExtension springExtension() { - return new SpringExtension(); - } - - @Bean - public Loader templateLoader() { - return new ClasspathLoader(); - } - - @Bean - public ViewResolver viewResolver(PebbleEngine pebbleEngine) { - PebbleViewResolver viewResolver = new PebbleViewResolver(); - viewResolver.setPrefix("com/mitchellbosecke/pebble/spring/template/"); - viewResolver.setSuffix(".html"); - viewResolver.setPebbleEngine(pebbleEngine); - viewResolver.setContentType("text/html"); - return viewResolver; - } -} diff --git a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/beansTest.html b/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/beansTest.html deleted file mode 100644 index d4e7ab655..000000000 --- a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/beansTest.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - foo - - - - - \ No newline at end of file diff --git a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/bindingResultTest.html b/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/bindingResultTest.html deleted file mode 100644 index d48671b3e..000000000 --- a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/bindingResultTest.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - - test - - - -true -true -true - -false -false -false - -Some error -Some global error with params param1 and param2 -Some field error with params param1 and param2 - - \ No newline at end of file diff --git a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/bindingResultWithMacroTest.html b/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/bindingResultWithMacroTest.html deleted file mode 100644 index d48671b3e..000000000 --- a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/bindingResultWithMacroTest.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - - test - - - -true -true -true - -false -false -false - -Some error -Some global error with params param1 and param2 -Some field error with params param1 and param2 - - \ No newline at end of file diff --git a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/hrefFunctionTest.html b/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/hrefFunctionTest.html deleted file mode 100644 index 02d2040e0..000000000 --- a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/hrefFunctionTest.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - - test - - - -HrefFunction string interpolation = /testContextPath/foo -HrefFunction static = /testContextPath/foobar -HrefFunction expression = /testContextPath/foo - - \ No newline at end of file diff --git a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/messageEnTest.html b/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/messageEnTest.html deleted file mode 100644 index 8e8c535a8..000000000 --- a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/messageEnTest.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - test - - - -Label = Some label -Label with params = Some label with params params1 and params2 - - \ No newline at end of file diff --git a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/messageFrTest.html b/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/messageFrTest.html deleted file mode 100644 index c94d10eea..000000000 --- a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/messageFrTest.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - test - - - -Label = Un libellé -Label with params = Un libellé avec les paramètres params1 et params2 - - \ No newline at end of file diff --git a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/requestTest.html b/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/requestTest.html deleted file mode 100644 index e5db6c754..000000000 --- a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/requestTest.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - test - - - -Context path = /testContextPath - - \ No newline at end of file diff --git a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/responseTest.html b/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/responseTest.html deleted file mode 100644 index b50bcdb8d..000000000 --- a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/responseTest.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - test - - - -Response contentType = text/html -Response character encoding = UTF-8 - - \ No newline at end of file diff --git a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/sessionTest.html b/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/sessionTest.html deleted file mode 100644 index 71313d1a1..000000000 --- a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/expectedResponse/sessionTest.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - test - - - -Session maxInactiveInterval = 600 - - \ No newline at end of file diff --git a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/messages_en.properties b/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/messages_en.properties deleted file mode 100644 index 83bd8f773..000000000 --- a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/messages_en.properties +++ /dev/null @@ -1,5 +0,0 @@ -label.test=Some label -label.test.params=Some label with params {0} and {1} -error.test=Some error -error.global.test.params=Some global error with params {0} and {1} -error.field.test.params=Some field error with params {0} and {1} \ No newline at end of file diff --git a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/messages_fr.properties b/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/messages_fr.properties deleted file mode 100644 index 24c990fd7..000000000 --- a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/messages_fr.properties +++ /dev/null @@ -1,5 +0,0 @@ -label.test=Un libellé -label.test.params=Un libellé avec les paramètres {0} et {1} -error.test=Une erreur -error.global.test.params=Une erreur globale avec les paramètres {0} et {1} -error.field.test.params=Une erreur sur un champ avec les paramètres {0} et {1} \ No newline at end of file diff --git a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/beansTest.html b/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/beansTest.html deleted file mode 100644 index acc8a913b..000000000 --- a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/beansTest.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - {{ beans.foo.foo() }} - - - - - \ No newline at end of file diff --git a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/bindingResultTest.html b/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/bindingResultTest.html deleted file mode 100644 index 3df8bdf4c..000000000 --- a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/bindingResultTest.html +++ /dev/null @@ -1,26 +0,0 @@ - - - - - test - - - -{{ hasErrors('formName') }} -{{ hasGlobalErrors('formName') }} -{{ hasFieldErrors('formName', 'testField') }} - -{{ hasErrors('') }} -{{ hasGlobalErrors('') }} -{{ hasFieldErrors('formName', '') }} - -{% for err in getAllErrors('formName') %}{{ err }}{% endfor %} -{% for err in getGlobalErrors('formName') %}{{ err }}{% endfor %} -{% for err in getFieldErrors('formName', 'testField') %}{{ err }}{% endfor %} - -{% for err in getAllErrors('') %}{{ err }}{% endfor %} -{% for err in getGlobalErrors('') %}{{ err }}{% endfor %} -{% for err in getFieldErrors('', 'testField') %}{{ err }}{% endfor %} -{% for err in getFieldErrors('formName', '') %}{{ err }}{% endfor %} - - \ No newline at end of file diff --git a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/bindingResultWithMacroTest.html b/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/bindingResultWithMacroTest.html deleted file mode 100644 index d60aa6c1d..000000000 --- a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/bindingResultWithMacroTest.html +++ /dev/null @@ -1,29 +0,0 @@ - - - - - test - - - -{{ test(_context) }} -{% macro test(_context) %} - {{ hasErrors('formName') }} - {{ hasGlobalErrors('formName') }} - {{ hasFieldErrors('formName', 'testField') }} - - {{ hasErrors('') }} - {{ hasGlobalErrors('') }} - {{ hasFieldErrors('formName', '') }} - - {% for err in getAllErrors('formName') %}{{ err }}{% endfor %} - {% for err in getGlobalErrors('formName') %}{{ err }}{% endfor %} - {% for err in getFieldErrors('formName', 'testField') %}{{ err }}{% endfor %} - - {% for err in getAllErrors('') %}{{ err }}{% endfor %} - {% for err in getGlobalErrors('') %}{{ err }}{% endfor %} - {% for err in getFieldErrors('', 'testField') %}{{ err }}{% endfor %} - {% for err in getFieldErrors('formName', '') %}{{ err }}{% endfor %} -{% endmacro %} - - \ No newline at end of file diff --git a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/hrefFunctionTest.html b/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/hrefFunctionTest.html deleted file mode 100644 index 9c6781027..000000000 --- a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/hrefFunctionTest.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - - test - - - -HrefFunction string interpolation = {{ href("/#{beans.foo.foo}") }} -HrefFunction static = {{ href('/foobar') }} -HrefFunction expression = {{ href('/' + beans.foo.foo) }} - - \ No newline at end of file diff --git a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/messageEnTest.html b/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/messageEnTest.html deleted file mode 100644 index db8f0ff96..000000000 --- a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/messageEnTest.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - test - - - -Label = {{ message('label.test') }} -Label with params = {{ message('label.test.params', 'params1', 'params2') }} - - \ No newline at end of file diff --git a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/messageFrTest.html b/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/messageFrTest.html deleted file mode 100644 index db8f0ff96..000000000 --- a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/messageFrTest.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - test - - - -Label = {{ message('label.test') }} -Label with params = {{ message('label.test.params', 'params1', 'params2') }} - - \ No newline at end of file diff --git a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/requestTest.html b/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/requestTest.html deleted file mode 100644 index 36bae1c17..000000000 --- a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/requestTest.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - test - - - -Context path = {{ request.contextPath }} - - \ No newline at end of file diff --git a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/responseTest.html b/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/responseTest.html deleted file mode 100644 index d468d1ee9..000000000 --- a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/responseTest.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - test - - - -Response contentType = {{ response.contentType }} -Response character encoding = {{ response.characterEncoding }} - - \ No newline at end of file diff --git a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/sessionTest.html b/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/sessionTest.html deleted file mode 100644 index 856fd1113..000000000 --- a/pebble-spring/pebble-spring3/src/test/resources/com/mitchellbosecke/pebble/spring/template/sessionTest.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - test - - - -Session maxInactiveInterval = {{ session.maxInactiveInterval }} - - \ No newline at end of file diff --git a/pebble-spring/pebble-spring4/pom.xml b/pebble-spring/pebble-spring4/pom.xml index 3cb3aaf1f..ec8bd3ada 100644 --- a/pebble-spring/pebble-spring4/pom.xml +++ b/pebble-spring/pebble-spring4/pom.xml @@ -3,7 +3,7 @@ io.pebbletemplates pebble-spring - 3.0.11-SNAPSHOT + 3.1.0-SNAPSHOT pebble-spring4 @@ -14,7 +14,7 @@ 3.0.1 - 4.1.0.RELEASE + 4.3.25.RELEASE diff --git a/pebble-spring/pebble-spring5/pom.xml b/pebble-spring/pebble-spring5/pom.xml index 21ae1d2ea..1e62e028a 100644 --- a/pebble-spring/pebble-spring5/pom.xml +++ b/pebble-spring/pebble-spring5/pom.xml @@ -4,7 +4,7 @@ pebble-spring io.pebbletemplates - 3.0.11-SNAPSHOT + 3.1.0-SNAPSHOT pebble-spring5 @@ -15,7 +15,7 @@ 3.1.0 - 5.0.5.RELEASE + 5.1.9.RELEASE diff --git a/pebble-spring/pom.xml b/pebble-spring/pom.xml index ab7560447..2ea6acacd 100644 --- a/pebble-spring/pom.xml +++ b/pebble-spring/pom.xml @@ -4,18 +4,17 @@ io.pebbletemplates pebble-project - 3.0.11-SNAPSHOT + 3.1.0-SNAPSHOT pebble-spring pom - pebble-spring3 pebble-spring4 pebble-spring5 + pebble-legacy-spring-boot-starter pebble-spring-boot-starter - pebble-spring-boot-2-starter Pebble Spring Project diff --git a/pebble/pom.xml b/pebble/pom.xml index 9d9385578..cad09c0cf 100644 --- a/pebble/pom.xml +++ b/pebble/pom.xml @@ -4,7 +4,7 @@ io.pebbletemplates pebble-project - 3.0.11-SNAPSHOT + 3.1.0-SNAPSHOT pebble diff --git a/pom.xml b/pom.xml index fac94a8e6..0f8f24bd3 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 io.pebbletemplates pebble-project - 3.0.11-SNAPSHOT + 3.1.0-SNAPSHOT pom