This is an automated email from the ASF dual-hosted git repository.

benjobs pushed a commit to branch dev-2.1.3
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git


The following commit(s) were added to refs/heads/dev-2.1.3 by this push:
     new c51ec156b [Improve] maven build env check improvement
c51ec156b is described below

commit c51ec156b0da000ce8b00714c19ec2dfa5e0f48c
Author: benjobs <[email protected]>
AuthorDate: Mon Dec 18 08:49:17 2023 +0800

    [Improve] maven build env check improvement
---
 .../streampark/console/core/entity/Project.java     | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/entity/Project.java
 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/entity/Project.java
index 316daf87a..ae47d129a 100644
--- 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/entity/Project.java
+++ 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/entity/Project.java
@@ -20,7 +20,6 @@ package org.apache.streampark.console.core.entity;
 import org.apache.streampark.common.conf.CommonConfig;
 import org.apache.streampark.common.conf.InternalConfigHolder;
 import org.apache.streampark.common.conf.Workspace;
-import org.apache.streampark.common.util.CommandUtils;
 import org.apache.streampark.common.util.Utils;
 import org.apache.streampark.console.base.exception.ApiDetailException;
 import org.apache.streampark.console.base.util.CommonUtils;
@@ -194,13 +193,21 @@ public class Project implements Serializable {
     if (mavenHome == null) {
       mavenHome = System.getenv("MAVEN_HOME");
     }
+
+    boolean useWrapper = true;
     if (mavenHome != null) {
       mvn = mavenHome + "/bin/" + mvn;
+      try {
+        Process process = Runtime.getRuntime().exec(mvn + " --version");
+        process.waitFor();
+        Utils.required(process.exitValue() == 0);
+        useWrapper = false;
+      } catch (Exception ignored) {
+        log.warn("try using user-installed maven failed, now use 
maven-wrapper.");
+      }
     }
 
-    try {
-      CommandUtils.execute(mvn + " --version");
-    } catch (Exception e) {
+    if (useWrapper) {
       if (windows) {
         mvn = WebUtils.getAppHome().concat("/bin/mvnw.cmd");
       } else {
@@ -217,7 +224,7 @@ public class Project implements Serializable {
       } else {
         throw new IllegalArgumentException(
             String.format(
-                "Invalid build args, dangerous operation symbol detected: %s, 
in your buildArgs: %s",
+                "Invalid maven argument, dangerous operation symbol detected: 
%s, in your buildArgs: %s",
                 dangerArgs.stream().collect(Collectors.joining(",")), 
this.buildArgs));
       }
     }
@@ -231,12 +238,12 @@ public class Project implements Serializable {
           cmdBuffer.append(" --settings ").append(setting);
         } else {
           throw new IllegalArgumentException(
-              String.format("Invalid maven setting path, %s no exists or not 
file", setting));
+              String.format("Invalid maven-setting file path, %s no exists or 
not file", setting));
         }
       } else {
         throw new IllegalArgumentException(
             String.format(
-                "Invalid maven setting path, dangerous operation symbol 
detected: %s, in your maven setting path: %s",
+                "Invalid maven-setting file path, dangerous operation symbol 
detected: %s, in your maven setting path: %s",
                 dangerArgs.stream().collect(Collectors.joining(",")), 
setting));
       }
     }

Reply via email to