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

Function parsePom

opensca/sca/java/mvn.go:305–438  ·  view source on GitHub ↗

parsePom 解析单个pom 返回该pom的依赖图

(ctx context.Context, pom *Pom, getpom getPomFunc)

Source from the content-addressed store, hash-verified

303
304// parsePom 解析单个pom 返回该pom的依赖图
305func parsePom(ctx context.Context, pom *Pom, getpom getPomFunc) *model.DepGraph {
306
307 // 补全nil值
308 if pom.Properties == nil {
309 pom.Properties = PomProperties{}
310 }
311
312 pom.Update(&pom.PomDependency)
313
314 // 继承pom
315 inheritPom(pom, getpom)
316
317 // 记录在根pom的dependencyManagement中非import组件信息
318 rootPomManagement := map[string]*PomDependency{}
319 for _, dep := range pom.DependencyManagement {
320 if dep.Scope != "import" {
321 rootPomManagement[dep.Index2()] = dep
322 }
323 }
324
325 root := &model.DepGraph{Vendor: pom.GroupId, Name: pom.ArtifactId, Version: pom.Version, Path: pom.File.Relpath()}
326 root.Expand = pom
327
328 // 解析子依赖构建依赖关系
329 depIndex2Set := map[string]bool{}
330 root.ForEachNode(func(p, n *model.DepGraph) bool {
331
332 select {
333 case <-ctx.Done():
334 return false
335 default:
336 }
337
338 if n.Expand == nil {
339 return true
340 }
341
342 np := n.Expand.(*Pom)
343
344 for _, lic := range np.Licenses {
345 n.AppendLicense(lic)
346 }
347
348 // 记录在当前pom的dependencyManagement中非import组件信息
349 depManagement := map[string]*PomDependency{}
350 for _, dep := range np.DependencyManagement {
351 if dep.Scope != "import" {
352 depManagement[dep.Index2()] = dep
353 }
354 }
355
356 for _, dep := range np.Dependencies {
357
358 // 丢弃provided或optional=true的组件
359 if dep.Scope == "provided" || dep.Optional {
360 continue
361 }
362 // 丢弃scope为test的间接依赖

Callers 1

ParsePomsFunction · 0.85

Calls 13

ForEachNodeMethod · 0.95
DebugfFunction · 0.92
WarnfFunction · 0.92
inheritPomFunction · 0.85
replacePomDependencyFunction · 0.85
Index2Method · 0.80
RelpathMethod · 0.80
AppendLicenseMethod · 0.80
NeedExclusionMethod · 0.80
CheckMethod · 0.80
ImportPathStackMethod · 0.80
AppendChildMethod · 0.80

Tested by

no test coverage detected