-
Notifications
You must be signed in to change notification settings - Fork 87
Refactor maven xml updater #1011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v3_er
Are you sure you want to change the base?
Conversation
- Update MavenPackageUpdater to handle multiple Components - Loop through all Components and update each pom.xml file - Extracts file paths from Component.Location.File - Handles same vulnerability in multiple modules (e.g., backend + frontend) - All changes go into ONE PR (same vuln, same fix) - Update all tests to populate Components array with Location - Backward compatible: falls back to 'pom.xml' if no Components
- Remove backward compatibility fallback that masked bugs - If Components array is empty or missing Location data, fail explicitly - Better error message explains the issue is with scan results - Forces engine to always populate Components with Location - Prevents silent failures in multi-module projects
- Add constants for magic strings (separator, property prefix/suffix) - Extract parseMavenCoordinate() and toMavenCoordinate() helpers - Extract extractPropertyName() for property placeholder parsing - Remove all comments (code is self-documenting) - Simplify debug logs (no fmt.Sprintf) - DRY: no repetition anywhere - All tests still pass
- Better naming: matches ImpactedDependencyName field - parseDependencyName() / toDependencyName() - More accurate: we parse dependency names (groupId:artifactId), not coordinates (which include version)
- Replace encoding/xml with github.com/beevik/etree - Use DOM-based XML manipulation instead of unmarshal/marshal - Should preserve formatting, namespaces, and all XML attributes - All tests still pass - Need to test on real repo to verify formatting preservation
- Parse XML to understand structure (encoding/xml) - Use regex to replace ONLY the version text - Preserves ALL formatting, namespaces, blank lines, comments - Minimal diffs - only version numbers change - All tests pass - Ready for real-world testing
- Document all 5 test cases (simple, property, parent, depMgmt, multi-module) - Document engine limitations (parent POM resolution, non-standard pom names) - Document text-based replacement approach - Document multi-module support - Recommendations for engine team - Testing checklist
| if !repository.Params.FrogbotConfig.CreateAutoFixPr { | ||
| log.Info(fmt.Sprintf("This command is running in detection mode only. To enable automatic fixing of issues, set the '%s' flag under the repository's coniguration settings in Jfrog platform", createAutoFixPrConfigNameInProfile)) | ||
| return totalFindings, nil | ||
| } | ||
| //if !repository.Params.FrogbotConfig.CreateAutoFixPr { | ||
| // log.Info(fmt.Sprintf("This command is running in detection mode only. To enable automatic fixing of issues, set the '%s' flag under the repository's coniguration settings in Jfrog platform", createAutoFixPrConfigNameInProfile)) | ||
| // return totalFindings, nil | ||
| //} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will revert back
| func (mpu *MavenPackageUpdater) getPomPaths(vulnDetails *utils.VulnerabilityDetails) []string { | ||
| var pomPaths []string | ||
| for _, component := range vulnDetails.Components { | ||
| if component.Location != nil && component.Location.File != "" { | ||
| pomPaths = append(pomPaths, component.Location.File) | ||
| } | ||
| } | ||
| return pomPaths | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this gets all occurrences of a vulnerability (the exact package and version)
can be moved to a utils because multiple package updaters will use this logic
| ) | ||
|
|
||
| const ( | ||
| mavenCoordinateSeparator = ":" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can rename to package instead of coordinate
| updated := false | ||
| newContent := content | ||
|
|
||
| if updated, newContent = mpu.updateInParent(&project, groupId, artifactId, fixedVersion, newContent); updated { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently not working because of the engine
| return fmt.Errorf("dependency %s not found in %s", toDependencyName(groupId, artifactId), pomPath) | ||
| } | ||
|
|
||
| func (mpu *MavenPackageUpdater) SetCommonParams(serverDetails *config.ServerDetails, depsRepo string) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will remove once common package handler is deprecated ( can add todo)
6c8a76c to
c2727a7
Compare
c2727a7 to
d10294c
Compare
Uh oh!
There was an error while loading. Please reload this page.