Skip to content

Commit ce8ede9

Browse files
committed
fix: rework printBanner
No need to store the versions or use resolvers. They are only used in the `printBanner` method.
1 parent 62a789f commit ce8ede9

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

grails-core/src/main/groovy/grails/boot/GrailsBanner.groovy

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,25 @@ class GrailsBanner implements Banner {
3535
private static final int VERSIONS_MARGIN = 4
3636
private static final String VERSIONS_SEPARATOR = ' | '
3737

38-
private final String asciiArt
39-
private final Map versions
38+
private final String bannerFile
4039

41-
GrailsBanner(String grailsBannerFile) {
42-
def bannerResource = new ClassPathResource(grailsBannerFile)
43-
def appNameResolver = { Environment env -> env.getProperty('info.app.name') ?: 'application' }
44-
def appVersionResolver = { Environment env -> env.getProperty('info.app.version') ?: 'unknown' }
45-
asciiArt = bannerResource.exists() ? bannerResource.inputStream.text : ''
46-
def javaVendor = System.getProperty('java.vendor')
47-
versions = [
48-
(appNameResolver): appVersionResolver,
49-
'Grails': BuildSettings.grailsVersion,
50-
'Groovy': GroovySystem.version,
51-
'JVM': System.getProperty('java.version')+(javaVendor ? "-${javaVendor}": ''),
52-
'Spring Boot': SpringBootVersion.version,
53-
'Spring': SpringVersion.version
54-
]
40+
GrailsBanner(String bannerFile) {
41+
this.bannerFile = bannerFile
5542
}
5643

5744
@Override
5845
void printBanner(Environment environment, Class<?> sourceClass, PrintStream out) {
46+
def bannerResource = new ClassPathResource(bannerFile)
47+
def asciiArt = bannerResource.exists() ? bannerResource.inputStream.text : ''
5948
int bannerWidth = longestLineLength(asciiArt) ?: FALLBACK_BANNER_WIDTH
49+
def versions = [
50+
(environment.getProperty('info.app.name') ?: 'application'): environment.getProperty('info.app.version') ?: 'unknown',
51+
'JVM': System.getProperty('java.vendor') + ' ' + System.getProperty('java.version'),
52+
'Grails': BuildSettings.grailsVersion,
53+
'Groovy': GroovySystem.version,
54+
'Spring Boot': SpringBootVersion.version,
55+
'Spring': SpringVersion.version
56+
]
6057
def versionPairs = versions.collectEntries {
6158
[(resolveValue(it.key, environment)): resolveValue(it.value, environment)]
6259
}
@@ -80,8 +77,8 @@ class GrailsBanner implements Banner {
8077
def countInRow = 0
8178
versions.each {
8279
String value = "$it.key: $it.value"
83-
int proposedLength = currentRow.size() + (countInRow > 0 ? VERSIONS_SEPARATOR.size() : 0) + value.size()
84-
boolean wouldOverflow = proposedLength > maxWidth
80+
def proposedLength = currentRow.size() + (countInRow > 0 ? VERSIONS_SEPARATOR.size() : 0) + value.size()
81+
def wouldOverflow = proposedLength > maxWidth
8582
if (wouldOverflow) {
8683
rows << currentRow.center(bannerWidth)
8784
currentRow.length = 0

0 commit comments

Comments
 (0)