Skip to content

Commit 2716496

Browse files
committed
use spotbugs cli to solve classpath issue
1 parent fbd7a15 commit 2716496

2 files changed

Lines changed: 139 additions & 26 deletions

File tree

.github/workflows/verify.yml

Lines changed: 135 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ jobs:
2020
java-version: ${{ env.JAVA_VERSION }}
2121
- name: Set up Workspace Environment Variable
2222
run: echo "WORKSPACE=${{ github.workspace }}" >> $GITHUB_ENV
23-
- name: Cache Maven dependencies
24-
uses: actions/cache@v4
25-
with:
26-
path: /home/runner/.m2/repository
27-
key: ${{ runner.os }}-maven-0-${{ hashFiles('**/pom.xml') }}
23+
- name: Cache Maven and p2 dependencies
24+
uses: actions/cache@v4
25+
with:
26+
path: |
27+
/home/runner/.m2/repository
28+
/home/runner/.p2
29+
key: ${{ runner.os }}-maven-0-${{ hashFiles('**/pom.xml') }}
2830
- name: Compile with Maven
2931
run: mvn clean compile -f ./ddk-parent/pom.xml --batch-mode -T3C
3032
- name: Upload compiled artifacts
@@ -108,11 +110,13 @@ jobs:
108110
java-version: ${{ env.JAVA_VERSION }}
109111
- name: Set up Workspace Environment Variable
110112
run: echo "WORKSPACE=${{ github.workspace }}" >> $GITHUB_ENV
111-
- name: Cache Maven dependencies
112-
uses: actions/cache@v4
113-
with:
114-
path: /home/runner/.m2/repository
115-
key: ${{ runner.os }}-maven-0-${{ hashFiles('**/pom.xml') }}
113+
- name: Cache Maven and p2 dependencies
114+
uses: actions/cache@v4
115+
with:
116+
path: |
117+
/home/runner/.m2/repository
118+
/home/runner/.p2
119+
key: ${{ runner.os }}-maven-0-${{ hashFiles('**/pom.xml') }}
116120
- name: Run ${{ matrix.tool }}
117121
run: |
118122
case "${{ matrix.tool }}" in
@@ -140,18 +144,125 @@ jobs:
140144
java-version: ${{ env.JAVA_VERSION }}
141145
- name: Set up Workspace Environment Variable
142146
run: echo "WORKSPACE=${{ github.workspace }}" >> $GITHUB_ENV
143-
- name: Cache Maven dependencies
144-
uses: actions/cache@v4
145-
with:
146-
path: /home/runner/.m2/repository
147-
key: ${{ runner.os }}-maven-0-${{ hashFiles('**/pom.xml') }}
147+
- name: Cache Maven and p2 dependencies
148+
uses: actions/cache@v4
149+
with:
150+
path: |
151+
/home/runner/.m2/repository
152+
/home/runner/.p2
153+
key: ${{ runner.os }}-maven-0-${{ hashFiles('**/pom.xml') }}
148154
- name: Download compiled artifacts
149155
uses: actions/download-artifact@v4
150156
with:
151157
name: compiled-classes
152158
path: .
153-
- name: Run SpotBugs
154-
run: mvn spotbugs:check -f ./ddk-parent/pom.xml --batch-mode -T2C
159+
- name: Run SpotBugs
160+
run: |
161+
set -eo pipefail
162+
mkdir -p target/spotbugs
163+
164+
# Collect all compiled class directories
165+
mapfile -t CLASS_DIRS < <(find . -type d -path '*/target/classes' -print | sort)
166+
if [ "${#CLASS_DIRS[@]}" -eq 0 ]; then
167+
echo "No class directories found. Did the compile artifacts download?"
168+
exit 1
169+
fi
170+
171+
# Build classpath from all class directories
172+
CLASS_CP=$(IFS=:; echo "${CLASS_DIRS[*]}")
173+
174+
# Add Tycho-resolved target platform bundles from the local Maven repo p2 cache
175+
P2_ROOT="$HOME/.m2/repository/p2"
176+
P2_CP=""
177+
if [ -d "$P2_ROOT" ]; then
178+
echo "Collecting p2 bundle jars from $P2_ROOT"
179+
mapfile -t P2_JARS < <(find "$P2_ROOT" -type f \( -path '*/plugins/*.jar' -o -path '*/bundles/*.jar' \) -print | sort -u)
180+
if [ "${#P2_JARS[@]}" -gt 0 ]; then
181+
P2_CP=$(IFS=:; echo "${P2_JARS[*]}")
182+
fi
183+
else
184+
echo "WARNING: p2 cache not found at $P2_ROOT; aux classpath may be incomplete"
185+
fi
186+
187+
# Also include Tycho cache location used by some setups
188+
TYCHO_CACHE_ROOT="$HOME/.m2/repository/.cache/tycho"
189+
TYCHO_CP=""
190+
if [ -d "$TYCHO_CACHE_ROOT" ]; then
191+
echo "Collecting Tycho cache bundle jars from $TYCHO_CACHE_ROOT"
192+
mapfile -t TYCHO_JARS < <(find "$TYCHO_CACHE_ROOT" -type f \( -path '*/plugins/*.jar' -o -path '*/bundles/*.jar' \) -print | sort -u)
193+
if [ "${#TYCHO_JARS[@]}" -gt 0 ]; then
194+
TYCHO_CP=$(IFS=:; echo "${TYCHO_JARS[*]}")
195+
fi
196+
fi
197+
198+
# Include Eclipse p2 shared pool used by Tycho on GitHub runners
199+
P2_POOL_ROOT="$HOME/.p2/pool"
200+
P2_POOL_CP=""
201+
if [ -d "$P2_POOL_ROOT" ]; then
202+
echo "Collecting p2 pool bundle jars from $P2_POOL_ROOT"
203+
mapfile -t P2_POOL_JARS < <(find "$P2_POOL_ROOT" -type f -path '*/plugins/*.jar' -print | sort -u)
204+
if [ "${#P2_POOL_JARS[@]}" -gt 0 ]; then
205+
P2_POOL_CP=$(IFS=:; echo "${P2_POOL_JARS[*]}")
206+
fi
207+
fi
208+
209+
# Combine to final AUX_CP
210+
AUX_CP="$CLASS_CP"
211+
if [ -n "$P2_CP" ]; then
212+
AUX_CP="$AUX_CP:$P2_CP"
213+
fi
214+
if [ -n "$TYCHO_CP" ]; then
215+
AUX_CP="$AUX_CP:$TYCHO_CP"
216+
fi
217+
if [ -n "$P2_POOL_CP" ]; then
218+
AUX_CP="$AUX_CP:$P2_POOL_CP"
219+
fi
220+
221+
# Fetch SpotBugs distribution ZIP (includes all dependencies)
222+
mvn -q dependency:copy \
223+
-Dartifact=com.github.spotbugs:spotbugs:4.9.6:zip \
224+
-DoutputDirectory=target/spotbugs
225+
226+
unzip -q -o target/spotbugs/spotbugs-4.9.6.zip -d target/spotbugs/dist
227+
SPOTBUGS_HOME=$(find target/spotbugs/dist -maxdepth 1 -type d -name 'spotbugs-*' | head -n1)
228+
echo "Using SpotBugs home: $SPOTBUGS_HOME"
229+
230+
# Run SpotBugs CLI via main class with full lib classpath
231+
set +e
232+
java -Xmx6g -cp "$SPOTBUGS_HOME/lib/*" edu.umd.cs.findbugs.LaunchAppropriateUI \
233+
-textui -effort:max -low -maxRank 15 -exitcode \
234+
-exclude ddk-configuration/findbugs/exclusion-filter.xml \
235+
-auxclasspath "$AUX_CP" \
236+
-xml:withMessages \
237+
-output target/spotbugs/spotbugs.xml \
238+
"${CLASS_DIRS[@]}" 2>&1 | tee target/spotbugs/spotbugs.log
239+
SPOTBUGS_RC=${PIPESTATUS[0]}
240+
set -e
241+
242+
# Optional: fail if any missing classes remain
243+
MISSING=0
244+
if grep -q "needed for analysis were missing" target/spotbugs/spotbugs.log; then
245+
echo "ERROR: SpotBugs reported missing classes. Aux classpath is incomplete."
246+
MISSING=1
247+
fi
248+
249+
# Preserve SpotBugs exit status but still report missing-classes
250+
if [ "$SPOTBUGS_RC" -ne 0 ]; then
251+
exit "$SPOTBUGS_RC"
252+
fi
253+
if [ "$MISSING" -ne 0 ]; then
254+
exit 2
255+
fi
256+
257+
- name: Upload SpotBugs report
258+
if: always()
259+
uses: actions/upload-artifact@v4
260+
with:
261+
name: spotbugs-report
262+
path: |
263+
target/spotbugs/spotbugs.xml
264+
target/spotbugs/spotbugs.log
265+
retention-days: 7
155266

