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 16aca3a18 [Improve] mavenWrapper check improvement
16aca3a18 is described below
commit 16aca3a181c7820f8e3a880b350aa8de082a1e5a
Author: benjobs <[email protected]>
AuthorDate: Thu Dec 14 17:42:32 2023 +0800
[Improve] mavenWrapper check improvement
---
.mvn/wrapper/MavenWrapperHelper.java | 180 ++++++++++++++++++++-
.mvn/wrapper/maven-wrapper.properties | 1 +
mvnw | 12 +-
.../src/main/assembly/bin/mvnw | 12 +-
4 files changed, 199 insertions(+), 6 deletions(-)
diff --git a/.mvn/wrapper/MavenWrapperHelper.java
b/.mvn/wrapper/MavenWrapperHelper.java
index 428fa81ff..183349ca3 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,24 +91,101 @@ 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);
System.exit(1);
}
String fileMd5 = getFileMd5(wrapperJar);
+ if (!wrapperMd5.equals(fileMd5)) {
+ System.exit(1);
+ }
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 +227,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
##########################################################################################