From e5361d887c3827896ac3af042fbabba0cef50027 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 13 Dec 2017 12:01:23 +0100 Subject: [PATCH] Relocate banner properties to spring.banner Closes gh-11339 --- .../appendix-application-properties.adoc | 18 ++--- .../main/asciidoc/spring-boot-features.adoc | 10 +-- .../org/springframework/boot/ImageBanner.java | 15 ++-- .../springframework/boot/ResourceBanner.java | 2 +- .../boot/SpringApplicationBannerPrinter.java | 6 +- ...itional-spring-configuration-metadata.json | 81 +++++++++++++++++-- .../boot/ImageBannerTests.java | 16 ++-- .../boot/SpringApplicationTests.java | 4 +- 8 files changed, 112 insertions(+), 40 deletions(-) diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 5eb7c2eb2f..854423f154 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -28,15 +28,6 @@ content into your application. Rather, pick only the properties that you need. # CORE PROPERTIES # ---------------------------------------- - # BANNER - banner.charset=UTF-8 # Banner file encoding. - banner.location=classpath:banner.txt # Banner file location. - banner.image.location=classpath:banner.gif # Banner image file location (jpg or png can also be used). - banner.image.width= # Width of the banner image in chars (default 76) - banner.image.height= # Height of the banner image in chars (default based on image height) - banner.image.margin= # Left hand image margin in chars (default 2) - banner.image.invert= # Whether images should be inverted for dark terminal themes (default false) - # LOGGING logging.config= # Location of the logging configuration file. For instance, `classpath:logback.xml` for Logback logging.exception-conversion-word=%wEx # Conversion word used when logging exceptions. @@ -66,6 +57,15 @@ content into your application. Rather, pick only the properties that you need. # AUTO-CONFIGURATION spring.autoconfigure.exclude= # Auto-configuration classes to exclude. + # BANNER + spring.banner.charset=UTF-8 # Banner file encoding. + spring.banner.location=classpath:banner.txt # Banner file location. + spring.banner.image.location=classpath:banner.gif # Banner image file location (jpg or png can also be used). + spring.banner.image.width= # Width of the banner image in chars (default 76) + spring.banner.image.height= # Height of the banner image in chars (default based on image height) + spring.banner.image.margin= # Left hand image margin in chars (default 2) + spring.banner.image.invert= # Whether images should be inverted for dark terminal themes (default false) + # SPRING CORE spring.beaninfo.ignore=true # Whether to skip search of BeanInfo classes. diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 4701ba28c6..8c4ac023c1 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -92,11 +92,11 @@ the `debug` property as follows: [[boot-features-banner]] === Customizing the Banner The banner that is printed on start up can be changed by adding a `banner.txt` file to -your classpath or by setting the `banner.location` property to the location of such a -file. If the file has an encoding other than UTF-8, you can set `banner.charset`. In -addition to a text file, you can also add a `banner.gif`, `banner.jpg`, or `banner.png` -image file to your classpath or set the `banner.image.location` property. Images are -converted into an ASCII art representation and printed above any text banner. +your classpath or by setting the `spring.banner.location` property to the location of such +a file. If the file has an encoding other than UTF-8, you can set `spring.banner.charset`. +In addition to a text file, you can also add a `banner.gif`, `banner.jpg`, or `banner.png` +image file to your classpath or set the `spring.banner.image.location` property. Images +are converted into an ASCII art representation and printed above any text banner. Inside your `banner.txt` file, you can use any of the following placeholders: diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ImageBanner.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ImageBanner.java index 6abdb74573..1ddfdb3247 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ImageBanner.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ImageBanner.java @@ -55,6 +55,8 @@ import org.springframework.util.Assert; */ public class ImageBanner implements Banner { + private static final String BANNER_IMAGE_PREFIX = "spring.banner.image."; + private static final Log logger = LogFactory.getLog(ImageBanner.class); private static final double[] RGB_WEIGHT = { 0.2126d, 0.7152d, 0.0722d }; @@ -98,11 +100,14 @@ public class ImageBanner implements Banner { private void printBanner(Environment environment, PrintStream out) throws IOException { - int width = environment.getProperty("banner.image.width", Integer.class, 76); - int height = environment.getProperty("banner.image.height", Integer.class, 0); - int margin = environment.getProperty("banner.image.margin", Integer.class, 2); - boolean invert = environment.getProperty("banner.image.invert", Boolean.class, - false); + int width = environment.getProperty(BANNER_IMAGE_PREFIX + "width", + Integer.class, 76); + int height = environment.getProperty(BANNER_IMAGE_PREFIX + "height", + Integer.class, 0); + int margin = environment.getProperty(BANNER_IMAGE_PREFIX + "margin", + Integer.class, 2); + boolean invert = environment.getProperty(BANNER_IMAGE_PREFIX + "invert", + Boolean.class, false); Frame[] frames = readFrames(width, height); for (int i = 0; i < frames.length; i++) { if (i > 0) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ResourceBanner.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ResourceBanner.java index 992ae560b9..703bb00a8a 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ResourceBanner.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ResourceBanner.java @@ -62,7 +62,7 @@ public class ResourceBanner implements Banner { PrintStream out) { try { String banner = StreamUtils.copyToString(this.resource.getInputStream(), - environment.getProperty("banner.charset", Charset.class, + environment.getProperty("spring.banner.charset", Charset.class, StandardCharsets.UTF_8)); for (PropertyResolver resolver : getPropertyResolvers(environment, diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplicationBannerPrinter.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplicationBannerPrinter.java index 3d4636829f..7bd4fb6c3e 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplicationBannerPrinter.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplicationBannerPrinter.java @@ -36,9 +36,9 @@ import org.springframework.util.StringUtils; */ class SpringApplicationBannerPrinter { - static final String BANNER_LOCATION_PROPERTY = "banner.location"; + static final String BANNER_LOCATION_PROPERTY = "spring.banner.location"; - static final String BANNER_IMAGE_LOCATION_PROPERTY = "banner.image.location"; + static final String BANNER_IMAGE_LOCATION_PROPERTY = "spring.banner.image.location"; static final String DEFAULT_BANNER_LOCATION = "banner.txt"; @@ -114,7 +114,7 @@ class SpringApplicationBannerPrinter { Class mainApplicationClass) throws UnsupportedEncodingException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); banner.printBanner(environment, mainApplicationClass, new PrintStream(baos)); - String charset = environment.getProperty("banner.charset", "UTF-8"); + String charset = environment.getProperty("spring.banner.charset", "UTF-8"); return baos.toString(charset); } diff --git a/spring-boot-project/spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-project/spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 6471052902..b440e5e6b0 100644 --- a/spring-boot-project/spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-project/spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -7,40 +7,40 @@ ], "properties": [ { - "name": "banner.charset", + "name": "spring.banner.charset", "type": "java.nio.charset.Charset", "description": "Banner file encoding.", "defaultValue": "UTF-8" }, { - "name": "banner.location", + "name": "spring.banner.location", "type": "org.springframework.core.io.Resource", "description": "Banner text resource location.", "defaultValue": "classpath:banner.txt" }, { - "name": "banner.image.location", + "name": "spring.banner.image.location", "type": "org.springframework.core.io.Resource", "description": "Banner image file location (jpg or png can also be used).", "defaultValue": "banner.gif" }, { - "name": "banner.image.width", + "name": "spring.banner.image.width", "type": "java.lang.Integer", "description": "Banner image width (in chars)." }, { - "name": "banner.image.height", + "name": "spring.banner.image.height", "type": "java.lang.Integer", "description": "Banner image height (in chars)." }, { - "name": "banner.image.margin", + "name": "spring.banner.image.margin", "type": "java.lang.Integer", "description": "Left hand image margin (in chars)." }, { - "name": "banner.image.invert", + "name": "spring.banner.image.invert", "type": "java.lang.Boolean", "description": "Whether images should be inverted for dark terminal themes.", "defaultValue": false @@ -254,6 +254,73 @@ "description": "Enable trace logs.", "sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener", "defaultValue": false + }, + { + "name": "banner.charset", + "type": "java.nio.charset.Charset", + "description": "Banner file encoding.", + "defaultValue": "UTF-8", + "deprecation": { + "replacement": "spring.banner.charset", + "level": "error" + } + }, + { + "name": "banner.image.height", + "type": "java.lang.Integer", + "description": "Banner image height (in chars).", + "deprecation": { + "replacement": "spring.banner.image.height", + "level": "error" + } + }, + { + "name": "banner.image.invert", + "type": "java.lang.Boolean", + "description": "Invert images for dark console themes.", + "defaultValue": false, + "deprecation": { + "replacement": "spring.banner.image.invert", + "level": "error" + } + }, + { + "name": "banner.image.location", + "type": "org.springframework.core.io.Resource", + "description": "Banner image file location (jpg/png can also be used).", + "defaultValue": "banner.gif", + "deprecation": { + "replacement": "spring.banner.image.location", + "level": "error" + } + }, + { + "name": "banner.image.margin", + "type": "java.lang.Integer", + "description": "Left hand image margin (in chars).", + "deprecation": { + "replacement": "spring.banner.image.margin", + "level": "error" + } + }, + { + "name": "banner.image.width", + "type": "java.lang.Integer", + "description": "Banner image width (in chars).", + "deprecation": { + "replacement": "spring.banner.image.width", + "level": "error" + } + }, + { + "name": "banner.location", + "type": "org.springframework.core.io.Resource", + "description": "Banner text resource location.", + "defaultValue": "classpath:banner.txt", + "deprecation": { + "replacement": "spring.banner.location", + "level": "error" + } } ], "hints": [ diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/ImageBannerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/ImageBannerTests.java index 820539904d..a97604e9ba 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/ImageBannerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/ImageBannerTests.java @@ -48,7 +48,7 @@ public class ImageBannerTests { private static final char LOW_LUMINANCE_CHARACTER = '@'; - private static final String INVERT_TRUE = "banner.image.invert=true"; + private static final String INVERT_TRUE = "spring.banner.image.invert=true"; @Before public void setup() { @@ -119,28 +119,28 @@ public class ImageBannerTests { @Test public void printBannerShouldRenderGradient() { AnsiOutput.setEnabled(AnsiOutput.Enabled.NEVER); - String banner = printBanner("gradient.gif", "banner.image.width=10", - "banner.image.margin=0"); + String banner = printBanner("gradient.gif", "spring.banner.image.width=10", + "spring.banner.image.margin=0"); assertThat(banner).contains("@#8&o:*. "); } @Test public void printBannerShouldCalculateHeight() { - String banner = printBanner("large.gif", "banner.image.width=20"); + String banner = printBanner("large.gif", "spring.banner.image.width=20"); assertThat(getBannerHeight(banner)).isEqualTo(10); } @Test public void printBannerWhenHasHeightPropertyShouldSetHeight() { - String banner = printBanner("large.gif", "banner.image.width=20", - "banner.image.height=30"); + String banner = printBanner("large.gif", "spring.banner.image.width=20", + "spring.banner.image.height=30"); assertThat(getBannerHeight(banner)).isEqualTo(30); } @Test public void printBannerShouldCapWidthAndCalculateHeight() { AnsiOutput.setEnabled(AnsiOutput.Enabled.NEVER); - String banner = printBanner("large.gif", "banner.image.margin=0"); + String banner = printBanner("large.gif", "spring.banner.image.margin=0"); assertThat(getBannerWidth(banner)).isEqualTo(76); assertThat(getBannerHeight(banner)).isEqualTo(37); } @@ -158,7 +158,7 @@ public class ImageBannerTests { @Test public void printBannerWhenHasMarginPropertyShouldPrintSizedMargin() { AnsiOutput.setEnabled(AnsiOutput.Enabled.NEVER); - String banner = printBanner("large.gif", "banner.image.margin=4"); + String banner = printBanner("large.gif", "spring.banner.image.margin=4"); String[] lines = banner.split(NEW_LINE); for (int i = 2; i < lines.length - 1; i++) { assertThat(lines[i]).startsWith(" @"); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java index 1ede3d5a84..c4df2b4760 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java @@ -188,7 +188,7 @@ public class SpringApplicationTests { public void customBanner() { SpringApplication application = spy(new SpringApplication(ExampleConfig.class)); application.setWebApplicationType(WebApplicationType.NONE); - this.context = application.run("--banner.location=classpath:test-banner.txt"); + this.context = application.run("--spring.banner.location=classpath:test-banner.txt"); assertThat(this.output.toString()).startsWith("Running a Test!"); } @@ -197,7 +197,7 @@ public class SpringApplicationTests { SpringApplication application = spy(new SpringApplication(ExampleConfig.class)); application.setWebApplicationType(WebApplicationType.NONE); this.context = application.run( - "--banner.location=classpath:test-banner-with-placeholder.txt", + "--spring.banner.location=classpath:test-banner-with-placeholder.txt", "--test.property=123456"); assertThat(this.output.toString()).containsPattern("Running a Test!\\s+123456"); }