You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampark.apache.org by be...@apache.org on 2023/12/14 10:29:35 UTC
(incubator-streampark) branch maven_wrapper_improve created (now 6a6a2da3f)
This is an automated email from the ASF dual-hosted git repository.
benjobs pushed a change to branch maven_wrapper_improve
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git
at 6a6a2da3f [Improve] check maven-wrapper improvement
This branch includes the following new commits:
new 6a6a2da3f [Improve] check maven-wrapper improvement
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(incubator-streampark) 01/01: [Improve] check maven-wrapper improvement
Posted by be...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
benjobs pushed a commit to branch maven_wrapper_improve
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git
commit 6a6a2da3f30dac6858622ebcef2dc99e68ce8c04
Author: benjobs <be...@gmail.com>
AuthorDate: Thu Dec 14 18:29:23 2023 +0800
[Improve] check maven-wrapper improvement
---
.mvn/wrapper/MavenWrapperHelper.java | 177 ++++++++++++++++++++-
.mvn/wrapper/maven-wrapper.properties | 1 +
mvnw | 12 +-
.../src/main/assembly/bin/mvnw | 12 +-
.../src/main/assembly/bin/streampark.sh | 13 +-
5 files changed, 207 insertions(+), 8 deletions(-)
diff --git a/.mvn/wrapper/MavenWrapperHelper.java b/.mvn/wrapper/MavenWrapperHelper.java
index 428fa81ff..d2385b441 100644
--- a/.mvn/wrapper/MavenWrapperHelper.java
+++ b/.mvn/wrapper/MavenWrapperHelper.java
@@ -21,24 +21,54 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
+import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.security.MessageDigest;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import java.util.Properties;
+import java.util.zip.ZipFile;
public final class MavenWrapperHelper {
+ public static final String MVNW_VERBOSE = "MVNW_VERBOSE";
+
+ public static final String PROJECT_STRING = "PROJECT";
+
private static final String WRAPPER_VERSION = "3.2.0";
+ public static final String DISTRIBUTION_BASE_PROPERTY = "distributionBase";
+
+ public static final String DISTRIBUTION_PATH_PROPERTY = "distributionPath";
+
+ public static final String MAVEN_USER_HOME_ENV_KEY = "MAVEN_USER_HOME";
+
+ public static final String MAVEN_USER_HOME_STRING = "MAVEN_USER_HOME";
+
+ public static final String MAVEN_USER_HOME_PROPERTY_KEY = "maven.user.home";
+
+ public static final String ZIP_STORE_BASE_PROPERTY = "zipStoreBase";
+
+ public static final String ZIP_STORE_PATH_PROPERTY = "zipStorePath";
+
+ public static final Path DEFAULT_DISTRIBUTION_PATH = Paths.get("wrapper", "dists");
+
+ private static final Path DEFAULT_MAVEN_USER_HOME =
+ Paths.get(System.getProperty("user.home")).resolve(".m2");
+
private static final boolean VERBOSE = Boolean.parseBoolean(System.getenv("MVNW_VERBOSE"));
public static void main(String[] args) throws Exception {
String action = args[0].toLowerCase();
String[] actionArgs = Arrays.copyOfRange(args, 1, args.length);
+
switch (action) {
case "download":
log("Apache Maven Wrapper Downloader " + WRAPPER_VERSION);
@@ -61,12 +91,13 @@ public final class MavenWrapperHelper {
System.exit(1);
}
break;
- case "verify":
+
+ case "verify_wrapper":
String wrapperJar = actionArgs[0];
String propertiesPath = actionArgs[1];
- log("maven-wrapper file checking: " + wrapperJar);
Properties properties = new Properties();
properties.load(Files.newInputStream(new File(propertiesPath).toPath()));
+
String wrapperMd5 = properties.getProperty("wrapperMd5");
if (wrapperMd5 == null) {
System.err.println("wrapperMd5 not in " + propertiesPath);
@@ -74,11 +105,84 @@ public final class MavenWrapperHelper {
}
String fileMd5 = getFileMd5(wrapperJar);
System.exit(wrapperMd5.equals(fileMd5) ? 0 : 1);
+
+ case "verify_dist":
+ propertiesPath = actionArgs[0];
+ properties = new Properties();
+ properties.load(Files.newInputStream(new File(propertiesPath).toPath()));
+ LocalDistribution distribution = getLocalDistribution(properties);
+ if (distribution.getZipFile().toFile().exists()) {
+ String distributionPath = distribution.getZipFile().toFile().getAbsolutePath();
+ List<Path> distDir = listDirs(distribution.getDistributionDir());
+ if (distDir.isEmpty()) {
+ String distributionMd5 = properties.getProperty("distributionMd5");
+ if (distributionMd5 != null) {
+ fileMd5 = getFileMd5(distributionPath);
+ if (!distributionMd5.equals(fileMd5)) {
+ int exit = deleteDistribution(distribution);
+ System.out.println(distribution.getZipFile().toFile().getAbsolutePath());
+ System.exit(exit);
+ }
+ } else {
+ try {
+ ZipFile zipFile = new ZipFile(distribution.getZipFile().toFile());
+ zipFile.close();
+ } catch (Exception e) {
+ int exit = deleteDistribution(distribution);
+ System.out.println(distribution.getZipFile().toFile().getAbsolutePath());
+ System.exit(exit);
+ }
+ }
+ }
+ }
+ System.exit(0);
default:
throw new UnsupportedOperationException("Unknown action \"" + action + "\".");
}
}
+ private static int deleteDistribution(LocalDistribution distribution) {
+ String distPath = distribution.getZipFile().toFile().getAbsolutePath();
+ String unzipPath = distribution.getDistributionDir().toFile().getAbsolutePath();
+ System.err.println("- check distribution error: " + distPath + "is invalid");
+ try {
+ distribution.getZipFile().toFile().delete();
+ return 0;
+ } catch (Exception e) {
+ System.err.println("- delete distribution error: " + distPath);
+ return 1;
+ }
+ }
+
+ private static LocalDistribution getLocalDistribution(Properties properties)
+ throws URISyntaxException {
+ String distributionUrl = properties.getProperty("distributionUrl");
+ URI uri = new URI(distributionUrl);
+ String baseName = getBaseName(uri);
+ String distName = removeExtension(baseName);
+ Path rootDirName = rootDirName(distName, uri);
+
+ String distributionBase =
+ properties.getProperty(DISTRIBUTION_BASE_PROPERTY, MAVEN_USER_HOME_STRING);
+
+ Path distributionPath =
+ Paths.get(
+ properties.getProperty(
+ DISTRIBUTION_PATH_PROPERTY, DEFAULT_DISTRIBUTION_PATH.toString()));
+
+ String zipBase = properties.getProperty(ZIP_STORE_BASE_PROPERTY, MAVEN_USER_HOME_STRING);
+
+ Path zipPath =
+ Paths.get(
+ properties.getProperty(ZIP_STORE_PATH_PROPERTY, DEFAULT_DISTRIBUTION_PATH.toString()));
+
+ Path distDir = getBaseDir(distributionBase).resolve(distributionPath).resolve(rootDirName);
+
+ Path distZip = getBaseDir(zipBase).resolve(zipPath).resolve(rootDirName).resolve(baseName);
+
+ return new LocalDistribution(distDir, distZip);
+ }
+
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) {
@@ -120,4 +224,73 @@ public final class MavenWrapperHelper {
System.out.println(msg);
}
}
+
+ private static String getBaseName(URI uri) {
+ return Paths.get(uri.getPath()).getFileName().toString();
+ }
+
+ private static String removeExtension(String name) {
+ int dot = name.lastIndexOf(".");
+ return dot > 0 ? name.substring(0, dot) : name;
+ }
+
+ private static Path rootDirName(String distName, URI uri) {
+ String urlHash = getHash(uri);
+ return Paths.get(distName, urlHash);
+ }
+
+ private static String getHash(URI path) {
+ return Integer.toHexString(path.hashCode());
+ }
+
+ private static Path getBaseDir(String base) {
+ if (MAVEN_USER_HOME_STRING.equals(base)) {
+ return mavenUserHome();
+ } else if (PROJECT_STRING.equals(base)) {
+ return Paths.get(System.getProperty("user.dir"));
+ } else {
+ throw new RuntimeException("Base: " + base + " is unknown");
+ }
+ }
+
+ private static List<Path> listDirs(Path distDir) throws IOException {
+ List<Path> dirs = new ArrayList<>();
+ if (Files.exists(distDir)) {
+ try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(distDir)) {
+ for (Path file : dirStream) {
+ if (Files.isDirectory(file)) {
+ dirs.add(file);
+ }
+ }
+ }
+ }
+ return dirs;
+ }
+
+ private static Path mavenUserHome() {
+ String mavenUserHome = System.getProperty(MAVEN_USER_HOME_PROPERTY_KEY);
+ if (mavenUserHome == null) {
+ mavenUserHome = System.getenv(MAVEN_USER_HOME_ENV_KEY);
+ }
+ return mavenUserHome == null ? DEFAULT_MAVEN_USER_HOME : Paths.get(mavenUserHome);
+ }
+
+ public static class LocalDistribution {
+ private final Path distZip;
+
+ private final Path distDir;
+
+ public LocalDistribution(Path distDir, Path distZip) {
+ this.distDir = distDir;
+ this.distZip = distZip;
+ }
+
+ public Path getDistributionDir() {
+ return distDir;
+ }
+
+ public Path getZipFile() {
+ return distZip;
+ }
+ }
}
diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties
index e42c9fef2..7b6b3c632 100644
--- a/.mvn/wrapper/maven-wrapper.properties
+++ b/.mvn/wrapper/maven-wrapper.properties
@@ -16,5 +16,6 @@
#
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip
+distributionMd5=4face1fea2cf66bcb25303d4ba994bef
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
wrapperMd5=6058337c6ed4603858c3b72f754efa9b
diff --git a/mvnw b/mvnw
index 9a7fa3704..368dfcb03 100755
--- a/mvnw
+++ b/mvnw
@@ -210,7 +210,7 @@ fi
if [ -r "$wrapperJarPath" ]; then
log "Found $wrapperJarPath"
log "Check found $wrapperJarPath starting"
- ("$JAVA_HOME/bin/java" -cp "$MAVEN_PROJECTBASEDIR/.mvn/wrapper" MavenWrapperHelper "verify" "$wrapperJarPath" "$wrapperProperties")
+ ("$JAVA_HOME/bin/java" -cp "$MAVEN_PROJECTBASEDIR/.mvn/wrapper" MavenWrapperHelper "verify_wrapper" "$wrapperJarPath" "$wrapperProperties")
if [ $? -eq 1 ]; then
echo "WARN: Check found $wrapperJarPath invalided."
rm -f $wrapperJarPath
@@ -264,12 +264,20 @@ if [ ! -e "$wrapperJarPath" ]; then
fi
log "Check $wrapperJarPath."
- ("$JAVA_HOME/bin/java" -cp "$MAVEN_PROJECTBASEDIR/.mvn/wrapper" MavenWrapperHelper "verify" "$wrapperJarPath" "$wrapperProperties")
+ ("$JAVA_HOME/bin/java" -cp "$MAVEN_PROJECTBASEDIR/.mvn/wrapper" MavenWrapperHelper "verify_wrapper" "$wrapperJarPath" "$wrapperProperties")
if [ $? -eq 1 ]; then
echo "ERROR: Check $wrapperJarPath invalided, please retry"
exit 1
fi
fi
+
+# check distribution file
+dist_path=`("$JAVA_HOME/bin/java" -cp "$MAVEN_PROJECTBASEDIR/.mvn/wrapper" MavenWrapperHelper "verify_dist" "$wrapperProperties")`
+if [ $? -eq 1 ]; then
+ rm -f $dist_path
+ echo "WARN: Check $dist_path invalided, forcefully delete the file...."
+fi
+
##########################################################################################
# End of extension
##########################################################################################
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 9a7fa3704..368dfcb03 100755
--- a/streampark-console/streampark-console-service/src/main/assembly/bin/mvnw
+++ b/streampark-console/streampark-console-service/src/main/assembly/bin/mvnw
@@ -210,7 +210,7 @@ fi
if [ -r "$wrapperJarPath" ]; then
log "Found $wrapperJarPath"
log "Check found $wrapperJarPath starting"
- ("$JAVA_HOME/bin/java" -cp "$MAVEN_PROJECTBASEDIR/.mvn/wrapper" MavenWrapperHelper "verify" "$wrapperJarPath" "$wrapperProperties")
+ ("$JAVA_HOME/bin/java" -cp "$MAVEN_PROJECTBASEDIR/.mvn/wrapper" MavenWrapperHelper "verify_wrapper" "$wrapperJarPath" "$wrapperProperties")
if [ $? -eq 1 ]; then
echo "WARN: Check found $wrapperJarPath invalided."
rm -f $wrapperJarPath
@@ -264,12 +264,20 @@ if [ ! -e "$wrapperJarPath" ]; then
fi
log "Check $wrapperJarPath."
- ("$JAVA_HOME/bin/java" -cp "$MAVEN_PROJECTBASEDIR/.mvn/wrapper" MavenWrapperHelper "verify" "$wrapperJarPath" "$wrapperProperties")
+ ("$JAVA_HOME/bin/java" -cp "$MAVEN_PROJECTBASEDIR/.mvn/wrapper" MavenWrapperHelper "verify_wrapper" "$wrapperJarPath" "$wrapperProperties")
if [ $? -eq 1 ]; then
echo "ERROR: Check $wrapperJarPath invalided, please retry"
exit 1
fi
fi
+
+# check distribution file
+dist_path=`("$JAVA_HOME/bin/java" -cp "$MAVEN_PROJECTBASEDIR/.mvn/wrapper" MavenWrapperHelper "verify_dist" "$wrapperProperties")`
+if [ $? -eq 1 ]; then
+ rm -f $dist_path
+ echo "WARN: Check $dist_path invalided, forcefully delete the file...."
+fi
+
##########################################################################################
# End of extension
##########################################################################################
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 7e7c31545..216f886cb 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
@@ -270,8 +270,8 @@ print_logo() {
printf ' %s ___/ / /_/ / / __/ /_/ / / / / / / /_/ / /_/ / / / ,< %s\n' $PRIMARY $RESET
printf ' %s /____/\__/_/ \___/\__,_/_/ /_/ /_/ ____/\__,_/_/ /_/|_| %s\n' $PRIMARY $RESET
printf ' %s /_/ %s\n\n' $PRIMARY $RESET
- printf ' %s Version: 2.2.0-SNAPSHOT %s\n' $BLUE $RESET
- printf ' %s WebSite: https://streampark.apache.org%s\n' $BLUE $RESET
+ printf ' %s Version: 2.2.0 %s\n' $BLUE $RESET
+ printf ' %s WebSite: https://streampark.apache.org%s\n' $BLUE $RESET
printf ' %s GitHub : http://github.com/apache/streampark%s\n\n' $BLUE $RESET
printf ' %s ──────── Apache StreamPark, Make stream processing easier ô~ô!%s\n\n' $PRIMARY $RESET
}
@@ -340,6 +340,13 @@ get_pid() {
fi
}
+ready() {
+ local mavenWrapper="$APP_HOME/bin/.mvn/wrapper/MavenWrapperHelper.class"
+ if [[ -f $mavenWrapper ]]; then
+ rm -f $mavenWrapper >/dev/null 2>&1
+ fi
+}
+
# shellcheck disable=SC2120
start() {
# shellcheck disable=SC2006
@@ -604,9 +611,11 @@ main() {
debug
;;
"start")
+ ready
start
;;
"start_docker")
+ ready
start_docker
;;
"stop")