|
|
|
@ -17,6 +17,7 @@
|
|
|
|
|
package org.springframework.boot.autoconfigure.info;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.nio.charset.Charset;
|
|
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
|
|
@ -36,6 +37,7 @@ import org.springframework.core.env.Environment;
|
|
|
|
|
import org.springframework.core.io.DefaultResourceLoader;
|
|
|
|
|
import org.springframework.core.io.Resource;
|
|
|
|
|
import org.springframework.core.io.ResourceLoader;
|
|
|
|
|
import org.springframework.core.io.support.EncodedResource;
|
|
|
|
|
import org.springframework.core.io.support.PropertiesLoaderUtils;
|
|
|
|
|
import org.springframework.core.type.AnnotatedTypeMetadata;
|
|
|
|
|
|
|
|
|
@ -60,20 +62,22 @@ public class ProjectInfoAutoConfiguration {
|
|
|
|
|
@ConditionalOnMissingBean
|
|
|
|
|
@Bean
|
|
|
|
|
public GitProperties gitProperties() throws Exception {
|
|
|
|
|
return new GitProperties(loadFrom(this.properties.getGit().getLocation(), "git"));
|
|
|
|
|
return new GitProperties(loadFrom(this.properties.getGit().getLocation(), "git",
|
|
|
|
|
this.properties.getGit().getEncoding()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ConditionalOnResource(resources = "${spring.info.build.location:classpath:META-INF/build-info.properties}")
|
|
|
|
|
@ConditionalOnMissingBean
|
|
|
|
|
@Bean
|
|
|
|
|
public BuildProperties buildProperties() throws Exception {
|
|
|
|
|
return new BuildProperties(
|
|
|
|
|
loadFrom(this.properties.getBuild().getLocation(), "build"));
|
|
|
|
|
return new BuildProperties(loadFrom(this.properties.getBuild().getLocation(),
|
|
|
|
|
"build", this.properties.getBuild().getEncoding()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected Properties loadFrom(Resource location, String prefix) throws IOException {
|
|
|
|
|
protected Properties loadFrom(Resource location, String prefix, Charset encoding)
|
|
|
|
|
throws IOException {
|
|
|
|
|
String p = prefix.endsWith(".") ? prefix : prefix + ".";
|
|
|
|
|
Properties source = PropertiesLoaderUtils.loadProperties(location);
|
|
|
|
|
Properties source = loadSource(location, encoding);
|
|
|
|
|
Properties target = new Properties();
|
|
|
|
|
for (String key : source.stringPropertyNames()) {
|
|
|
|
|
if (key.startsWith(p)) {
|
|
|
|
@ -83,6 +87,17 @@ public class ProjectInfoAutoConfiguration {
|
|
|
|
|
return target;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Properties loadSource(Resource location, Charset encoding)
|
|
|
|
|
throws IOException {
|
|
|
|
|
if (encoding != null) {
|
|
|
|
|
return PropertiesLoaderUtils
|
|
|
|
|
.loadProperties(new EncodedResource(location, encoding));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return PropertiesLoaderUtils.loadProperties(location);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static class GitResourceAvailableCondition extends SpringBootCondition {
|
|
|
|
|
|
|
|
|
|
private final ResourceLoader defaultResourceLoader = new DefaultResourceLoader();
|
|
|
|
|