Commit 7c9c9a5
fix(maven): resolve version ranges in component analysis (#491)
## Summary
Maven version ranges (e.g. `[1.2.17,1.3.0)`, `(1.0,2.0]`) in `pom.xml`
dependency versions are preserved verbatim by `mvn help:effective-pom`.
Component analysis uses the effective POM to extract dependency
versions, so range expressions end up as the version in the PackageURL
(e.g. `pkg:maven/log4j/log4j@[1.2.17,1.3.0)`). The backend cannot look
up vulnerabilities for a range-valued purl, so these dependencies are
silently dropped — no editor diagnostics appear for them.
Stack analysis is unaffected because it uses `mvn dependency:tree`,
which resolves ranges to concrete versions before output.
## How it works
After extracting dependencies from the effective POM,
`resolveVersionRanges` checks whether any dependency has a version range
(starts with `[` or `(`). If none do, it returns immediately — no
performance impact for normal projects.
When ranges are detected, it runs `mvn dependency:tree -DoutputType=text
-Dscope=compile` and parses the direct dependencies (depth 1) from the
text output using the existing `getDepth()` and `parseDep()` methods.
Each resolved `groupId:artifactId → version` mapping is collected, and
range-valued versions in the dependency list are replaced with the
concrete resolved versions before SBOM generation.
If the dependency tree invocation fails for any reason, a warning is
logged and the method falls back to the original unresolved versions, so
the overall flow is never broken.
## Changes
- **`JavaMavenProvider.java`** — Add `isVersionRange` and
`resolveVersionRanges` methods. Call `resolveVersionRanges` in
`generateSbomFromEffectivePom` after extracting deps from the effective
POM.
- **`Java_Maven_Provider_Test.java`** — Add `deps_with_version_range`
test folder. Update `test_the_provideComponent` and
`test_the_provideComponent_With_Path` mocks to dispatch both `-Doutput=`
(effective POM) and `-DoutputFile` (dep tree) arguments, with
`-Doutput=` changed from `-Doutput` to avoid matching `-DoutputFile` and
`-DoutputType`.
- **`src/test/resources/tst_manifests/maven/deps_with_version_range/`**
— New fixture with a range-valued dependency (`log4j [1.2.17,1.3.0)`),
verifying both stack and component analysis resolve the range to
`1.2.17`.
## Test plan
- [x] All existing Maven provider tests pass (stack + component analysis
+ component with path)
- [x] New version range test passes for all three test methods
- [x] Companion JS client PR:
guacsec/trustify-da-javascript-client#536
Ref:
fabric8-analytics/fabric8-analytics-vscode-extension#812
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent 0cce5c0 commit 7c9c9a5
7 files changed
Lines changed: 549 additions & 6 deletions
File tree
- src
- main/java/io/github/guacsec/trustifyda/providers
- test
- java/io/github/guacsec/trustifyda/providers
- resources/tst_manifests/maven/deps_with_version_range
Lines changed: 87 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| 44 | + | |
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
| |||
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
| 64 | + | |
| 65 | + | |
62 | 66 | | |
63 | 67 | | |
64 | 68 | | |
| |||
135 | 139 | | |
136 | 140 | | |
137 | 141 | | |
138 | | - | |
| 142 | + | |
139 | 143 | | |
140 | 144 | | |
141 | 145 | | |
| |||
228 | 232 | | |
229 | 233 | | |
230 | 234 | | |
| 235 | + | |
231 | 236 | | |
232 | 237 | | |
233 | 238 | | |
| |||
239 | 244 | | |
240 | 245 | | |
241 | 246 | | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
242 | 328 | | |
243 | 329 | | |
244 | 330 | | |
| |||
Lines changed: 83 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
59 | | - | |
| 60 | + | |
| 61 | + | |
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
| |||
143 | 145 | | |
144 | 146 | | |
145 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
146 | 156 | | |
147 | 157 | | |
148 | 158 | | |
149 | 159 | | |
150 | | - | |
151 | | - | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
152 | 171 | | |
153 | 172 | | |
154 | 173 | | |
| |||
189 | 208 | | |
190 | 209 | | |
191 | 210 | | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
192 | 219 | | |
193 | 220 | | |
194 | 221 | | |
195 | 222 | | |
196 | | - | |
197 | | - | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
198 | 234 | | |
199 | 235 | | |
200 | 236 | | |
| |||
209 | 245 | | |
210 | 246 | | |
211 | 247 | | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
212 | 290 | | |
213 | 291 | | |
214 | 292 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
0 commit comments