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

Method Supply

src/java/containers/tomcat.go:51–160  ·  view source on GitHub ↗

Supply installs Tomcat and dependencies

()

Source from the content-addressed store, hash-verified

49
50// Supply installs Tomcat and dependencies
51func (t *TomcatContainer) Supply() error {
52 t.context.Log.BeginStep("Supplying Tomcat")
53
54 // Determine Java version to select appropriate Tomcat version
55 // Tomcat 10.x requires Java 11+, Tomcat 9.x supports Java 8-22
56 javaHome := os.Getenv("JAVA_HOME")
57 var dep libbuildpack.Dependency
58 var err error
59
60 t.config, err = t.loadConfig()
61 if err != nil {
62 return fmt.Errorf("failed to load tomcat config: %w", err)
63 }
64
65 if javaHome != "" {
66 versionPattern, versionErr := SelectTomcatVersionPattern(javaHome, DetermineTomcatVersion(t.config.Tomcat.Version))
67 if versionErr != nil {
68 return versionErr
69 }
70
71 if versionPattern != "" {
72 allVersions := t.context.Manifest.AllDependencyVersions("tomcat")
73 resolvedVersion, err := libbuildpack.FindMatchingVersion(versionPattern, allVersions)
74 if err != nil {
75 return fmt.Errorf("tomcat version resolution error for pattern %q: %w", versionPattern, err)
76 }
77 dep.Name = "tomcat"
78 dep.Version = resolvedVersion
79 t.context.Log.Debug("Resolved Tomcat version pattern '%s' to %s", versionPattern, resolvedVersion)
80 } else {
81 t.context.Log.Warning("Unable to determine Java version from JAVA_HOME, falling back to manifest default Tomcat version")
82 }
83 }
84
85 // Fallback to default version if we couldn't determine Java version
86 if dep.Version == "" {
87 dep, err = t.context.Manifest.DefaultVersion("tomcat")
88 if err != nil {
89 return fmt.Errorf("failed to determine Tomcat version: no JAVA_HOME set and no default version in manifest: %w", err)
90 }
91 }
92
93 // Install Tomcat with strip components to remove the top-level directory
94 // Apache Tomcat tarballs extract to apache-tomcat-X.Y.Z/ subdirectory
95 tomcatDir := t.tomcatDir()
96 if err := t.context.Installer.InstallDependencyWithStrip(dep, tomcatDir, 1); err != nil {
97 return fmt.Errorf("failed to install Tomcat: %w", err)
98 }
99
100 t.context.Log.Info("Installed Tomcat (%s)", dep.Version)
101
102 // Get buildpack index for multi-buildpack support
103 depsIdx := t.context.Stager.DepsIdx()
104 // Write profile.d script to set CATALINA_HOME, CATALINA_BASE, and JAVA_OPTS at runtime
105 tomcatPath := fmt.Sprintf("$DEPS_DIR/%s/tomcat", depsIdx)
106
107 // Determine access logging configuration (default: disabled, matching Ruby buildpack)
108 // Can be enabled via: JBP_CONFIG_TOMCAT='{access_logging_support: {access_logging: enabled}}'

Callers

nothing calls this directly

Tested by

no test coverage detected