diff --git a/viz/filter.go b/viz/filter.go index 75213f9..4c7694e 100644 --- a/viz/filter.go +++ b/viz/filter.go @@ -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 +} diff --git a/viz/tq_viz_cli/cmd/coll.go b/viz/tq_viz_cli/cmd/coll.go index a130167..e36d351 100644 --- a/viz/tq_viz_cli/cmd/coll.go +++ b/viz/tq_viz_cli/cmd/coll.go @@ -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) }, } @@ -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("-----------") + +} \ No newline at end of file diff --git a/viz/tq_viz_cli/cmd/tar.go b/viz/tq_viz_cli/cmd/tar.go index c055ac3..2826505 100644 --- a/viz/tq_viz_cli/cmd/tar.go +++ b/viz/tq_viz_cli/cmd/tar.go @@ -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 }) @@ -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") }