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

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

commit 898425b79e2287834c221f194431c0688a1db415
Author: benjobs <[email protected]>
AuthorDate: Fri Oct 6 19:56:09 2023 +0800

    [Improve] maven-wrapper downloader improvement
---
 .mvn/wrapper/MavenWrapperChecker.java              | 39 ---------
 .mvn/wrapper/MavenWrapperDownloader.java           | 86 -------------------
 .mvn/wrapper/MavenWrapperHelper.java               | 98 ++++++++++++++++++++++
 build.sh                                           | 21 ++---
 mvnw                                               | 10 +--
 .../streampark/console/MavenWrapperChecker.java    | 41 ---------
 6 files changed, 112 insertions(+), 183 deletions(-)

diff --git a/.mvn/wrapper/MavenWrapperChecker.java 
b/.mvn/wrapper/MavenWrapperChecker.java
deleted file mode 100644
index 70c98524e..000000000
--- a/.mvn/wrapper/MavenWrapperChecker.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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/.mvn/wrapper/MavenWrapperDownloader.java 
b/.mvn/wrapper/MavenWrapperDownloader.java
deleted file mode 100644
index 3d765bee0..000000000
--- a/.mvn/wrapper/MavenWrapperDownloader.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * 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.io.IOException;
-import java.io.InputStream;
-import java.net.Authenticator;
-import java.net.PasswordAuthentication;
-import java.net.URL;
-import java.nio.file.Files;
-import java.nio.file.LinkOption;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.nio.file.StandardCopyOption;
-import java.nio.file.StandardOpenOption;
-import java.util.Properties;
-
-public final class MavenWrapperDownloader {
-
-    private static final String WRAPPER_VERSION = "3.2.0";
-
-    private static final boolean VERBOSE = 
Boolean.parseBoolean(System.getenv("MVNW_VERBOSE"));
-
-    public static void main(String[] args) {
-        log("Apache Maven Wrapper Downloader " + WRAPPER_VERSION);
-
-        if (args.length != 2) {
-            System.err.println(" - ERROR wrapperUrl or wrapperJarPath 
parameter missing");
-            System.exit(1);
-        }
-
-        try {
-            log(" - Downloader started");
-            final URL wrapperUrl = new URL(args[0]);
-            final String jarPath = args[1].replace("..", ""); // Sanitize path
-            final Path wrapperJarPath = 
Paths.get(jarPath).toAbsolutePath().normalize();
-            downloadFileFromURL(wrapperUrl, wrapperJarPath);
-            log("Done");
-        } catch (IOException e) {
-            System.err.println("- Error downloading: " + e.getMessage());
-            if (VERBOSE) {
-                e.printStackTrace();
-            }
-            System.exit(1);
-        }
-    }
-
-    private static void downloadFileFromURL(URL wrapperUrl, Path 
wrapperJarPath)
-        throws IOException {
-        log(" - Downloading to: " + wrapperJarPath);
-        if (System.getenv("MVNW_USERNAME") != null && 
System.getenv("MVNW_PASSWORD") != null) {
-            final String username = System.getenv("MVNW_USERNAME");
-            final char[] password = 
System.getenv("MVNW_PASSWORD").toCharArray();
-            Authenticator.setDefault(new Authenticator() {
-                @Override
-                protected PasswordAuthentication getPasswordAuthentication() {
-                    return new PasswordAuthentication(username, password);
-                }
-            });
-        }
-        try (InputStream inStream = wrapperUrl.openStream()) {
-            Files.copy(inStream, wrapperJarPath, 
StandardCopyOption.REPLACE_EXISTING);
-        }
-        log(" - Downloader complete");
-    }
-
-    private static void log(String msg) {
-        if (VERBOSE) {
-            System.out.println(msg);
-        }
-    }
-
-}
diff --git a/.mvn/wrapper/MavenWrapperHelper.java 
b/.mvn/wrapper/MavenWrapperHelper.java
new file mode 100644
index 000000000..da55d396e
--- /dev/null
+++ b/.mvn/wrapper/MavenWrapperHelper.java
@@ -0,0 +1,98 @@
+/*
+ * 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.io.IOException;
+import java.io.InputStream;
+import java.net.Authenticator;
+import java.net.PasswordAuthentication;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.Arrays;
+import java.util.jar.JarFile;
+
+public final class MavenWrapperHelper {
+
+  private static final String WRAPPER_VERSION = "3.2.0";
+
+  private static final boolean VERBOSE = 
Boolean.parseBoolean(System.getenv("MVNW_VERBOSE"));
+
+  public static void main(String[] args) {
+    String action = args[0].toLowerCase();
+    String[] actionArgs = Arrays.copyOfRange(args, 1, args.length);
+    switch (action) {
+      case "download":
+        log("Apache Maven Wrapper Downloader " + WRAPPER_VERSION);
+        if (actionArgs.length != 2) {
+          System.err.println(" - ERROR wrapperUrl or wrapperJarPath parameter 
missing");
+          System.exit(1);
+        }
+        try {
+          log(" - Downloader started");
+          final URL wrapperUrl = new URL(actionArgs[0]);
+          final String jarPath = actionArgs[1].replace("src/main", ""); // 
Sanitize path
+          final Path wrapperJarPath = 
Paths.get(jarPath).toAbsolutePath().normalize();
+          downloadFileFromURL(wrapperUrl, wrapperJarPath);
+          log("Done");
+        } catch (IOException e) {
+          System.err.println("- Error downloading: " + e.getMessage());
+          if (VERBOSE) {
+            e.printStackTrace();
+          }
+          System.exit(1);
+        }
+        break;
+      case "verify":
+        String wrapperJar = actionArgs[0];
+        log("maven-wrapper file checking: " + wrapperJar);
+        try (JarFile ignored = new JarFile(wrapperJar, true)) {
+          System.exit(0);
+        } catch (Exception e) {
+          System.exit(1);
+        }
+      default:
+        throw new UnsupportedOperationException("Unknown action \"" + action + 
"\".");
+    }
+  }
+
+  private static void downloadFileFromURL(URL wrapperUrl, Path wrapperJarPath) 
throws IOException {
+    log(" - Downloading to: " + wrapperJarPath);
+    if (System.getenv("MVNW_USERNAME") != null && 
System.getenv("MVNW_PASSWORD") != null) {
+      final String username = System.getenv("MVNW_USERNAME");
+      final char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
+      Authenticator.setDefault(
+          new Authenticator() {
+            @Override
+            protected PasswordAuthentication getPasswordAuthentication() {
+              return new PasswordAuthentication(username, password);
+            }
+          });
+    }
+    try (InputStream inStream = wrapperUrl.openStream()) {
+      Files.copy(inStream, wrapperJarPath, 
StandardCopyOption.REPLACE_EXISTING);
+    }
+    log(" - Downloader complete");
+  }
+
+  private static void log(String msg) {
+    if (VERBOSE) {
+      System.out.println(msg);
+    }
+  }
+}
diff --git a/build.sh b/build.sh
index ba6859443..baf384cee 100755
--- a/build.sh
+++ b/build.sh
@@ -180,9 +180,8 @@ build() {
        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"
+        javaSource="$PRG_DIR/.mvn/wrapper/MavenWrapperHelper.java"
+        javaClass="$PRG_DIR/.mvn/wrapper/MavenWrapperHelper.class"
         wrapperJarPath="$PRG_DIR/.mvn/wrapper/maven-wrapper.jar"
         # For Cygwin, switch paths to Windows format before running javac
         if $cygwin; then
@@ -190,17 +189,15 @@ build() {
           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
+            [ ! -e "$javaClass" ] && ("$JAVA_HOME/bin/javac" "$javaSource")
             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..."
+                echo_g "Check maven-wrapper starting..."
+                ("$JAVA_HOME/bin/java" -cp "$PRG_DIR/.mvn/wrapper" 
MavenWrapperHelper "verify" "$wrapperJarPath")
+                if [ $? -eq 0 ]; then
+                  echo_r ""
+                else
+                  echo_y "Error: $wrapperJarPath is invalid. retry download it 
and build project again..."
                   rm -f $wrapperJarPath
-                  echo_y " build project again..."
                   build
                 fi
             fi
diff --git a/mvnw b/mvnw
index 66df28542..916dee8a3 100755
--- a/mvnw
+++ b/mvnw
@@ -228,8 +228,8 @@ else
         fi
     else
         log "Falling back to using Java to download"
-        
javaSource="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.java"
-        
javaClass="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.class"
+        javaSource="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperHelper.java"
+        javaClass="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperHelper.class"
         # For Cygwin, switch paths to Windows format before running javac
         if $cygwin; then
           javaSource=$(cygpath --path --windows "$javaSource")
@@ -237,12 +237,12 @@ else
         fi
         if [ -e "$javaSource" ]; then
             if [ ! -e "$javaClass" ]; then
-                log " - Compiling MavenWrapperDownloader.java ..."
+                log " - Compiling MavenWrapperHelper.java ..."
                 ("$JAVA_HOME/bin/javac" "$javaSource")
             fi
             if [ -e "$javaClass" ]; then
-                log " - Running MavenWrapperDownloader.java ..."
-                ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader 
"$wrapperUrl" "$wrapperJarPath") || rm -f "$wrapperJarPath"
+                log " - Running MavenWrapperHelper.java ..."
+                ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperHelper 
"download" "$wrapperUrl" "$wrapperJarPath") || rm -f "$wrapperJarPath"
             fi
         fi
     fi
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
deleted file mode 100644
index 5496e7799..000000000
--- 
a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/MavenWrapperChecker.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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