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

Function parseMvnTree

opensca/sca/java/mvn.go:586–647  ·  view source on GitHub ↗

parseMvnTree 解析 mvn dependency:tree 的输出

(lines []string)

Source from the content-addressed store, hash-verified

584
585// parseMvnTree 解析 mvn dependency:tree 的输出
586func parseMvnTree(lines []string) *model.DepGraph {
587
588 // 记录当前的顶点节点列表
589 var tops = []*model.DepGraph{}
590 // 上一层级
591 lastLevel := -1
592
593 _dep := model.NewDepGraphMap(nil, func(s ...string) *model.DepGraph {
594 return &model.DepGraph{
595 Vendor: s[0],
596 Name: s[1],
597 Version: s[2],
598 }
599 }).LoadOrStore
600
601 for _, line := range lines {
602
603 // 计算层级
604 level := 0
605 for level*3+2 < len(line) && line[level*3+2] == ' ' {
606 level++
607 }
608 if level*3+2 >= len(line) {
609 continue
610 }
611
612 if level-lastLevel > 1 {
613 // 在某个依赖解析失败的时候 子依赖会出现这种情况
614 continue
615 }
616
617 tags := strings.Split(line[level*3:], ":")
618 if len(tags) < 4 {
619 continue
620 }
621
622 dep := _dep(tags[0], tags[1], tags[3])
623
624 if dep == nil {
625 continue
626 }
627
628 scope := tags[len(tags)-1]
629 if scope == "test" || scope == "provided" {
630 dep.Develop = true
631 }
632
633 if level > 0 {
634 tops[level-1].AppendChild(dep)
635 }
636
637 tops = append(tops[:level], dep)
638
639 lastLevel = level
640 }
641
642 if len(tops) > 0 {
643 return tops[0]

Callers 1

MvnTreeFunction · 0.85

Calls 2

NewDepGraphMapFunction · 0.92
AppendChildMethod · 0.80

Tested by

no test coverage detected