Skip to content

Conversation

@maishivamhoo123
Copy link

Description

This PR addresses issue #9989 by adding support for parsing <mirrors> in Maven settings.xml.

Previously, Trivy only retrieved repositories from <profiles>. This change ensures that mirrors defined in settings.xml are correctly parsed and applied. Specifically, it maps the mirrorOf field to ensure traffic intended for a repository (like central) is correctly routed to the configured mirror URL.

Related Issue

Checklist

  • Added Mirror struct and parsing logic in settings.go
  • Added unit tests covering various mirror configurations
  • Verified locally with go test ./pkg/dependency/parser/java/pom/...

@CLAassistant
Copy link

CLAassistant commented Dec 30, 2025

CLA assistant check
All committers have signed the CLA.

@maishivamhoo123
Copy link
Author

Dear @knqyf263 and @DmitriyLewen,

Thank you for your time. When you get a chance, could you please review this PR?

I would really appreciate any feedback or suggestions for improvement—I'm eager to learn and happy to make any required changes to align with the project’s standards.

Thanks again for your guidance and support. 🙏

s.LocalRepository = globalSettings.LocalRepository
}
//merge Mirrors
s.Mirrors = append(s.Mirrors, globalSettings.Mirrors...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked how mvn merges mirrors?
For example, global and local settings use a mirror for maven-central, but with different URLs.
What will mvn do?

Will it check both URLs or just one (from global or local)?

s.ActiveProfiles[i] = evaluateVariable(activeProfile, nil, nil)
}
}
func (s settings) ResolveMirror(repoID, repoURL string) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this function is used only in tests.
The parser still doesn't use mirrors.

Comment on lines +160 to +161
if strings.HasPrefix(pattern, "!") {
if pattern[1:] == repoID {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if strings.HasPrefix(pattern, "!") {
if pattern[1:] == repoID {
if p, ok := strings.CutPrefix(pattern, "!"); ok {
if p == repoID {

Comment on lines +167 to +168
matches = true
continue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC we can return true here

}
if pattern == "external:*" {
if s.isExternalRepo(repoURL) {
matches = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

continue
}
if pattern == repoID {
matches = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

}
return repoURL
}
func (s settings) isMirrorMatch(mirror Mirror, repoID, repoURL string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be great if you add some small comments with descriptions and/or examples in this function.
It will help support this code later.

@maishivamhoo123
Copy link
Author

Raising a new PR I actually lost my previous changes. So Raising a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(maven): add mirrors support for settings.xml files

3 participants