1
1
/*
2
- * Copyright 2012-2019 the original author or authors.
2
+ * Copyright 2012-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
19
19
import java .io .PrintStream ;
20
20
import java .nio .charset .Charset ;
21
21
import java .nio .charset .StandardCharsets ;
22
- import java .util .ArrayList ;
23
22
import java .util .Collections ;
24
23
import java .util .HashMap ;
25
24
import java .util .List ;
29
28
import org .apache .commons .logging .LogFactory ;
30
29
31
30
import org .springframework .boot .ansi .AnsiPropertySource ;
31
+ import org .springframework .core .env .ConfigurableEnvironment ;
32
32
import org .springframework .core .env .Environment ;
33
33
import org .springframework .core .env .MapPropertySource ;
34
34
import org .springframework .core .env .MutablePropertySources ;
45
45
* @author Phillip Webb
46
46
* @author Vedran Pavic
47
47
* @author Toshiaki Maki
48
+ * @author Krzysztof Krason
48
49
* @since 1.2.0
49
50
*/
50
51
public class ResourceBanner implements Banner {
51
52
52
53
private static final Log logger = LogFactory .getLog (ResourceBanner .class );
53
54
54
- private Resource resource ;
55
+ private final Resource resource ;
55
56
56
57
public ResourceBanner (Resource resource ) {
57
58
Assert .notNull (resource , "Resource must not be null" );
@@ -77,18 +78,18 @@ public void printBanner(Environment environment, Class<?> sourceClass, PrintStre
77
78
}
78
79
79
80
protected List <PropertyResolver > getPropertyResolvers (Environment environment , Class <?> sourceClass ) {
80
- List <PropertyResolver > resolvers = new ArrayList <>();
81
- resolvers .add (environment );
82
- resolvers .add (getVersionResolver (sourceClass ));
83
- resolvers .add (getAnsiResolver ());
84
- resolvers .add (getTitleResolver (sourceClass ));
85
- return resolvers ;
81
+ MutablePropertySources propertySources = new MutablePropertySources ();
82
+ if (environment instanceof ConfigurableEnvironment ) {
83
+ ((ConfigurableEnvironment ) environment ).getPropertySources ().forEach (propertySources ::addLast );
84
+ }
85
+ propertySources .addLast (getTitleSource (sourceClass ));
86
+ propertySources .addLast (getAnsiSource ());
87
+ propertySources .addLast (getVersionSource (sourceClass ));
88
+ return Collections .singletonList (new PropertySourcesPropertyResolver (propertySources ));
86
89
}
87
90
88
- private PropertyResolver getVersionResolver (Class <?> sourceClass ) {
89
- MutablePropertySources propertySources = new MutablePropertySources ();
90
- propertySources .addLast (new MapPropertySource ("version" , getVersionsMap (sourceClass )));
91
- return new PropertySourcesPropertyResolver (propertySources );
91
+ private MapPropertySource getVersionSource (Class <?> sourceClass ) {
92
+ return new MapPropertySource ("version" , getVersionsMap (sourceClass ));
92
93
}
93
94
94
95
private Map <String , Object > getVersionsMap (Class <?> sourceClass ) {
@@ -118,19 +119,15 @@ private String getVersionString(String version, boolean format) {
118
119
return format ? " (v" + version + ")" : version ;
119
120
}
120
121
121
- private PropertyResolver getAnsiResolver () {
122
- MutablePropertySources sources = new MutablePropertySources ();
123
- sources .addFirst (new AnsiPropertySource ("ansi" , true ));
124
- return new PropertySourcesPropertyResolver (sources );
122
+ private AnsiPropertySource getAnsiSource () {
123
+ return new AnsiPropertySource ("ansi" , true );
125
124
}
126
125
127
- private PropertyResolver getTitleResolver (Class <?> sourceClass ) {
128
- MutablePropertySources sources = new MutablePropertySources ();
126
+ private MapPropertySource getTitleSource (Class <?> sourceClass ) {
129
127
String applicationTitle = getApplicationTitle (sourceClass );
130
128
Map <String , Object > titleMap = Collections .singletonMap ("application.title" ,
131
129
(applicationTitle != null ) ? applicationTitle : "" );
132
- sources .addFirst (new MapPropertySource ("title" , titleMap ));
133
- return new PropertySourcesPropertyResolver (sources );
130
+ return new MapPropertySource ("title" , titleMap );
134
131
}
135
132
136
133
protected String getApplicationTitle (Class <?> sourceClass ) {
0 commit comments