Skip to content

Commit 6602fa3

Browse files
committed
Clean line breaks in configuration metadata descriptions.
Closes gh-13601
1 parent c23c18d commit 6602fa3

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public String getJavaDoc(Element element) {
142142
String javadoc = (element != null
143143
? this.env.getElementUtils().getDocComment(element) : null);
144144
if (javadoc != null) {
145+
javadoc = javadoc.replaceAll("\\n", "");
145146
javadoc = javadoc.trim();
146147
}
147148
return ("".equals(javadoc) ? null : javadoc);

spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.springframework.boot.configurationsample.method.SimpleMethodConfig;
5656
import org.springframework.boot.configurationsample.simple.ClassWithNestedProperties;
5757
import org.springframework.boot.configurationsample.simple.DeprecatedSingleProperty;
58+
import org.springframework.boot.configurationsample.simple.DescriptionProperties;
5859
import org.springframework.boot.configurationsample.simple.HierarchicalProperties;
5960
import org.springframework.boot.configurationsample.simple.NotAnnotated;
6061
import org.springframework.boot.configurationsample.simple.SimpleArrayProperties;
@@ -192,6 +193,20 @@ public void hierarchicalProperties() throws Exception {
192193
.fromSource(HierarchicalProperties.class));
193194
}
194195

196+
@Test
197+
public void descriptionProperties() {
198+
ConfigurationMetadata metadata = compile(DescriptionProperties.class);
199+
assertThat(metadata).has(Metadata.withGroup("description")
200+
.fromSource(DescriptionProperties.class));
201+
assertThat(metadata).has(Metadata.withProperty("description.simple", String.class)
202+
.fromSource(DescriptionProperties.class)
203+
.withDescription("A simple description."));
204+
assertThat(metadata).has(Metadata
205+
.withProperty("description.multi-line", String.class)
206+
.fromSource(DescriptionProperties.class).withDescription(
207+
"This is a lengthy description that spans across multiple lines to showcase that the carriage return is cleaned automatically."));
208+
}
209+
195210
@Test
196211
@SuppressWarnings("deprecation")
197212
public void deprecatedProperties() throws Exception {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2012-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.configurationsample.simple;
18+
19+
import org.springframework.boot.configurationsample.ConfigurationProperties;
20+
21+
/**
22+
* Configuration properties with various description styles.
23+
*
24+
* @author Stephane Nicoll
25+
*/
26+
@ConfigurationProperties("description")
27+
public class DescriptionProperties {
28+
29+
/**
30+
* A simple description.
31+
*/
32+
private String simple;
33+
34+
/**
35+
* This is a lengthy description that spans across multiple lines to showcase that the
36+
* carriage return is cleaned automatically.
37+
*/
38+
private String multiLine;
39+
40+
public String getSimple() {
41+
return this.simple;
42+
}
43+
44+
public void setSimple(String simple) {
45+
this.simple = simple;
46+
}
47+
48+
public String getMultiLine() {
49+
return this.multiLine;
50+
}
51+
52+
public void setMultiLine(String multiLine) {
53+
this.multiLine = multiLine;
54+
}
55+
56+
}

0 commit comments

Comments
 (0)