Collect and display build information
This commit updates the Maven plugin to generate a `META-INF/boot/build.properties` file with various build-specific settings (group, artifact, name, version and build time). Additionally, the plugin can be configured to write an arbitrary number of additional properties. A new `BuildProperties` bean is automatically exposed when such a file is present. If that bean is present, an `InfoContributor` is automatically created to expose that information under the `build` key. As for the git contributor, it is possible to only display the core settings or everything using the `management.info.build.mode` property. See gh-2559
This commit is contained in:
@@ -22,9 +22,11 @@ import java.util.Properties;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.actuate.info.BuildInfoContributor;
|
||||
import org.springframework.boot.actuate.info.GitInfoContributor;
|
||||
import org.springframework.boot.actuate.info.Info;
|
||||
import org.springframework.boot.actuate.info.InfoContributor;
|
||||
import org.springframework.boot.info.BuildProperties;
|
||||
import org.springframework.boot.info.GitProperties;
|
||||
import org.springframework.boot.test.EnvironmentTestUtils;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
@@ -111,6 +113,41 @@ public class InfoContributorAutoConfigurationTests {
|
||||
.isSameAs(this.context.getBean("customGitInfoContributor"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void buildPropertiesDefaultMode() {
|
||||
load(BuildPropertiesConfiguration.class);
|
||||
Map<String, InfoContributor> beans = this.context
|
||||
.getBeansOfType(InfoContributor.class);
|
||||
assertThat(beans).containsKeys("buildInfoContributor");
|
||||
Map<String, Object> content =
|
||||
invokeContributor(this.context.getBean("buildInfoContributor", InfoContributor.class));
|
||||
Object build = content.get("build");
|
||||
assertThat(build).isInstanceOf(Map.class);
|
||||
Map<String, Object> gitInfo = (Map<String, Object>) build;
|
||||
assertThat(gitInfo).containsOnlyKeys("group", "artifact");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void buildPropertiesFullMode() {
|
||||
load(BuildPropertiesConfiguration.class, "management.info.build.mode=full");
|
||||
Map<String, Object> content =
|
||||
invokeContributor(this.context.getBean("buildInfoContributor", InfoContributor.class));
|
||||
Object build = content.get("build");
|
||||
assertThat(build).isInstanceOf(Map.class);
|
||||
Map<String, Object> gitInfo = (Map<String, Object>) build;
|
||||
assertThat(gitInfo).containsOnlyKeys("group", "artifact", "foo");
|
||||
assertThat(gitInfo.get("foo")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customBuildInfoContributor() {
|
||||
load(CustomBuildInfoProviderConfiguration.class);
|
||||
assertThat(this.context.getBean(BuildInfoContributor.class))
|
||||
.isSameAs(this.context.getBean("customBuildInfoContributor"));
|
||||
}
|
||||
|
||||
private Map<String, Object> invokeContributor(InfoContributor contributor) {
|
||||
Info.Builder builder = new Info.Builder();
|
||||
contributor.contribute(builder);
|
||||
@@ -146,6 +183,20 @@ public class InfoContributorAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class BuildPropertiesConfiguration {
|
||||
|
||||
@Bean
|
||||
public BuildProperties buildProperties() {
|
||||
Properties properties = new Properties();
|
||||
properties.put("group", "com.example");
|
||||
properties.put("artifact", "demo");
|
||||
properties.put("foo", "bar");
|
||||
return new BuildProperties(properties);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class CustomInfoProviderConfiguration {
|
||||
|
||||
@@ -170,4 +221,14 @@ public class InfoContributorAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class CustomBuildInfoProviderConfiguration {
|
||||
|
||||
@Bean
|
||||
public BuildInfoContributor customBuildInfoContributor() {
|
||||
return new BuildInfoContributor(new BuildProperties(new Properties()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class GitInfoContributorTests {
|
||||
properties.put("branch", "master");
|
||||
properties.put("commit.time", "2016-03-04T14:36:33+0100");
|
||||
GitInfoContributor contributor = new GitInfoContributor(new GitProperties(properties));
|
||||
Map<String, Object> content = contributor.extractContent();
|
||||
Map<String, Object> content = contributor.generateContent();
|
||||
assertThat(content.get("commit")).isInstanceOf(Map.class);
|
||||
Map<String, Object> commit = (Map<String, Object>) content.get("commit");
|
||||
Object commitTime = commit.get("time");
|
||||
@@ -55,7 +55,7 @@ public class GitInfoContributorTests {
|
||||
properties.put("branch", "master");
|
||||
properties.put("commit.id", "8e29a0b0d423d2665c6ee5171947c101a5c15681");
|
||||
GitInfoContributor contributor = new GitInfoContributor(new GitProperties(properties));
|
||||
Map<String, Object> content = contributor.extractContent();
|
||||
Map<String, Object> content = contributor.generateContent();
|
||||
assertThat(content.get("commit")).isInstanceOf(Map.class);
|
||||
Map<String, Object> commit = (Map<String, Object>) content.get("commit");
|
||||
assertThat(commit.get("id")).isEqualTo("8e29a0b");
|
||||
|
||||
Reference in New Issue
Block a user