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

Method Finalize

src/java/containers/tomcat.go:557–601  ·  view source on GitHub ↗

Finalize performs final Tomcat configuration

()

Source from the content-addressed store, hash-verified

555
556// Finalize performs final Tomcat configuration
557func (t *TomcatContainer) Finalize() error {
558 t.context.Log.BeginStep("Finalizing Tomcat")
559
560 buildDir := t.context.Stager.BuildDir()
561 contextXMLPath := filepath.Join(t.tomcatDir(), "conf", "Catalina", "localhost", "ROOT.xml")
562
563 webInf := filepath.Join(buildDir, "WEB-INF")
564 if _, err := os.Stat(webInf); err == nil {
565 // the script name is prefixed with 'zzz' as it is important to be the last script sourced from profile.d
566 // so that the previous scripts assembling the CLASSPATH variable(left from frameworks) are sourced previous to it.
567 if err := t.context.Stager.WriteProfileD("zzz_classpath_symlinks.sh", fmt.Sprintf(symlinkScript, filepath.Join("WEB-INF", "lib"))); err != nil {
568 return fmt.Errorf("failed to write zzz_classpath_symlinks.sh: %w", err)
569 }
570
571 contextXMLDir := filepath.Dir(contextXMLPath)
572 if err := os.MkdirAll(contextXMLDir, 0755); err != nil {
573 return fmt.Errorf("failed to create context directory: %w", err)
574 }
575
576 appContextXML := filepath.Join(buildDir, "META-INF", "context.xml")
577 var contextContent string
578
579 if _, err := os.Stat(appContextXML); err == nil {
580 xmlBytes, err := os.ReadFile(appContextXML)
581 if err != nil {
582 return fmt.Errorf("failed to read META-INF/context.xml: %w", err)
583 }
584
585 xmlStr := string(xmlBytes)
586 xmlStr = strings.TrimSpace(xmlStr)
587
588 contextContent = injectDocBase(xmlStr, "${user.home}/app")
589 t.context.Log.Info("Merged META-INF/context.xml with ROOT.xml - realm and resource configurations preserved")
590 } else {
591 contextContent = fmt.Sprintf("<Context docBase=\"${user.home}/app\" reloadable=\"false\">\n</Context>\n")
592 t.context.Log.Info("Created ROOT.xml with docBase pointing to application directory")
593 }
594
595 if err := os.WriteFile(contextXMLPath, []byte(contextContent), 0644); err != nil {
596 return fmt.Errorf("failed to write ROOT.xml: %w", err)
597 }
598 }
599
600 return nil
601}
602
603// Release returns the Tomcat startup command
604func (t *TomcatContainer) Release() (string, error) {

Callers

nothing calls this directly

Calls 4

tomcatDirMethod · 0.95
injectDocBaseFunction · 0.85
BuildDirMethod · 0.65
WriteProfileDMethod · 0.65

Tested by

no test coverage detected