FindMainGroovyScript determines which Groovy script should be executed. Following Ruby buildpack logic, a file is a candidate if it has a static void main() method, is not a POGO, or has a shebang. Returns the single candidate if exactly one matches, empty string otherwise.
(scripts []string)
| 126 | // void main() method, is not a POGO, or has a shebang. |
| 127 | // Returns the single candidate if exactly one matches, empty string otherwise. |
| 128 | func FindMainGroovyScript(scripts []string) (string, error) { |
| 129 | g := &GroovyUtils{} |
| 130 | candidates := make(map[string]bool) |
| 131 | |
| 132 | for _, script := range scripts { |
| 133 | if !isValidGroovyFile(script) { |
| 134 | continue |
| 135 | } |
| 136 | if g.HasMainMethod(script) || !g.IsPOGO(script) || g.HasShebang(script) { |
| 137 | candidates[script] = true |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | if len(candidates) == 1 { |
| 142 | for script := range candidates { |
| 143 | return script, nil |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | return "", nil |
| 148 | } |
no test coverage detected