fix: combine SrcDir with sourcepath in FindbugsParser to produce complete file paths#197
Conversation
|
@copilot |
…e paths Co-authored-by: tomasbjerre <439571+tomasbjerre@users.noreply.github.com>
|
@copilot keep existing functionality if there is several SrcDir and only use SrcDir if there is exactly one. |
…ype SrcDir exists Co-authored-by: tomasbjerre <439571+tomasbjerre@users.noreply.github.com>
Done in 8ee6760. Removed the synthetic
Done in 8ee6760. |
|
@copilot the spotbugs-main.xml has several SrcDir, i want that case handled just like before. Only change behavior for when there is exactly one SrcDir. |
…xactly one Co-authored-by: tomasbjerre <439571+tomasbjerre@users.noreply.github.com>
Fixed in 9d446d8. |
|
@copilot there is no test case for the use case in original issue |
…rcDir exists Co-authored-by: tomasbjerre <439571+tomasbjerre@users.noreply.github.com>
Added in afb90be. New fixture Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
FindbugsParserwas ignoring<SrcDir>from the<Project>element and using only the rawsourcepathattribute (e.g.,com/example/Foo.java), producing package-relative paths that can't be resolved to actual files — especially in multi-module Maven projects.Changes
parseReportOutput(): collects<SrcDir>entries from the<Project>element via streaming parse, passes them toparseBugInstance()parseBugInstance(): delegates filename resolution to newresolveFilePath()resolveFilePath(): prepends the singleSrcDirtosourcepath; only applies when there is exactly oneSrcDirentry in total and it is a directory (not ending with.java) — falls back to rawsourcepathunchanged when there are zero or multipleSrcDirentries, fully preserving existing behaviorExample
Given:
Before:
violation.getFile()→com/example/Foo.javaAfter:
violation.getFile()→/builds/my-project/module-a/src/main/java/com/example/Foo.javaThe absolute path can then be made project-relative via
ViolationUtils.relativePath.Reports with multiple
SrcDirentries (e.g. a mix of a source root and individual.javafile paths) are unaffected — the rawsourcepathis returned as-is.Test coverage
testThatSrcDirIsCombinedWithSourcepathWhenExactlyOneSrcDir: new test usingspotbugs-one-srcdir.xml— a minimal real-format SpotBugs report with exactly one directorySrcDir, asserting the combined path/builds/my-project/module-a/src/main/java/com/example/Foo.javatestThatViolationsCanBeParsedFromSpotbugs2: uses the realspotbugs-main.xmlreport, which has multipleSrcDirentries, confirming the rawsourcepathis preserved unchanged in that caseOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.