MCPcopy Create free account
hub / github.com/cloudfoundry/java-buildpack / Release

Method Release

src/java/containers/groovy.go:93–136  ·  view source on GitHub ↗

Release returns the Groovy startup command

()

Source from the content-addressed store, hash-verified

91
92// Release returns the Groovy startup command
93func (g *GroovyContainer) Release() (string, error) {
94 // Determine which script to run
95 var mainScript string
96
97 // Check for GROOVY_SCRIPT environment variable
98 mainScript = os.Getenv("GROOVY_SCRIPT")
99
100 if mainScript == "" && len(g.groovyScripts) > 0 {
101 // Use Ruby buildpack logic to find the main script:
102 // 1. Files with static void main() method
103 // 2. Non-POGO files (simple scripts without class definitions)
104 // 3. Files with shebang
105 // Returns the single candidate if exactly one matches
106 selectedScript, err := FindMainGroovyScript(g.groovyScripts)
107 if err != nil {
108 g.context.Log.Warning("Error finding main Groovy script: %s", err.Error())
109 }
110 if selectedScript != "" {
111 mainScript = filepath.Base(selectedScript)
112 g.context.Log.Debug("Selected main script: %s", mainScript)
113 } else {
114 // Fall back to the first script if no clear candidate
115 mainScript = filepath.Base(g.groovyScripts[0])
116 g.context.Log.Debug("Using first script: %s", mainScript)
117 }
118 }
119
120 if mainScript == "" {
121 return "", fmt.Errorf("no Groovy script specified (set GROOVY_SCRIPT)")
122 }
123
124 // Build classpath from all JARs under the app root (mirrors Ruby buildpack's add_libs + as_classpath)
125 cpFlag := g.buildClasspath()
126
127 // Note: JAVA_OPTS is set via environment variables (profile.d/java_opts.sh)
128 // The groovy command reads JAVA_OPTS from the environment, not command-line args
129 var cmd string
130 if cpFlag != "" {
131 cmd = fmt.Sprintf("$GROOVY_HOME/bin/groovy %s %s", cpFlag, mainScript)
132 } else {
133 cmd = fmt.Sprintf("$GROOVY_HOME/bin/groovy %s", mainScript)
134 }
135 return cmd, nil
136}
137
138// buildClasspath globs all JARs under the build dir and returns a "-cp <...>" flag string
139// with runtime-relative paths (using $HOME), mirroring the Ruby buildpack's add_libs behaviour.

Callers

nothing calls this directly

Calls 2

buildClasspathMethod · 0.95
FindMainGroovyScriptFunction · 0.85

Tested by

no test coverage detected