Browse Source

删除 git-commit-id-plugin 插件, 因此也不再使用 cn.reghao.jutil.jdk.web.result.AppVersion 读取本地 git.properties 文件中的 git 版本

reghao 4 weeks ago
parent
commit
7632b04e48

+ 0 - 78
agent/pom.xml

@@ -71,84 +71,6 @@
                     </execution>
                     </execution>
                 </executions>
                 </executions>
             </plugin>
             </plugin>
-
-            <!--git-commit-id-plugin 插件,用于实现打包带git版本信息-->
-            <plugin>
-                <groupId>pl.project13.maven</groupId>
-                <artifactId>git-commit-id-plugin</artifactId>
-                <version>2.1.5</version>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>revision</goal>
-                        </goals>
-                    </execution>
-                </executions>
-                <configuration>
-                    <!--日期格式;默认值:dd.MM.yyyy '@' HH:mm:ss z;-->
-                    <dateFormat>yyyy-MM-dd HH:mm:ss</dateFormat>
-                    <!--,构建过程中,是否打印详细信息;默认值:false;-->
-                    <verbose>true</verbose>
-                    <!-- ".git"文件路径;默认值:${project.basedir}/.git;
-                      注意: 如果是多模块(多模块)项目,则需要修改到.git文件夹的目录-->
-                    <dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
-                    <!--若项目打包类型为pom,是否取消构建;默认值:true;-->
-                    <skipPoms>false</skipPoms>
-                    <!--是否生成"git.properties"文件;默认值:false;-->
-                    <generateGitPropertiesFile>true</generateGitPropertiesFile>
-                    <!--指定"git.properties"文件的存放路径(相对于${project.basedir}的一个路径);
-                    注意:该地址决定接口代码是否可以读取到git版本信息,请自行修改-->
-                    <generateGitPropertiesFilename>src/main/resources/git.properties</generateGitPropertiesFilename>
-                    <!--".git"文件夹未找到时,构建是否失败;若设置true,则构建失败;若设置false,则跳过执行该目标;默认值:true;-->
-                    <failOnNoGitDirectory>true</failOnNoGitDirectory>
-                    <!--git描述配置,可选;由JGit提供实现;-->
-                    <gitDescribe>
-                        <!--是否生成描述属性-->
-                        <skip>false</skip>
-                        <!--提交操作未发现tag时,仅打印提交操作ID,-->
-                        <always>false</always>
-                        <!--提交操作ID显式字符长度,最大值为:40;默认值:7;
-                            0代表特殊意义;后面有解释;
-                        -->
-                        <abbrev>8</abbrev>
-                        <!--构建触发时,代码有修改时(即"dirty state"),添加指定后缀;默认值:"";-->
-                        <dirty>-dirty</dirty>
-                        <!--always print using the "tag-commits_from_tag-g_commit_id-maybe_dirty" format, even if "on" a tag.
-                            The distance will always be 0 if you're "on" the tag.
-                        -->
-                        <forceLongFormat>false</forceLongFormat>
-                    </gitDescribe>
-                </configuration>
-            </plugin>
-            <!--apache maven插件,用于执行ant脚本函数-->
-            <plugin>
-                <artifactId>maven-antrun-plugin</artifactId>
-                <version>1.8</version>
-                <executions>
-                    <execution>
-                        <!--maven 插件生命周期,我试过用compile 发现打包以后没有git.properties,因为打包的时候,还没有生成
-                        注意,这里改成 initialize 的话, 上面 git-commit-id-plugin 插件对应也该添加 phase 配置,并设置为 initialize
-                         否则你生成的文件,写入的就不会对应的值,而是变量名-->
-                        <phase>initialize</phase>
-                        <goals>
-                            <goal>run</goal>
-                        </goals>
-                        <configuration>
-                            <tasks>
-                                <echo message="写入 git 版本信息"/>
-                                <!-- concat 常用于把一些信息写入文件,我这里用于把 git-commit-id-plugin 生成的git环境变量写入文件 -->
-                                <concat destfile="src/main/resources/git.properties">
-                                    repo=${git.remote.origin.url}
-                                    branch=${git.branch}
-                                    commitId=${git.commit.id.abbrev}
-                                    commitTime=${git.commit.time}
-                                    buildTime=${git.build.time}
-                                </concat>
-                            </tasks>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
         </plugins>
         </plugins>
     </build>
     </build>
 </project>
 </project>

+ 1 - 2
common/src/main/java/cn/reghao/devops/common/util/Machine.java

@@ -1,7 +1,6 @@
 package cn.reghao.devops.common.util;
 package cn.reghao.devops.common.util;
 
 
 import cn.reghao.devops.common.msg.event.EvtAgentStart;
 import cn.reghao.devops.common.msg.event.EvtAgentStart;
-import cn.reghao.jutil.jdk.web.result.AppVersion;
 import oshi.SystemInfo;
 import oshi.SystemInfo;
 import oshi.hardware.CentralProcessor;
 import oshi.hardware.CentralProcessor;
 import oshi.hardware.GlobalMemory;
 import oshi.hardware.GlobalMemory;
