|
|
|
@ -36,8 +36,10 @@ 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;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@link EnableAutoConfiguration Auto-configuration} for various project information.
|
|
|
|
@ -60,7 +62,8 @@ 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}")
|
|
|
|
@ -68,12 +71,18 @@ public class ProjectInfoAutoConfiguration {
|
|
|
|
|
@Bean
|
|
|
|
|
public BuildProperties buildProperties() throws Exception {
|
|
|
|
|
return new BuildProperties(
|
|
|
|
|
loadFrom(this.properties.getBuild().getLocation(), "build"));
|
|
|
|
|
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, String encoding) throws IOException {
|
|
|
|
|
String p = prefix.endsWith(".") ? prefix : prefix + ".";
|
|
|
|
|
Properties source = PropertiesLoaderUtils.loadProperties(location);
|
|
|
|
|
Properties source = null;
|
|
|
|
|
if (StringUtils.isEmpty(encoding)) {
|
|
|
|
|
source = PropertiesLoaderUtils.loadProperties(location);
|
|
|
|
|
} else {
|
|
|
|
|
source = PropertiesLoaderUtils.loadProperties(new EncodedResource(location, encoding));
|
|
|
|
|
}
|
|
|
|
|
Properties target = new Properties();
|
|
|
|
|
for (String key : source.stringPropertyNames()) {
|
|
|
|
|
if (key.startsWith(p)) {
|
|
|
|
|