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

Function WriteJavaOptsWithPriority

src/java/jres/jre.go:341–366  ·  view source on GitHub ↗

WriteJavaOptsWithPriority writes JAVA_OPTS to a numbered .opts file for centralized assembly Priority determines execution order (lower numbers run first) Multiple calls with the same priority/name will append to the same file

(ctx *common.Context, priority int, name string, opts string)

Source from the content-addressed store, hash-verified

339// Priority determines execution order (lower numbers run first)
340// Multiple calls with the same priority/name will append to the same file
341func WriteJavaOptsWithPriority(ctx *common.Context, priority int, name string, opts string) error {
342 // Create java_opts directory in deps
343 optsDir := filepath.Join(ctx.Stager.DepDir(), "java_opts")
344 if err := os.MkdirAll(optsDir, 0755); err != nil {
345 return fmt.Errorf("failed to create java_opts directory: %w", err)
346 }
347
348 // Write .opts file with priority prefix (e.g., 05_jre.opts)
349 filename := fmt.Sprintf("%02d_%s.opts", priority, name)
350 optsFile := filepath.Join(optsDir, filename)
351
352 // Append to existing content if file exists
353 var content string
354 if existing, err := os.ReadFile(optsFile); err == nil {
355 content = strings.TrimSpace(string(existing)) + " " + opts
356 } else {
357 content = opts
358 }
359
360 if err := os.WriteFile(optsFile, []byte(content), 0644); err != nil {
361 return fmt.Errorf("failed to write %s: %w", filename, err)
362 }
363
364 ctx.Log.Debug("Wrote JAVA_OPTS to %s (priority %d)", filename, priority)
365 return nil
366}
367
368// WriteJavaHomeProfileD creates a profile.d script that exports JAVA_HOME, JRE_HOME, and PATH at runtime
369// This is needed for containers that use startup scripts expecting $JAVA_HOME environment variable

Callers 1

WriteJavaOptsFunction · 0.85

Calls 1

DepDirMethod · 0.65

Tested by

no test coverage detected