-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial golang callgraph implementation
- Loading branch information
1 parent
58ac790
commit c66044f
Showing
26 changed files
with
896 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package finder | ||
|
||
type IFinder interface { | ||
FindMavenRoots(files []string) ([]string, error) | ||
FindJavaClassDirs(files []string, findJars bool) ([]string, error) | ||
FindRoots(files []string) ([]string, error) | ||
FindDependencyDirs(files []string, findJars bool) ([]string, error) | ||
FindFiles(paths []string, exclusions []string) ([]string, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package golanfinder | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/debricked/cli/internal/callgraph/finder" | ||
"github.com/debricked/cli/internal/file" | ||
) | ||
|
||
type GolangFinder struct{} | ||
|
||
func (f GolangFinder) FindRoots(files []string) ([]string, error) { | ||
mainFiles := finder.FilterFiles(files, "main.go") | ||
return mainFiles, nil | ||
} | ||
|
||
func (f GolangFinder) FindDependencyDirs(files []string, findJars bool) ([]string, error) { | ||
// Not needed for golang | ||
return []string{}, nil | ||
} | ||
|
||
func (f GolangFinder) FindFiles(roots []string, exclusions []string) ([]string, error) { | ||
files := make(map[string]bool) | ||
var err error = nil | ||
|
||
for _, root := range roots { | ||
err = filepath.Walk(root, func(path string, info os.FileInfo, err error) error { | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
excluded := file.Excluded(exclusions, path) | ||
|
||
if info.IsDir() && excluded { | ||
return filepath.SkipDir | ||
} | ||
|
||
if !info.IsDir() && !excluded && filepath.Ext(path) == ".go" { | ||
files[path] = true | ||
} | ||
|
||
return nil | ||
}) | ||
|
||
if err != nil { | ||
break | ||
} | ||
} | ||
|
||
fileList := make([]string, len(files)) | ||
i := 0 | ||
for k := range files { | ||
fileList[i] = k | ||
i++ | ||
} | ||
|
||
return fileList, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package golanfinder | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/debricked/cli/internal/callgraph/finder" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGolangFinderImplementsFinder(t *testing.T) { | ||
assert.Implements(t, (*finder.IFinder)(nil), new(GolangFinder)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# TODO: add docs to this readme on how we generate go CGs |
Oops, something went wrong.