156267
integration-tests:
157268
needs: compile
@@ -169,11 +280,13 @@ jobs:
169280
java-version: ${{ env.JAVA_VERSION }}
170281
- name: Set up Workspace Environment Variable
171282
run: echo "WORKSPACE=${{ github.workspace }}" >> $GITHUB_ENV
172-
- name: Cache Maven dependencies
173-
uses: actions/cache@v4
174-
with:
175-
path: /home/runner/.m2/repository
176-
key: ${{ runner.os }}-maven-0-${{ hashFiles('**/pom.xml') }}
283+
- name: Cache Maven and p2 dependencies
284+
uses: actions/cache@v4
285+
with:
286+
path: |
287+
/home/runner/.m2/repository
288+
/home/runner/.p2
289+
key: ${{ runner.os }}-maven-0-${{ hashFiles('**/pom.xml') }}
177290
- name: Download compiled artifacts
178291
uses: actions/download-artifact@v4
179292
with:

ddk-parent/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
33
<modelVersion>4.0.0</modelVersion>
44

55
<groupId>com.avaloq.tools.ddk</groupId>
@@ -51,13 +51,14 @@
5151
<clean.version>3.5.0</clean.version>
5252
<deploy.version>3.1.4</deploy.version>
5353
<spotbugs.plugin.version>4.9.6.0</spotbugs.plugin.version>
54-
<spotbugs.version>4.9.5</spotbugs.version>
54+
<spotbugs.version>4.9.6</spotbugs.version>
5555
<pmd.plugin.version>3.27.0</pmd.plugin.version>
5656
<pmd.version>7.17.0</pmd.version>
5757
<tycho.version>5.0.0</tycho.version>
5858
<xtend.version>2.40.0</xtend.version>
5959
</properties>
6060

61+
6162
<modules>
6263
<module>../ddk-target</module>
6364
<module>../ddk-repository</module>
@@ -360,7 +361,6 @@
360361
<excludeFilterFile>${spotbugs.excludeFilterFile}</excludeFilterFile>
361362
<maxHeap>1024</maxHeap>
362363
<classFilesDirectory>${project.build.directory}/classes</classFilesDirectory>
363-
<auxclasspath>${project.build.directory}/../*/target/classes</auxclasspath>
364364
</configuration>
365365
</plugin>
366366
</plugins>

0 commit comments

Comments
 (0)