Reverting changes.移除重复建设的git 提交信息查看,有对应需求的建议通过management.info.git.mode=full在/actuator/info端点查看完整信息

This commit is contained in:
lishangbu 2021-10-26 19:14:36 +08:00
parent f87eddd57e
commit a5b6721715
4 changed files with 1 additions and 157 deletions

View File

@ -1,94 +0,0 @@
package com.pig4cloud.pig.common.core.git;
import lombok.Data;
import java.io.Serializable;
import java.util.Properties;
/**
* git仓库状态
*
* @author lishangbu
* @date 2021/10/10
*/
@Data
public class GitRepositoryState implements Serializable {
private String tags;
private String branch;
private String dirty;
private String remoteOriginUrl;
private String commitId;
private String commitIdAbbrev;
private String describe;
private String describeShort;
private String commitUserName;
private String commitUserEmail;
private String commitMessageFull;
private String commitMessageShort;
private String commitTime;
private String closestTagName;
private String closestTagCommitCount;
private String buildUserName;
private String buildUserEmail;
private String buildTime;
private String buildHost;
private String buildVersion;
private String buildNumber;
private String buildNumberUnique;
private String totalCommitCount;
public GitRepositoryState() {
}
public GitRepositoryState(Properties properties) {
this.tags = properties.getProperty("git.tags", "");
this.branch = properties.getProperty("git.branch", "");
this.dirty = properties.getProperty("git.dirty", "");
this.remoteOriginUrl = properties.getProperty("git.remote.origin.url", "");
this.commitId = properties.getProperty("git.commit.id", "");
this.commitIdAbbrev = properties.getProperty("git.commit.id.abbrev", "");
this.describe = properties.getProperty("git.commit.id.describe", "");
this.describeShort = properties.getProperty("git.commit.id.describe-short", "");
this.commitUserName = properties.getProperty("git.commit.user.name", "");
this.commitUserEmail = properties.getProperty("git.commit.user.email", "");
this.commitMessageFull = properties.getProperty("git.commit.message.full", "");
this.commitMessageShort = properties.getProperty("git.commit.message.short", "");
this.commitTime = properties.getProperty("git.commit.time", "");
this.closestTagName = properties.getProperty("git.closest.tag.name", "");
this.closestTagCommitCount = properties.getProperty("git.closest.tag.commit.count", "");
this.buildUserName = properties.getProperty("git.build.user.name", "");
this.buildUserEmail = properties.getProperty("git.build.user.email", "");
this.buildTime = properties.getProperty("git.build.time", "");
this.buildHost = properties.getProperty("git.build.host", "");
this.buildVersion = properties.getProperty("git.build.version", "");
this.buildNumber = properties.getProperty("git.build.number", "");
this.buildNumberUnique = properties.getProperty("git.build.number.unique", "");
this.totalCommitCount = properties.getProperty("git.total.commit.count", "");
}
}

View File

@ -1,62 +0,0 @@
package com.pig4cloud.pig.common.core.git;
import lombok.Cleanup;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.util.ResourceUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
* 版本号端点
* <p>
* 可以通过该接口检查线上版本与代码库中的版本的一致性
* <p>
* 实现发布的二进制文件和代码进行关联
* <p>
* 该功能依赖于<a href=
* "https://github.com/git-commit-id/git-commit-id-maven-plugin">git-commit-id-maven-plugin</a>实现
* <p>
* 因此,只适用于项目构建工具为<a href="https://maven.apache.org/">maven</a>,版本控制软件为<a href=
* "https://git-scm.com">git</a>的情况
*
* @author lishangbu
* @date 2021/10/10
*/
@Slf4j
@Endpoint(id = "gitrepositorystate")
public class GitRepositoryStateEndpoint {
private GitRepositoryState gitRepositoryState;
@ReadOperation
public GitRepositoryState getGitRepositoryState() throws IOException {
if (gitRepositoryState != null) {
return gitRepositoryState;
}
try {
File file = ResourceUtils.getFile(ResourceUtils.CLASSPATH_URL_PREFIX + "git.properties");
@Cleanup
InputStream inputStream = new FileInputStream(file);
if (inputStream != null) {
Properties properties = new Properties();
properties.load(inputStream);
gitRepositoryState = new GitRepositoryState(properties);
return gitRepositoryState;
}
}
catch (RuntimeException e) {
log.error("加载git资源文件git.properties失败,错误原因为:[{}]", e.getMessage(), e);
}
// 资源文件加载可能没有报错但在某些情况下可能为空,此时,日志里给出提示,交给开发人员自行解决
log.warn("git仓库状态信息初始化失败,您将无法调用/actuator/gitrepositorystate端点");
log.warn("请保证这个仓库是一个git托管的仓库并且经过了maven的编译");
return null;
}
}

View File

@ -2,6 +2,5 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.pig4cloud.pig.common.core.config.JacksonConfiguration,\
com.pig4cloud.pig.common.core.config.RedisTemplateConfiguration,\
com.pig4cloud.pig.common.core.config.RestTemplateConfiguration,\
com.pig4cloud.pig.common.core.git.GitRepositoryStateEndpoint,\
com.pig4cloud.pig.common.core.util.SpringContextHolder,\
com.pig4cloud.pig.common.core.config.WebMvcConfiguration

View File

@ -218,6 +218,7 @@
<configuration>
<failOnNoGitDirectory>false</failOnNoGitDirectory>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<!--因为项目定制了jackson的日期时间序列化/反序列化格式,因此这里要进行配置,不然通过management.info.git.mode=full进行完整git信息监控时会存在问题-->
<dateFormat>yyyy-MM-dd HH:mm:ss</dateFormat>
<includeOnlyProperties>
<includeOnlyProperty>^git.build.(time|version)$</includeOnlyProperty>