From cfb99b6105e066ef5fafc4dd9940a19b29deb093 Mon Sep 17 00:00:00 2001 From: Zzm0809 <934230207@qq.com> Date: Sat, 9 Mar 2024 23:49:01 +0800 Subject: [PATCH] [Optimization]Optimize the environment check of git project build (#3265) --- .../main/java/org/dinky/sse/git/HeadStepSse.java | 3 ++- .../src/main/java/org/dinky/utils/MavenUtil.java | 15 +++++++-------- .../main/java/org/dinky/data/enums/Status.java | 1 + .../main/resources/i18n/messages_en_US.properties | 1 + .../main/resources/i18n/messages_zh_CN.properties | 1 + 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/dinky-admin/src/main/java/org/dinky/sse/git/HeadStepSse.java b/dinky-admin/src/main/java/org/dinky/sse/git/HeadStepSse.java index 3db7dae401..0151db05c3 100644 --- a/dinky-admin/src/main/java/org/dinky/sse/git/HeadStepSse.java +++ b/dinky-admin/src/main/java/org/dinky/sse/git/HeadStepSse.java @@ -19,6 +19,7 @@ package org.dinky.sse.git; +import org.dinky.data.enums.Status; import org.dinky.data.model.GitProject; import org.dinky.sse.StepSse; import org.dinky.utils.MavenUtil; @@ -67,7 +68,7 @@ private void checkJava() { String mavenHome = MavenUtil.getMavenHome(); if (StrUtil.isBlank(mavenHome)) { - addFileMsg("Please set the environment variable:MAVEN_HOME"); + addFileMsg(Status.GIT_MAVEN_HOME_NOT_SET.getMessage()); setFinish(false); } String mavenVersionMsg = MavenUtil.getMavenVersion(); diff --git a/dinky-admin/src/main/java/org/dinky/utils/MavenUtil.java b/dinky-admin/src/main/java/org/dinky/utils/MavenUtil.java index 9dd5023c6e..3302f0fbfb 100644 --- a/dinky-admin/src/main/java/org/dinky/utils/MavenUtil.java +++ b/dinky-admin/src/main/java/org/dinky/utils/MavenUtil.java @@ -19,6 +19,8 @@ package org.dinky.utils; +import org.dinky.data.enums.Status; +import org.dinky.data.exception.BusException; import org.dinky.data.exception.DinkyException; import org.dinky.data.model.SystemConfiguration; import org.dinky.function.constant.PathConstant; @@ -181,11 +183,8 @@ public static String getMavenVersion() { public static String getMavenHome() { String mavenHome = SystemUtil.get("MAVEN_HOME"); if (StrUtil.isNotBlank(mavenHome)) { - return mavenHome; - } - String searchCmd = SystemUtil.getOsInfo().isWindows() ? "where" : "which"; - mavenHome = RuntimeUtil.execForStr(searchCmd + " " + EXECTOR).trim(); - if (StrUtil.isNotBlank(mavenHome)) { + String searchCmd = SystemUtil.getOsInfo().isWindows() ? "where" : "which"; + mavenHome = RuntimeUtil.execForStr(searchCmd + " " + EXECTOR).trim(); try { return new File(mavenHome) .toPath() @@ -194,11 +193,11 @@ public static String getMavenHome() { .getParent() .toString(); } catch (IOException e) { - e.printStackTrace(); - return null; + throw new RuntimeException(e); } + } else { + throw new BusException(Status.GIT_MAVEN_HOME_NOT_SET); } - return null; } public static List getJars(File pom) { diff --git a/dinky-common/src/main/java/org/dinky/data/enums/Status.java b/dinky-common/src/main/java/org/dinky/data/enums/Status.java index 4423963f2f..26933fffb5 100644 --- a/dinky-common/src/main/java/org/dinky/data/enums/Status.java +++ b/dinky-common/src/main/java/org/dinky/data/enums/Status.java @@ -232,6 +232,7 @@ public enum Status { GIT_BRANCH_NOT_FOUND(16003, "git.branch.not.found"), GIT_BUILDING(16004, "git.building"), GIT_BUILD_SUCCESS(16005, "git.build.success"), + GIT_MAVEN_HOME_NOT_SET(16006, "git.maven.home.not.set"), /** * dolphin scheduler diff --git a/dinky-common/src/main/resources/i18n/messages_en_US.properties b/dinky-common/src/main/resources/i18n/messages_en_US.properties index afe031668c..60b21f193e 100644 --- a/dinky-common/src/main/resources/i18n/messages_en_US.properties +++ b/dinky-common/src/main/resources/i18n/messages_en_US.properties @@ -13,6 +13,7 @@ schedule.status.unknown=Unknown Status: {0} user.binding.role.delete.all=User Binding Role Delete All modify.failed=Update Failed git.build.success=Pre-update status success, start executing the build process +git.maven.home.not.set=Maven Home Not Set, Please Set MAVEN_HOME Environment Variable First menu.has.child=Menu Has Child, Can Not Delete tenant.already.exists=Tenant Already Exists save.failed=Save Failed diff --git a/dinky-common/src/main/resources/i18n/messages_zh_CN.properties b/dinky-common/src/main/resources/i18n/messages_zh_CN.properties index 89da9de646..da50d559a5 100644 --- a/dinky-common/src/main/resources/i18n/messages_zh_CN.properties +++ b/dinky-common/src/main/resources/i18n/messages_zh_CN.properties @@ -13,6 +13,7 @@ schedule.status.unknown=未知状态: {0} user.binding.role.delete.all=用户绑定角色删除所有 modify.failed=修改失败 git.build.success=预更新状态成功,开始执行构建流程 +git.maven.home.not.set=未设置 Maven Home,请先设置 MAVEN_HOME 环境变量 menu.has.child=存在子菜单 不允许删除 tenant.already.exists=租户已存在 save.failed=保存失败