From 74f3d32c49aea89562c203668e6944f9a017e015 Mon Sep 17 00:00:00 2001 From: xuxuhe <1821992002@qq.com> Date: Thu, 31 Jul 2025 22:26:56 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix=EF=BC=9A=20fix=20the=20bug=20in=20JDK?= =?UTF-8?q?=20version=20comparison?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/assembly/static/bin/init-store.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/hugegraph-server/hugegraph-dist/src/assembly/static/bin/init-store.sh b/hugegraph-server/hugegraph-dist/src/assembly/static/bin/init-store.sh index cde2cff742..2444a74fe9 100755 --- a/hugegraph-server/hugegraph-dist/src/assembly/static/bin/init-store.sh +++ b/hugegraph-server/hugegraph-dist/src/assembly/static/bin/init-store.sh @@ -47,9 +47,16 @@ cd "${TOP}" || exit DEFAULT_JAVA_OPTIONS="" JAVA_VERSION=$($JAVA -version 2>&1 | awk 'NR==1{gsub(/"/,""); print $3}' | awk -F'_' '{print $1}') -# TODO: better not string number compare, use `bc` like github.com/koalaman/shellcheck/wiki/SC2072 -if [[ $? -eq 0 && $JAVA_VERSION > "1.9" ]]; then - DEFAULT_JAVA_OPTIONS="--add-exports=java.base/jdk.internal.reflect=ALL-UNNAMED" + +# 提取主版本号进行数值比较 +if [[ $JAVA_VERSION == 1.* ]]; then + MAJOR_VERSION=$(echo $JAVA_VERSION | cut -d'.' -f2) +else + MAJOR_VERSION=$(echo $JAVA_VERSION | cut -d'.' -f1) +fi + +if [[ $? -eq 0 && $MAJOR_VERSION -ge 9 ]]; then + DEFAULT_JAVA_OPTIONS="--add-exports=java.base/jdk.internal.reflect=ALL-UNNAMED" fi echo "Initializing HugeGraph Store..." From aaa6168ecf685830ae1db741f7fea5ede8dfc495 Mon Sep 17 00:00:00 2001 From: xuxuhe <1821992002@qq.com> Date: Mon, 4 Aug 2025 22:46:24 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix=EF=BC=9A=20fix=20the=20bug=20in=20JDK?= =?UTF-8?q?=20version=20comparison?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/assembly/static/bin/start-hugegraph-pd.sh | 10 +++++++++- .../src/assembly/static/bin/init-store.sh | 9 +++++++-- .../src/assembly/static/bin/start-hugegraph-store.sh | 9 ++++++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/hugegraph-pd/hg-pd-dist/src/assembly/static/bin/start-hugegraph-pd.sh b/hugegraph-pd/hg-pd-dist/src/assembly/static/bin/start-hugegraph-pd.sh index b5d5346f34..27959ea1b8 100644 --- a/hugegraph-pd/hg-pd-dist/src/assembly/static/bin/start-hugegraph-pd.sh +++ b/hugegraph-pd/hg-pd-dist/src/assembly/static/bin/start-hugegraph-pd.sh @@ -79,7 +79,15 @@ fi # check jdk version JAVA_VERSION=$($JAVA -version 2>&1 | awk 'NR==1{gsub(/"/,""); print $3}' | awk -F'_' '{print $1}') -if [[ $? -ne 0 || $JAVA_VERSION < $EXPECT_JDK_VERSION ]]; then + +if [[ $JAVA_VERSION == 1.* ]]; then + MAJOR_VERSION=$(echo $JAVA_VERSION | cut -d'.' -f2) +else + MAJOR_VERSION=$(echo $JAVA_VERSION | cut -d'.' -f1) +fi + + +if [[ $? -ne 0 || $MAJOR_VERSION -lt $EXPECT_JDK_VERSION ]]; then echo "Please make sure that the JDK is installed and the version >= $EXPECT_JDK_VERSION" >> ${OUTPUT} exit 1 fi diff --git a/hugegraph-server/hugegraph-dist/src/assembly/static/bin/init-store.sh b/hugegraph-server/hugegraph-dist/src/assembly/static/bin/init-store.sh index 2444a74fe9..6a33cb0aee 100755 --- a/hugegraph-server/hugegraph-dist/src/assembly/static/bin/init-store.sh +++ b/hugegraph-server/hugegraph-dist/src/assembly/static/bin/init-store.sh @@ -25,6 +25,7 @@ function abs_path() { cd -P "$(dirname "$SOURCE")" && pwd } +REQUIRED_JAVA_VERSION="11" BIN=$(abs_path) TOP="$(cd "${BIN}"/../ && pwd)" CONF="$TOP/conf" @@ -48,15 +49,19 @@ cd "${TOP}" || exit DEFAULT_JAVA_OPTIONS="" JAVA_VERSION=$($JAVA -version 2>&1 | awk 'NR==1{gsub(/"/,""); print $3}' | awk -F'_' '{print $1}') -# 提取主版本号进行数值比较 +# Extract the major version number for numerical comparison if [[ $JAVA_VERSION == 1.* ]]; then MAJOR_VERSION=$(echo $JAVA_VERSION | cut -d'.' -f2) else MAJOR_VERSION=$(echo $JAVA_VERSION | cut -d'.' -f1) fi -if [[ $? -eq 0 && $MAJOR_VERSION -ge 9 ]]; then +# Compare with the required Java version +if [[ $? -eq 0 && $MAJOR_VERSION -ge $REQUIRED_JAVA_VERSION ]]; then DEFAULT_JAVA_OPTIONS="--add-exports=java.base/jdk.internal.reflect=ALL-UNNAMED" +else + echo "Error: This application requires Java version $REQUIRED_JAVA_VERSION or higher." + exit 1 fi echo "Initializing HugeGraph Store..." diff --git a/hugegraph-store/hg-store-dist/src/assembly/static/bin/start-hugegraph-store.sh b/hugegraph-store/hg-store-dist/src/assembly/static/bin/start-hugegraph-store.sh index d8b965a07d..bf7cc4c148 100644 --- a/hugegraph-store/hg-store-dist/src/assembly/static/bin/start-hugegraph-store.sh +++ b/hugegraph-store/hg-store-dist/src/assembly/static/bin/start-hugegraph-store.sh @@ -131,7 +131,14 @@ fi # check jdk version JAVA_VERSION=$($JAVA -version 2>&1 | awk 'NR==1{gsub(/"/,""); print $3}' | awk -F'_' '{print $1}') -if [[ $? -ne 0 || $JAVA_VERSION < $EXPECT_JDK_VERSION ]]; then + +if [[ $JAVA_VERSION == 1.* ]]; then + MAJOR_VERSION=$(echo $JAVA_VERSION | cut -d'.' -f2) +else + MAJOR_VERSION=$(echo $JAVA_VERSION | cut -d'.' -f1) +fi + +if [[ $? -ne 0 || $MAJOR_VERSION -lt $EXPECT_JDK_VERSION ]]; then echo "Please make sure that the JDK is installed and the version >= $EXPECT_JDK_VERSION" >> ${OUTPUT} exit 1 fi From 986d472d740925d906dfac3a6c3ef73ccc0c9320 Mon Sep 17 00:00:00 2001 From: xuxuhe <1821992002@qq.com> Date: Sun, 10 Aug 2025 19:33:32 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix=EF=BC=9A=20fix=20the=20bug=20in=20JDK?= =?UTF-8?q?=20version=20comparison?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../assembly/static/bin/start-hugegraph-store.sh | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/hugegraph-store/hg-store-dist/src/assembly/static/bin/start-hugegraph-store.sh b/hugegraph-store/hg-store-dist/src/assembly/static/bin/start-hugegraph-store.sh index bf7cc4c148..a11dcf5076 100644 --- a/hugegraph-store/hg-store-dist/src/assembly/static/bin/start-hugegraph-store.sh +++ b/hugegraph-store/hg-store-dist/src/assembly/static/bin/start-hugegraph-store.sh @@ -129,18 +129,13 @@ else JAVA="$JAVA_HOME/bin/java" fi -# check jdk version -JAVA_VERSION=$($JAVA -version 2>&1 | awk 'NR==1{gsub(/"/,""); print $3}' | awk -F'_' '{print $1}') +EXPECT_JDK_VERSION=11 -if [[ $JAVA_VERSION == 1.* ]]; then - MAJOR_VERSION=$(echo $JAVA_VERSION | cut -d'.' -f2) -else - MAJOR_VERSION=$(echo $JAVA_VERSION | cut -d'.' -f1) -fi +# Extract and check Java version +JAVA_VERSION=$(java -version 2>&1 | head -n1 | sed -n 's/.*version "\([0-9]*\)\..*/\1/p') -if [[ $? -ne 0 || $MAJOR_VERSION -lt $EXPECT_JDK_VERSION ]]; then - echo "Please make sure that the JDK is installed and the version >= $EXPECT_JDK_VERSION" >> ${OUTPUT} - exit 1 +if [[ "$JAVA_VERSION" != "$EXPECT_JDK_VERSION" ]]; then + echo "Expected Java ${EXPECT_JDK_VERSION}, but found Java ${JAVA_VERSION} ✗" >> ${OUTPUT} fi # Set Java options From 8157bb41cb348d889d97b979a89b267914f09826 Mon Sep 17 00:00:00 2001 From: xuxuhe <1821992002@qq.com> Date: Sun, 10 Aug 2025 19:35:02 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix=EF=BC=9A=20fix=20the=20bug=20in=20JDK?= =?UTF-8?q?=20version=20comparison?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/assembly/static/bin/start-hugegraph-pd.sh | 11 ++++++----- .../src/assembly/static/bin/start-hugegraph-store.sh | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/hugegraph-pd/hg-pd-dist/src/assembly/static/bin/start-hugegraph-pd.sh b/hugegraph-pd/hg-pd-dist/src/assembly/static/bin/start-hugegraph-pd.sh index 27959ea1b8..2b0ea0ec7e 100644 --- a/hugegraph-pd/hg-pd-dist/src/assembly/static/bin/start-hugegraph-pd.sh +++ b/hugegraph-pd/hg-pd-dist/src/assembly/static/bin/start-hugegraph-pd.sh @@ -78,12 +78,13 @@ else fi # check jdk version -JAVA_VERSION=$($JAVA -version 2>&1 | awk 'NR==1{gsub(/"/,""); print $3}' | awk -F'_' '{print $1}') +EXPECT_JDK_VERSION=11 -if [[ $JAVA_VERSION == 1.* ]]; then - MAJOR_VERSION=$(echo $JAVA_VERSION | cut -d'.' -f2) -else - MAJOR_VERSION=$(echo $JAVA_VERSION | cut -d'.' -f1) +# Extract and check Java version +JAVA_VERSION=$($JAVA -version 2>&1 | head -n1 | sed -n 's/.*version "\([0-9]*\)\..*/\1/p') + +if [[ "$JAVA_VERSION" != "$EXPECT_JDK_VERSION" ]]; then + echo "Expected Java ${EXPECT_JDK_VERSION}, but found Java ${JAVA_VERSION} ✗" >> ${OUTPUT} fi diff --git a/hugegraph-store/hg-store-dist/src/assembly/static/bin/start-hugegraph-store.sh b/hugegraph-store/hg-store-dist/src/assembly/static/bin/start-hugegraph-store.sh index a11dcf5076..291b1e4e33 100644 --- a/hugegraph-store/hg-store-dist/src/assembly/static/bin/start-hugegraph-store.sh +++ b/hugegraph-store/hg-store-dist/src/assembly/static/bin/start-hugegraph-store.sh @@ -132,7 +132,7 @@ fi EXPECT_JDK_VERSION=11 # Extract and check Java version -JAVA_VERSION=$(java -version 2>&1 | head -n1 | sed -n 's/.*version "\([0-9]*\)\..*/\1/p') +JAVA_VERSION=$($JAVA -version 2>&1 | head -n1 | sed -n 's/.*version "\([0-9]*\)\..*/\1/p') if [[ "$JAVA_VERSION" != "$EXPECT_JDK_VERSION" ]]; then echo "Expected Java ${EXPECT_JDK_VERSION}, but found Java ${JAVA_VERSION} ✗" >> ${OUTPUT}