Relocate banner properties to spring.banner
Closes gh-11339
This commit is contained in:
parent
b6aa0f24e2
commit
e5361d887c
|
@ -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.
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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": [
|
||||
|
|
|
@ -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(" @");
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue