@@ -80,37 +80,56 @@ public AttributedString version() {
80
80
String templateResource = resourceAsString (resourceLoader .getResource (template ));
81
81
82
82
Map <String , Object > attributes = new HashMap <>();
83
+ String buildGroup = null ;
84
+ String buildArtifact = null ;
85
+ String buildName = null ;
86
+ String buildVersion = null ;
87
+ String buildTime = null ;
88
+ String gitBranch = null ;
89
+ String gitCommitId = null ;
90
+ String gitShortCommitId = null ;
91
+ String gitCommitTime = null ;
83
92
if (buildProperties != null ) {
84
93
if (showBuildGroup && StringUtils .hasText (buildProperties .getGroup ())) {
85
- attributes . put ( " buildGroup" , buildProperties .getGroup () );
94
+ buildGroup = buildProperties .getGroup ();
86
95
}
87
96
if (showBuildArtifact && StringUtils .hasText (buildProperties .getArtifact ())) {
88
- attributes . put ( " buildArtifact" , buildProperties .getArtifact () );
97
+ buildArtifact = buildProperties .getArtifact ();
89
98
}
90
99
if (showBuildName && StringUtils .hasText (buildProperties .getName ())) {
91
- attributes . put ( " buildName" , buildProperties .getName () );
100
+ buildName = buildProperties .getName ();
92
101
}
93
102
if (showBuildVersion && StringUtils .hasText (buildProperties .getVersion ())) {
94
- attributes . put ( " buildVersion" , buildProperties .getVersion () );
103
+ buildVersion = buildProperties .getVersion ();
95
104
}
96
105
if (showBuildTime && buildProperties .getTime () != null ) {
97
- attributes . put ( " buildTime" , buildProperties .getTime ().toString () );
106
+ buildTime = buildProperties .getTime ().toString ();
98
107
}
99
108
}
100
109
if (gitProperties != null ) {
101
110
if (showGitBranch && StringUtils .hasText (gitProperties .getBranch ())) {
102
- attributes . put ( " gitBranch" , gitProperties .getBranch () );
111
+ gitBranch = gitProperties .getBranch ();
103
112
}
104
113
if (showGitCommitId && StringUtils .hasText (gitProperties .getCommitId ())) {
105
- attributes . put ( " gitCommitId" , gitProperties .getCommitId () );
114
+ gitCommitId = gitProperties .getCommitId ();
106
115
}
107
116
if (showGitShortCommitId && StringUtils .hasText (gitProperties .getShortCommitId ())) {
108
- attributes . put ( " gitShortCommitId" , gitProperties .getShortCommitId () );
117
+ gitShortCommitId = gitProperties .getShortCommitId ();
109
118
}
110
119
if (showGitCommitTime && gitProperties .getCommitTime () != null ) {
111
- attributes . put ( " gitCommitTime" , gitProperties .getCommitTime ().toString () );
120
+ gitCommitTime = gitProperties .getCommitTime ().toString ();
112
121
}
113
122
}
123
+ // make sure we pass arguments, even as nulls, so that ST don't complain
124
+ attributes .put ("buildGroup" , buildGroup );
125
+ attributes .put ("buildArtifact" , buildArtifact );
126
+ attributes .put ("buildName" , buildName );
127
+ attributes .put ("buildVersion" , buildVersion );
128
+ attributes .put ("buildTime" , buildTime );
129
+ attributes .put ("gitBranch" , gitBranch );
130
+ attributes .put ("gitCommitId" , gitCommitId );
131
+ attributes .put ("gitShortCommitId" , gitShortCommitId );
132
+ attributes .put ("gitCommitTime" , gitCommitTime );
114
133
AttributedString rendered = templateExecutor .render (templateResource , attributes );
115
134
return rendered ;
116
135
}
0 commit comments