Commit e5361d88 authored by Stephane Nicoll's avatar Stephane Nicoll

Relocate banner properties to spring.banner

Closes gh-11339
parent b6aa0f24
...@@ -28,15 +28,6 @@ content into your application. Rather, pick only the properties that you need. ...@@ -28,15 +28,6 @@ content into your application. Rather, pick only the properties that you need.
# CORE PROPERTIES # 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
logging.config= # Location of the logging configuration file. For instance, `classpath:logback.xml` for Logback 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. 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. ...@@ -66,6 +57,15 @@ content into your application. Rather, pick only the properties that you need.
# AUTO-CONFIGURATION # AUTO-CONFIGURATION
spring.autoconfigure.exclude= # Auto-configuration classes to exclude. 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 CORE
spring.beaninfo.ignore=true # Whether to skip search of BeanInfo classes. spring.beaninfo.ignore=true # Whether to skip search of BeanInfo classes.
......
...@@ -92,11 +92,11 @@ the `debug` property as follows: ...@@ -92,11 +92,11 @@ the `debug` property as follows:
[[boot-features-banner]] [[boot-features-banner]]
=== Customizing the Banner === Customizing the Banner
The banner that is printed on start up can be changed by adding a `banner.txt` file to 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 your classpath or by setting the `spring.banner.location` property to the location of such
file. If the file has an encoding other than UTF-8, you can set `banner.charset`. In a file. If the file has an encoding other than UTF-8, you can set `spring.banner.charset`.
addition to a text file, you can also add a `banner.gif`, `banner.jpg`, or `banner.png` 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 image file to your classpath or set the `spring.banner.image.location` property. Images
converted into an ASCII art representation and printed above any text banner. 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: Inside your `banner.txt` file, you can use any of the following placeholders:
......
...@@ -55,6 +55,8 @@ import org.springframework.util.Assert; ...@@ -55,6 +55,8 @@ import org.springframework.util.Assert;
*/ */
public class ImageBanner implements Banner { 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 Log logger = LogFactory.getLog(ImageBanner.class);
private static final double[] RGB_WEIGHT = { 0.2126d, 0.7152d, 0.0722d }; private static final double[] RGB_WEIGHT = { 0.2126d, 0.7152d, 0.0722d };
...@@ -98,11 +100,14 @@ public class ImageBanner implements Banner { ...@@ -98,11 +100,14 @@ public class ImageBanner implements Banner {
private void printBanner(Environment environment, PrintStream out) private void printBanner(Environment environment, PrintStream out)
throws IOException { throws IOException {
int width = environment.getProperty("banner.image.width", Integer.class, 76); int width = environment.getProperty(BANNER_IMAGE_PREFIX + "width",
int height = environment.getProperty("banner.image.height", Integer.class, 0); Integer.class, 76);
int margin = environment.getProperty("banner.image.margin", Integer.class, 2); int height = environment.getProperty(BANNER_IMAGE_PREFIX + "height",
boolean invert = environment.getProperty("banner.image.invert", Boolean.class, Integer.class, 0);
false); 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); Frame[] frames = readFrames(width, height);
for (int i = 0; i < frames.length; i++) { for (int i = 0; i < frames.length; i++) {
if (i > 0) { if (i > 0) {
......
...@@ -62,7 +62,7 @@ public class ResourceBanner implements Banner { ...@@ -62,7 +62,7 @@ public class ResourceBanner implements Banner {
PrintStream out) { PrintStream out) {
try { try {
String banner = StreamUtils.copyToString(this.resource.getInputStream(), String banner = StreamUtils.copyToString(this.resource.getInputStream(),
environment.getProperty("banner.charset", Charset.class, environment.getProperty("spring.banner.charset", Charset.class,
StandardCharsets.UTF_8)); StandardCharsets.UTF_8));
for (PropertyResolver resolver : getPropertyResolvers(environment, for (PropertyResolver resolver : getPropertyResolvers(environment,
......
...@@ -36,9 +36,9 @@ import org.springframework.util.StringUtils; ...@@ -36,9 +36,9 @@ import org.springframework.util.StringUtils;
*/ */
class SpringApplicationBannerPrinter { 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"; static final String DEFAULT_BANNER_LOCATION = "banner.txt";
...@@ -114,7 +114,7 @@ class SpringApplicationBannerPrinter { ...@@ -114,7 +114,7 @@ class SpringApplicationBannerPrinter {
Class<?> mainApplicationClass) throws UnsupportedEncodingException { Class<?> mainApplicationClass) throws UnsupportedEncodingException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
banner.printBanner(environment, mainApplicationClass, new PrintStream(baos)); 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); return baos.toString(charset);
} }
......
...@@ -7,40 +7,40 @@ ...@@ -7,40 +7,40 @@
], ],
"properties": [ "properties": [
{ {
"name": "banner.charset", "name": "spring.banner.charset",
"type": "java.nio.charset.Charset", "type": "java.nio.charset.Charset",
"description": "Banner file encoding.", "description": "Banner file encoding.",
"defaultValue": "UTF-8" "defaultValue": "UTF-8"
}, },
{ {
"name": "banner.location", "name": "spring.banner.location",
"type": "org.springframework.core.io.Resource", "type": "org.springframework.core.io.Resource",
"description": "Banner text resource location.", "description": "Banner text resource location.",
"defaultValue": "classpath:banner.txt" "defaultValue": "classpath:banner.txt"
}, },
{ {
"name": "banner.image.location", "name": "spring.banner.image.location",
"type": "org.springframework.core.io.Resource", "type": "org.springframework.core.io.Resource",
"description": "Banner image file location (jpg or png can also be used).", "description": "Banner image file location (jpg or png can also be used).",
"defaultValue": "banner.gif" "defaultValue": "banner.gif"
}, },
{ {
"name": "banner.image.width", "name": "spring.banner.image.width",
"type": "java.lang.Integer", "type": "java.lang.Integer",
"description": "Banner image width (in chars)." "description": "Banner image width (in chars)."
}, },
{ {
"name": "banner.image.height", "name": "spring.banner.image.height",
"type": "java.lang.Integer", "type": "java.lang.Integer",
"description": "Banner image height (in chars)." "description": "Banner image height (in chars)."
}, },
{ {
"name": "banner.image.margin", "name": "spring.banner.image.margin",
"type": "java.lang.Integer", "type": "java.lang.Integer",
"description": "Left hand image margin (in chars)." "description": "Left hand image margin (in chars)."
}, },
{ {
"name": "banner.image.invert", "name": "spring.banner.image.invert",
"type": "java.lang.Boolean", "type": "java.lang.Boolean",
"description": "Whether images should be inverted for dark terminal themes.", "description": "Whether images should be inverted for dark terminal themes.",
"defaultValue": false "defaultValue": false
...@@ -254,6 +254,73 @@ ...@@ -254,6 +254,73 @@
"description": "Enable trace logs.", "description": "Enable trace logs.",
"sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener", "sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener",
"defaultValue": false "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": [ "hints": [
......
...@@ -48,7 +48,7 @@ public class ImageBannerTests { ...@@ -48,7 +48,7 @@ public class ImageBannerTests {
private static final char LOW_LUMINANCE_CHARACTER = '@'; 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 @Before
public void setup() { public void setup() {
...@@ -119,28 +119,28 @@ public class ImageBannerTests { ...@@ -119,28 +119,28 @@ public class ImageBannerTests {
@Test @Test
public void printBannerShouldRenderGradient() { public void printBannerShouldRenderGradient() {
AnsiOutput.setEnabled(AnsiOutput.Enabled.NEVER); AnsiOutput.setEnabled(AnsiOutput.Enabled.NEVER);
String banner = printBanner("gradient.gif", "banner.image.width=10", String banner = printBanner("gradient.gif", "spring.banner.image.width=10",
"banner.image.margin=0"); "spring.banner.image.margin=0");
assertThat(banner).contains("@#8&o:*. "); assertThat(banner).contains("@#8&o:*. ");
} }
@Test @Test
public void printBannerShouldCalculateHeight() { 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); assertThat(getBannerHeight(banner)).isEqualTo(10);
} }
@Test @Test
public void printBannerWhenHasHeightPropertyShouldSetHeight() { public void printBannerWhenHasHeightPropertyShouldSetHeight() {
String banner = printBanner("large.gif", "banner.image.width=20", String banner = printBanner("large.gif", "spring.banner.image.width=20",
"banner.image.height=30"); "spring.banner.image.height=30");
assertThat(getBannerHeight(banner)).isEqualTo(30); assertThat(getBannerHeight(banner)).isEqualTo(30);
} }
@Test @Test
public void printBannerShouldCapWidthAndCalculateHeight() { public void printBannerShouldCapWidthAndCalculateHeight() {
AnsiOutput.setEnabled(AnsiOutput.Enabled.NEVER); 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(getBannerWidth(banner)).isEqualTo(76);
assertThat(getBannerHeight(banner)).isEqualTo(37); assertThat(getBannerHeight(banner)).isEqualTo(37);
} }
...@@ -158,7 +158,7 @@ public class ImageBannerTests { ...@@ -158,7 +158,7 @@ public class ImageBannerTests {
@Test @Test
public void printBannerWhenHasMarginPropertyShouldPrintSizedMargin() { public void printBannerWhenHasMarginPropertyShouldPrintSizedMargin() {
AnsiOutput.setEnabled(AnsiOutput.Enabled.NEVER); 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); String[] lines = banner.split(NEW_LINE);
for (int i = 2; i < lines.length - 1; i++) { for (int i = 2; i < lines.length - 1; i++) {
assertThat(lines[i]).startsWith(" @"); assertThat(lines[i]).startsWith(" @");
......
...@@ -188,7 +188,7 @@ public class SpringApplicationTests { ...@@ -188,7 +188,7 @@ public class SpringApplicationTests {
public void customBanner() { public void customBanner() {
SpringApplication application = spy(new SpringApplication(ExampleConfig.class)); SpringApplication application = spy(new SpringApplication(ExampleConfig.class));
application.setWebApplicationType(WebApplicationType.NONE); 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!"); assertThat(this.output.toString()).startsWith("Running a Test!");
} }
...@@ -197,7 +197,7 @@ public class SpringApplicationTests { ...@@ -197,7 +197,7 @@ public class SpringApplicationTests {
SpringApplication application = spy(new SpringApplication(ExampleConfig.class)); SpringApplication application = spy(new SpringApplication(ExampleConfig.class));
application.setWebApplicationType(WebApplicationType.NONE); application.setWebApplicationType(WebApplicationType.NONE);
this.context = application.run( this.context = application.run(
"--banner.location=classpath:test-banner-with-placeholder.txt", "--spring.banner.location=classpath:test-banner-with-placeholder.txt",
"--test.property=123456"); "--test.property=123456");
assertThat(this.output.toString()).containsPattern("Running a Test!\\s+123456"); assertThat(this.output.toString()).containsPattern("Running a Test!\\s+123456");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment