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

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


The following commit(s) were added to refs/heads/maven-wrapper by this push:
     new e3844e3d7 maven-wrapper improvement
e3844e3d7 is described below

commit e3844e3d7ff0a42fa5fa81ce8979f7d931553290
Author: benjobs <[email protected]>
AuthorDate: Fri Oct 6 17:27:10 2023 +0800

    maven-wrapper improvement
---
 .mvn/wrapper/MavenWrapperChecker.java              |  39 ++++++++
 build.sh                                           | 101 +++++++++++++++++++--
 .../streampark/console/core/entity/Project.java    |  10 ++
 .../streampark/console/MavenWrapperChecker.java    |  41 +++++++++
 4 files changed, 185 insertions(+), 6 deletions(-)

diff --git a/.mvn/wrapper/MavenWrapperChecker.java 
b/.mvn/wrapper/MavenWrapperChecker.java
new file mode 100644
index 000000000..70c98524e
--- /dev/null
+++ b/.mvn/wrapper/MavenWrapperChecker.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.jar.JarFile;
+import java.util.zip.ZipException;
+public class MavenWrapperChecker {
+
+    private static final boolean VERBOSE = 
Boolean.parseBoolean(System.getenv("MVNW_VERBOSE"));
+
+    public static void main(String[] args) {
+        String wrapperJar = args[0];
+        log("maven-wrapper file checking: " + wrapperJar);
+        try(JarFile ignored = new JarFile(wrapperJar, true)) {
+            System.exit(0);
+        } catch (Exception e) {
+            System.exit(1);
+        }
+    }
+    private static void log(String msg) {
+        if (VERBOSE) {
+            System.out.println(msg);
+        }
+    }
+
+}
diff --git a/build.sh b/build.sh
index fbdf66e8b..ba6859443 100755
--- a/build.sh
+++ b/build.sh
@@ -58,6 +58,13 @@ echo_r () {
     printf "[%sStreamPark%s] %s$1%s\n"  $BLUE $RESET $RED $RESET
 }
 
+echo_y () {
+    # Color yellow: Warning
+    [[ $# -ne 1 ]] && return 1
+    # shellcheck disable=SC2059
+    printf "[%sStreamPark%s] %s$1%s\n"  $BLUE $RESET $YELLOW $RESET
+}
+
 echo_g () {
     # Color green: Success
     [[ $# -ne 1 ]] && return 1
@@ -66,14 +73,69 @@ echo_g () {
 }
 
 # OS specific support.  $var _must_ be set to either true or false.
-cygwin=false
-os400=false
-# shellcheck disable=SC2006
-case "`uname`" in
-CYGWIN*) cygwin=true;;
-OS400*) os400=true;;
+cygwin=false;
+darwin=false;
+mingw=false
+case "$(uname)" in
+  CYGWIN*) cygwin=true ;;
+  MINGW*) mingw=true;;
+  Darwin*) darwin=true
+    # Use /usr/libexec/java_home if available, otherwise fall back to 
/Library/Java/Home
+    # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
+    if [ -z "$JAVA_HOME" ]; then
+      if [ -x "/usr/libexec/java_home" ]; then
+        JAVA_HOME="$(/usr/libexec/java_home)"; export JAVA_HOME
+      else
+        JAVA_HOME="/Library/Java/Home"; export JAVA_HOME
+      fi
+    fi
+    ;;
 esac
 
+if [ -z "$JAVA_HOME" ] ; then
+  if [ -r /etc/gentoo-release ] ; then
+    JAVA_HOME=$(java-config --jre-home)
+  fi
+fi
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched
+if $cygwin ; then
+  [ -n "$JAVA_HOME" ] &&
+    JAVA_HOME=$(cygpath --unix "$JAVA_HOME")
+  [ -n "$CLASSPATH" ] &&
+    CLASSPATH=$(cygpath --path --unix "$CLASSPATH")
+fi
+
+# For Mingw, ensure paths are in UNIX format before anything is touched
+if $mingw ; then
+  [ -n "$JAVA_HOME" ] && [ -d "$JAVA_HOME" ] &&
+    JAVA_HOME="$(cd "$JAVA_HOME" || (echo "cannot cd into $JAVA_HOME."; exit 
1); pwd)"
+fi
+
+if [ -z "$JAVA_HOME" ]; then
+  javaExecutable="$(which javac)"
+  if [ -n "$javaExecutable" ] && ! [ "$(expr "\"$javaExecutable\"" : '\([^ 
]*\)')" = "no" ]; then
+    # readlink(1) is not available as standard on Solaris 10.
+    readLink=$(which readlink)
+    if [ ! "$(expr "$readLink" : '\([^ ]*\)')" = "no" ]; then
+      if $darwin ; then
+        javaHome="$(dirname "\"$javaExecutable\"")"
+        javaExecutable="$(cd "\"$javaHome\"" && pwd -P)/javac"
+      else
+        javaExecutable="$(readlink -f "\"$javaExecutable\"")"
+      fi
+      javaHome="$(dirname "\"$javaExecutable\"")"
+      javaHome=$(expr "$javaHome" : '\(.*\)/bin')
+      JAVA_HOME="$javaHome"
+      export JAVA_HOME
+    fi
+  fi
+fi
+
+if [ -z "$JAVA_HOME" ] ; then
+  echo "Warning: JAVA_HOME environment variable is not set."
+fi
+
 # resolve links - $0 may be a softlink
 PRG="$0"
 
