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

Method writeProfileDScript

src/java/jres/zing.go:165–193  ·  view source on GitHub ↗

writeProfileDScript creates the java.sh profile.d script This script sets JAVA_HOME, JRE_HOME, and updates PATH at application runtime

()

Source from the content-addressed store, hash-verified

163// writeProfileDScript creates the java.sh profile.d script
164// This script sets JAVA_HOME, JRE_HOME, and updates PATH at application runtime
165func (z *ZingJRE) writeProfileDScript() error {
166 // Compute relative path from jreDir to javaHome
167 relPath, err := filepath.Rel(z.jreDir, z.javaHome)
168 if err != nil {
169 return fmt.Errorf("failed to compute relative path: %w", err)
170 }
171
172 // Build the runtime JAVA_HOME path
173 // At runtime, DEPS_DIR will point to the app's dependency directory
174 javaHomePath := filepath.Join("$DEPS_DIR", "0", "jre", relPath)
175
176 // Create the environment script content
177 envContent := fmt.Sprintf(`export JAVA_HOME=%s
178export JRE_HOME=$JAVA_HOME
179export PATH=$JAVA_HOME/bin:$PATH
180`, javaHomePath)
181
182 // Write the profile.d script using libbuildpack API
183 if err := z.ctx.Stager.WriteProfileD("java.sh", envContent); err != nil {
184 return fmt.Errorf("failed to write profile.d script: %w", err)
185 }
186
187 // Also set environment for the staging process
188 os.Setenv("JAVA_HOME", z.javaHome)
189 os.Setenv("JRE_HOME", z.javaHome)
190 os.Setenv("PATH", fmt.Sprintf("%s/bin:%s", z.javaHome, os.Getenv("PATH")))
191
192 return nil
193}

Callers 1

SupplyMethod · 0.95

Calls 1

WriteProfileDMethod · 0.65

Tested by

no test coverage detected