Commit dbbf877
authored
fix(maven): resolve property updates from parent POMs (#90)
* fix(maven): update properties in the POM that defines them
What:
- Resolve Maven property updates to the POM where the property is declared.
- Check the current POM first, then the direct parent POM, including parent relativePath values that point to a directory.
- Route dependency patches that use `${property}` through the same resolver before calling UpdatePom.
- Stop creating missing properties when the target property cannot be found.
- Add tests for current and parent property resolution, parent directory paths, dependency-backed property updates, shared properties, and missing-property errors.
Why:
- Maven modules often inherit dependency versions from parent POM properties.
- Updating or creating the property in the child POM can shadow the parent and leave the real version source unchanged.
- Resolving property ownership before patching keeps updates in the correct file and fails clearly when the property is not defined.
Fixes: https://linear.app/chainguard/issue/AUTO-631/
Signed-off-by: David Negreira <david.negreira@chainguard.dev>
* fix(maven): fail on conflicting version updates
What:
- Add a generic ErrVersionConflict for conflicting requested versions.
- Detect when multiple dependency patches for the same direct dependency request different versions.
- Detect when dependencies sharing the same Maven property request different versions.
- Detect when an explicit property update conflicts with a dependency update controlled by that property.
- Add tests for direct dependency, shared property, and explicit property conflict cases.
Why:
- Maven properties can control multiple dependencies, so only one requested version can actually be applied.
- Previously those conflicts surfaced later as confusing validation warnings like “dependency not found”.
- Failing early gives users a clear explanation before writing inconsistent or surprising POM updates.
Fixes: https://linear.app/chainguard/issue/AUTO-640/
Signed-off-by: David Negreira <david.negreira@chainguard.dev>
* fix(maven): reject POM updates outside project root
What:
- Validate Maven POM paths before updating and before writing files.
- Resolve symlinks before checking whether a POM path stays under the configured root.
- Add coverage for unsafe parent relative paths, absolute parent paths, direct manifest paths, and symlink escapes.
Why:
- Parent POM relative paths come from project XML and can point outside the repository.
- Without a root-boundary check, Maven updates could write to attacker-controlled paths outside the project.
- The tests lock in that only POMs inside the configured project root can be updated.
Signed-off-by: David Negreira <david.negreira@chainguard.dev>
* fix(maven): resolve properties through parent POM chain
What:
- Walk the full local parent POM chain when resolving where a Maven property is defined.
- Track visited POM paths to stop parent relativePath cycles.
- Collect inherited properties through the same parent chain during validation.
- Add tests for grandparent-defined dependency properties and parent POM cycles.
Why:
- Maven can resolve properties through multi-level parent chains, but we previously stopped after one parent.
- This caused valid leaf -> parent -> root configurations to fail with ErrPropertyNotFound.
- Cycle detection prevents malformed parent chains from looping forever.
Signed-off-by: David Negreira <david.negreira@chainguard.dev>
* fix(maven): small fixes
- Return error instead of just logging whent a property is not found
- Change matchedPatches from map[Patch]bool to map[Patch]struct{},
Using struct{} makes that intent clearer and avoids storing a bool
value that is always true.
Signed-off-by: David Negreira <david.negreira@chainguard.dev>
* fix(maven): add mavenLanguageName const
Signed-off-by: David Negreira <david.negreira@chainguard.dev>
---------
Signed-off-by: David Negreira <david.negreira@chainguard.dev>1 parent 2bee3b7 commit dbbf877
4 files changed
Lines changed: 1486 additions & 32 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
375 | 375 | | |
376 | 376 | | |
377 | 377 | | |
378 | | - | |
| 378 | + | |
379 | 379 | | |
380 | 380 | | |
381 | 381 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
38 | | - | |
| 37 | + | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
57 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
58 | 62 | | |
59 | 63 | | |
60 | 64 | | |
| |||
91 | 95 | | |
92 | 96 | | |
93 | 97 | | |
94 | | - | |
| 98 | + | |
95 | 99 | | |
96 | 100 | | |
97 | 101 | | |
| |||
147 | 151 | | |
148 | 152 | | |
149 | 153 | | |
150 | | - | |
| 154 | + | |
151 | 155 | | |
152 | 156 | | |
153 | 157 | | |
| |||
184 | 188 | | |
185 | 189 | | |
186 | 190 | | |
187 | | - | |
| 191 | + | |
188 | 192 | | |
189 | 193 | | |
190 | 194 | | |
| |||
207 | 211 | | |
208 | 212 | | |
209 | 213 | | |
210 | | - | |
211 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
212 | 217 | | |
213 | | - | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
214 | 262 | | |
215 | 263 | | |
216 | 264 | | |
217 | | - | |
| 265 | + | |
218 | 266 | | |
219 | 267 | | |
220 | 268 | | |
221 | | - | |
222 | | - | |
223 | | - | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
224 | 277 | | |
225 | 278 | | |
226 | | - | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
227 | 282 | | |
228 | 283 | | |
229 | 284 | | |
| |||
237 | 292 | | |
238 | 293 | | |
239 | 294 | | |
240 | | - | |
| 295 | + | |
241 | 296 | | |
| 297 | + | |
242 | 298 | | |
243 | 299 | | |
244 | 300 | | |
| |||
257 | 313 | | |
258 | 314 | | |
259 | 315 | | |
260 | | - | |
| 316 | + | |
261 | 317 | | |
262 | 318 | | |
263 | 319 | | |
| |||
268 | 324 | | |
269 | 325 | | |
270 | 326 | | |
271 | | - | |
| 327 | + | |
272 | 328 | | |
273 | 329 | | |
274 | 330 | | |
| |||
281 | 337 | | |
282 | 338 | | |
283 | 339 | | |
284 | | - | |
285 | | - | |
286 | | - | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
287 | 343 | | |
288 | 344 | | |
289 | 345 | | |
290 | | - | |
291 | | - | |
| 346 | + | |
292 | 347 | | |
293 | 348 | | |
| 349 | + | |
294 | 350 | | |
295 | 351 | | |
296 | 352 | | |
| |||
326 | 382 | | |
327 | 383 | | |
328 | 384 | | |
329 | | - | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
330 | 390 | | |
331 | 391 | | |
332 | 392 | | |
| |||
345 | 405 | | |
346 | 406 | | |
347 | 407 | | |
| 408 | + | |
348 | 409 | | |
349 | 410 | | |
350 | 411 | | |
| |||
382 | 443 | | |
383 | 444 | | |
384 | 445 | | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
385 | 455 | | |
386 | 456 | | |
387 | 457 | | |
| |||
0 commit comments