(f *model.File, doc *model.BomSWDocument)
| 16 | } |
| 17 | |
| 18 | func parseBomSWDoc(f *model.File, doc *model.BomSWDocument) *model.DepGraph { |
| 19 | |
| 20 | if doc == nil { |
| 21 | return nil |
| 22 | } |
| 23 | |
| 24 | depIdMap := map[string]*model.DepGraph{} |
| 25 | _dep := model.NewDepGraphMap(func(s ...string) string { |
| 26 | return s[0] |
| 27 | }, func(s ...string) *model.DepGraph { |
| 28 | vendor, name, version, language := model.ParsePurl(s[0]) |
| 29 | return &model.DepGraph{ |
| 30 | Vendor: vendor, |
| 31 | Name: name, |
| 32 | Version: version, |
| 33 | Language: language, |
| 34 | } |
| 35 | }).LoadOrStore |
| 36 | |
| 37 | for _, pkg := range doc.Software.Components { |
| 38 | dep := _dep(pkg.ID) |
| 39 | dep.Licenses = pkg.License |
| 40 | depIdMap[pkg.ID] = dep |
| 41 | } |
| 42 | |
| 43 | for _, dependOn := range doc.Software.Dependencies { |
| 44 | parent, ok := depIdMap[dependOn.Ref] |
| 45 | if !ok { |
| 46 | continue |
| 47 | } |
| 48 | for _, dep := range dependOn.DependsOn { |
| 49 | child, ok := depIdMap[dep.Ref] |
| 50 | if !ok { |
| 51 | continue |
| 52 | } |
| 53 | parent.AppendChild(child) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | root := &model.DepGraph{Path: f.Relpath()} |
| 58 | for _, dep := range depIdMap { |
| 59 | if len(dep.Parents) == 0 { |
| 60 | root.AppendChild(dep) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | return root |
| 65 | } |
no test coverage detected