@@ -29,7 +28,7 @@ public class Machine {
     static {
     static {
         ID = getMachineId();
         ID = getMachineId();
         IPV4 = getIpv4Address();
         IPV4 = getIpv4Address();
-        AGENT_VERSION = AppVersion.getVersion().getCommitId();
+        AGENT_VERSION = "12345678";
     }
     }
     static SystemInfo si = new SystemInfo();
     static SystemInfo si = new SystemInfo();
     static HardwareAbstractionLayer hal = si.getHardware();
     static HardwareAbstractionLayer hal = si.getHardware();

+ 0 - 79
mgr/pom.xml

@@ -272,85 +272,6 @@
                     <outputDirectory>${project.build.outputDir}</outputDirectory>
                     <outputDirectory>${project.build.outputDir}</outputDirectory>
                 </configuration>
                 </configuration>
             </plugin>
             </plugin>
-
-            <!--git-commit-id-plugin 插件,用于实现打包带git版本信息-->
-            <plugin>
-                <groupId>pl.project13.maven</groupId>
-                <artifactId>git-commit-id-plugin</artifactId>
-                <version>2.1.5</version>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>revision</goal>
-                        </goals>
-                    </execution>
-                </executions>
-                <configuration>
-                    <!--日期格式;默认值:dd.MM.yyyy '@' HH:mm:ss z;-->
-                    <dateFormat>yyyy-MM-dd HH:mm:ss</dateFormat>
-                    <!--,构建过程中,是否打印详细信息;默认值:false;-->
-                    <verbose>true</verbose>
-                    <!-- ".git"文件路径;默认值:${project.basedir}/.git;
-                      注意: 如果是多模块(多模块)项目,则需要修改到.git文件夹的目录-->
-                    <dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
-                    <!--若项目打包类型为pom,是否取消构建;默认值:true;-->
-                    <skipPoms>false</skipPoms>
-                    <!--是否生成"git.properties"文件;默认值:false;-->
-                    <generateGitPropertiesFile>true</generateGitPropertiesFile>
-                    <!--指定"git.properties"文件的存放路径(相对于${project.basedir}的一个路径);
-                    注意:该地址决定接口代码是否可以读取到git版本信息,请自行修改-->
-                    <generateGitPropertiesFilename>src/main/resources/git.properties</generateGitPropertiesFilename>
-                    <!--".git"文件夹未找到时,构建是否失败;若设置true,则构建失败;若设置false,则跳过执行该目标;默认值:true;-->
-                    <failOnNoGitDirectory>true</failOnNoGitDirectory>
-                    <!--git描述配置,可选;由JGit提供实现;-->
-                    <gitDescribe>
-                        <!--是否生成描述属性-->
-                        <skip>false</skip>
-                        <!--提交操作未发现tag时,仅打印提交操作ID,-->
-                        <always>false</always>
-                        <!--提交操作ID显式字符长度,最大值为:40;默认值:7;
-                            0代表特殊意义;后面有解释;
-                        -->
-                        <abbrev>8</abbrev>
-                        <!--构建触发时,代码有修改时(即"dirty state"),添加指定后缀;默认值:"";-->
-                        <dirty>-dirty</dirty>
-                        <!--always print using the "tag-commits_from_tag-g_commit_id-maybe_dirty" format, even if "on" a tag.
-                            The distance will always be 0 if you're "on" the tag.
-                        -->
-                        <forceLongFormat>false</forceLongFormat>
-                    </gitDescribe>
-                </configuration>
-            </plugin>
-            <!--apache maven插件,用于执行ant脚本函数-->
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-antrun-plugin</artifactId>
-                <version>1.8</version>
-                <executions>
-                    <execution>
-                        <!--maven 插件生命周期,我试过用compile 发现打包以后没有git.properties,因为打包的时候,还没有生成
-                        注意,这里改成 initialize 的话, 上面 git-commit-id-plugin 插件对应也该添加 phase 配置,并设置为 initialize
-                         否则你生成的文件,写入的就不会对应的值,而是变量名-->
-                        <phase>initialize</phase>
-                        <goals>
-                            <goal>run</goal>
-                        </goals>
-                        <configuration>
-                            <tasks>
-                                <echo message="写入 git 版本信息"/>
-                                <!-- concat 常用于把一些信息写入文件,我这里用于把 git-commit-id-plugin 生成的git环境变量写入文件 -->
-                                <concat destfile="src/main/resources/git.properties">
-                                    repo=${git.remote.origin.url}
-                                    branch=${git.branch}
-                                    commitId=${git.commit.id.abbrev}
-                                    commitTime=${git.commit.time}
-                                    buildTime=${git.build.time}
-                                </concat>
-                            </tasks>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
         </plugins>
         </plugins>
     </build>
     </build>
 </project>
 </project>

+ 0 - 65
mgr/src/main/java/cn/reghao/devops/mgr/admin/service/AppVersion.java

@@ -1,65 +0,0 @@
-package cn.reghao.devops.mgr.admin.service;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Serializable;
-import java.util.Properties;
-
-/**
- * @author reghao
- * @date 2022-05-11 22:29:49
- */
-public class AppVersion implements Serializable {
-    private static final long serialVersionUID = 1L;
-
-    private final String repo;
-    private final String branch;
-    private final String commitId;
-    private final String commitTime;
-    private final String buildTime;
-
-    private AppVersion(String repo, String branch, String commitId, String commitTime, String builtTime) {
-        this.repo = repo;
-        this.branch = branch;
-        this.commitId = commitId;
-        this.commitTime = commitTime;
-        this.buildTime = builtTime;
-    }
-
-    public String getRepo() {
-        return repo;
-    }
-
-    public String getBranch() {
-        return branch;
-    }
-
-    public String getCommitId() {
-        return commitId;
-    }
-
-    public String getCommitTime() {
-        return commitTime;
-    }
-
-    public String getBuildTime() {
-        return buildTime;
-    }
-
-    public static AppVersion getVersion() {
-        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-        try {
-            // 读取 src/main/resources 目录下的文件
-            InputStream inputStream = classLoader.getResourceAsStream("git.properties");
-            Properties props = new Properties();
-            props.load(inputStream);String repo = props.get("repo").toString();
-            String branch = props.get("branch").toString();
-            String commitId = props.get("commitId").toString();
-            String commitTime = props.get("commitTime").toString();
-            String buildTime = props.get("buildTime").toString();
-            return new AppVersion(repo, branch, commitId, commitTime, buildTime);
-        } catch (IOException ignore) {
-        }
-        return null;
-    }
-}

+ 0 - 14
mgr/src/main/java/cn/reghao/devops/mgr/admin/service/HomeViewService.java

@@ -20,13 +20,11 @@ import java.util.List;
 @Service
 @Service
 public class HomeViewService {
 public class HomeViewService {
     private final JVM jvm;
     private final JVM jvm;
-    private final AppVersion appVersion;
     private final MachineQuery machineQuery;
     private final MachineQuery machineQuery;
     private final RoleService roleService;
     private final RoleService roleService;
 
 
     public HomeViewService(MachineQuery machineQuery, RoleService roleService) {
     public HomeViewService(MachineQuery machineQuery, RoleService roleService) {
         this.jvm = new JVM();
         this.jvm = new JVM();
-        this.appVersion = AppVersion.getVersion();
         this.machineQuery = machineQuery;
         this.machineQuery = machineQuery;
         this.roleService = roleService;
         this.roleService = roleService;
     }
     }
@@ -72,10 +70,6 @@ public class HomeViewService {
         model.addAttribute("machineStatList", machineStatList);
         model.addAttribute("machineStatList", machineStatList);
 
 
         String commitId = NotAvailable.na.getDesc();
         String commitId = NotAvailable.na.getDesc();
-        if (appVersion != null) {
-            commitId = appVersion.getCommitId();
-        }
-
         JvmInfo jvmInfo = jvm.info();
         JvmInfo jvmInfo = jvm.info();
         //JvmStat jvmStat = jvm.stat();
         //JvmStat jvmStat = jvm.stat();
         String osInfo = String.format("%s %s", jvmInfo.getOsName(), jvmInfo.getOsVersion());
         String osInfo = String.format("%s %s", jvmInfo.getOsName(), jvmInfo.getOsVersion());
@@ -104,10 +98,6 @@ public class HomeViewService {
     public DashboardData getDashboardData() {
     public DashboardData getDashboardData() {
         List<MachineStat> machineStatList = machineQuery.getMachineStats();
         List<MachineStat> machineStatList = machineQuery.getMachineStats();
         String commitId = NotAvailable.na.getDesc();
         String commitId = NotAvailable.na.getDesc();
-        if (appVersion != null) {
-            commitId = appVersion.getCommitId();
-        }
-
         JvmInfo jvmInfo = jvm.info();
         JvmInfo jvmInfo = jvm.info();
         String osInfo = String.format("%s %s", jvmInfo.getOsName(), jvmInfo.getOsVersion());
         String osInfo = String.format("%s %s", jvmInfo.getOsName(), jvmInfo.getOsVersion());
         String jvmInfo1 = String.format("%s %s", jvmInfo.getJvmName(), jvmInfo.getJvmVersion());
         String jvmInfo1 = String.format("%s %s", jvmInfo.getJvmName(), jvmInfo.getJvmVersion());
@@ -123,10 +113,6 @@ public class HomeViewService {
         model.addAttribute("machineStatList", machineStatList);
         model.addAttribute("machineStatList", machineStatList);
 
 
         String commitId = NotAvailable.na.getDesc();
         String commitId = NotAvailable.na.getDesc();
-        if (appVersion != null) {
-            commitId = appVersion.getCommitId();
-        }
-
         JvmInfo jvmInfo = jvm.info();
         JvmInfo jvmInfo = jvm.info();
         //JvmStat jvmStat = jvm.stat();
         //JvmStat jvmStat = jvm.stat();
         String osInfo = String.format("%s %s", jvmInfo.getOsName(), jvmInfo.getOsVersion());
         String osInfo = String.format("%s %s", jvmInfo.getOsName(), jvmInfo.getOsVersion());