Skip to content

Commit

Permalink
fix: maven 扫描,mvn命令返回的根节点是当前项目,应返回其子节点
Browse files Browse the repository at this point in the history
  • Loading branch information
iseki-working committed Jun 26, 2022
1 parent 1370266 commit 3a9a118
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions module/maven/mvn_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ type dependencyGraph struct {
}

func (d dependencyGraph) Tree() []Dependency {
// from -> listOf to
edges := map[int][]int{}
for _, it := range d.Dependencies {
edges[it.NumericFrom] = append(edges[it.NumericFrom], it.NumericTo)
}

root := make([]bool, len(d.Artifacts))
for _, it := range d.Dependencies {
root[it.NumericTo] = true
Expand All @@ -133,23 +139,34 @@ func (d dependencyGraph) Tree() []Dependency {
rootNums = append(rootNums, idx)
}
}

// from -> listOf to
edges := map[int][]int{}
for _, it := range d.Dependencies {
edges[it.NumericFrom] = append(edges[it.NumericFrom], it.NumericTo)
if len(rootNums) == 0 {
logger.Warn.Println("root node not found")
return nil
} else if len(rootNums) > 1 {
logger.Warn.Println("found more than one root node")
visited := make([]bool, len(d.Artifacts))
var rs []Dependency
for _, rootN := range rootNums {
t := d._tree(rootN, visited, edges)
if t == nil {
continue
}
rs = append(rs, *t)
}
return rs
} else {
visited := make([]bool, len(d.Artifacts))
t := d._tree(rootNums[0], visited, edges)
if t != nil {
return t.Children
}
}

var rs []Dependency
visited := make([]bool, len(d.Artifacts))
for _, rootN := range rootNums {
t := d._tree(rootN, visited, edges)
if t == nil {
continue
}
rs = append(rs, *t)
t := d._tree(rootNums[0], visited, edges)
if t != nil {
return t.Children
}
return rs
return nil
}

func (d dependencyGraph) _tree(id int, visitedId []bool, edges map[int][]int) *Dependency {
Expand Down

0 comments on commit 3a9a118

Please sign in to comment.