parsePom 解析单个pom 返回该pom的依赖图
(ctx context.Context, pom *Pom, getpom getPomFunc)
| 303 | |
| 304 | // parsePom 解析单个pom 返回该pom的依赖图 |
| 305 | func 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的间接依赖 |
no test coverage detected