Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/integration/tomcat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,27 @@ func testTomcat(platform switchblade.Platform, fixtures string) func(*testing.T,
})
})

// Regression test for https://github.com/cloudfoundry/java-buildpack/issues/1219
// Staging failed with "improper constraint: 10.1.+" when using a two-segment
// minor version wildcard (e.g. 10.1.+) in JBP_CONFIG_TOMCAT. The fix normalises
// "10.1.+" → "10.1.*" before passing it to libbuildpack's FindMatchingVersion.
context("with a two-segment minor version wildcard in JBP_CONFIG_TOMCAT (issue #1219)", func() {
it("successfully stages with version: 10.1.+ and JBP_CONFIG_OPEN_JDK_JRE 17.+", func() {
deployment, logs, err := platform.Deploy.
WithEnv(map[string]string{
"JBP_CONFIG_OPEN_JDK_JRE": "{ jre: { version: 17.+ } }",
"JBP_CONFIG_TOMCAT": "{tomcat: { version: 10.1.+ }}",
}).
Execute(name, filepath.Join(fixtures, "containers", "tomcat_jakarta"))

Expect(err).NotTo(HaveOccurred(), logs.String)

Expect(logs.String()).To(ContainSubstring("Installing OpenJDK 17."))
Expect(logs.String()).To(ContainSubstring("Tomcat 10.1."))
Eventually(deployment).Should(matchers.Serve(ContainSubstring("OK")))
})
})

context("with memory limits", func() {
it("respects memory calculator settings with JAVA_OPTS", func() {
deployment, logs, err := platform.Deploy.
Expand Down
19 changes: 6 additions & 13 deletions src/java/containers/tomcat.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,9 @@ func DetermineTomcatVersion(raw string) string {

// determineTomcatVersion determines the version of the tomcat
// based on the JBP_CONFIG_TOMCAT field from manifest.
// It looks for a tomcat block with a version of the form "<major>.+" (e.g. "9.+", "10.+").
// Returns "<major>.x" (e.g. "9.x", "10.x") so libbuildpack can resolve it,
// It looks for a tomcat block with a version of the form "<major>.+" (e.g. "9.+", "10.+", "10.1.+").
// Returns the pattern with "+" replaced by "*" (e.g. "9.*", "10.*", "10.1.*") so libbuildpack can resolve it.
// Masterminds/semver treats x, X, and * as equivalent wildcards.
func determineTomcatVersion(raw string) string {
raw = strings.TrimSpace(raw)
if raw == "" {
Expand All @@ -479,17 +480,9 @@ func determineTomcatVersion(raw string) string {
return ""
}

pattern := match[1] // e.g. "9.+", "10.+", "10.23.+"

// If it's just "<major>.+" (no additional dot), convert to "<major>.x"
if !strings.Contains(strings.TrimSuffix(pattern, ".+"), ".") {
// "9.+" -> "9.x"
major := strings.TrimSuffix(pattern, ".+")
return major + ".x"
}

// Otherwise, it's something like "10.23.+": pass it through unchanged
return pattern
// Replace "+" with "*" so libbuildpack's FindMatchingVersion can resolve it.
// e.g. "9.+" -> "9.*", "10.+" -> "10.*", "10.1.+" -> "10.1.*"
return strings.ReplaceAll(match[1], "+", "*")
}

// isAccessLoggingEnabled checks if access logging is enabled in configuration
Expand Down
18 changes: 12 additions & 6 deletions src/java/containers/tomcat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,22 +203,28 @@ var _ = Describe("Tomcat Container", func() {
Expect(v).To(Equal(""))
})

It("returns 9.x for tomcat version 9.+", func() {
It("returns 9.* for tomcat version 9.+", func() {
raw := `{ tomcat: { version: "9.+" } }`
v := containers.DetermineTomcatVersion(raw)
Expect(v).To(Equal("9.x"))
Expect(v).To(Equal("9.*"))
})

It("returns 10.x for tomcat version 10.+", func() {
It("returns 10.* for tomcat version 10.+", func() {
raw := `{ tomcat: { version: "10.+" } }`
v := containers.DetermineTomcatVersion(raw)
Expect(v).To(Equal("10.x"))
Expect(v).To(Equal("10.*"))
})

It("returns 10.23.+ for tomcat version 10.23.+", func() {
It("returns 10.1.* for tomcat version 10.1.+", func() {
raw := `{tomcat: { version: 10.1.+, external_configuration_enabled: true }, external_configuration: { version: "1.4.0", repository_root: "https://example.com" }}`
v := containers.DetermineTomcatVersion(raw)
Expect(v).To(Equal("10.1.*"))
})

It("returns 10.23.* for tomcat version 10.23.+", func() {
raw := `{ tomcat: { version: "10.23.+" } }`
v := containers.DetermineTomcatVersion(raw)
Expect(v).To(Equal("10.23.+"))
Expect(v).To(Equal("10.23.*"))
})

It("returns empty string when only access logging is configured", func() {
Expand Down