Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .mvn/jvm.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-Xmx10240m
-XX:MaxMetaspaceSize=2560m
-XX:+UseG1GC
-XX:+UseStringDeduplication
-XX:ReservedCodeCacheSize=512m
-XX:NonProfiledCodeHeapSize=240m
18 changes: 2 additions & 16 deletions abstraction/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,10 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${project.compiler.version}</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<source>${project.java.version}</source>
<target>${project.java.version}</target>
<debuglevel>lines,vars,source</debuglevel>
<release>${project.java.version}</release>
<debug>true</debug>
<parameters>true</parameters>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>${groovy.eclipse.compiler}</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>${groovy.eclipse.batch}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Expand Down
11 changes: 9 additions & 2 deletions build/debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ conf_dir=$zstack_dir/conf
classpath=
is_suspend="$1"

# 加载Java 17 JVM参数
jvm_options_file="$conf_dir/jvm-options-java17.conf"
jvm_options=""
if [ -f "$jvm_options_file" ]; then
jvm_options=$(cat "$jvm_options_file" | grep -v '^#' | tr '\n' ' ')
fi
Comment on lines +11 to +16
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Line 11 的中文注释请改为英文

注释语言需统一为英文。

As per coding guidelines: 代码里不应当有有中文,包括报错、注释等都应当使用正确的、无拼写错误的英文来写

🤖 Prompt for AI Agents
In `@build/debug.sh` around lines 11 - 16, Replace the Chinese comment "加载Java 17
JVM参数" with an English comment describing the same purpose (e.g., "Load Java 17
JVM options") so comments are consistently in English; update the comment near
the jvm_options_file and jvm_options declarations to use the corrected English
text.


if [ x"$is_suspend" == x"true" ]; then
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

cat -n build/debug.sh | sed -n '10,25p'

Repository: MatheMatrix/zstack

Length of output: 742


🏁 Script executed:

# 检查是否存在 build/debug.sh 文件
ls -la build/debug.sh 2>&1 | head -20

Repository: MatheMatrix/zstack

Length of output: 125


🌐 Web query:

POSIX sh test operator == vs = compatibility dash busybox

