MCPcopy Create free account
hub / github.com/XmirrorSecurity/OpenSCA-cli / Scan

Method Scan

opensca/sca/groovy/variable.go:60–97  ·  view source on GitHub ↗

Scan 提取文件中的变量

(file *model.File)

Source from the content-addressed store, hash-verified

58
59// Scan 提取文件中的变量
60func (v Variable) Scan(file *model.File) {
61
62 if file == nil {
63 return
64 }
65
66 var text string
67 file.OpenReader(func(reader io.Reader) {
68 data, _ := io.ReadAll(reader)
69 text = string(data)
70 })
71
72 blockIndex := startReg.FindAllStringIndex(text, -1)
73 for i, bi := range blockIndex {
74 end := len(text)
75 if i+1 < len(blockIndex) {
76 end = blockIndex[i+1][0]
77 }
78 m := startReg.FindStringSubmatch(text[bi[0]:bi[1]])
79 var object string
80 if len(m) == 2 {
81 object = m[1]
82 }
83 if object == "" {
84 continue
85 }
86 for line := range strings.SplitSeq(text[bi[1]:end], "\n") {
87 match := varReg.FindStringSubmatch(line)
88 if len(match) == 3 {
89 if object == "ext" {
90 v[match[1]] = match[2]
91 }
92 v[fmt.Sprintf("%s.%s", object, match[1])] = match[2]
93 }
94 }
95 }
96
97}

Callers 6

ParseGradleFunction · 0.95
pipenvGraphFunction · 0.80
GoModGraphFunction · 0.80
MvnTreeFunction · 0.80
ReadLineFunction · 0.80
TaskLogFunction · 0.80

Calls 1

OpenReaderMethod · 0.80

Tested by

no test coverage detected