Skip to content

Commit b406c3c

Browse files
committed
feat(java): wire scan.maven.mirrors to the pom analyzer
1 parent 0283653 commit b406c3c

5 files changed

Lines changed: 12 additions & 1 deletion

File tree

pkg/commands/artifact/run.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ func (r *runner) initScannerConfig(ctx context.Context, opts flag.Options) (Scan
653653
AWSEndpoint: opts.Endpoint,
654654
FileChecksum: fileChecksum,
655655
DetectionPriority: opts.DetectionPriority,
656+
MavenMirrors: opts.MavenMirrors,
656657

657658
// For image scanning
658659
ImageOption: ftypes.ImageOptions{

pkg/fanal/analyzer/analyzer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ func (f FilePatterns) Match(filePath string) bool {
172172
type AnalysisOptions struct {
173173
Offline bool
174174
FileChecksum bool
175+
176+
// MavenMirrors maps a Maven repository URL to an ordered list of fallback mirror URLs.
177+
MavenMirrors map[string][]string
175178
}
176179

177180
type AnalysisResult struct {

pkg/fanal/analyzer/language/java/pom/pom.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ type pomAnalyzer struct{}
2525

2626
func (a pomAnalyzer) Analyze(ctx context.Context, input analyzer.AnalysisInput) (*analyzer.AnalysisResult, error) {
2727
filePath := filepath.Join(input.Dir, input.FilePath)
28-
p := pom.NewParser(filePath, pom.WithOffline(input.Options.Offline))
28+
p := pom.NewParser(filePath,
29+
pom.WithOffline(input.Options.Offline),
30+
pom.WithConfigFileMirrors(input.Options.MavenMirrors),
31+
)
2932
res, err := language.Analyze(ctx, types.Pom, input.FilePath, input.Content, p)
3033
if err != nil {
3134
return nil, xerrors.Errorf("%s parse error: %w", input.FilePath, err)

pkg/fanal/artifact/artifact.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ type Option struct {
3333
FileChecksum bool // For SPDX
3434
DetectionPriority types.DetectionPriority
3535

36+
// MavenMirrors maps a Maven repository URL to an ordered list of fallback mirror URLs.
37+
MavenMirrors map[string][]string
38+
3639
// Original is the original target location, e.g. "github.com/aquasecurity/trivy"
3740
// Currently, it is used only for remote git repositories
3841
Original string

pkg/fanal/artifact/local/fs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ func (a Artifact) Inspect(ctx context.Context) (artifact.Reference, error) {
201201
opts := analyzer.AnalysisOptions{
202202
Offline: a.artifactOption.Offline,
203203
FileChecksum: a.artifactOption.FileChecksum,
204+
MavenMirrors: a.artifactOption.MavenMirrors,
204205
}
205206

206207
// Prepare filesystem for post analysis

0 commit comments

Comments
 (0)