fix: #713, 开发环境也能获取版本信息了 (#714)

* fix #713, 开发环境也能获取版本信息了

* banner version show ok
pull/732/head
ming 2020-03-28 14:33:23 +08:00 committed by GitHub
parent f21f5933bf
commit 49486198df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 15 deletions

View File

@ -39,10 +39,15 @@ configurations {
} }
} }
bootJar {
manifest { springBoot {
attributes("Implementation-Title": "Halo Application", buildInfo()
"Implementation-Version": archiveVersion) }
// gradle Property Expansion ${..} springboot springboot \${..}
processResources {
filesMatching("application.yaml") {
expand(project.properties)
} }
} }

View File

@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.info.BuildProperties;
import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -15,8 +16,10 @@ import run.halo.app.cache.AbstractStringCacheStore;
import run.halo.app.cache.InMemoryCacheStore; import run.halo.app.cache.InMemoryCacheStore;
import run.halo.app.cache.LevelCacheStore; import run.halo.app.cache.LevelCacheStore;
import run.halo.app.config.properties.HaloProperties; import run.halo.app.config.properties.HaloProperties;
import run.halo.app.model.support.HaloConst;
import run.halo.app.utils.HttpClientUtils; import run.halo.app.utils.HttpClientUtils;
import javax.annotation.PostConstruct;
import java.security.KeyManagementException; import java.security.KeyManagementException;
import java.security.KeyStoreException; import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
@ -34,6 +37,9 @@ public class HaloConfiguration {
@Autowired @Autowired
HaloProperties haloProperties; HaloProperties haloProperties;
@Autowired
BuildProperties buildProperties;
@Bean @Bean
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) { public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
builder.failOnEmptyBeans(false); builder.failOnEmptyBeans(false);
@ -70,4 +76,8 @@ public class HaloConfiguration {
} }
@PostConstruct
public void init() {
HaloConst.HALO_VERSION = buildProperties.getVersion();
}
} }

View File

@ -50,10 +50,6 @@ public class HaloConst {
*/ */
public final static String DEFAULT_THEME_ID = "caicai_anatole"; public final static String DEFAULT_THEME_ID = "caicai_anatole";
/**
* Version constant. (Available in production environment)
*/
public static final String HALO_VERSION;
/** /**
* Path separator. * Path separator.
*/ */
@ -143,8 +139,9 @@ public class HaloConst {
*/ */
public static String USER_SESSION_KEY = "user_session"; public static String USER_SESSION_KEY = "user_session";
static { /**
// Set version * Version constant.
HALO_VERSION = HaloConst.class.getPackage().getImplementationVersion(); */
} public static String HALO_VERSION = null;
} }

View File

@ -37,7 +37,7 @@ spring:
multipart: multipart:
max-file-size: 10240MB max-file-size: 10240MB
max-request-size: 10240MB max-request-size: 10240MB
location: ${java.io.tmpdir} location: \${java.io.tmpdir}
management: management:
endpoints: endpoints:
web: web:
@ -48,7 +48,10 @@ logging:
level: level:
run.halo.app: INFO run.halo.app: INFO
file: file:
path: ${user.home}/.halo/logs path: \${user.home}/.halo/logs
halo: halo:
download-timeout: 5m download-timeout: 5m
application:
version: ${version}