Skip to content

Commit

Permalink
fix: maven analyzer, sort modules
Browse files Browse the repository at this point in the history
  • Loading branch information
iseki0 committed May 13, 2022
1 parent e729614 commit cd7d646
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.17

require (
github.com/AlecAivazis/survey/v2 v2.3.4
github.com/Masterminds/semver/v3 v3.1.1
github.com/antchfx/xmlquery v1.3.10
github.com/briandowns/spinner v1.18.1
github.com/denisbrodbeck/machineid v1.0.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/AlecAivazis/survey/v2 v2.3.4 h1:pchTU9rsLUSvWEl2Aq9Pv3k0IE2fkqtGxazskAMd9Ng=
github.com/AlecAivazis/survey/v2 v2.3.4/go.mod h1:hrV6Y/kQCLhIZXGcriDCUBtB3wnN7156gMXJ3+b23xM=
github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0=
github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
Expand Down
10 changes: 9 additions & 1 deletion module/maven/maven.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"murphysec-cli-simple/logger"
"murphysec-cli-simple/module/base"
"path/filepath"
"sort"
"sync"
)

Expand Down Expand Up @@ -40,7 +41,14 @@ func ScanMavenProject(dir string) ([]base.Module, error) {
pomFiles := InspectModule(dir)
logger.Info.Printf("scanned pom modules: %d", len(pomFiles))
resolver := NewResolver()
for _, builder := range pomFiles {
var builders []*PomBuilder
for _, it := range pomFiles {
builders = append(builders, it)
}
sort.Slice(builders, func(i, j int) bool {
return builders[i].Path < builders[j].Path
})
for _, builder := range builders {
{
pf := resolver.ResolveLocally(builder, nil)
if pf == nil {
Expand Down
10 changes: 7 additions & 3 deletions module/maven/resolve_deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ package maven

import (
"fmt"
"sort"
"strings"
)

type DepGraph map[Coordinate]map[Coordinate]struct{}

func (d DepGraph) DOT() string {
var s []string
s = append(s, "digraph dep {")
var t []string
for k, list := range d {
for v := range list {
s = append(s, fmt.Sprintf(" \"%s\" -> \"%s\"", k.String(), v.String()))
t = append(t, fmt.Sprintf(" \"%s\" -> \"%s\"", k.String(), v.String()))
}
}
sort.Strings(t)
var s []string
s = append(s, "digraph dep {")
s = append(s, t...)
s = append(s, "}")
return strings.Join(s, "\n")
}
Expand Down

0 comments on commit cd7d646

Please sign in to comment.