💡 Result:

  • POSIX sh / POSIX test ([ ... ]) string equality operator is = (and != for inequality). == is not required by POSIX. Use: if [ "$a" = "$b" ]; then ...; fi.[1]
  • dash (Debian Almquist shell) is strict here: [ x == x ] fails with [: unexpected operator, so == is not compatible with dash scripts.[2]
  • BusyBox ash/sh often accepts == in [ ... ] as an extension, so [ x == x ] may work there—but that’s exactly why it’s a portability trap: it works on BusyBox but breaks on dash.[2]
  • Some test implementations (e.g., GNU coreutils test) document == as a non-portable synonym for =.[3]
  • [[ ... ]] is not POSIX sh (and its behavior varies); BusyBox only supports it in some builds and with limited compatibility options, so don’t use it in scripts that must run under dash/POSIX sh.[4]

Rule for maximum compatibility (dash + BusyBox + POSIX): use = inside [ ... ], not ==.[1][2]

Sources:
[1] man7 test(1) (string tests: STRING1 = STRING2) (man7.org)
[2] Unix & Linux SE showing dash rejects == while BusyBox accepts it (unix.stackexchange.com)
[3] GNU coreutils manual: == is a synonym for = but “not as portable” (gnu.org)
[4] Unix & Linux SE on BusyBox [[...]] support being optional/limited (unix.stackexchange.com)

Citations:


在 POSIX sh 中应使用单等号 = 而非 ==

第 18 行使用了 == 作为条件比较操作符,但 POSIX 标准 sh 规定应使用单等号 =。在 dash(Debian Almquist shell)等严格遵循 POSIX 标准的 shell 实现中,== 会导致错误 [: unexpected operator。此外,== 是一些 shell 的非标准扩展,使用它会降低脚本的可移植性。

🔧 建议修复
-if [ x"$is_suspend" == x"true" ]; then
+if [ x"$is_suspend" = x"true" ]; then
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [ x"$is_suspend" == x"true" ]; then
if [ x"$is_suspend" = x"true" ]; then
🧰 Tools
🪛 Shellcheck (0.11.0)

[warning] 18-18: In POSIX sh, == in place of = is undefined.

(SC3014)

🤖 Prompt for AI Agents
In `@build/debug.sh` at line 18, 第 18 行条件判断使用了非 POSIX 的比较运算符 "=="(在 if [
x"$is_suspend" == x"true" ]; then),会在严格的 sh 实现中失败;将该比较改为单等号 "="(即使用 if [
x"$is_suspend" = x"true" ]; then)以确保与 POSIX sh(dash 等)兼容并提高可移植性,保留变量前的 x
前缀和引号以防空值或特殊字符。

java_optitons="-Xdebug -Xms256m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y"
java_optitons="$jvm_options -Xdebug -Xms256m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y"
else
java_optitons="-Xdebug -Xms256m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"
java_optitons="$jvm_options -Xdebug -Xms256m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"
fi


Expand Down
283 changes: 283 additions & 0 deletions build/fix-groovy-compiler.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
#!/bin/bash

# 批量修复Groovy编译配置脚本
# 用于将groovy-eclipse-compiler替换为标准Java编译器或GMavenPlus

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"

cd "$PROJECT_ROOT"

echo "=========================================="
echo "批量修复Groovy编译配置"
echo "=========================================="
Comment on lines +3 to +15
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

脚本注释与输出请改为英文

Line 3-15 等处包含中文注释/输出,与当前仓库规范不一致,请统一为英文。

As per coding guidelines: 代码里不应当有有中文,包括报错、注释等都应当使用正确的、无拼写错误的英文来写

🤖 Prompt for AI Agents
In `@build/fix-groovy-compiler.sh` around lines 3 - 15, The script contains
Chinese comments and echo output (lines around the header and description) that
must be converted to English to match repo conventions; update the top comment
block and all echo strings (e.g., the header lines currently printed with echo
"==========================================" and the "批量修复Groovy编译配置" message)
to clear, correctly spelled English, and ensure inline comments (above set -e,
SCRIPT_DIR, PROJECT_ROOT) are rewritten in English as well so all user-facing
and inline text in this script (fix-groovy-compiler.sh) uses English only.

echo ""

# 查找所有包含groovy-eclipse-compiler的pom.xml文件
FILES=$(grep -r "groovy-eclipse-compiler" --include="pom.xml" . | cut -d: -f1 | sort -u)

TOTAL=$(echo "$FILES" | wc -l | tr -d ' ')
CURRENT=0
FIXED=0
SKIPPED=0

# 标准Java编译器配置(用于没有Groovy源文件的模块)
STANDARD_JAVA_CONFIG=' <configuration>
<source>${project.java.version}</source>
<target>${project.java.version}</target>
<debug>true</debug>
<parameters>true</parameters>
</configuration>'

# GMavenPlus配置(用于有Groovy源文件的模块)
GMAVENPLUS_CONFIG=' <!-- 标准Java编译器 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${project.compiler.version}</version>
<configuration>
<source>${project.java.version}</source>
<target>${project.java.version}</target>
<debug>true</debug>
<parameters>true</parameters>
</configuration>
</plugin>
<!-- GMavenPlus 用于编译Groovy代码 -->
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>4.2.1</version>
<executions>
<execution>
<goals>
<goal>generateStubs</goal>
<goal>compile</goal>
<goal>generateTestStubs</goal>
<goal>compileTests</goal>
</goals>
</execution>
</executions>
<configuration>
<groovyVersion>${groovy.version}</groovyVersion>
<targetBytecode>${project.java.version}</targetBytecode>
</configuration>
</plugin>'

for FILE in $FILES; do
CURRENT=$((CURRENT + 1))
echo "[$CURRENT/$TOTAL] 处理: $FILE"

# 检查模块目录是否有Groovy源文件
MODULE_DIR=$(dirname "$FILE")
HAS_GROOVY=$(find "$MODULE_DIR" -name "*.groovy" -type f 2>/dev/null | head -1)

if [ -n "$HAS_GROOVY" ]; then
echo " ⚠️ 发现Groovy源文件,需要手动配置GMavenPlus"
echo " 📝 请手动编辑此文件,参考test/pom.xml的配置"
SKIPPED=$((SKIPPED + 1))
continue
fi

# 读取文件内容
if [ ! -f "$FILE" ]; then
echo " ❌ 文件不存在,跳过"
SKIPPED=$((SKIPPED + 1))
continue
fi

# 创建备份
BACKUP_FILE="${FILE}.backup.$(date +%Y%m%d_%H%M%S)"
cp "$FILE" "$BACKUP_FILE"
echo " 💾 备份文件: $BACKUP_FILE"

# 使用Python进行精确替换(因为sed处理多行和缩进比较复杂)
python3 <<PYTHON_SCRIPT
import re
import sys

file_path = "$FILE"

with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()

# 匹配groovy-eclipse-compiler配置块
# 匹配从<plugin>开始到</plugin>结束,包含groovy-eclipse-compiler的整个块
pattern = r'''\s*<plugin>\s*
\s*<groupId>org\.apache\.maven\.plugins</groupId>\s*
\s*<artifactId>maven-compiler-plugin</artifactId>\s*
\s*<version>.*?</version>\s*
\s*<configuration>\s*
\s*<compilerId>groovy-eclipse-compiler</compilerId>\s*
\s*<source>\$\{project\.java\.version\}</source>\s*
\s*<target>\$\{project\.java\.version\}</target>\s*
\s*<debuglevel>lines,vars,source</debuglevel>\s*
\s*<debug>true</debug>\s*
\s*</configuration>\s*
\s*<dependencies>\s*
\s*<dependency>\s*
\s*<groupId>org\.codehaus\.groovy</groupId>\s*
\s*<artifactId>groovy-eclipse-compiler</artifactId>\s*
\s*<version>.*?</version>\s*
\s*</dependency>\s*
\s*<dependency>\s*
\s*<groupId>org\.codehaus\.groovy</groupId>\s*
\s*<artifactId>groovy-eclipse-batch</artifactId>\s*
\s*<version>.*?</version>\s*
\s*</dependency>\s*
\s*</dependencies>\s*
\s*</plugin>'''

# 更灵活的匹配模式(处理不同的缩进和换行)
pattern2 = r'''(\s*)<plugin>\s*
\1<groupId>org\.apache\.maven\.plugins</groupId>\s*
\1<artifactId>maven-compiler-plugin</artifactId>\s*
\1<version>([^<]+)</version>\s*
\1<configuration>\s*
\1\s*<compilerId>groovy-eclipse-compiler</compilerId>\s*
\1\s*<source>\$\{project\.java\.version\}</source>\s*
\1\s*<target>\$\{project\.java\.version\}</target>\s*
\1\s*<debuglevel>lines,vars,source</debuglevel>\s*
\1\s*<debug>true</debug>\s*
\1</configuration>\s*
\1<dependencies>\s*
\1\s*<dependency>\s*
\1\s*<groupId>org\.codehaus\.groovy</groupId>\s*
\1\s*<artifactId>groovy-eclipse-compiler</artifactId>\s*
\1\s*<version>[^<]+</version>\s*
\1\s*</dependency>\s*
\1\s*<dependency>\s*
\1\s*<groupId>org\.codehaus\.groovy</groupId>\s*
\1\s*<artifactId>groovy-eclipse-batch</artifactId>\s*
\1\s*<version>[^<]+</version>\s*
\1\s*</dependency>\s*
\1</dependencies>\s*
\1</plugin>'''

# 尝试匹配并替换
def replace_plugin(match):
indent = match.group(1)
version = match.group(2).strip()
replacement = f'''{indent}<plugin>
{indent} <groupId>org.apache.maven.plugins</groupId>
{indent} <artifactId>maven-compiler-plugin</artifactId>
{indent} <version>{version}</version>
{indent} <configuration>
{indent} <source>${{project.java.version}}</source>
{indent} <target>${{project.java.version}}</target>
{indent} <debug>true</debug>
{indent} <parameters>true</parameters>
{indent} </configuration>
{indent}</plugin>'''
return replacement

# 使用更简单的方法:逐行处理
lines = content.split('\n')
new_lines = []
i = 0
in_plugin = False
in_config = False
in_dependencies = False
plugin_start = -1
indent = ""

while i < len(lines):
line = lines[i]

# 检测plugin开始
if '<plugin>' in line and 'maven-compiler-plugin' in '\n'.join(lines[max(0, i-3):i+3]):
# 向前查找groupId和artifactId
if i > 0 and 'maven-compiler-plugin' in lines[i-1]:
plugin_start = len(new_lines)
indent = line[:len(line) - len(line.lstrip())]
in_plugin = True
new_lines.append(line)
i += 1
continue

# 如果在plugin块中,检测groovy-eclipse-compiler
if in_plugin:
if '<compilerId>groovy-eclipse-compiler</compilerId>' in line:
# 找到了,需要替换整个plugin块
# 回退到plugin开始位置
new_lines = new_lines[:plugin_start]
# 添加新的标准配置
version_line = None
for j in range(plugin_start, i):
if '<version>' in lines[j] and '</version>' in lines[j]:
version_line = lines[j]
break

version = '${project.compiler.version}'
if version_line:
version_match = re.search(r'<version>([^<]+)</version>', version_line)
if version_match:
version = version_match.group(1).strip()

new_lines.append(f'{indent}<plugin>')
new_lines.append(f'{indent} <groupId>org.apache.maven.plugins</groupId>')
new_lines.append(f'{indent} <artifactId>maven-compiler-plugin</artifactId>')
new_lines.append(f'{indent} <version>{version}</version>')
new_lines.append(f'{indent} <configuration>')
new_lines.append(f'{indent} <source>${{project.java.version}}</source>')
new_lines.append(f'{indent} <target>${{project.java.version}}</target>')
new_lines.append(f'{indent} <debug>true</debug>')
new_lines.append(f'{indent} <parameters>true</parameters>')
new_lines.append(f'{indent} </configuration>')
new_lines.append(f'{indent}</plugin>')

# 跳过到</plugin>
while i < len(lines) and '</plugin>' not in lines[i]:
i += 1
if i < len(lines):
i += 1 # 跳过</plugin>
in_plugin = False
continue
elif '</plugin>' in line:
in_plugin = False
new_lines.append(line)
i += 1
continue

new_lines.append(line)
i += 1

new_content = '\n'.join(new_lines)

# 如果内容有变化,写入文件
if new_content != content:
with open(file_path, 'w', encoding='utf-8') as f:
f.write(new_content)
print(" ✅ 修复完成")
sys.exit(0)
else:
print(" ⚠️ 未找到需要替换的内容(可能已修复或格式不同)")
sys.exit(1)

PYTHON_SCRIPT

if [ $? -eq 0 ]; then
FIXED=$((FIXED + 1))
echo " ✅ 修复成功"
else
echo " ⚠️ 修复失败或无需修复,请手动检查"
SKIPPED=$((SKIPPED + 1))
fi
Comment on lines +95 to +266
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

cat -n build/fix-groovy-compiler.sh | head -100 | tail -20

Repository: MatheMatrix/zstack

Length of output: 592


🏁 Script executed:

wc -l build/fix-groovy-compiler.sh

Repository: MatheMatrix/zstack

Length of output: 94


🏁 Script executed:

sed -n '90,110p' build/fix-groovy-compiler.sh

Repository: MatheMatrix/zstack

Length of output: 635


🏁 Script executed:

rg '使用|修复|错误|检测|匹配' build/fix-groovy-compiler.sh -c

Repository: MatheMatrix/zstack

Length of output: 64


🏁 Script executed:

sed -n '1,30p' build/fix-groovy-compiler.sh

Repository: MatheMatrix/zstack

Length of output: 862


🏁 Script executed:

sed -n '200,266p' build/fix-groovy-compiler.sh

Repository: MatheMatrix/zstack

Length of output: 2478


🏁 Script executed:

sed -n '95,200p' build/fix-groovy-compiler.sh

Repository: MatheMatrix/zstack

Length of output: 3346


消除代码中的中文内容并改进 heredoc 处理方式

此脚本违反编码规范:代码、注释和错误消息中包含大量中文(第 2、3、12、15-17、85、95、263、265、267 行等),应使用正确的英文改写。

其次,第 96 行的未引号 heredoc 允许 shell 展开变量,虽然当前代码中的 ${project.java.version} 已通过 \$ 转义避免了问题,但使用带引号的 heredoc(<<'PYTHON_SCRIPT')并通过环境变量传递 $FILE 是更安全、更清晰的做法:

🔧 建议修复
-    # 使用Python进行精确替换(因为sed处理多行和缩进比较复杂)
-    python3 <<PYTHON_SCRIPT
+    # Use Python for precise replacement (sed is complex with multiline and indentation)
+    if FILE="$FILE" python3 <<'PYTHON_SCRIPT'
 import re
 import sys
+import os
@@
-file_path = "$FILE"
+file_path = os.environ["FILE"]
@@
-PYTHON_SCRIPT
-
-    if [ $? -eq 0 ]; then
-        FIXED=$((FIXED + 1))
-        echo "  ✅ 修复成功"
-    else
-        echo "  ⚠️  修复失败或无需修复,请手动检查"
-        SKIPPED=$((SKIPPED + 1))
-    fi
+PYTHON_SCRIPT
+    then
+        FIXED=$((FIXED + 1))
+        echo "  ✅ Fix successful"
+    else
+        echo "  ⚠️  Fix failed or no changes needed, please check manually"
+        SKIPPED=$((SKIPPED + 1))
+    fi

同时,将整个脚本中的所有中文注释、输出消息和日志改为清晰的英文。

🧰 Tools
🪛 Shellcheck (0.11.0)

[error] 167-167: Parameter expansions can't start with {. Double check syntax.

(SC2296)


[error] 168-168: Parameter expansions can't start with {. Double check syntax.

(SC2296)


[warning] 212-212: project is referenced but not assigned.

(SC2154)


[error] 223-223: Parameter expansions can't start with {. Double check syntax.

(SC2296)


[error] 224-224: Parameter expansions can't start with {. Double check syntax.

(SC2296)

🤖 Prompt for AI Agents
In `@build/fix-groovy-compiler.sh` around lines 95 - 266, The script contains
Chinese text and uses an unquoted heredoc for the embedded Python block; replace
all Chinese comments and user-facing messages with English and switch the
heredoc to a single-quoted form (use <<'PYTHON_SCRIPT') so the shell will not
expand variables inside the block, and pass the FILE path into the Python script
via an exported environment variable (or as an argument) instead of relying on
unescaped expansions; update prints like "✅ 修复完成"/"⚠️  未找到需要替换的内容" and shell
echoes "✅ 修复成功"/"⚠️  修复失败或无需修复,请手动检查" to clear English equivalents, ensure the
Python logic (functions/variables: pattern, pattern2, replace_plugin,
lines/new_lines, version detection using version_line and version_match)
continues to work with the quoted heredoc and the existing escaped
${project.java.version} strings, and verify the script exits with the same
status behavior.

echo ""
done

echo "=========================================="
echo "修复完成!"
echo "=========================================="
echo "总计: $TOTAL 个文件"
echo "修复: $FIXED 个文件"
echo "跳过: $SKIPPED 个文件"
echo ""
echo "备份文件已保存,如需恢复请使用:"
echo " cp <file>.backup.* <file>"
echo ""
echo "建议运行验证:"
echo " mvn clean compile -DskipTests"
echo " 或"
echo " bash ./build/verify-java17.sh"
9 changes: 2 additions & 7 deletions build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<version>3.3.2</version>
<configuration>
<packagingExcludes>
%regex[WEB-INF/lib/maven(?!-artifact).*.jar],
Expand Down Expand Up @@ -410,11 +410,6 @@
<artifactId>twoFactorAuthentication</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.zstack</groupId>
<artifactId>crypto</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.zstack</groupId>
<artifactId>loginControl</artifactId>
Expand Down Expand Up @@ -670,7 +665,7 @@
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<version>3.3.2</version>
<configuration>
<packagingExcludes>
%regex[WEB-INF/lib/maven(?!-artifact).*.jar],
Expand Down
Loading