Commit dbc525e8fb59f70c474863304e3c580e81dcedf0

Authored by 648540858
1 parent 689de6c5

添加版本信息接口

@@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
13 <artifactId>wvp-pro</artifactId> 13 <artifactId>wvp-pro</artifactId>
14 <version>2.0</version> 14 <version>2.0</version>
15 <name>web video platform</name> 15 <name>web video platform</name>
  16 + <description>国标28181视频平台</description>
16 17
17 <repositories> 18 <repositories>
18 <repository> 19 <repository>
@@ -251,6 +252,11 @@ @@ -251,6 +252,11 @@
251 </plugin> 252 </plugin>
252 253
253 <plugin> 254 <plugin>
  255 + <groupId>pl.project13.maven</groupId>
  256 + <artifactId>git-commit-id-plugin</artifactId>
  257 + </plugin>
  258 +
  259 + <plugin>
254 <groupId>org.apache.maven.plugins</groupId> 260 <groupId>org.apache.maven.plugins</groupId>
255 <artifactId>maven-surefire-plugin</artifactId> 261 <artifactId>maven-surefire-plugin</artifactId>
256 <configuration> 262 <configuration>
src/main/java/com/genersoft/iot/vmp/common/VersionPo.java 0 → 100644
  1 +package com.genersoft.iot.vmp.common;
  2 +
  3 +import com.alibaba.fastjson.annotation.JSONField;
  4 +
  5 +public class VersionPo {
  6 + /**
  7 + * git的全版本号
  8 + */
  9 + @JSONField(name="GIT-Revision")
  10 + private String GIT_Revision;
  11 + /**
  12 + * maven版本
  13 + */
  14 + @JSONField(name = "Create-By")
  15 + private String Create_By;
  16 + /**
  17 + * git的分支
  18 + */
  19 + @JSONField(name = "GIT-BRANCH")
  20 + private String GIT_BRANCH;
  21 + /**
  22 + * git的url
  23 + */
  24 + @JSONField(name = "GIT-URL")
  25 + private String GIT_URL;
  26 + /**
  27 + * 构建日期
  28 + */
  29 + @JSONField(name = "BUILD-DATE")
  30 + private String BUILD_DATE;
  31 + /**
  32 + * 项目名称 配合pom使用
  33 + */
  34 + @JSONField(name = "artifactId")
  35 + private String artifactId;
  36 + /**
  37 + * git局部版本号
  38 + */
  39 + @JSONField(name = "GIT-Revision-SHORT")
  40 + private String GIT_Revision_SHORT;
  41 + /**
  42 + * 项目的版本如2.0.1.0 配合pom使用
  43 + */
  44 + @JSONField(name = "version")
  45 + private String version;
  46 + /**
  47 + * 子系统名称
  48 + */
  49 + @JSONField(name = "project")
  50 + private String project;
  51 + /**
  52 + * jdk版本
  53 + */
  54 + @JSONField(name="Build_Jdk")
  55 + private String Build_Jdk;
  56 +
  57 + public void setGIT_Revision(String GIT_Revision) {
  58 + this.GIT_Revision = GIT_Revision;
  59 + }
  60 +
  61 + public void setCreate_By(String create_By) {
  62 + Create_By = create_By;
  63 + }
  64 +
  65 + public void setGIT_BRANCH(String GIT_BRANCH) {
  66 + this.GIT_BRANCH = GIT_BRANCH;
  67 + }
  68 +
  69 + public void setGIT_URL(String GIT_URL) {
  70 + this.GIT_URL = GIT_URL;
  71 + }
  72 +
  73 + public void setBUILD_DATE(String BUILD_DATE) {
  74 + this.BUILD_DATE = BUILD_DATE;
  75 + }
  76 +
  77 + public void setArtifactId(String artifactId) {
  78 + this.artifactId = artifactId;
  79 + }
  80 +
  81 + public void setGIT_Revision_SHORT(String GIT_Revision_SHORT) {
  82 + this.GIT_Revision_SHORT = GIT_Revision_SHORT;
  83 + }
  84 +
  85 + public void setVersion(String version) {
  86 + this.version = version;
  87 + }
  88 +
  89 + public void setProject(String project) {
  90 + this.project = project;
  91 + }
  92 +
  93 + public void setBuild_Jdk(String build_Jdk) {
  94 + Build_Jdk = build_Jdk;
  95 + }
  96 +
  97 + public String getGIT_Revision() {
  98 + return GIT_Revision;
  99 + }
  100 +
  101 + public String getCreate_By() {
  102 + return Create_By;
  103 + }
  104 +
  105 + public String getGIT_BRANCH() {
  106 + return GIT_BRANCH;
  107 + }
  108 +
  109 + public String getGIT_URL() {
  110 + return GIT_URL;
  111 + }
  112 +
  113 + public String getBUILD_DATE() {
  114 + return BUILD_DATE;
  115 + }
  116 +
  117 + public String getArtifactId() {
  118 + return artifactId;
  119 + }
  120 +
  121 + public String getGIT_Revision_SHORT() {
  122 + return GIT_Revision_SHORT;
  123 + }
  124 +
  125 + public String getVersion() {
  126 + return version;
  127 + }
  128 +
  129 + public String getProject() {
  130 + return project;
  131 + }
  132 +
  133 + public String getBuild_Jdk() {
  134 + return Build_Jdk;
  135 + }
  136 +}
