Skip to content

Fenrir fixes

Fenrir fixes #39

Workflow file for this run

name: SpotBugs Static Analysis
on:
pull_request:
branches: [ '*' ]
paths:
- '**/*.java'
- 'build.xml'
- 'spotbugs-exclude.xml'
jobs:
spotbugs:
runs-on: ubuntu-latest
name: Run SpotBugs
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Java 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- name: Set up Ant
run: |
sudo apt-get update
sudo apt-get install -y ant
- name: Download JUnit
run: |
mkdir -p /tmp/junit
wget -q -P /tmp/junit \
"https://repo1.maven.org/maven2/junit/junit/4.13.2/junit-4.13.2.jar"
echo "JUNIT_HOME=/tmp/junit" >> $GITHUB_ENV
- name: Download and set up SpotBugs
run: |
SPOTBUGS_VERSION="4.9.3"
wget -q "https://github.com/spotbugs/spotbugs/releases/download/${SPOTBUGS_VERSION}/spotbugs-${SPOTBUGS_VERSION}.tgz"
tar xzf "spotbugs-${SPOTBUGS_VERSION}.tgz"
echo "SPOTBUGS_HOME=${GITHUB_WORKSPACE}/spotbugs-${SPOTBUGS_VERSION}" >> $GITHUB_ENV
- name: Run SpotBugs
run: |
ant spotbugs
- name: Check for SpotBugs warnings
if: always()
run: |
REPORT="build/reports/spotbugs.html"
if [ ! -f "$REPORT" ]; then
echo "SpotBugs report not found"
exit 1
fi
# Extract warning count from report
COUNT=$(python3 -c "
import re
with open('$REPORT', 'r') as f:
content = f.read()
m = re.search(r'<b>Total Warnings</b>.*?<b>(\d+)</b>', content, re.DOTALL)
print(m.group(1) if m else '0')
")
if [ "$COUNT" -eq 0 ]; then
echo "=================================="
echo "SpotBugs: 0 warnings found"
echo "=================================="
exit 0
fi
echo "=================================="
echo "SpotBugs: $COUNT warning(s) found"
echo "=================================="
echo ""
# Print each warning
python3 -c "
import re
with open('$REPORT', 'r') as f:
content = f.read()
pattern = r'priority-(\d)\">([\w]+)</span>.*?</td>\s*<td>(.*?)</td>.*?Bug type (\w+).*?</p>'
warnings = re.findall(pattern, content, re.DOTALL)
for pri, code, desc, full_type in warnings:
d = re.sub(r'<[^>]+>', '', desc).strip()
loc = ''
m2 = re.search(r'At ([\w.]+:\[line \d+\])', d)
print(f'[P{pri}] {full_type}')
print(f' {d[:200]}')
print()
"
exit 1