Переглянути джерело

还原 AppLifecycle 中的 initBuildDir 方法

reghao 1 рік тому
батько
коміт
b238db79a8

+ 27 - 1
web/src/main/java/cn/reghao/bnt/web/config/spring/AppLifecycle.java

@@ -1,6 +1,8 @@
 package cn.reghao.bnt.web.config.spring;
 
 import cn.reghao.bnt.web.account.service.AccountService;
+import cn.reghao.bnt.web.config.AppProperties;
+import cn.reghao.bnt.web.devops.app.service.config.BuildDirService;
 import cn.reghao.bnt.web.devops.machine.service.MachineService;
 import cn.reghao.bnt.web.account.service.RoleService;
 import cn.reghao.bnt.web.devops.app.db.repository.config.build.CompilerConfigRepository;
@@ -36,10 +38,13 @@ public class AppLifecycle implements ApplicationRunner, DisposableBean {
     private final SysMessageRepository sysMessageRepository;
     private final BuildStat buildStat;
     private final MachineService machineService;
+    private BuildDirService buildDirService;
+    private AppProperties appProperties;
 
     public AppLifecycle(LogHandler logHandler, CompilerConfigRepository compilerConfigRepository,
                         RoleService roleService, AccountService accountService, SysMessageRepository sysMessageRepository,
-                        BuildStat buildStat, MachineService machineService) {
+                        BuildStat buildStat, MachineService machineService, BuildDirService buildDirService,
+                        AppProperties appProperties) {
         this.logHandler = logHandler;
         this.compilerConfigRepository = compilerConfigRepository;
         this.roleService = roleService;
@@ -47,6 +52,8 @@ public class AppLifecycle implements ApplicationRunner, DisposableBean {
         this.sysMessageRepository = sysMessageRepository;
         this.buildStat = buildStat;
         this.machineService = machineService;
+        this.buildDirService = buildDirService;
+        this.appProperties = appProperties;
     }
 
     @Override
@@ -65,10 +72,29 @@ public class AppLifecycle implements ApplicationRunner, DisposableBean {
     private void initSys() throws IOException {
         roleService.initRole();
         accountService.initAccount();
+        initBuildDir();
         initLogConfig();
         checkCompilerConfig();
     }
 
+    @Deprecated
+    private void initBuildDir() {
+        String userDir = System.getProperty("user.dir");
+        String baseDir = appProperties.getBaseDir();
+        File dir = new File(baseDir);
+        if (!dir.exists() && !dir.mkdirs()) {
+            log.error("创建本地构建目录 {} 失败,bnt-web 结束运行", baseDir);
+            System.exit(1);
+        } else {
+            try {
+                buildDirService.init(baseDir);
+            } catch (Exception e) {
+                log.error("初始化本地构建目录失败: {},bnt-web 结束运行", e.getMessage());
+                System.exit(1);
+            }
+        }
+    }
+
     private void initLogConfig() {
         String app = "bnt-web";
         String host = "localhost";