src/main/java/com/genersoft/iot/vmp/conf/ProxyServletConfig.java
@@ -141,8 +141,6 @@ public class ProxyServletConfig { @@ -141,8 +141,6 @@ public class ProxyServletConfig {
141 } 141 }
142 } 142 }
143 143
144 -  
145 -  
146 @Bean 144 @Bean
147 public ServletRegistrationBean recordServletRegistrationBean(){ 145 public ServletRegistrationBean recordServletRegistrationBean(){
148 ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new RecordProxySerlet(),"/record_proxy/*"); 146 ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new RecordProxySerlet(),"/record_proxy/*");
src/main/java/com/genersoft/iot/vmp/conf/VersionConfig.java 0 → 100644
  1 +package com.genersoft.iot.vmp.conf;
  2 +
  3 +import org.springframework.boot.context.properties.ConfigurationProperties;
  4 +import org.springframework.stereotype.Component;
  5 +
  6 +@Component
  7 +@ConfigurationProperties(prefix = "version")
  8 +public class VersionConfig {
  9 +
  10 + private String version;
  11 + private String artifactId;
  12 + private String description;
  13 +
  14 + public void setVersion(String version) {
  15 + this.version = version;
  16 + }
  17 +
  18 + public void setArtifactId(String artifactId) {
  19 + this.artifactId = artifactId;
  20 + }
  21 +
  22 + public void setDescription(String description) {
  23 + this.description = description;
  24 + }
  25 +
  26 + public String getVersion() {
  27 + return version;
  28 + }
  29 +
  30 + public String getArtifactId() {
  31 + return artifactId;
  32 + }
  33 +
  34 + public String getDescription() {
  35 + return description;
  36 + }
  37 +}
