This is an automated email from the ASF dual-hosted git repository.
kriszu pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git
The following commit(s) were added to refs/heads/dev by this push:
new 5755289c7 [Improve] maven-wrapper downloader improvement (#3214)
5755289c7 is described below
commit 5755289c76bcfb97bf7b5914218ce06300d86229
Author: benjobs <[email protected]>
AuthorDate: Fri Oct 6 22:19:56 2023 -0500
[Improve] maven-wrapper downloader improvement (#3214)
---
.mvn/wrapper/MavenWrapperChecker.java | 39 ---------
.mvn/wrapper/MavenWrapperDownloader.java | 86 -------------------
.mvn/wrapper/MavenWrapperHelper.java | 98 ++++++++++++++++++++++
build.sh | 76 ++++++++---------
mvnw | 10 +--
.../src/main/assembly/bin/mvnw | 10 +--
.../streampark/console/MavenWrapperChecker.java | 41 ---------
7 files changed, 143 insertions(+), 217 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..cad35d8ee 100755
--- a/build.sh
+++ b/build.sh
@@ -22,14 +22,14 @@
have_tty=0
# shellcheck disable=SC2006
if [[ "`tty`" != "not a tty" ]]; then
- have_tty=1
+ have_tty=1
fi
# Bugzilla 37848: When no TTY is available, don't output to console
have_tty=0
# shellcheck disable=SC2006
if [[ "`tty`" != "not a tty" ]]; then
- have_tty=1
+ have_tty=1
fi
# Only use colors if connected to a terminal
@@ -52,24 +52,24 @@ else
fi
echo_r () {
- # Color red: Error, Failed
- [[ $# -ne 1 ]] && return 1
- # shellcheck disable=SC2059
- printf "[%sStreamPark%s] %s$1%s\n" $BLUE $RESET $RED $RESET
+ # Color red: Error, Failed
+ [[ $# -ne 1 ]] && return 1
+ # shellcheck disable=SC2059
+ 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
+ # 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
- # shellcheck disable=SC2059
- printf "[%sStreamPark%s] %s$1%s\n" $BLUE $RESET $GREEN $RESET
+ # Color green: Success
+ [[ $# -ne 1 ]] && return 1
+ # shellcheck disable=SC2059
+ printf "[%sStreamPark%s] %s$1%s\n" $BLUE $RESET $GREEN $RESET
}
# OS specific support. $var _must_ be set to either true or false.
@@ -176,35 +176,29 @@ build() {
echo_g "Apache StreamPark, building..."
"$PRG_DIR/mvnw" -Pshaded,webapp,dist -DskipTests clean install
if [ $? -eq 0 ]; then
- printf '\n'
- echo_g """StreamPark project build successful!
- dist: $(cd "$PRG_DIR" &>/dev/null && pwd)/dist\n"""
+ 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
+ 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
+ fi
fi
+ fi
fi
else
echo_r "permission denied: $PRG_DIR/mvnw, please check."
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/main/assembly/bin/mvnw
b/streampark-console/streampark-console-service/src/main/assembly/bin/mvnw
old mode 100644
new mode 100755
index 66df28542..916dee8a3
--- a/streampark-console/streampark-console-service/src/main/assembly/bin/mvnw
+++ b/streampark-console/streampark-console-service/src/main/assembly/bin/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);
- }
- }
-}