This commit is contained in:
Phillip Webb
2016-03-21 18:32:16 -07:00
parent 2ae1435916
commit 7942d9f787
61 changed files with 494 additions and 343 deletions

View File

@@ -82,7 +82,8 @@ public class InfoContributorAutoConfiguration {
@ConditionalOnSingleCandidate(BuildProperties.class)
@Order(DEFAULT_ORDER)
public InfoContributor buildInfoContributor(BuildProperties buildProperties) {
return new BuildInfoContributor(buildProperties, this.properties.getBuild().getMode());
return new BuildInfoContributor(buildProperties,
this.properties.getBuild().getMode());
}
}

View File

@@ -23,7 +23,6 @@ import org.springframework.boot.info.BuildProperties;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.env.PropertySource;
/**
* An {@link InfoContributor} that exposes {@link BuildProperties}.
*

View File

@@ -62,9 +62,12 @@ public class GitInfoContributor extends InfoPropertiesInfoContributor<GitPropert
* are converted to {@link Date} instances.
* @param content the content to expose
*/
@Override
protected void postProcessContent(Map<String, Object> content) {
replaceValue(getNestedMap(content, "commit"), "time", getProperties().getCommitTime());
replaceValue(getNestedMap(content, "build"), "time", getProperties().getDate("build.time"));
replaceValue(getNestedMap(content, "commit"), "time",
getProperties().getCommitTime());
replaceValue(getNestedMap(content, "build"), "time",
getProperties().getDate("build.time"));
}
}

View File

@@ -32,7 +32,8 @@ import org.springframework.util.StringUtils;
* @author Stephane Nicoll
* @since 1.4.0
*/
public abstract class InfoPropertiesInfoContributor<T extends InfoProperties> implements InfoContributor {
public abstract class InfoPropertiesInfoContributor<T extends InfoProperties>
implements InfoContributor {
private final T properties;
@@ -103,9 +104,7 @@ public abstract class InfoPropertiesInfoContributor<T extends InfoProperties> im
if (this.mode.equals(Mode.FULL)) {
return this.properties.toPropertySource();
}
else {
return toSimplePropertySource();
}
return toSimplePropertySource();
}
/**
@@ -141,16 +140,13 @@ public abstract class InfoPropertiesInfoContributor<T extends InfoProperties> im
*/
@SuppressWarnings("unchecked")
protected Map<String, Object> getNestedMap(Map<String, Object> map, String key) {
Object o = map.get(key);
if (o == null) {
Object value = map.get(key);
if (value == null) {
return Collections.emptyMap();
}
else {
return (Map<String, Object>) o;
}
return (Map<String, Object>) value;
}
/**
* Defines how properties should be exposed.
*/

View File

@@ -269,9 +269,10 @@ public class EndpointAutoConfigurationTests {
if (location.exists()) {
Properties gitInfoProperties = PropertiesLoaderUtils
.loadProperties(location);
PropertiesPropertySource gitPropertySource =
new PropertiesPropertySource("git", gitInfoProperties);
this.content = new PropertySourcesBinder(gitPropertySource).extractAll("git");
PropertiesPropertySource gitPropertySource = new PropertiesPropertySource(
"git", gitInfoProperties);
this.content = new PropertySourcesBinder(gitPropertySource)
.extractAll("git");
}
}

View File

@@ -85,8 +85,8 @@ public class InfoContributorAutoConfigurationTests {
Map<String, InfoContributor> beans = this.context
.getBeansOfType(InfoContributor.class);
assertThat(beans).containsKeys("gitInfoContributor");
Map<String, Object> content =
invokeContributor(this.context.getBean("gitInfoContributor", InfoContributor.class));
Map<String, Object> content = invokeContributor(
this.context.getBean("gitInfoContributor", InfoContributor.class));
Object git = content.get("git");
assertThat(git).isInstanceOf(Map.class);
Map<String, Object> gitInfo = (Map<String, Object>) git;
@@ -97,8 +97,8 @@ public class InfoContributorAutoConfigurationTests {
@Test
public void gitPropertiesFullMode() {
load(GitPropertiesConfiguration.class, "management.info.git.mode=full");
Map<String, Object> content =
invokeContributor(this.context.getBean("gitInfoContributor", InfoContributor.class));
Map<String, Object> content = invokeContributor(
this.context.getBean("gitInfoContributor", InfoContributor.class));
Object git = content.get("git");
assertThat(git).isInstanceOf(Map.class);
Map<String, Object> gitInfo = (Map<String, Object>) git;
@@ -120,8 +120,8 @@ public class InfoContributorAutoConfigurationTests {
Map<String, InfoContributor> beans = this.context
.getBeansOfType(InfoContributor.class);
assertThat(beans).containsKeys("buildInfoContributor");
Map<String, Object> content =
invokeContributor(this.context.getBean("buildInfoContributor", InfoContributor.class));
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;
@@ -132,8 +132,8 @@ public class InfoContributorAutoConfigurationTests {
@Test
public void buildPropertiesFullMode() {
load(BuildPropertiesConfiguration.class, "management.info.build.mode=full");
Map<String, Object> content =
invokeContributor(this.context.getBean("buildInfoContributor", InfoContributor.class));
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;

View File

@@ -62,24 +62,24 @@ public class SpringApplicationHierarchyTests {
@EnableAutoConfiguration(exclude = { ElasticsearchDataAutoConfiguration.class,
ElasticsearchRepositoriesAutoConfiguration.class,
CassandraAutoConfiguration.class,
CassandraDataAutoConfiguration.class,
CassandraAutoConfiguration.class, CassandraDataAutoConfiguration.class,
RedisAutoConfiguration.class,
RedisRepositoriesAutoConfiguration.class}, excludeName = {
RedisRepositoriesAutoConfiguration.class }, excludeName = {
"org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration" })
public static class Child {
}
@EnableAutoConfiguration(exclude = { JolokiaAutoConfiguration.class,
EndpointMBeanExportAutoConfiguration.class,
ElasticsearchDataAutoConfiguration.class,
ElasticsearchRepositoriesAutoConfiguration.class,
CassandraAutoConfiguration.class,
CassandraDataAutoConfiguration.class,
CassandraAutoConfiguration.class, CassandraDataAutoConfiguration.class,
RedisAutoConfiguration.class,
RedisRepositoriesAutoConfiguration.class }, excludeName = {
"org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration" })
public static class Parent {
}
}

View File

@@ -39,7 +39,8 @@ public class GitInfoContributorTests {
Properties properties = new Properties();
properties.put("branch", "master");
properties.put("commit.time", "2016-03-04T14:36:33+0100");
GitInfoContributor contributor = new GitInfoContributor(new GitProperties(properties));
GitInfoContributor contributor = new GitInfoContributor(
new GitProperties(properties));
Map<String, Object> content = contributor.generateContent();
assertThat(content.get("commit")).isInstanceOf(Map.class);
Map<String, Object> commit = (Map<String, Object>) content.get("commit");
@@ -54,7 +55,8 @@ public class GitInfoContributorTests {
Properties properties = new Properties();
properties.put("branch", "master");
properties.put("commit.id", "8e29a0b0d423d2665c6ee5171947c101a5c15681");
GitInfoContributor contributor = new GitInfoContributor(new GitProperties(properties));
GitInfoContributor contributor = new GitInfoContributor(
new GitProperties(properties));
Map<String, Object> content = contributor.generateContent();
assertThat(content.get("commit")).isInstanceOf(Map.class);
Map<String, Object> commit = (Map<String, Object>) content.get("commit");