Skip to content

Commit 544e4ae

Browse files
committed
Fix version command attributes
- Now passing version command attributes even if those are nulls(not set) as ST logs those in a listener as errors while it doesn't cause any failures. - Change all LoggingSTErrorListener methods into debug level to limit more noise. - Fixes #363
1 parent 785a926 commit 544e4ae

File tree

2 files changed

+32
-13
lines changed
  • spring-shell-core/src/main/java/org/springframework/shell/style
  • spring-shell-standard-commands/src/main/java/org/springframework/shell/standard/commands

2 files changed

+32
-13
lines changed

spring-shell-core/src/main/java/org/springframework/shell/style/TemplateExecutor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,22 @@ private static class LoggingSTErrorListener implements STErrorListener {
9494

9595
@Override
9696
public void compileTimeError(STMessage msg) {
97-
log.error("compileTimeError [{}]", msg);
97+
log.debug("compileTimeError [{}]", msg);
9898
}
9999

100100
@Override
101101
public void runTimeError(STMessage msg) {
102-
log.error("runTimeError [{}]", msg);
102+
log.debug("runTimeError [{}]", msg);
103103
}
104104

105105
@Override
106106
public void IOError(STMessage msg) {
107-
log.error("IOError [{}]", msg);
107+
log.debug("IOError [{}]", msg);
108108
}
109109

110110
@Override
111111
public void internalError(STMessage msg) {
112-
log.error("internalError [{}]", msg);
112+
log.debug("internalError [{}]", msg);
113113
}
114114
}
115115
}

spring-shell-standard-commands/src/main/java/org/springframework/shell/standard/commands/Version.java

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,37 +80,56 @@ public AttributedString version() {
8080
String templateResource = resourceAsString(resourceLoader.getResource(template));
8181

8282
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;
8392
if (buildProperties != null) {
8493
if (showBuildGroup && StringUtils.hasText(buildProperties.getGroup())) {
85-
attributes.put("buildGroup", buildProperties.getGroup());
94+
buildGroup = buildProperties.getGroup();
8695
}
8796
if (showBuildArtifact && StringUtils.hasText(buildProperties.getArtifact())) {
88-
attributes.put("buildArtifact", buildProperties.getArtifact());
97+
buildArtifact = buildProperties.getArtifact();
8998
}
9099
if (showBuildName && StringUtils.hasText(buildProperties.getName())) {
91-
attributes.put("buildName", buildProperties.getName());
100+
buildName = buildProperties.getName();
92101
}
93102
if (showBuildVersion && StringUtils.hasText(buildProperties.getVersion())) {
94-
attributes.put("buildVersion", buildProperties.getVersion());
103+
buildVersion = buildProperties.getVersion();
95104
}
96105
if (showBuildTime && buildProperties.getTime() != null) {
97-
attributes.put("buildTime", buildProperties.getTime().toString());
106+
buildTime = buildProperties.getTime().toString();
98107
}
99108
}
100109
if (gitProperties != null) {
101110
if (showGitBranch && StringUtils.hasText(gitProperties.getBranch())) {
102-
attributes.put("gitBranch", gitProperties.getBranch());
111+
gitBranch = gitProperties.getBranch();
103112
}
104113
if (showGitCommitId && StringUtils.hasText(gitProperties.getCommitId())) {
105-
attributes.put("gitCommitId", gitProperties.getCommitId());
114+
gitCommitId = gitProperties.getCommitId();
106115
}
107116
if (showGitShortCommitId && StringUtils.hasText(gitProperties.getShortCommitId())) {
108-
attributes.put("gitShortCommitId", gitProperties.getShortCommitId());
117+
gitShortCommitId = gitProperties.getShortCommitId();
109118
}
110119
if (showGitCommitTime && gitProperties.getCommitTime() != null) {
111-
attributes.put("gitCommitTime", gitProperties.getCommitTime().toString());
120+
gitCommitTime = gitProperties.getCommitTime().toString();
112121
}
113122
}
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);
114133
AttributedString rendered = templateExecutor.render(templateResource, attributes);
115134
return rendered;
116135
}

0 commit comments

Comments
 (0)