Skip to content

Commit d051cb9

Browse files
authored
Merge pull request #1220 from cloudfoundry/fix/tomcat-version-wildcard-issue-1219
fix: normalise tomcat version wildcard + to * (fixes #1219)
2 parents 51d7ffc + 96af84e commit d051cb9

File tree

3 files changed

+39
-19
lines changed

3 files changed

+39
-19
lines changed

src/integration/tomcat_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,27 @@ func testTomcat(platform switchblade.Platform, fixtures string) func(*testing.T,
242242
})
243243
})
244244

245+
// Regression test for https://github.com/cloudfoundry/java-buildpack/issues/1219
246+
// Staging failed with "improper constraint: 10.1.+" when using a two-segment
247+
// minor version wildcard (e.g. 10.1.+) in JBP_CONFIG_TOMCAT. The fix normalises
248+
// "10.1.+" → "10.1.*" before passing it to libbuildpack's FindMatchingVersion.
249+
context("with a two-segment minor version wildcard in JBP_CONFIG_TOMCAT (issue #1219)", func() {
250+
it("successfully stages with version: 10.1.+ and JBP_CONFIG_OPEN_JDK_JRE 17.+", func() {
251+
deployment, logs, err := platform.Deploy.
252+
WithEnv(map[string]string{
253+
"JBP_CONFIG_OPEN_JDK_JRE": "{ jre: { version: 17.+ } }",
254+
"JBP_CONFIG_TOMCAT": "{tomcat: { version: 10.1.+ }}",
255+
}).
256+
Execute(name, filepath.Join(fixtures, "containers", "tomcat_jakarta"))
257+
258+
Expect(err).NotTo(HaveOccurred(), logs.String)
259+
260+
Expect(logs.String()).To(ContainSubstring("Installing OpenJDK 17."))
261+
Expect(logs.String()).To(ContainSubstring("Tomcat 10.1."))
262+
Eventually(deployment).Should(matchers.Serve(ContainSubstring("OK")))
263+
})
264+
})
265+
245266
context("with memory limits", func() {
246267
it("respects memory calculator settings with JAVA_OPTS", func() {
247268
deployment, logs, err := platform.Deploy.

src/java/containers/tomcat.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,9 @@ func DetermineTomcatVersion(raw string) string {
465465

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

482-
pattern := match[1] // e.g. "9.+", "10.+", "10.23.+"
483-
484-
// If it's just "<major>.+" (no additional dot), convert to "<major>.x"
485-
if !strings.Contains(strings.TrimSuffix(pattern, ".+"), ".") {
486-
// "9.+" -> "9.x"
487-
major := strings.TrimSuffix(pattern, ".+")
488-
return major + ".x"
489-
}
490-
491-
// Otherwise, it's something like "10.23.+": pass it through unchanged
492-
return pattern
483+
// Replace "+" with "*" so libbuildpack's FindMatchingVersion can resolve it.
484+
// e.g. "9.+" -> "9.*", "10.+" -> "10.*", "10.1.+" -> "10.1.*"
485+
return strings.ReplaceAll(match[1], "+", "*")
493486
}
494487

495488
// isAccessLoggingEnabled checks if access logging is enabled in configuration

src/java/containers/tomcat_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,22 +203,28 @@ var _ = Describe("Tomcat Container", func() {
203203
Expect(v).To(Equal(""))
204204
})
205205

206-
It("returns 9.x for tomcat version 9.+", func() {
206+
It("returns 9.* for tomcat version 9.+", func() {
207207
raw := `{ tomcat: { version: "9.+" } }`
208208
v := containers.DetermineTomcatVersion(raw)
209-
Expect(v).To(Equal("9.x"))
209+
Expect(v).To(Equal("9.*"))
210210
})
211211

212-
It("returns 10.x for tomcat version 10.+", func() {
212+
It("returns 10.* for tomcat version 10.+", func() {
213213
raw := `{ tomcat: { version: "10.+" } }`
214214
v := containers.DetermineTomcatVersion(raw)
215-
Expect(v).To(Equal("10.x"))
215+
Expect(v).To(Equal("10.*"))
216216
})
217217

218-
It("returns 10.23.+ for tomcat version 10.23.+", func() {
218+
It("returns 10.1.* for tomcat version 10.1.+", func() {
219+
raw := `{tomcat: { version: 10.1.+, external_configuration_enabled: true }, external_configuration: { version: "1.4.0", repository_root: "https://example.com" }}`
220+
v := containers.DetermineTomcatVersion(raw)
221+
Expect(v).To(Equal("10.1.*"))
222+
})
223+
224+
It("returns 10.23.* for tomcat version 10.23.+", func() {
219225
raw := `{ tomcat: { version: "10.23.+" } }`
220226
v := containers.DetermineTomcatVersion(raw)
221-
Expect(v).To(Equal("10.23.+"))
227+
Expect(v).To(Equal("10.23.*"))
222228
})
223229

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

0 commit comments

Comments
 (0)