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