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 afce197cc [Improve] check maven distribution unzip file improvement
afce197cc is described below

commit afce197cc53a084521e96cf486b4d1236847fc0c
Author: benjobs <[email protected]>
AuthorDate: Fri Dec 15 09:30:45 2023 +0800

    [Improve] check maven distribution unzip file improvement
---
 .mvn/wrapper/MavenWrapperHelper.java               | 100 +++++++++++++++------
 mvnw                                               |   4 +-
 .../src/main/assembly/bin/mvnw                     |   4 +-
 .../src/main/assembly/bin/streampark.sh            |   5 --
 4 files changed, 75 insertions(+), 38 deletions(-)

diff --git a/.mvn/wrapper/MavenWrapperHelper.java 
b/.mvn/wrapper/MavenWrapperHelper.java
index 45e1a70f9..9c8ffdfc7 100644
--- a/.mvn/wrapper/MavenWrapperHelper.java
+++ b/.mvn/wrapper/MavenWrapperHelper.java
@@ -24,10 +24,13 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.nio.file.DirectoryStream;
+import java.nio.file.FileVisitResult;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.nio.file.SimpleFileVisitor;
 import java.nio.file.StandardCopyOption;
+import java.nio.file.attribute.BasicFileAttributes;
 import java.security.MessageDigest;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -115,42 +118,59 @@ public final class MavenWrapperHelper {
                 properties = new Properties();
                 properties.load(Files.newInputStream(new 
File(propertiesPath).toPath()));
                 LocalDistribution distribution = 
getLocalDistribution(properties);
-                if (distribution.getZipFile().toFile().exists()) {
+                List<Path> distUnzipDir = 
listDirs(distribution.getDistributionDir());
+
+                if (!distUnzipDir.isEmpty()) {
+                    // 1) check distribution unzip files
+                    String javaCMD = actionArgs[1];
+                    String mvnWrapperHome = actionArgs[2];
+                    String format =
+                        "%s -classpath %s/.mvn/wrapper/maven-wrapper.jar "
+                            + "-Dmaven.multiModuleProjectDirectory=%s "
+                            + "org.apache.maven.wrapper.MavenWrapperMain -h";
+                    String cmd = String.format(format, javaCMD, 
mvnWrapperHome, mvnWrapperHome);
+                    boolean success;
+                    try {
+                        Process process = Runtime.getRuntime().exec(cmd);
+                        success = process.exitValue() == 0;
+                    } catch (Exception e) {
+                        success = false;
+                    }
+                    if (!success) {
+                        try {
+                            for (Path dir : distUnzipDir) {
+                                deleteDir(dir);
+                            }
+                        } catch (Exception e1) {
+                        }
+                        
System.out.println(distribution.getDistributionDir().toFile().getAbsolutePath());
+                        System.exit(1);
+                    }
+                } else if (distribution.getZipFile().toFile().exists()) {
+                    // 1) check distribution zip file
                     String distributionPath = 
distribution.getZipFile().toFile().getAbsolutePath();
-                    List<Path> distDir = 
listDirs(distribution.getDistributionDir());
-                    if (distDir.isEmpty()) {
-                        String distributionMd5 = 
properties.getProperty("distributionMd5");
-                        if (distributionMd5 != null) {
-                            String fileMd5 = getFileMd5(distributionPath);
-                            if (!distributionMd5.equals(fileMd5)) {
-                                boolean success = 
deleteDistribution(distribution);
-                                if (!success) {
-                                    
System.out.println(distribution.getZipFile().toFile().getAbsolutePath());
-                                    System.exit(1);
-                                }
+                    String distributionMd5 = 
properties.getProperty("distributionMd5");
+                    if (distributionMd5 != null) {
+                        String fileMd5 = getFileMd5(distributionPath);
+                        if (!distributionMd5.equals(fileMd5)) {
+                            boolean success = deleteDistribution(distribution);
+                            if (!success) {
+                                
System.out.println(distribution.getZipFile().toFile().getAbsolutePath());
+                                System.exit(1);
                             }
-                        } else {
-                            try (ZipFile ignored = new 
ZipFile(distribution.getZipFile().toFile())) {
-                            } catch (Exception e) {
-                                boolean success = 
deleteDistribution(distribution);
-                                if (!success) {
-                                    
System.out.println(distribution.getZipFile().toFile().getAbsolutePath());
-                                    System.exit(1);
-                                }
+                        }
+                    } else {
+                        try (ZipFile ignored = new 
ZipFile(distribution.getZipFile().toFile())) {
+                        } catch (Exception e) {
+                            boolean success = deleteDistribution(distribution);
+                            if (!success) {
+                                
System.out.println(distribution.getZipFile().toFile().getAbsolutePath());
+                                System.exit(1);
                             }
                         }
                     }
                 }
                 break;
-
-            case "path_dist":
-                propertiesPath = actionArgs[0];
-                properties = new Properties();
-                properties.load(Files.newInputStream(new 
File(propertiesPath).toPath()));
-                distribution = getLocalDistribution(properties);
-                String unzip = 
distribution.getDistributionDir().toFile().getAbsolutePath();
-                System.out.println(unzip);
-                System.exit(0);
             default:
                 System.out.println("Unknown action");
                 System.exit(2);
@@ -290,6 +310,28 @@ public final class MavenWrapperHelper {
         return mavenUserHome == null ? DEFAULT_MAVEN_USER_HOME : 
Paths.get(mavenUserHome);
     }
 
+    private static void deleteDir(Path dirPath) throws IOException {
+        Files.walkFileTree(
+            dirPath,
+            new SimpleFileVisitor<Path>() {
+                @Override
+                public FileVisitResult postVisitDirectory(Path dir, 
IOException exc) throws IOException {
+                    Files.delete(dir);
+                    if (exc != null) {
+                        throw exc;
+                    }
+                    return FileVisitResult.CONTINUE;
+                }
+
+                @Override
+                public FileVisitResult visitFile(Path file, 
BasicFileAttributes attrs)
+                    throws IOException {
+                    Files.delete(file);
+                    return FileVisitResult.CONTINUE;
+                }
+            });
+    }
+
     public static class LocalDistribution {
         private final Path distZip;
 
diff --git a/mvnw b/mvnw
index 368dfcb03..44eb84bf2 100755
--- a/mvnw
+++ b/mvnw
@@ -272,9 +272,9 @@ if [ ! -e "$wrapperJarPath" ]; then
 fi
 
 # check distribution file
-dist_path=`("$JAVA_HOME/bin/java" -cp "$MAVEN_PROJECTBASEDIR/.mvn/wrapper" 
MavenWrapperHelper "verify_dist" "$wrapperProperties")`
+dist_path=`("$JAVA_HOME/bin/java" -cp "$MAVEN_PROJECTBASEDIR/.mvn/wrapper" 
MavenWrapperHelper "verify_dist" "$wrapperProperties" "$JAVACMD" 
"$MAVEN_PROJECTBASEDIR")`
 if [ $? -eq 1 ]; then
-  rm -f $dist_path
+  rm -f $dist_path > /dev/null 2>&1
   echo "WARN: Check $dist_path invalided, forcefully delete the file...."
 fi
 
diff --git 
a/streampark-console/streampark-console-service/src/main/assembly/bin/mvnw 
b/streampark-console/streampark-console-service/src/main/assembly/bin/mvnw
index 368dfcb03..44eb84bf2 100755
--- a/streampark-console/streampark-console-service/src/main/assembly/bin/mvnw
+++ b/streampark-console/streampark-console-service/src/main/assembly/bin/mvnw
@@ -272,9 +272,9 @@ if [ ! -e "$wrapperJarPath" ]; then
 fi
 
 # check distribution file
-dist_path=`("$JAVA_HOME/bin/java" -cp "$MAVEN_PROJECTBASEDIR/.mvn/wrapper" 
MavenWrapperHelper "verify_dist" "$wrapperProperties")`
+dist_path=`("$JAVA_HOME/bin/java" -cp "$MAVEN_PROJECTBASEDIR/.mvn/wrapper" 
MavenWrapperHelper "verify_dist" "$wrapperProperties" "$JAVACMD" 
"$MAVEN_PROJECTBASEDIR")`
 if [ $? -eq 1 ]; then
-  rm -f $dist_path
+  rm -f $dist_path > /dev/null 2>&1
   echo "WARN: Check $dist_path invalided, forcefully delete the file...."
 fi
 
diff --git 
a/streampark-console/streampark-console-service/src/main/assembly/bin/streampark.sh
 
b/streampark-console/streampark-console-service/src/main/assembly/bin/streampark.sh
index 409a1c835..385810028 100755
--- 
a/streampark-console/streampark-console-service/src/main/assembly/bin/streampark.sh
+++ 
b/streampark-console/streampark-console-service/src/main/assembly/bin/streampark.sh
@@ -350,11 +350,6 @@ ready() {
     javaClass=$(cygpath --path --windows "$javaClass")
   fi
   ("$JAVA_HOME/bin/javac" "$javaSource")
-  # get distribution unzip path
-  dist_path=`("$JAVA_HOME/bin/java" -cp "$APP_HOME/bin/.mvn/wrapper" 
MavenWrapperHelper "path_dist" "$wrapperProperties")`
-  if [ $? -eq 0 ]; then
-    rm -f $dist_path > /dev/null 2>&1
-  fi
 }
 
 # shellcheck disable=SC2120

Reply via email to