src/main/java/com/genersoft/iot/vmp/conf/VersionInfo.java 0 → 100644
  1 +package com.genersoft.iot.vmp.conf;
  2 +
  3 +import com.genersoft.iot.vmp.common.VersionPo;
  4 +import com.genersoft.iot.vmp.utils.GitUtil;
  5 +import com.genersoft.iot.vmp.utils.JarFileUtils;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.stereotype.Component;
  8 +
  9 +import java.util.Map;
  10 +
  11 +@Component
  12 +public class VersionInfo {
  13 +
  14 + @Autowired
  15 + VersionConfig config;
  16 + @Autowired
  17 + GitUtil gitUtil;
  18 + @Autowired
  19 + JarFileUtils jarFileUtils;
  20 +
  21 + public VersionPo getVersion() {
  22 + VersionPo versionPo = new VersionPo();
  23 + Map<String,String> map=jarFileUtils.readJarFile();
  24 + versionPo.setGIT_Revision(gitUtil.getGitCommitId());
  25 + versionPo.setCreate_By(map.get("Created-By"));
  26 + versionPo.setGIT_BRANCH(gitUtil.getBranch());
  27 + versionPo.setGIT_URL(gitUtil.getGitUrl());
  28 + versionPo.setBUILD_DATE(gitUtil.getBuildDate());
  29 + versionPo.setArtifactId(config.getArtifactId());
  30 + versionPo.setGIT_Revision_SHORT(gitUtil.getCommitIdShort());
  31 + versionPo.setVersion(config.getVersion());
  32 + versionPo.setProject(config.getDescription());
  33 + versionPo.setBuild_Jdk(map.get("Build-Jdk"));
  34 +
  35 + return versionPo;
  36 + }
  37 +}
src/main/java/com/genersoft/iot/vmp/utils/GitUtil.java 0 → 100644
  1 +package com.genersoft.iot.vmp.utils;
  2 +
  3 +import org.springframework.beans.factory.annotation.Value;
  4 +import org.springframework.context.annotation.PropertySource;
  5 +import org.springframework.stereotype.Component;
  6 +
  7 +/**
  8 + * 一个优秀的颓废程序猿(CSDN)
  9 + */
  10 +@Component
  11 +@PropertySource(value = {"classpath:git.properties" }, ignoreResourceNotFound = true)
  12 +public class GitUtil {
  13 +
  14 + @Value("${git.branch:null}")
  15 + private String branch;
  16 + @Value("${git.commit.id:null}")
  17 + private String gitCommitId;
  18 + @Value("${git.remote.origin.url:null}")
  19 + private String gitUrl;
  20 + @Value("${git.build.time:null}")
  21 + private String buildDate;
  22 + @Value("${git.commit.id.abbrev:null}")
  23 + private String commitIdShort;
  24 +
  25 + public String getGitCommitId() {
  26 + return gitCommitId;
  27 + }
  28 +
  29 + public String getBranch() {
  30 + return branch;
  31 + }
  32 +
  33 + public String getGitUrl() {
  34 + return gitUrl;
  35 + }
  36 +
  37 + public String getBuildDate() {
  38 + return buildDate;
  39 + }
  40 +
  41 + public String getCommitIdShort() {
  42 + return commitIdShort;
  43 + }
  44 +}
