-
Notifications
You must be signed in to change notification settings - Fork 89
fix:code check plugin(Checkstyle +PMD+SpotBugs) #324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
msslulu
wants to merge
188
commits into
opentiny:develop
Choose a base branch
from
msslulu:feat/codeCheckStyle
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
188 commits
Select commit
Hold shift + click to select a range
e5cde1b
fix:Checkstyle check
msslulu 95b5fb3
fix:Checkstyle check
msslulu e48f78a
fix:Checkstyle check
msslulu f7978be
fix:Checkstyle check
msslulu 4269943
fix:Checkstyle check
msslulu d3fd7b7
fix:Checkstyle check
msslulu b58e79f
fix:Checkstyle check
msslulu 45714f7
fix:Checkstyle check
msslulu 051cdc9
fix:Checkstyle check
msslulu 7d23198
fix:Checkstyle check
msslulu 35a3220
fix:Checkstyle check
msslulu 35bfea8
fix:Checkstyle check
msslulu 3843ac1
fix:Checkstyle check
msslulu 3a1b0c9
fix:Checkstyle check
msslulu c52edf3
fix:Checkstyle check
msslulu 929462f
fix:Checkstyle check
msslulu 989abaf
fix:Checkstyle check
msslulu c97a525
fix:Checkstyle check
msslulu 082e950
fix:Checkstyle check
msslulu 8ed95e0
fix:Checkstyle check
msslulu 5e47b0f
fix:Checkstyle check
msslulu ec22270
fix:Checkstyle check
msslulu f9fd623
fix:Checkstyle check test
msslulu 9025582
fix:Checkstyle check test
msslulu 8a82ac0
fix:Checkstyle check test
msslulu 2bee0b1
fix:Checkstyle check test
msslulu 4bf7806
fix:Checkstyle check test
msslulu 4102cc6
fix:Checkstyle check test
msslulu 9c654e9
fix:Checkstyle check test
msslulu 9c1e5c8
fix:Checkstyle check test
msslulu b1e0c25
fix:Checkstyle check test
msslulu 81d4c6b
fix:Checkstyle check test
msslulu 3e5b3ad
fix:Checkstyle check test
msslulu e5e0688
fix:Checkstyle check test
msslulu 44ab636
fix:Checkstyle check test
msslulu 08a2166
fix:Checkstyle check test
msslulu fc0c465
fix:Checkstyle check test
msslulu f931007
fix:Checkstyle check test
msslulu 625f4e9
fix:Checkstyle check test
msslulu 0ed0206
fix:Checkstyle check test
msslulu 2730cfc
fix:Checkstyle check test
msslulu a06b694
fix:Checkstyle check test
msslulu c0b8620
fix:Checkstyle check test
msslulu 63a64b9
fix:Checkstyle check test
msslulu 9b13999
fix:Checkstyle check test
msslulu 8413433
fix:Checkstyle check test
msslulu 9fb67ea
fix:Checkstyle check test
msslulu 22022b4
fix:Checkstyle check test
msslulu 3ceae07
fix:Checkstyle check test
msslulu 024bd39
fix:Checkstyle check test
msslulu 2f7db20
fix:Checkstyle check test
msslulu 05cb819
fix:Checkstyle check test
msslulu 70b30c9
fix:Checkstyle check test
msslulu 5d3ad7f
fix:Checkstyle check test
msslulu ccbc2c9
fix:Checkstyle check test
msslulu f3eecf9
fix:pmd test
msslulu 4384f22
fix:pmd test
msslulu eac5e85
fix:pmd test
msslulu f6012b6
fix:pmd test
msslulu b632204
fix:pmd test
msslulu 1a260c1
fix:pmd test
msslulu 4e52367
fix:pmd test
msslulu 81a56c3
fix:pmd test
msslulu 2cdffc4
fix:pmd test
msslulu aae082d
fix:pmd test
msslulu 1f12a91
fix:pmd test
msslulu fc02bcb
fix:pmd test
msslulu 3b63a2b
fix:pmd test
msslulu 1654700
fix:pmd test
msslulu b38b50a
fix:pmd test
msslulu 96e63c7
fix:pmd test
msslulu 8e5fb54
fix:pmd test
msslulu c8355ae
fix:pmd test
msslulu 424842f
fix:pmd test
msslulu 1ff2d9f
fix:pmd test
msslulu c6d5bb4
fix:pmd test
msslulu 1a7a165
fix:pmd test
msslulu 2ede5e4
fix:pmd test
msslulu 6937a69
fix:pmd test
msslulu 3afd810
fix:pmd test
msslulu 5580474
fix:pmd test
msslulu dec82dd
fix:pmd test
msslulu 631f8a1
fix:pmd test
msslulu 82a65e3
fix:pmd test
msslulu f55422b
fix:pmd test
msslulu a18fcdc
fix:pmd test
msslulu 9fc20ad
fix:pmd test
msslulu 6f87f7a
fix:pmd test
msslulu 472d06b
fix:pmd test
msslulu 0203930
fix:pmd test
msslulu c5e762c
fix:pmd test
msslulu 8506a6c
fix:pmd test
msslulu d766de0
fix:pmd test
msslulu 09fa71f
fix:pmd test
msslulu dceff4f
fix:pmd test
msslulu 7979afe
fix:pmd test
msslulu 3c9faf2
fix:code check test
msslulu 11b9e95
fix:code check test
msslulu 474acef
fix:code check test
msslulu ff97070
fix:code check test
msslulu cc7d855
fix:code check test
msslulu 5811ddc
fix:code check test
msslulu 8b81772
fix:code check test
msslulu 790c02c
fix:code check test
msslulu a518629
fix:code check test
msslulu c635530
fix:code check test
msslulu cdff35b
fix:code check test
msslulu 469d300
fix:code check test
msslulu 3d3435e
fix:code check test
msslulu 9bdc0ad
fix:code check test
msslulu 2cd2420
fix:code check test
msslulu 4916797
fix:code check test
msslulu 40eb809
fix:code check test
msslulu 8e46d1e
fix:code check test
msslulu 4efd3d7
fix:code check test
msslulu 1d2dab3
fix:code check test
msslulu e7e3871
fix:code check test
msslulu fe90229
fix:code check test
msslulu c58b1be
fix:code check test
msslulu 97df9cf
fix:code check test
msslulu f8b20fb
fix:code check test
msslulu cfb89c0
fix:code check test
msslulu fae1519
fix:code check test
msslulu f0229eb
fix:code check test
msslulu 19f3074
fix:code check test
msslulu 4f6ae1b
fix:code check test
msslulu ae30f19
fix:code check test
msslulu a3db57f
fix:code check test
msslulu a569a50
fix:code check test
msslulu d7a3834
fix:code check test
msslulu 71e0e73
fix:code check test
msslulu 344f69d
fix:code check test
msslulu b49067e
fix:code check test
msslulu 1f3cbce
fix:code check test
msslulu d451174
fix:code check test
msslulu b2ca052
fix:code check test
msslulu 954899a
fix:code check test
msslulu 437f0f4
fix:code check test
msslulu 48554eb
fix:code check test
msslulu 914515b
fix:code check test
msslulu a779bc7
fix:code check test
msslulu 85a786f
fix:code check test
msslulu 5df7d41
fix:code check test
msslulu a5d543b
fix:code check test
msslulu 35bb29e
fix:code check test
msslulu 03c659a
fix:code check test
msslulu f99e460
fix:code check test
msslulu f8ed350
fix:code check test
msslulu 54173f4
fix:code check test
msslulu 36473ef
fix:code check test
msslulu 91390a5
fix:code check test
msslulu 2bf9073
fix:code check test
msslulu 3c3a9ff
fix:code check test
msslulu 86b1f43
fix:code check test
msslulu 126fa92
fix:code check test
msslulu 0defb15
fix:code check test
msslulu 809fea7
fix:code check test
msslulu b6a118c
fix:code check test
msslulu fc7bed9
fix:code check test
msslulu a26a707
fix:code check test
msslulu caf7770
fix:code check test
msslulu 5a0e4c6
fix:code check test
msslulu d74df38
fix:code check test
msslulu 350192a
fix:code check test
msslulu 2757ebe
fix:code check test
msslulu 1128499
fix:code check test
msslulu b24b502
fix:code check test
msslulu da8dadb
fix:code check test
msslulu 664554d
fix:code check test
msslulu 34f8a99
fix:code check test
msslulu c83d468
fix:code check test
msslulu 87ec811
fix:code check test
msslulu e207886
fix:code check test
msslulu 6d816cd
fix:code check test
msslulu 748ac99
fix:code check test
msslulu f1dcf94
fix:code check test
msslulu d3f873e
fix:code check test
msslulu 0b411be
fix:code check test
msslulu 6e8e503
fix:code check test
msslulu d0c38e0
fix:code check test
msslulu 687bbf7
fix:code check test
msslulu 7cd5c8b
fix:code check test
msslulu 6d685d8
fix:code check test
msslulu 439ce95
fix:code check test
msslulu 4fc5207
fix:code check test
msslulu 0c47ddf
fix:code check test
msslulu dd3e7d3
fix:code check test
msslulu efde849
fix:code check test
msslulu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,207 @@ | ||
| #!/bin/bash | ||
| # ============================================================ | ||
| # checkstyle-pr.sh - 增量检查(扫描整个变更文件,不过滤行号) | ||
| # 功能:对本次提交中变更的 Java 文件执行完整的 Checkstyle 检查 | ||
| # 不阻断构建,生成完整报告 | ||
| # ============================================================ | ||
|
|
||
| set -e | ||
| unset GREP_OPTIONS | ||
| echo "========================================" | ||
| echo " Checkstyle 增量检查" | ||
| echo " 扫描范围:本次变更的 Java 文件(完整文件)" | ||
| echo "========================================" | ||
|
|
||
| # 1. 确定目标分支 | ||
| if [ -n "$GITHUB_BASE_REF" ]; then | ||
| BASE_BRANCH="origin/$GITHUB_BASE_REF" | ||
| elif [ -n "$GITHUB_REF" ] && [ "$GITHUB_EVENT_NAME" == "push" ]; then | ||
| BASE_BRANCH="HEAD^" | ||
| else | ||
| if git rev-parse --verify origin/main >/dev/null 2>&1; then | ||
| BASE_BRANCH="origin/main" | ||
| elif git rev-parse --verify origin/develop >/dev/null 2>&1; then | ||
| BASE_BRANCH="origin/develop" | ||
| else | ||
| echo "❌ 无法确定目标分支,请设置 BASE_BRANCH 环境变量。" | ||
| exit 1 | ||
| fi | ||
| echo "🔍 本地运行模式,对比分支: $BASE_BRANCH" | ||
| fi | ||
|
|
||
| # 2. 获取变更的 Java 文件 | ||
| if [ "$BASE_BRANCH" == "HEAD^" ]; then | ||
| CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRT "$BASE_BRANCH" HEAD -- '*.java' 2>/dev/null || true) | ||
| else | ||
| CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRT "$BASE_BRANCH"...HEAD -- '*.java' 2>/dev/null || true) | ||
| fi | ||
|
|
||
| if [ -z "$CHANGED_FILES" ]; then | ||
| echo "✅ 没有 Java 文件变更,跳过检查。" | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "📝 变更的 Java 文件:" | ||
| echo "$CHANGED_FILES" | ||
| echo "----------------------------------------" | ||
|
|
||
| # 按模块分组,并把路径转换为 Checkstyle includes 使用的源码相对路径 | ||
| declare -A module_files | ||
| for file in $CHANGED_FILES; do | ||
| module="${file%%/*}" | ||
| if [ -z "$module" ] || [ "$module" == "$file" ]; then | ||
| echo "⚠️ 忽略根目录文件: $file" | ||
| continue | ||
| fi | ||
| rel="${file#$module/}" | ||
| case "$rel" in | ||
| src/main/java/*) | ||
| include="${rel#src/main/java/}" | ||
| ;; | ||
| src/test/java/*) | ||
| include="${rel#src/test/java/}" | ||
| ;; | ||
| *) | ||
| echo "⚠️ 跳过非源码目录 Java 文件: $file" | ||
| continue | ||
| ;; | ||
| esac | ||
| if [ -z "${module_files[$module]}" ]; then | ||
| module_files[$module]="$include" | ||
| else | ||
| module_files[$module]="${module_files[$module]},$include" | ||
| fi | ||
| done | ||
|
|
||
| if [ ${#module_files[@]} -eq 0 ]; then | ||
| echo "⚠️ 没有识别到任何模块,跳过检查。" | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "📝 按模块分组后的相对路径:" | ||
| for module in "${!module_files[@]}"; do | ||
| echo " $module: ${module_files[$module]}" | ||
| done | ||
| echo "----------------------------------------" | ||
|
|
||
| total_violations=0 | ||
| execution_failures=0 | ||
|
|
||
| # 对每个模块执行 Checkstyle | ||
| for module in "${!module_files[@]}"; do | ||
| file_list="${module_files[$module]}" | ||
| report_file="$module/target/checkstyle-result.xml" | ||
| echo "🚀 扫描模块: $module" | ||
| echo " 文件列表: $file_list" | ||
|
|
||
| if [ ! -d "$module" ] || [ ! -f "$module/pom.xml" ]; then | ||
| echo "⚠️ 模块目录 $module 不存在或没有 pom.xml,跳过。" | ||
| continue | ||
| fi | ||
|
|
||
| echo " - 运行 Checkstyle 检查(增量扫描)..." | ||
| echo "$file_list" | ||
| set +e | ||
| PROJECT_ROOT=$(pwd) | ||
| rm -f "$report_file" | ||
| output=$(cd "$module" && \ | ||
| echo " Current directory: $(pwd)" && \ | ||
| echo " Checking file existence:" && \ | ||
| IFS=',' read -ra includes <<< "$file_list" && \ | ||
| for include in "${includes[@]}"; do \ | ||
| if [ -f "src/main/java/$include" ]; then \ | ||
| ls -l "src/main/java/$include"; \ | ||
| elif [ -f "src/test/java/$include" ]; then \ | ||
| ls -l "src/test/java/$include"; \ | ||
| else \ | ||
| echo " ⚠️ not found: $include"; \ | ||
| fi; \ | ||
| done && \ | ||
| mvn checkstyle:check \ | ||
| -Dcheckstyle.config.location="$PROJECT_ROOT/checkstyle/code-check-checkstyle.xml" \ | ||
| -Dcheckstyle.violationSeverity=warning \ | ||
| -Dcheckstyle.outputFormat=xml \ | ||
| -Dcheckstyle.includes="$file_list" 2>&1 ) | ||
| mvn_exit=$? | ||
| if [ $mvn_exit -ne 0 ]; then | ||
| echo " ⚠️ 模块 $module 的 Checkstyle 检查失败(但继续)" | ||
| fi | ||
| set -e | ||
| echo "$output" | ||
|
|
||
| # 从 XML 报告中统计违规数,比解析 Maven 日志更稳定 | ||
| if [ -f "$report_file" ]; then | ||
| count=$(grep -c -- '<error ' "$report_file" 2>/dev/null || true) | ||
| else | ||
| count=0 | ||
| fi | ||
| total_violations=$((total_violations + count)) | ||
| echo " 模块 $module 违规数: $count" | ||
|
|
||
| if [ $mvn_exit -ne 0 ] && [ "$count" -eq 0 ]; then | ||
| echo " ❌ 模块 $module 的 Checkstyle 执行失败,且未生成可解析的违规报告。" | ||
| execution_failures=$((execution_failures + 1)) | ||
| fi | ||
|
|
||
| # (可选)生成 HTML 报告供人工查看 | ||
| echo " - 生成 HTML 报告(可选)..." | ||
| set +e | ||
| (cd "$module" && mvn checkstyle:checkstyle \ | ||
| -Dcheckstyle.config.location="$PROJECT_ROOT/checkstyle/code-check-checkstyle.xml" \ | ||
| -Dcheckstyle.includes="$file_list" \ | ||
| -Dcheckstyle.violationSeverity=warning) > /dev/null 2>&1 | ||
| set -e | ||
| echo "" | ||
| done | ||
|
|
||
| # 汇总输出 | ||
| echo "----------------------------------------" | ||
| if [ $total_violations -eq 0 ]; then | ||
| echo "✅ 所有变更文件未发现违规!" | ||
| else | ||
| echo "⚠️ 总计发现 $total_violations 个违规。" | ||
| echo "" | ||
| echo "📋 违规摘要(前 30 条):" | ||
| for module in "${!module_files[@]}"; do | ||
| report_file="$module/target/checkstyle-result.xml" | ||
| if [ -f "$report_file" ] && grep -q -- '<error' "$report_file" 2>/dev/null; then | ||
| grep -- '<error' "$report_file" 2>/dev/null | head -30 | sed 's/<error //; s/\/>//' | \ | ||
| sed 's|line="|行号: |g; s|column="|列: |g; s|severity="|严重性: |g; s|message="|信息: |g; s|source="||g' | \ | ||
| while read -r line; do | ||
| echo " $line" | ||
| done || true | ||
| break | ||
| fi | ||
| done | ||
| fi | ||
|
|
||
| # Step Summary | ||
| if [ -n "$GITHUB_STEP_SUMMARY" ]; then | ||
| { | ||
| echo "## 📋 Checkstyle 汇总报告" | ||
| echo "" | ||
| echo "| 指标 | 结果 |" | ||
| echo "|------|------|" | ||
| if [ $total_violations -eq 0 ]; then | ||
| echo "| 总违规数 | ✅ **0** |" | ||
| else | ||
| echo "| 总违规数 | ⚠️ **$total_violations** |" | ||
| fi | ||
| echo "| 执行失败模块数 | $execution_failures |" | ||
| echo "| 涉及模块 | ${!module_files[*]} |" | ||
| echo "" | ||
| echo "📥 完整报告已作为 Artifact 上传。" | ||
| } >> "$GITHUB_STEP_SUMMARY" | ||
| fi | ||
|
|
||
| # 根据违规数决定退出码 | ||
| if [ $total_violations -eq 0 ] && [ $execution_failures -eq 0 ]; then | ||
| echo "✅ 检查通过,构建成功。" | ||
| exit 0 | ||
| elif [ $execution_failures -ne 0 ]; then | ||
| echo "❌ 有 $execution_failures 个模块 Checkstyle 执行失败,构建失败。" | ||
| exit 1 | ||
| else | ||
| echo "❌ 发现 $total_violations 个违规,构建失败。" | ||
| exit 1 | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| #!/bin/bash | ||
| # ============================================================ | ||
| # pmd-pr.sh - PMD 增量扫描脚本 | ||
| # 功能:只扫描本次提交中变更且仍存在的 Java 文件 | ||
| # 报告:target/pmd-report.xml、target/pmd-report.html | ||
| # ============================================================ | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| echo "========================================" | ||
| echo " PMD 增量扫描" | ||
| echo " 扫描范围:本次变更的 Java 文件" | ||
| echo "========================================" | ||
|
|
||
| # 1. 确定目标分支 | ||
| if [ -n "${GITHUB_BASE_REF:-}" ]; then | ||
| BASE_BRANCH="origin/$GITHUB_BASE_REF" | ||
| elif [ -n "${GITHUB_REF:-}" ] && [ "${GITHUB_EVENT_NAME:-}" == "push" ]; then | ||
| BASE_BRANCH="HEAD^" | ||
| else | ||
| if git rev-parse --verify origin/main >/dev/null 2>&1; then | ||
| BASE_BRANCH="origin/main" | ||
| elif git rev-parse --verify origin/develop >/dev/null 2>&1; then | ||
| BASE_BRANCH="origin/develop" | ||
| else | ||
| echo "❌ 无法确定目标分支,请设置 BASE_BRANCH 环境变量。" | ||
| exit 1 | ||
| fi | ||
| echo "🔍 本地运行模式,对比分支: $BASE_BRANCH" | ||
| fi | ||
|
|
||
| # 2. 获取变更的 Java 文件 | ||
| if [ "$BASE_BRANCH" == "HEAD^" ]; then | ||
| CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRT "$BASE_BRANCH" HEAD -- '*.java' 2>/dev/null || true) | ||
| else | ||
| CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRT "$BASE_BRANCH"...HEAD -- '*.java' 2>/dev/null || true) | ||
| fi | ||
|
|
||
| if [ -z "$CHANGED_FILES" ]; then | ||
| echo "✅ 没有 Java 文件变更,跳过 PMD 扫描。" | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "📝 变更的 Java 文件:" | ||
| echo "$CHANGED_FILES" | ||
| echo "----------------------------------------" | ||
|
|
||
| # 3. 生成文件列表(绝对路径),跳过已删除文件 | ||
| PROJECT_ROOT=$(pwd) | ||
| mkdir -p target | ||
| FILE_LIST="target/pmd-changed-files.txt" | ||
| REPORT_FILE="target/pmd-report.xml" | ||
| HTML_REPORT_FILE="target/pmd-report.html" | ||
| > "$FILE_LIST" | ||
| rm -f "$REPORT_FILE" "$HTML_REPORT_FILE" | ||
|
|
||
| scan_count=0 | ||
| for file in $CHANGED_FILES; do | ||
| if [ ! -f "$file" ]; then | ||
| echo "⚠️ 跳过不存在的文件: $file" | ||
| continue | ||
| fi | ||
|
|
||
| echo "$PROJECT_ROOT/$file" >> "$FILE_LIST" | ||
| scan_count=$((scan_count + 1)) | ||
| done | ||
|
|
||
| if [ "$scan_count" -eq 0 ]; then | ||
| echo "✅ 没有需要 PMD 扫描的现存 Java 文件。" | ||
| rm -f "$FILE_LIST" | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "📄 PMD 文件列表:$FILE_LIST" | ||
| cat "$FILE_LIST" | ||
| echo "----------------------------------------" | ||
|
|
||
| # 4. 准备 PMD(如果未安装) | ||
| PMD_VERSION="${PMD_VERSION:-6.55.0}" | ||
| PMD_HOME="${PMD_HOME:-target/pmd-bin-$PMD_VERSION}" | ||
| PMD_ZIP="target/pmd-bin-$PMD_VERSION.zip" | ||
| PMD_RULESETS="${PMD_RULESETS:-category/java/bestpractices.xml,category/java/codestyle.xml,category/java/design.xml,category/java/errorprone.xml,category/java/performance.xml,category/java/security.xml}" | ||
|
|
||
| if [ ! -x "$PMD_HOME/bin/run.sh" ]; then | ||
| echo "⬇️ 下载 PMD $PMD_VERSION ..." | ||
| rm -rf "$PMD_HOME" "$PMD_ZIP" "target/pmd-bin-$PMD_VERSION" | ||
| curl -fsSL "https://github.com/pmd/pmd/releases/download/pmd_releases%2F${PMD_VERSION}/pmd-bin-${PMD_VERSION}.zip" -o "$PMD_ZIP" | ||
| unzip -q "$PMD_ZIP" -d target | ||
| rm -f "$PMD_ZIP" | ||
| fi | ||
|
|
||
| PMD_CMD="$PMD_HOME/bin/run.sh" | ||
| chmod +x "$PMD_CMD" | ||
|
|
||
| # 5. 执行 PMD 扫描(使用 filelist) | ||
| echo "🚀 执行 PMD 扫描..." | ||
| set +e | ||
| "$PMD_CMD" pmd --no-cache \ | ||
| -filelist "$FILE_LIST" \ | ||
| -f xml \ | ||
| -R "$PMD_RULESETS" \ | ||
| -r "$REPORT_FILE" | ||
| pmd_exit=$? | ||
| set -e | ||
|
|
||
| # 6. 统计违规数 | ||
| if [ -f "$REPORT_FILE" ]; then | ||
| violations=$(grep -c -- '<violation ' "$REPORT_FILE" 2>/dev/null || true) | ||
| echo "✅ PMD 报告已生成:$REPORT_FILE" | ||
| else | ||
| violations=0 | ||
| echo "⚠️ PMD 未生成报告。" | ||
| fi | ||
|
|
||
| # 7. 生成 PMD HTML 可视化报告 | ||
| echo "🖼️ 生成 PMD HTML 报告..." | ||
| set +e | ||
| "$PMD_CMD" pmd --no-cache \ | ||
| -filelist "$FILE_LIST" \ | ||
| -f html \ | ||
| -R "$PMD_RULESETS" \ | ||
| -r "$HTML_REPORT_FILE" | ||
| pmd_html_exit=$? | ||
| set -e | ||
|
|
||
| if [ -f "$HTML_REPORT_FILE" ]; then | ||
| echo "✅ PMD HTML 报告已生成:$HTML_REPORT_FILE" | ||
| else | ||
| echo "⚠️ PMD HTML 报告未生成。" | ||
| fi | ||
|
|
||
| rm -f "$FILE_LIST" | ||
|
|
||
| if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then | ||
| { | ||
| echo "## PMD 增量扫描" | ||
| echo "" | ||
| echo "| 指标 | 结果 |" | ||
| echo "|------|------|" | ||
| echo "| 扫描文件数 | $scan_count |" | ||
| echo "| 违规数 | $violations |" | ||
| echo "| XML 报告 | $REPORT_FILE |" | ||
| echo "| HTML 报告 | $HTML_REPORT_FILE |" | ||
| } >> "$GITHUB_STEP_SUMMARY" | ||
| fi | ||
|
|
||
| if [ "$violations" -gt 0 ]; then | ||
| echo "❌ PMD 发现 $violations 个问题,构建失败。" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ "$pmd_exit" -ne 0 ]; then | ||
| echo "❌ PMD 执行失败,退出码: $pmd_exit" | ||
| exit "$pmd_exit" | ||
| fi | ||
|
|
||
| if [ "$pmd_html_exit" -ne 0 ]; then | ||
| echo "❌ PMD HTML 报告生成失败,退出码: $pmd_html_exit" | ||
| exit "$pmd_html_exit" | ||
| fi | ||
|
|
||
| echo "✅ PMD 未发现问题。" | ||
| exit 0 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] 多 commit push 只会扫描最后一个 commit。 push 分支把基线固定为
HEAD^,因此一次 push 包含多个 commit 时,较早 commit 修改、最后一个 commit 未再次触及的 Java 文件不会进入扫描范围;pmd-pr.sh:33-34和spotbugs-incremental.sh:296-297复制了同一逻辑,三种检查都会同时漏检。建议由 workflow 传入${{ github.event.before }}和${{ github.sha }},并处理全零 before SHA 的回退场景。