Replace static version field with ClassPathResource.

Previously, the default version was loaded from a java constant. This version used to be updated by hand after the release train was published to maven central, then built and deployed by hand. Spring-Cloud-Cli is now built and deployed automatically, but the bom version hasn't been updated.

The constant was replaced with the contents of a file that is updated at build time. This process works for development and release without any manual intervention.

Fixes gh-174
This commit is contained in:
spencergibb
2021-02-08 13:50:25 -05:00
parent de714224a9
commit 4ce50062df
6 changed files with 56 additions and 5 deletions

View File

@@ -113,7 +113,11 @@ public class DeployerApplication {
String getDefaultVersion() {
try (InputStream in = new ClassPathResource("META-INF/cli-version.txt").getInputStream()) {
return StreamUtils.copyToString(in, StandardCharsets.UTF_8);
String version = StreamUtils.copyToString(in, StandardCharsets.UTF_8);
if (StringUtils.hasText(version)) {
version = version.trim();
}
return version;
}
catch (IOException e) {
ReflectionUtils.rethrowRuntimeException(e);

View File

@@ -64,6 +64,6 @@ public class DeployerApplicationTests {
public void defaultVersionReadFromFile() {
String defaultVersion = new DeployerApplication("--launcher.deploy=foo,bar").getDefaultVersion();
// starts with one or more digits then a .
assertThat(defaultVersion).isNotBlank().containsPattern("^\\d+\\..*");
assertThat(defaultVersion).isNotBlank().doesNotContainAnyWhitespaces().containsPattern("^\\d+\\..*");
}
}