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

Function inheritModules

opensca/sca/java/mvn.go:102–182  ·  view source on GitHub ↗

inheritModules 继承modules属性

(poms []*Pom)

Source from the content-addressed store, hash-verified

100
101// inheritModules 继承modules属性
102func inheritModules(poms []*Pom) {
103
104 gavMap := map[string]bool{}
105 for _, pom := range poms {
106 gavMap[pom.GAV()] = true
107 }
108
109 // 记录pom继承关系
110 _mod := model.NewDepGraphMap(nil, func(s ...string) *model.DepGraph { return &model.DepGraph{Name: s[0]} })
111 for _, pom := range poms {
112 n := _mod.LoadOrStore(pom.ArtifactId)
113 n.Expand = pom
114 // 记录modules继承关系
115 for _, subMod := range pom.Modules {
116 n.AppendChild(_mod.LoadOrStore(subMod))
117 }
118 // 记录parent继承关系
119 if gavMap[pom.Parent.GAV()] {
120 _mod.LoadOrStore(pom.Parent.ArtifactId).AppendChild(n)
121 }
122 }
123
124 // 传递属性
125 _mod.Range(func(k string, v *model.DepGraph) bool {
126
127 // 跳过非根pom
128 if len(v.Parents) > 0 {
129 return true
130 }
131
132 // 从每个根pom开始遍历
133 v.ForEachPath(func(p, n *model.DepGraph) bool {
134
135 // Expand为空代表当前节点已传递属性
136 if n.Expand == nil {
137 return true
138 }
139
140 // 判断parent.Expand是否为空来判断parent是否已经传递过属性
141 for _, p := range n.Parents {
142 if p.Expand != nil {
143 // 至少一个parent尚未传递属性则不处理当前节点
144 return true
145 }
146 }
147
148 // 获取当前pom
149 pom, ok := n.Expand.(*Pom)
150 if !ok {
151 return true
152 }
153
154 // 置空Expand标记该节点已传递属性
155 n.Expand = nil
156
157 // 将属性传递给需要继承的pom
158 for _, c := range n.Children {
159 mod := _mod.LoadOrStore(c.Name)

Callers 1

ParsePomsFunction · 0.85

Calls 6

LoadOrStoreMethod · 0.95
RangeMethod · 0.95
NewDepGraphMapFunction · 0.92
GAVMethod · 0.80
AppendChildMethod · 0.80
ForEachPathMethod · 0.80

Tested by

no test coverage detected