Skip to content

Commit

Permalink
code dependencies by group, for split package
Browse files Browse the repository at this point in the history
  • Loading branch information
newlee committed Nov 30, 2018
1 parent bed7900 commit 6da80b3
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
23 changes: 23 additions & 0 deletions viz/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,26 @@ func (r *RegexpFilter) AddExcludes(fileName string) *RegexpFilter {
r.excludes = readFilterFile(fileName)
return r
}

type PrefixFilter struct {
whiteList []string
}


func CreatePrefixFilter(fileName string) *PrefixFilter {
pf := &PrefixFilter { whiteList: make([]string, 0)}
lines := readFilterFile(fileName)
for _, line := range lines {
pf.whiteList = append(pf.whiteList, line)
}
return pf
}

func (p *PrefixFilter) Match(s string) bool {
for _, prefix := range p.whiteList {
if strings.HasPrefix(s, prefix) {
return true
}
}
return false
}
80 changes: 80 additions & 0 deletions viz/tq_viz_cli/cmd/coll.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ var collCmd *cobra.Command = &cobra.Command{
}
return false
}
if cmd.Flag("java").Value.String() != "" && cmd.Flag("common").Value.String() != "" {
javaFilterFile := cmd.Flag("java").Value.String()
commonFilterFile := cmd.Flag("common").Value.String()
javaFilter := CreatePrefixFilter(javaFilterFile)

commonFilter := CreatePrefixFilter(commonFilterFile)
printRelation(result, javaFilter.Match, commonFilter.Match)
return

}
result.ToDot(cmd.Flag("output").Value.String(), ".", nodeFilter)
},
}
Expand All @@ -61,4 +71,74 @@ func init() {
collCmd.Flags().BoolP("entryPoints", "E", false, "list entry points")
collCmd.Flags().BoolP("fanInFanOut", "F", false, "sorted fan-in and fan-out")
collCmd.Flags().BoolP("mergePackage", "P", false, "merge package/folder for include dependencies")
collCmd.Flags().StringP("java", "j", "", "java class filter")
collCmd.Flags().StringP("common", "c", "", "common java class")

}


func printRelation(f *FullGraph, javaFilter func(string)(bool), commonFilter func(string)(bool)){

class2other,other2class,class2common,other2common, common2 := make([]*Relation, 0),make([]*Relation, 0),make([]*Relation, 0),make([]*Relation, 0),make([]*Relation, 0)

var isOther = func(s string) bool {
return !javaFilter(s) && !commonFilter(s)
}
for _, relation := range f.RelationList {
if !strings.Contains(relation.To, ".") {
continue
}
if javaFilter(relation.From) && !javaFilter(relation.To) {
if commonFilter(relation.To) {
class2common = append(class2common, relation)
}
if !commonFilter(relation.To) {
class2other = append(class2other, relation)
}
}

if isOther(relation.From) && !isOther(relation.To) {
if javaFilter(relation.To) {
other2class = append(other2class, relation)
}
if commonFilter(relation.To) {
other2common = append(other2common, relation)
}
}

if commonFilter(relation.From) && !commonFilter(relation.To) {
common2 = append(common2, relation)
}
}

fmt.Println("class2other:")
for _,r := range class2other {
fmt.Printf("%s -> %s\n", r.From, r.To)
}
fmt.Println("-----------")
fmt.Println("")
fmt.Println("other2class:")
for _,r := range other2class {
fmt.Printf("%s -> %s\n", r.From, r.To)
}
fmt.Println("-----------")
fmt.Println("")
fmt.Println("class2common:")
for _,r := range class2common {
fmt.Printf("%s -> %s\n", r.From, r.To)
}
fmt.Println("-----------")
fmt.Println("")
fmt.Println("other2common:")
for _,r := range other2common {
fmt.Printf("%s -> %s\n", r.From, r.To)
}
fmt.Println("-----------")
fmt.Println("")
fmt.Println("common2...:")
for _,r := range common2 {
fmt.Printf("%s -> %s\n", r.From, r.To)
}
fmt.Println("-----------")

}
13 changes: 13 additions & 0 deletions viz/tq_viz_cli/cmd/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ var tarCmd *cobra.Command = &cobra.Command{
if cmd.Flag("mergePackage").Value.String() == "true" {
result = result.MergeHeaderFile(MergePackageFunc)
}
if cmd.Flag("java").Value.String() != "" && cmd.Flag("common").Value.String() != "" {
javaFilterFile := cmd.Flag("java").Value.String()
commonFilterFile := cmd.Flag("common").Value.String()
javaFilter := CreatePrefixFilter(javaFilterFile)

commonFilter := CreatePrefixFilter(commonFilterFile)
printRelation(result, javaFilter.Match, commonFilter.Match)
return

}

result.ToDot(cmd.Flag("output").Value.String(), ".", func(s string) bool {
return false
})
Expand All @@ -117,4 +128,6 @@ func init() {
tarCmd.Flags().StringP("source", "s", "", "source code directory")
tarCmd.Flags().StringP("filter", "f", "coll__graph.dot", "dot file filter")
tarCmd.Flags().StringP("output", "o", "dep.dot", "output dot file name")
tarCmd.Flags().StringP("java", "j", "", "java class filter")
tarCmd.Flags().StringP("common", "c", "", "common java class")
}

0 comments on commit 6da80b3

Please sign in to comment.