MCPcopy Create free account
hub / github.com/XmirrorSecurity/OpenSCA-cli / ParsePoms

Function ParsePoms

opensca/sca/java/mvn.go:27–99  ·  view source on GitHub ↗

ParsePoms 解析一个项目中的pom文件 poms: 项目中全部的pom文件列表 exclusion: 不需要解析的pom文件 call: 每个pom文件会解析成一个依赖图 返回对应的依赖图

(ctx context.Context, poms []*Pom, exclusion []*Pom, call func(pom *Pom, root *model.DepGraph))

Source from the content-addressed store, hash-verified

25// exclusion: 不需要解析的pom文件
26// call: 每个pom文件会解析成一个依赖图 返回对应的依赖图
27func ParsePoms(ctx context.Context, poms []*Pom, exclusion []*Pom, call func(pom *Pom, root *model.DepGraph)) {
28
29 // modules继承属性
30 inheritModules(poms)
31
32 // 记录当前项目的pom文件信息
33 gavMap := map[string]*model.File{}
34 PathMap := map[string]*model.File{}
35 for _, pom := range poms {
36 gavMap[pom.GAV()] = pom.File
37 pom.Update(&pom.PomDependency)
38 gavMap[pom.GAV()] = pom.File
39 if pom.File.Relpath() != "" {
40 PathMap[pom.File.Relpath()] = pom.File
41 }
42 }
43
44 // 获取dependency对应的pom
45 getpom := func(dep PomDependency, repos ...[]string) *Pom {
46 // 通过gav查找pom
47 f, ok := gavMap[dep.GAV()]
48 // 通过relativaPath查找pom
49 if !ok && dep.RelativePath != "" && dep.Define != nil && dep.Define.File.Relpath() != "" {
50 pompath := filepath.Join(filepath.Dir(dep.Define.File.Relpath()), dep.RelativePath)
51 f, ok = PathMap[pompath]
52 }
53 var p *Pom
54 if ok {
55 f.OpenReader(func(reader io.Reader) {
56 p = ReadPom(reader)
57 p.File = f
58 })
59 }
60 if p != nil {
61 return p
62 }
63 // 从组件仓库下载pom
64 var rs []common.RepoConfig
65 for _, urls := range repos {
66 for _, url := range urls {
67 rs = append(rs, common.RepoConfig{Url: url})
68 }
69 }
70 p = mavenOrigin(dep.GroupId, dep.ArtifactId, dep.Version, rs...)
71
72 if p == nil {
73 logs.Warnf("not found pom %s", dep.Index3())
74 }
75
76 return p
77 }
78
79 exclusionMap := map[*Pom]bool{}
80 for _, pom := range exclusion {
81 exclusionMap[pom] = true
82 }
83
84 wg := sync.WaitGroup{}

Callers 3

mainFunction · 0.92
ParseGradleFunction · 0.92
ScaMethod · 0.85

Calls 9

WarnfFunction · 0.92
inheritModulesFunction · 0.85
ReadPomFunction · 0.85
parsePomFunction · 0.85
GAVMethod · 0.80
RelpathMethod · 0.80
OpenReaderMethod · 0.80
Index3Method · 0.80
UpdateMethod · 0.45

Tested by

no test coverage detected