diff --git a/spring-boot-project/spring-boot-properties-migrator/src/main/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationReport.java b/spring-boot-project/spring-boot-properties-migrator/src/main/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationReport.java index 234cb9a021b..7d59b67b7eb 100644 --- a/spring-boot-project/spring-boot-properties-migrator/src/main/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationReport.java +++ b/spring-boot-project/spring-boot-properties-migrator/src/main/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationReport.java @@ -76,8 +76,8 @@ class PropertiesMigrationReport { + "supported was found in the environment:%n%n")); append(report, content, (metadata) -> "Reason: " - + (StringUtils.hasText(metadata.getDeprecation().getReason()) - ? metadata.getDeprecation().getReason() : "none")); + + (StringUtils.hasText(metadata.getDeprecation().getShortReason()) + ? metadata.getDeprecation().getShortReason() : "none")); report.append(String.format("%n")); report.append("Please refer to the migration guide or reference guide for " + "potential alternatives."); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/Deprecation.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/Deprecation.java index 0f9d228184a..0cc184fe74b 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/Deprecation.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/Deprecation.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,8 @@ public class Deprecation implements Serializable { private String reason; + private String shortReason; + private String replacement; /** @@ -49,6 +51,7 @@ public class Deprecation implements Serializable { /** * A reason why the related property is deprecated, if any. Can be multi-lines. * @return the deprecation reason + * @see #getShortReason() */ public String getReason() { return this.reason; @@ -58,6 +61,20 @@ public class Deprecation implements Serializable { this.reason = reason; } + /** + * A single-line, single-sentence reason why the related property is deprecated, if + * any. + * @return the short deprecation reason + * @see #getShortReason() + */ + public String getShortReason() { + return this.shortReason; + } + + public void setShortReason(String shortReason) { + this.shortReason = shortReason; + } + /** * The full name of the property that replaces the related deprecated property, if * any. diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/JsonReader.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/JsonReader.java index a46e2efc253..6c5fb69f56f 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/JsonReader.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/JsonReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,7 +37,7 @@ class JsonReader { private static final int BUFFER_SIZE = 4096; - private final DescriptionExtractor descriptionExtractor = new DescriptionExtractor(); + private final SentenceExtractor sentenceExtractor = new SentenceExtractor(); public RawConfigurationMetadata read(InputStream in, Charset charset) throws IOException { @@ -108,7 +108,7 @@ class JsonReader { String description = json.optString("description", null); source.setDescription(description); source.setShortDescription( - this.descriptionExtractor.getShortDescription(description)); + this.sentenceExtractor.getFirstSentence(description)); source.setSourceType(json.optString("sourceType", null)); source.setSourceMethod(json.optString("sourceMethod", null)); return source; @@ -121,7 +121,7 @@ class JsonReader { String description = json.optString("description", null); item.setDescription(description); item.setShortDescription( - this.descriptionExtractor.getShortDescription(description)); + this.sentenceExtractor.getFirstSentence(description)); item.setDefaultValue(readItemValue(json.opt("defaultValue"))); item.setDeprecation(parseDeprecation(json)); item.setSourceType(json.optString("sourceType", null)); @@ -141,7 +141,7 @@ class JsonReader { String description = value.optString("description", null); valueHint.setDescription(description); valueHint.setShortDescription( - this.descriptionExtractor.getShortDescription(description)); + this.sentenceExtractor.getFirstSentence(description)); hint.getValueHints().add(valueHint); } } @@ -172,7 +172,10 @@ class JsonReader { Deprecation deprecation = new Deprecation(); deprecation.setLevel(parseDeprecationLevel( deprecationJsonObject.optString("level", null))); - deprecation.setReason(deprecationJsonObject.optString("reason", null)); + String reason = deprecationJsonObject.optString("reason", null); + deprecation.setReason(reason); + deprecation.setShortReason( + this.sentenceExtractor.getFirstSentence(reason)); deprecation .setReplacement(deprecationJsonObject.optString("replacement", null)); return deprecation; diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/DescriptionExtractor.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/SentenceExtractor.java similarity index 77% rename from spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/DescriptionExtractor.java rename to spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/SentenceExtractor.java index 8dbf686bcc2..433253cfc34 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/DescriptionExtractor.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/SentenceExtractor.java @@ -20,26 +20,26 @@ import java.text.BreakIterator; import java.util.Locale; /** - * Utility to extract a description. + * Utility to extract the first sentence of a text. * * @author Stephane Nicoll */ -class DescriptionExtractor { +class SentenceExtractor { - public String getShortDescription(String description) { - if (description == null) { + public String getFirstSentence(String text) { + if (text == null) { return null; } - int dot = description.indexOf('.'); + int dot = text.indexOf('.'); if (dot != -1) { BreakIterator breakIterator = BreakIterator.getSentenceInstance(Locale.US); - breakIterator.setText(description); - String text = description + breakIterator.setText(text); + String sentence = text .substring(breakIterator.first(), breakIterator.next()).trim(); - return removeSpaceBetweenLine(text); + return removeSpaceBetweenLine(sentence); } else { - String[] lines = description.split(System.lineSeparator()); + String[] lines = text.split(System.lineSeparator()); return lines[0].trim(); } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/test/java/org/springframework/boot/configurationmetadata/DescriptionExtractorTests.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/test/java/org/springframework/boot/configurationmetadata/DescriptionExtractorTests.java deleted file mode 100644 index ed42644fe65..00000000000 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/test/java/org/springframework/boot/configurationmetadata/DescriptionExtractorTests.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.configurationmetadata; - -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link DescriptionExtractor}. - * - * @author Stephane Nicoll - */ -public class DescriptionExtractorTests { - - private static final String NEW_LINE = System.lineSeparator(); - - private DescriptionExtractor extractor = new DescriptionExtractor(); - - @Test - public void extractShortDescription() { - String description = this.extractor - .getShortDescription("My short " + "description. More stuff."); - assertThat(description).isEqualTo("My short description."); - } - - @Test - public void extractShortDescriptionNewLineBeforeDot() { - String description = this.extractor.getShortDescription( - "My short" + NEW_LINE + "description." + NEW_LINE + "More stuff."); - assertThat(description).isEqualTo("My short description."); - } - - @Test - public void extractShortDescriptionNewLineBeforeDotWithSpaces() { - String description = this.extractor.getShortDescription( - "My short " + NEW_LINE + " description. " + NEW_LINE + "More stuff."); - assertThat(description).isEqualTo("My short description."); - } - - @Test - public void extractShortDescriptionNoDot() { - String description = this.extractor.getShortDescription("My short description"); - assertThat(description).isEqualTo("My short description"); - } - - @Test - public void extractShortDescriptionNoDotMultipleLines() { - String description = this.extractor - .getShortDescription("My short description " + NEW_LINE + " More stuff"); - assertThat(description).isEqualTo("My short description"); - } - - @Test - public void extractShortDescriptionNull() { - assertThat(this.extractor.getShortDescription(null)).isEqualTo(null); - } - -} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/test/java/org/springframework/boot/configurationmetadata/JsonReaderTests.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/test/java/org/springframework/boot/configurationmetadata/JsonReaderTests.java index fbcc3c5c04d..7fd2ddac5f5 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/test/java/org/springframework/boot/configurationmetadata/JsonReaderTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/test/java/org/springframework/boot/configurationmetadata/JsonReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -156,6 +156,8 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests { assertThat(item.isDeprecated()).isTrue(); assertThat(item.getDeprecation().getReason()) .isEqualTo("Server namespace has moved to spring.server"); + assertThat(item.getDeprecation().getShortReason()) + .isEqualTo("Server namespace has moved to spring.server"); assertThat(item.getDeprecation().getReplacement()) .isEqualTo("server.spring.port"); assertThat(item.getDeprecation().getLevel()).isEqualTo(Deprecation.Level.WARNING); @@ -165,6 +167,7 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests { null); assertThat(item2.isDeprecated()).isTrue(); assertThat(item2.getDeprecation().getReason()).isNull(); + assertThat(item2.getDeprecation().getShortReason()).isNull(); assertThat(item2.getDeprecation().getReplacement()).isNull(); assertThat(item.getDeprecation().getLevel()).isEqualTo(Deprecation.Level.WARNING); @@ -179,6 +182,7 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests { null); assertThat(item4.isDeprecated()).isTrue(); assertThat(item4.getDeprecation().getReason()).isNull(); + assertThat(item2.getDeprecation().getShortReason()).isNull(); assertThat(item4.getDeprecation().getReplacement()) .isEqualTo("spring.server.name"); assertThat(item4.getDeprecation().getLevel()).isEqualTo(Deprecation.Level.ERROR); @@ -188,6 +192,7 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests { null); assertThat(item5.isDeprecated()).isTrue(); assertThat(item5.getDeprecation().getReason()).isNull(); + assertThat(item2.getDeprecation().getShortReason()).isNull(); assertThat(item5.getDeprecation().getReplacement()) .isEqualTo("spring.server.name"); assertThat(item5.getDeprecation().getLevel()) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/test/java/org/springframework/boot/configurationmetadata/SentenceExtractorTests.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/test/java/org/springframework/boot/configurationmetadata/SentenceExtractorTests.java new file mode 100644 index 00000000000..1ca1c409563 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/test/java/org/springframework/boot/configurationmetadata/SentenceExtractorTests.java @@ -0,0 +1,73 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.configurationmetadata; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link SentenceExtractor}. + * + * @author Stephane Nicoll + */ +public class SentenceExtractorTests { + + private static final String NEW_LINE = System.lineSeparator(); + + private SentenceExtractor extractor = new SentenceExtractor(); + + @Test + public void extractFirstSentence() { + String sentence = this.extractor + .getFirstSentence("My short " + "description. More stuff."); + assertThat(sentence).isEqualTo("My short description."); + } + + @Test + public void extractFirstSentenceNewLineBeforeDot() { + String sentence = this.extractor.getFirstSentence( + "My short" + NEW_LINE + "description." + NEW_LINE + "More stuff."); + assertThat(sentence).isEqualTo("My short description."); + } + + @Test + public void extractFirstSentenceNewLineBeforeDotWithSpaces() { + String sentence = this.extractor.getFirstSentence( + "My short " + NEW_LINE + " description. " + NEW_LINE + "More stuff."); + assertThat(sentence).isEqualTo("My short description."); + } + + @Test + public void extractFirstSentenceNoDot() { + String sentence = this.extractor.getFirstSentence("My short description"); + assertThat(sentence).isEqualTo("My short description"); + } + + @Test + public void extractFirstSentenceNoDotMultipleLines() { + String sentence = this.extractor + .getFirstSentence("My short description " + NEW_LINE + " More stuff"); + assertThat(sentence).isEqualTo("My short description"); + } + + @Test + public void extractFirstSentenceNull() { + assertThat(this.extractor.getFirstSentence(null)).isEqualTo(null); + } + +}