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:
@@ -15,6 +15,15 @@
|
||||
<version>2.2.4.BUILD-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud.launcher</groupId>
|
||||
|
||||
@@ -16,10 +16,18 @@
|
||||
|
||||
package org.springframework.cloud.cli.compiler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.codehaus.groovy.control.CompilePhase;
|
||||
import org.codehaus.groovy.transform.GroovyASTTransformation;
|
||||
import org.springframework.boot.cli.compiler.DependencyManagementBomTransformation;
|
||||
import org.springframework.boot.cli.compiler.GenericBomAstTransformation;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -28,11 +36,9 @@ import org.springframework.boot.cli.compiler.GenericBomAstTransformation;
|
||||
@GroovyASTTransformation(phase = CompilePhase.CONVERSION)
|
||||
public class SpringCloudBomAstTransformation extends GenericBomAstTransformation {
|
||||
|
||||
private static final String SPRING_CLOUD_VERSION = "Hoxton.SR7";
|
||||
|
||||
@Override
|
||||
protected String getBomModule() {
|
||||
return "org.springframework.cloud:spring-cloud-starter-parent:" + SPRING_CLOUD_VERSION;
|
||||
return "org.springframework.cloud:spring-cloud-starter-parent:" + getBomVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,4 +46,19 @@ public class SpringCloudBomAstTransformation extends GenericBomAstTransformation
|
||||
return DependencyManagementBomTransformation.ORDER - 50;
|
||||
}
|
||||
|
||||
String getBomVersion() {
|
||||
try (InputStream in = new ClassPathResource("META-INF/springcloudbom-version.txt").getInputStream()) {
|
||||
String version = StreamUtils.copyToString(in, StandardCharsets.UTF_8);
|
||||
if (StringUtils.hasText(version)) {
|
||||
version = version.trim();
|
||||
}
|
||||
return version;
|
||||
}
|
||||
catch (IOException e) {
|
||||
ReflectionUtils.rethrowRuntimeException(e);
|
||||
}
|
||||
// not reachable since exception rethrown at runtime
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
@spring-cloud.version@
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.springframework.cloud.cli.compiler;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class SpringCloudBomAstTransformationTests {
|
||||
|
||||
@Test
|
||||
public void defaultVersionReadFromFile() {
|
||||
String version = new SpringCloudBomAstTransformation().getBomVersion();
|
||||
// starts with one or more word chars then a .
|
||||
// TODO: change to \\d (digits) when merged to master
|
||||
assertThat(version).isNotBlank().doesNotContainAnyWhitespaces().containsPattern("^\\w+\\..*");
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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+\\..*");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user