SelectTomcatVersionPattern determines the Tomcat version pattern to use based on the detected Java version and any user-configured Tomcat version. Returns ("", nil) when Java version cannot be determined — the caller should fall back to the manifest default (matching Ruby buildpack behaviour).
(javaHome, configVersion string)
| 444 | // Returns ("", nil) when Java version cannot be determined — the caller should fall back |
| 445 | // to the manifest default (matching Ruby buildpack behaviour). |
| 446 | func SelectTomcatVersionPattern(javaHome, configVersion string) (string, error) { |
| 447 | if javaHome == "" { |
| 448 | return "", nil |
| 449 | } |
| 450 | |
| 451 | javaMajorVersion, err := common.DetermineJavaVersion(javaHome) |
| 452 | if err != nil { |
| 453 | if configVersion != "" { |
| 454 | return configVersion, nil |
| 455 | } |
| 456 | return "", nil |
| 457 | } |
| 458 | |
| 459 | if configVersion != "" { |
| 460 | if strings.HasPrefix(configVersion, "10.") && javaMajorVersion < 11 { |
| 461 | return "", fmt.Errorf("Tomcat 10.x requires Java 11+, but Java %d detected", javaMajorVersion) |
| 462 | } |
| 463 | return configVersion, nil |
| 464 | } |
| 465 | |
| 466 | if javaMajorVersion >= 11 { |
| 467 | return "10.x", nil |
| 468 | } |
| 469 | return "9.x", nil |
| 470 | } |
| 471 | |
| 472 | |
| 473 | // based on the JBP_CONFIG_TOMCAT field from manifest. |
no test coverage detected