src/main/java/com/genersoft/iot/vmp/utils/JarFileUtils.java 0 → 100644
  1 +package com.genersoft.iot.vmp.utils;
  2 +
  3 +import org.slf4j.Logger;
  4 +import org.slf4j.LoggerFactory;
  5 +import org.springframework.stereotype.Component;
  6 +import org.springframework.util.ClassUtils;
  7 +
  8 +import java.io.BufferedReader;
  9 +import java.io.IOException;
  10 +import java.io.InputStream;
  11 +import java.io.InputStreamReader;
  12 +import java.util.HashMap;
  13 +import java.util.Map;
  14 +import java.util.jar.JarEntry;
  15 +import java.util.jar.JarFile;
  16 +
  17 +/**
  18 + * 一个优秀的颓废程序猿
  19 + */
  20 +@Component
  21 +public class JarFileUtils {
  22 + private static Logger log = LoggerFactory.getLogger(JarFileUtils.class);
  23 + private static Map<String, String> map = new HashMap<>();
  24 +
  25 + public Map<String, String> readJarFile() {
  26 + JarFile jarFile = null;
  27 + BufferedReader br = null;
  28 + try {
  29 + // 获取jar的运行路径,因linux下jar的路径为”file:/app/.../test.jar!/BOOT-INF/class!/“这种格式,所以需要去掉”file:“和”!/BOOT-INF/class!/“
  30 + String jarFilePath = ClassUtils.getDefaultClassLoader().getResource("").getPath().replace("!/BOOT-INF/classes!/", "");
  31 + if (jarFilePath.startsWith("file")) {
  32 + jarFilePath = jarFilePath.substring(5);
  33 + }
  34 + log.debug("jarFilePath:" + jarFilePath);
  35 + // 通过JarFile的getJarEntry方法读取META-INF/MANIFEST.MF
  36 + jarFile = new JarFile(jarFilePath);
  37 + JarEntry entry = jarFile.getJarEntry("META-INF/MANIFEST.MF");
  38 + log.info("读取的内容:" + entry.toString());
  39 + // 如果读取到MANIFEST.MF文件内容,则转换为string
  40 + if (entry != null) {
  41 + InputStream in = jarFile.getInputStream(entry);
  42 +
  43 + StringBuilder sb = new StringBuilder();
  44 + br = new BufferedReader(new InputStreamReader(in));
  45 + String line = "";
  46 + while ((line = br.readLine()) != null) {
  47 + if (line != null && line.contains(":")) {
  48 + int index = line.indexOf(":");
  49 + map.put(line.substring(0, index).trim(), line.substring(index + 1, line.length()).trim());
  50 + }
  51 + }
  52 + return map;
  53 + }
  54 + } catch (IOException e) {
  55 + log.debug("读取MANIFEST.MF文件异常:" + e.getMessage());
  56 + } finally {
  57 + try {
  58 + if (null != br) {
  59 + br.close();
  60 + }
  61 + if (null != jarFile) {
  62 + jarFile.close();
  63 + }
  64 + } catch (IOException e) {
  65 + e.printStackTrace();
  66 + }
  67 + }
  68 +
  69 + return map;
  70 +
  71 + }
  72 +
  73 +}
src/main/java/com/genersoft/iot/vmp/vmanager/server/ServerController.java
1 package com.genersoft.iot.vmp.vmanager.server; 1 package com.genersoft.iot.vmp.vmanager.server;
2 2
3 import com.genersoft.iot.vmp.VManageBootstrap; 3 import com.genersoft.iot.vmp.VManageBootstrap;
  4 +import com.genersoft.iot.vmp.common.VersionPo;
  5 +import com.genersoft.iot.vmp.conf.VersionInfo;
4 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; 6 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
5 import com.genersoft.iot.vmp.service.IMediaServerService; 7 import com.genersoft.iot.vmp.service.IMediaServerService;
6 import com.genersoft.iot.vmp.utils.SpringBeanFactory; 8 import com.genersoft.iot.vmp.utils.SpringBeanFactory;
@@ -31,6 +33,9 @@ public class ServerController { @@ -31,6 +33,9 @@ public class ServerController {
31 @Autowired 33 @Autowired
32 private IMediaServerService mediaServerService; 34 private IMediaServerService mediaServerService;
33 35
  36 + @Autowired
  37 + VersionInfo versionInfo;
  38 +
34 39
35 @ApiOperation("流媒体服务列表") 40 @ApiOperation("流媒体服务列表")
36 @GetMapping(value = "/media_server/list") 41 @GetMapping(value = "/media_server/list")
@@ -97,4 +102,15 @@ public class ServerController { @@ -97,4 +102,15 @@ public class ServerController {
97 restartThread.start(); 102 restartThread.start();
98 return "success"; 103 return "success";
99 } 104 }
  105 +
  106 + @ApiOperation("版本信息")
  107 + @GetMapping(value = "/version")
  108 + @ResponseBody
  109 + public WVPResult<VersionPo> getVersion(){
  110 + WVPResult<VersionPo> result = new WVPResult<>();
  111 + result.setCode(0);
  112 + result.setMsg("success");
  113 + result.setData(versionInfo.getVersion());
  114 + return result;
  115 + }
100 } 116 }