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

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


The following commit(s) were added to refs/heads/dev-2.1.2 by this push:
     new b47463be0 [Improve] build project improvement
b47463be0 is described below

commit b47463be0e7d8ebf5b4eca141071e3d56bbdfbdd
Author: benjobs <[email protected]>
AuthorDate: Thu Oct 19 14:55:39 2023 +0800

    [Improve] build project improvement
---
 .mvn/wrapper/MavenWrapperDownloader.java |  86 --------------------
 .mvn/wrapper/MavenWrapperHelper.java     |  98 +++++++++++++++++++++++
 build.sh                                 | 130 +++++++++++++++----------------
 3 files changed, 162 insertions(+), 152 deletions(-)

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..3772b1d7b
--- /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);
+        }
+    }
+}
\ No newline at end of file
diff --git a/build.sh b/build.sh
index 89e86081d..d04e04887 100755
--- a/build.sh
+++ b/build.sh
@@ -122,14 +122,6 @@ print_logo() {
   printf '      %s   ──────── Apache StreamPark, Make stream processing easier 
ô~ô!%s\n\n'         $PRIMARY  $RESET
 }
 
-checkPerm() {
-  if [ -x "$PRG_DIR/mvnw" ]; then
-    return 0
-  else
-    return 1
-  fi
-}
-
 selectScala() {
   echo_w 'StreamPark supports Scala 2.11 and 2.12. Which version do you need ?'
   select scala in "2.11" "2.12"
@@ -150,12 +142,12 @@ selectScala() {
 }
 
 selectMode() {
-  echo_w 'StreamPark supports front-end and server-side mixed / detached 
packaging mode, Which mode do you need ?'
-  select scala in "mixed mode" "detached mode"
+  echo_w 'StreamPark supports front-end and server-side mixed/detached build 
mode, Which mode do you need ?'
+  select scala in "mixed mode (recommend)" "detached mode"
   do
     case $scala in
-      "mixed mode")
-        echo_g "mixed mode selected (mixed build project of front-end and 
back-ends)"
+      "mixed mode (recommend)")
+        echo_g "mixed mode selected (mixed build project front-end and 
back-ends)"
         return 1
         ;;
       "detached mode")
@@ -170,74 +162,80 @@ selectMode() {
   done
 }
 
+build() {
+  scalaArg=$1
+  modeArg=$2
 
-mixedPackage() {
-  scala="scala-2.11"
-  if [ "$1" == 2 ]; then
-    scala="scala-2.12"
-  fi
-
-  echo_g "build info: package mode @ mixed, $scala, now build starting..."
-
-  "$PRG_DIR/mvnw" -P$scala,shaded,webapp,dist -DskipTests clean install
-
-  if [ $? -eq 0 ]; then
-     printf '\n'
-     echo_g """StreamPark project build successful!
-     info: package mode @ mixed, $scala
-     dist: $(cd "$PRG_DIR" &>/dev/null && pwd)/dist\n"""
-  fi
-}
-
-detachedPackage () {
-  scala="scala-2.11"
-  if [ "$1" == 2 ]; then
+  if [ ! -x "$PRG_DIR/mvnw" ]; then
+    # shellcheck disable=SC2006
+    echo_r "permission denied: $PRG_DIR/mvnw, please check."
+    exit 1
+  else
     scala="scala-2.12"
-  fi
+    if [ $scalaArg == 1 ]; then
+      scala="scala-2.11"
+    fi
 
-  echo_g "build info: package mode @ detached, $scala, now build starting..."
+    profile="-P${scala},shaded,dist"
+    if [ $modeArg == 1 ]; then
+      profile="${profile},webapp"
+      echo_g "build info: package mode @ mixed, $scala, now build starting..."
+    else
+      echo_g "build info: package mode @ detached, $scala, now build 
starting..."
+    fi
 
-  "$PRG_DIR"/mvnw -P$scala,shaded,dist -DskipTests clean install
+    "$PRG_DIR"/mvnw $profile -DskipTests clean install
 
-  if [ $? -eq 0 ]; then
-    printf '\n'
-    echo_g """StreamPark project build successful!
-    info: package mode @ detached, $scala
-    dist: $(cd "$PRG_DIR" &>/dev/null && pwd)/dist
+    if [ $? -eq 0 ]; then
+      if [ $modeArg == 1 ]; then
+        printf '\n'
+        echo_g """StreamPark project build successful!
+        info: package mode @ mixed, $scala
+        dist: $(cd "$PRG_DIR" &>/dev/null && pwd)/dist\n"""
+      else
+        printf '\n'
+        echo_g """StreamPark project build successful!
+        info: package mode @ detached, $scala
+        dist: $(cd "$PRG_DIR" &>/dev/null && pwd)/dist
 
-    Next, you need to build front-end by yourself.
+        Next, you need to build front-end by yourself.
 
-     1) cd $(cd "$PRG_DIR" &>/dev/null && 
pwd)/streampark-console/streampark-console-webapp
-     2) pnpm install && pnpm build
+         1) cd $(cd "$PRG_DIR" &>/dev/null && 
pwd)/streampark-console/streampark-console-webapp
+         2) pnpm install && pnpm build
 
-    please visit: https://streampark.apache.org/docs/user-guide/deployment for 
more detail. \n"""
+        please visit: https://streampark.apache.org/docs/user-guide/deployment 
for more detail. \n"""
+      fi
+    else
+      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
+        javaSource=$(cygpath --path --windows "$javaSource")
+        javaClass=$(cygpath --path --windows "$javaClass")
+      fi
+      if [ -e "$javaSource" ]; then
+        [ ! -e "$javaClass" ] && ("$JAVA_HOME/bin/javac" "$javaSource")
+        if [ -e "$javaClass" ]; then
+          ("$JAVA_HOME/bin/java" -cp "$PRG_DIR/.mvn/wrapper" 
MavenWrapperHelper "verify" "$wrapperJarPath")
+          if [ $? -eq 1 ]; then
+            echo_r "Error: $wrapperJarPath is invalid. retry download it and 
build project again..."
+            rm -f $wrapperJarPath
+            build $scalaArg $modeArg
+          fi
+        fi
+      fi
+    fi
   fi
 }
 
 main() {
   print_logo
-  checkPerm
-  if [ $? -eq 1 ]; then
-    # shellcheck disable=SC2006
-    echo_r "permission denied: $PRG_DIR/mvnw, please check."
-    exit 1
-  fi
   selectMode
-  if [ $? -eq 1 ]; then
-    selectScala
-    if [ $? -eq 1 ]; then
-      mixedPackage 1
-    else
-      mixedPackage 2
-    fi
-  else
-    selectScala
-    if [ $? -eq 1 ]; then
-      detachedPackage 1
-    else
-      detachedPackage 2
-    fi
-  fi
+  mode=$?
+  selectScala
+  scala=$?
+  build $scala $mode
 }
 
 main "$@"

Reply via email to