/
ParseModules.go
64 lines (57 loc) · 1.32 KB
/
ParseModules.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package codebase
import (
"log"
"strings"
"sync"
)
func ProcessModules(moduleList *Repository, module *Module, path string) {
targetList, closure := listTargets(path)
defer closure()
if targetList == nil {
return
}
var wg sync.WaitGroup
for _, target := range targetList {
targetName := target.Name()
newPath := path + "/" + targetName
if target.IsDir() {
if strings.HasPrefix(targetName, ".") {
continue
}
targetIsModule(moduleList, newPath, targetName, &wg)
} else {
if isNotReadable(newPath) || !isSupportedLanguage(newPath) {
continue
}
targetIsFile(module, newPath, targetName, &wg)
}
}
wg.Wait()
}
func targetIsModule(moduleList *Repository, path, name string, wg *sync.WaitGroup) {
newModule := &Module{
Path: path,
Name: name,
Files: nil,
}
//newModule := moduleList.Append(path, name)
wg.Add(1)
go func() {
ProcessModules(moduleList, newModule, path)
if !newModule.IsEmpty() {
moduleList.Modules = append(moduleList.Modules, newModule)
log.Println("module", name, "processed and added")
} else {
log.Println("module", name, "processed but not added")
}
wg.Done()
}()
}
func targetIsFile(module *Module, path, name string, wg *sync.WaitGroup) {
newFile := module.Append(path, name)
wg.Add(1)
go func() {
parseFile(newFile, path)
wg.Done()
}()
}