@@ -90,6 +152,7 @@ while [[ -h "$PRG" ]]; do
   fi
 done
 
+
 # Get standard environment variables
 # shellcheck disable=SC2006
 PRG_DIR=`dirname "$PRG"`
@@ -116,6 +179,32 @@ build() {
        printf '\n'
        echo_g """StreamPark project build successful!
        dist: $(cd "$PRG_DIR" &>/dev/null && pwd)/dist\n"""
+    else
+        echo_g "Check maven-wrapper starting..."
+        javaSource="$PRG_DIR/.mvn/wrapper/MavenWrapperChecker.java"
+        javaClass="$PRG_DIR/.mvn/wrapper/MavenWrapperChecker.class"
+        wrapperJarPath="$PRG_DIR/.mvn/wrapper/maven-wrapper.jar"
+        # For Cygwin, switch paths to Windows format before running javac
+        if $cygwin; then
+          javaSource=$(cygpath --path --windows "$javaSource")
+          javaClass=$(cygpath --path --windows "$javaClass")
+        fi
+        if [ -e "$javaSource" ]; then
+            if [ ! -e "$javaClass" ]; then
+                echo_g " - Compiling MavenWrapperChecker.java ..."
+                ("$JAVA_HOME/bin/javac" "$javaSource")
+            fi
+            if [ -e "$javaClass" ]; then
+                echo_y " - Running MavenWrapperChecker.java ..."
+                "$JAVA_HOME/bin/java" -cp "$PRG_DIR/.mvn/wrapper" 
MavenWrapperChecker "$wrapperJarPath"
+                if [ $? -eq 1 ]; then
+                  echo_y " $wrapperJarPath is invalid. now remove 
maven-wrapper..."
+                  rm -f $wrapperJarPath
+                  echo_y " build project again..."
+                  build
+                fi
+            fi
+        fi
     fi
   else
     echo_r "permission denied: $PRG_DIR/mvnw, please check."
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 ffc0175ff..ec201a65a 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
@@ -45,6 +45,7 @@ import java.io.IOException;
 import java.io.Serializable;
 import java.util.Date;
 import java.util.List;
+import java.util.jar.JarFile;
 
 @Slf4j
 @Data
@@ -193,6 +194,15 @@ public class Project implements Serializable {
         CommandUtils.execute("mvn --version");
       }
     } catch (Exception e) {
+      File wrapperJar = new 
File(WebUtils.getAppHome().concat("/.mvn/wrapper/maven-wrapper.jar"));
+      if (wrapperJar.exists()) {
+        try {
+          JarFile jarFile = new JarFile(wrapperJar, true);
+          jarFile.close();
+        } catch (Exception ignored) {
+          FileUtils.deleteQuietly(wrapperJar);
+        }
+      }
       if (windows) {
         mvn = WebUtils.getAppHome().concat("/bin/mvnw.cmd");
       } else {
diff --git 
a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/MavenWrapperChecker.java
 
b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/MavenWrapperChecker.java
new file mode 100644
index 000000000..5496e7799
--- /dev/null
+++ 
b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/MavenWrapperChecker.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.streampark.console;
+
+import java.util.jar.JarFile;
+
+public class MavenWrapperChecker {
+
+  private static final boolean VERBOSE = 
Boolean.parseBoolean(System.getenv("MVNW_VERBOSE"));
+
+  public static void main(String[] args) {
+    String wrapperJar = args[0];
+    log("maven-wrapper file checking: " + wrapperJar);
+    try (JarFile ignored = new JarFile(wrapperJar, true)) {
+      System.exit(0);
+    } catch (Exception e) {
+      System.exit(1);
+    }
+  }
+
+  private static void log(String msg) {
+    if (VERBOSE) {
+      System.out.println(msg);
+    }
+  }
+}

Reply via email to