Skip to content

Commit be97e79

Browse files
committed
Rationalize Groovy Template configuration properties
Previously, spring.groovy.template.configuration properties were bound directly to GroovyMarkupConfigurer. This meant that the properties had no description or default values in the metadata. It also resulted in some duplicate where a specific spring.groovy.template property was also provided. This commit deprecates the spring.groovy.template.configuration.* properties in favour of specific spring.groovy.template.* properties that are mapped to the GroovyMarkupConfigurer. Closes gh-44722
1 parent abc4389 commit be97e79

File tree

5 files changed

+328
-6
lines changed

5 files changed

+328
-6
lines changed

buildSrc/src/main/java/org/springframework/boot/build/context/properties/DocumentConfigurationProperties.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ private void templatePrefixes(Config prefix) {
191191
prefix.accept("spring.groovy");
192192
prefix.accept("spring.mustache");
193193
prefix.accept("spring.thymeleaf");
194-
prefix.accept("spring.groovy.template.configuration", "See GroovyMarkupConfigurer");
195194
}
196195

197196
private void serverPrefixes(Config prefix) {

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@
3333
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
3434
import org.springframework.boot.autoconfigure.template.TemplateLocation;
3535
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
36-
import org.springframework.boot.context.properties.ConfigurationProperties;
3736
import org.springframework.boot.context.properties.EnableConfigurationProperties;
37+
import org.springframework.boot.context.properties.PropertyMapper;
38+
import org.springframework.boot.context.properties.bind.Bindable;
39+
import org.springframework.boot.context.properties.bind.Binder;
3840
import org.springframework.context.ApplicationContext;
3941
import org.springframework.context.annotation.Bean;
4042
import org.springframework.context.annotation.Configuration;
4143
import org.springframework.context.i18n.LocaleContextHolder;
44+
import org.springframework.core.env.Environment;
4245
import org.springframework.core.log.LogMessage;
4346
import org.springframework.web.servlet.view.UrlBasedViewResolver;
4447
import org.springframework.web.servlet.view.groovy.GroovyMarkupConfig;
@@ -109,11 +112,23 @@ private boolean isUsingGroovyAllJar() {
109112

110113
@Bean
111114
@ConditionalOnMissingBean(GroovyMarkupConfig.class)
112-
@ConfigurationProperties("spring.groovy.template.configuration")
113-
public GroovyMarkupConfigurer groovyMarkupConfigurer(ObjectProvider<MarkupTemplateEngine> templateEngine) {
115+
GroovyMarkupConfigurer groovyMarkupConfigurer(ObjectProvider<MarkupTemplateEngine> templateEngine,
116+
Environment environment) {
114117
GroovyMarkupConfigurer configurer = new GroovyMarkupConfigurer();
115-
configurer.setResourceLoaderPath(this.properties.getResourceLoaderPath());
116-
configurer.setCacheTemplates(this.properties.isCache());
118+
PropertyMapper map = PropertyMapper.get();
119+
map.from(this.properties::isAutoEscape).to(configurer::setAutoEscape);
120+
map.from(this.properties::isAutoIndent).to(configurer::setAutoIndent);
121+
map.from(this.properties::getAutoIndentString).to(configurer::setAutoIndentString);
122+
map.from(this.properties::isAutoNewLine).to(configurer::setAutoNewLine);
123+
map.from(this.properties::getBaseTemplateClass).to(configurer::setBaseTemplateClass);
124+
map.from(this.properties::isCache).to(configurer::setCacheTemplates);
125+
map.from(this.properties::getDeclarationEncoding).to(configurer::setDeclarationEncoding);
126+
map.from(this.properties::isExpandEmptyElements).to(configurer::setExpandEmptyElements);
127+
map.from(this.properties::getLocale).to(configurer::setLocale);
128+
map.from(this.properties::getNewLineString).to(configurer::setNewLineString);
129+
map.from(this.properties::getResourceLoaderPath).to(configurer::setResourceLoaderPath);
130+
map.from(this.properties::isUseDoubleQuotes).to(configurer::setUseDoubleQuotes);
131+
Binder.get(environment).bind("spring.groovy.template.configuration", Bindable.ofInstance(configurer));
117132
templateEngine.ifAvailable(configurer::setTemplateEngine);
118133
return configurer;
119134
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateProperties.java

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
package org.springframework.boot.autoconfigure.groovy.template;
1818

19+
import java.util.Locale;
20+
21+
import groovy.text.markup.BaseTemplate;
22+
1923
import org.springframework.boot.autoconfigure.template.AbstractTemplateViewResolverProperties;
2024
import org.springframework.boot.context.properties.ConfigurationProperties;
2125

@@ -38,16 +42,139 @@ public class GroovyTemplateProperties extends AbstractTemplateViewResolverProper
3842

3943
public static final String DEFAULT_REQUEST_CONTEXT_ATTRIBUTE = "spring";
4044

45+
/**
46+
* Whether models that are assignable to CharSequence are escaped automatically.
47+
*/
48+
private boolean autoEscape;
49+
50+
/**
51+
* Whether indents are rendered automatically.
52+
*/
53+
private boolean autoIndent;
54+
55+
/**
56+
* String used for auto-indents.
57+
*/
58+
private String autoIndentString;
59+
60+
/**
61+
* Whether new lines are rendered automatically.
62+
*/
63+
private boolean autoNewLine;
64+
65+
/**
66+
* Template base class.
67+
*/
68+
private Class<? extends BaseTemplate> baseTemplateClass = BaseTemplate.class;
69+
70+
/**
71+
* Encoding used to write the declaration heading.
72+
*/
73+
private String declarationEncoding;
74+
75+
/**
76+
* Whether elements without a body should be written expanded (&lt;br&gt;&lt;/br&gt;)
77+
* or not (&lt;br/&gt;).
78+
*/
79+
private boolean expandEmptyElements;
80+
81+
/**
82+
* Default locale for template resolution.
83+
*/
84+
private Locale locale;
85+
86+
/**
87+
* String used to write a new line. Defaults to the system's line separator.
88+
*/
89+
private String newLineString;
90+
4191
/**
4292
* Template path.
4393
*/
4494
private String resourceLoaderPath = DEFAULT_RESOURCE_LOADER_PATH;
4595

96+
/**
97+
* Whether attributes should use double quotes.
98+
*/
99+
private boolean useDoubleQuotes;
100+
46101
public GroovyTemplateProperties() {
47102
super(DEFAULT_PREFIX, DEFAULT_SUFFIX);
48103
setRequestContextAttribute(DEFAULT_REQUEST_CONTEXT_ATTRIBUTE);
49104
}
50105

106+
public boolean isAutoEscape() {
107+
return this.autoEscape;
108+
}
109+
110+
public void setAutoEscape(boolean autoEscape) {
111+
this.autoEscape = autoEscape;
112+
}
113+
114+
public boolean isAutoIndent() {
115+
return this.autoIndent;
116+
}
117+
118+
public void setAutoIndent(boolean autoIndent) {
119+
this.autoIndent = autoIndent;
120+
}
121+
122+
public String getAutoIndentString() {
123+
return this.autoIndentString;
124+
}
125+
126+
public void setAutoIndentString(String autoIndentString) {
127+
this.autoIndentString = autoIndentString;
128+
}
129+
130+
public boolean isAutoNewLine() {
131+
return this.autoNewLine;
132+
}
133+
134+
public void setAutoNewLine(boolean autoNewLine) {
135+
this.autoNewLine = autoNewLine;
136+
}
137+
138+
public Class<? extends BaseTemplate> getBaseTemplateClass() {
139+
return this.baseTemplateClass;
140+
}
141+
142+
public void setBaseTemplateClass(Class<? extends BaseTemplate> baseTemplateClass) {
143+
this.baseTemplateClass = baseTemplateClass;
144+
}
145+
146+
public String getDeclarationEncoding() {
147+
return this.declarationEncoding;
148+
}
149+
150+
public void setDeclarationEncoding(String declarationEncoding) {
151+
this.declarationEncoding = declarationEncoding;
152+
}
153+
154+
public boolean isExpandEmptyElements() {
155+
return this.expandEmptyElements;
156+
}
157+
158+
public void setExpandEmptyElements(boolean expandEmptyElements) {
159+
this.expandEmptyElements = expandEmptyElements;
160+
}
161+
162+
public Locale getLocale() {
163+
return this.locale;
164+
}
165+
166+
public void setLocale(Locale locale) {
167+
this.locale = locale;
168+
}
169+
170+
public String getNewLineString() {
171+
return this.newLineString;
172+
}
173+
174+
public void setNewLineString(String newLineString) {
175+
this.newLineString = newLineString;
176+
}
177+
51178
public String getResourceLoaderPath() {
52179
return this.resourceLoaderPath;
53180
}
@@ -56,4 +183,12 @@ public void setResourceLoaderPath(String resourceLoaderPath) {
56183
this.resourceLoaderPath = resourceLoaderPath;
57184
}
58185

186+
public boolean isUseDoubleQuotes() {
187+
return this.useDoubleQuotes;
188+
}
189+
190+
public void setUseDoubleQuotes(boolean useDoubleQuotes) {
191+
this.useDoubleQuotes = useDoubleQuotes;
192+
}
193+
59194
}

spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,99 @@
15111511
"name": "spring.graphql.schema.locations",
15121512
"defaultValue": "classpath:graphql/**/"
15131513
},
1514+
{
1515+
"name": "spring.groovy.template.configuration.auto-escape",
1516+
"deprecation": {
1517+
"replacement": "spring.groovy.template.auto-escape",
1518+
"level": "warning"
1519+
}
1520+
},
1521+
{
1522+
"name": "spring.groovy.template.configuration.auto-indent",
1523+
"deprecation": {
1524+
"replacement": "spring.groovy.template.auto-indent",
1525+
"level": "warning"
1526+
}
1527+
},
1528+
{
1529+
"name": "spring.groovy.template.configuration.auto-indent-string",
1530+
"deprecation": {
1531+
"replacement": "spring.groovy.template.auto-indent-string",
1532+
"level": "warning"
1533+
}
1534+
},
1535+
{
1536+
"name": "spring.groovy.template.configuration.auto-new-line",
1537+
"deprecation": {
1538+
"replacement": "spring.groovy.template.auto-new-line",
1539+
"level": "warning",
1540+
"since": "3.5.0"
1541+
}
1542+
},
1543+
{
1544+
"name": "spring.groovy.template.configuration.base-template-class",
1545+
"deprecation": {
1546+
"replacement": "spring.groovy.template.base-template-class",
1547+
"level": "warning",
1548+
"since": "3.5.0"
1549+
}
1550+
},
1551+
{
1552+
"name": "spring.groovy.template.configuration.cache-templates",
1553+
"deprecation": {
1554+
"replacement": "spring.groovy.template.cache",
1555+
"level": "warning",
1556+
"since": "3.5.0"
1557+
}
1558+
},
1559+
{
1560+
"name": "spring.groovy.template.configuration.declaration-encoding",
1561+
"deprecation": {
1562+
"replacement": "spring.groovy.template.declaration-encoding",
1563+
"level": "warning",
1564+
"since": "3.5.0"
1565+
}
1566+
},
1567+
{
1568+
"name": "spring.groovy.template.configuration.expand-empty-elements",
1569+
"deprecation": {
1570+
"replacement": "spring.groovy.template.expand-empty-elements",
1571+
"level": "warning",
1572+
"since": "3.5.0"
1573+
}
1574+
},
1575+
{
1576+
"name": "spring.groovy.template.configuration.locale",
1577+
"deprecation": {
1578+
"replacement": "spring.groovy.template.locale",
1579+
"level": "warning",
1580+
"since": "3.5.0"
1581+
}
1582+
},
1583+
{
1584+
"name": "spring.groovy.template.configuration.new-line-string",
1585+
"deprecation": {
1586+
"replacement": "spring.groovy.template.new-line-string",
1587+
"level": "warning",
1588+
"since": "3.5.0"
1589+
}
1590+
},
1591+
{
1592+
"name": "spring.groovy.template.configuration.resource-loader-path",
1593+
"deprecation": {
1594+
"replacement": "spring.groovy.template.resource-loader-path",
1595+
"level": "warning",
1596+
"since": "3.5.0"
1597+
}
1598+
},
1599+
{
1600+
"name": "spring.groovy.template.configuration.use-double-quotes",
1601+
"deprecation": {
1602+
"replacement": "spring.groovy.template.use-double-quotes",
1603+
"level": "warning",
1604+
"since": "3.5.0"
1605+
}
1606+
},
15141607
{
15151608
"name": "spring.groovy.template.prefix",
15161609
"defaultValue": ""

0 commit comments

Comments
 (0)