@@ -2,11 +2,12 @@ package frameworks
22
33import (
44 "fmt"
5- "github.com/cloudfoundry/java-buildpack/src/java/common"
65 "os"
76 "path/filepath"
87 "strings"
98
9+ "github.com/cloudfoundry/java-buildpack/src/java/common"
10+
1011 "github.com/cloudfoundry/libbuildpack"
1112 "gopkg.in/yaml.v2"
1213)
@@ -31,8 +32,8 @@ func (j *JavaCfEnvFramework) Detect() (string, error) {
3132 return "" , nil
3233 }
3334
34- // Check if Spring Boot 3.x is present
35- if ! j .isSpringBoot3 ( ) {
35+ // Check if Spring Boot 3.x/4.x is present
36+ if ! j .isSpringBootMajor ( 4 ) && ! j . isSpringBootMajor ( 3 ) {
3637 return "" , nil
3738 }
3839
@@ -49,13 +50,21 @@ func (j *JavaCfEnvFramework) Detect() (string, error) {
4950func (j * JavaCfEnvFramework ) Supply () error {
5051 j .context .Log .BeginStep ("Installing Java CF Env" )
5152
53+ dependency := "java-cfenv"
54+ defaultVersion := "4.0.0"
55+
56+ if j .isSpringBootMajor (3 ) {
57+ dependency = "java-cfenv-sb3"
58+ defaultVersion = "3.1.0"
59+ }
60+
5261 // Get java-cfenv dependency from manifest
53- dep , err := j .context .Manifest .DefaultVersion ("java-cfenv" )
62+ dep , err := j .context .Manifest .DefaultVersion (dependency )
5463 if err != nil {
5564 j .context .Log .Warning ("Unable to determine Java CF Env version, using default" )
5665 dep = libbuildpack.Dependency {
57- Name : "java-cfenv" ,
58- Version : "3.1.0" , // Fallback version
66+ Name : dependency ,
67+ Version : defaultVersion ,
5968 }
6069 }
6170
@@ -139,15 +148,14 @@ func (j *JavaCfEnvFramework) isEnabled() bool {
139148 return true
140149}
141150
142- // isSpringBoot3 checks if the application is Spring Boot 3.x
143- func (j * JavaCfEnvFramework ) isSpringBoot3 () bool {
144- // Look for Spring Boot 3.x JARs
145- // Spring Boot 3.x uses spring-boot-3.*.jar
151+ // isSpringBootMajor checks if the application is Spring Boot <major>.x
152+ func (j * JavaCfEnvFramework ) isSpringBootMajor (major int ) bool {
153+ jarGlob := fmt .Sprintf ("spring-boot-%d.*.jar" , major )
146154 patterns := []string {
147- filepath .Join (j .context .Stager .BuildDir (), "**" , "spring-boot-3.*.jar" ),
148- filepath .Join (j .context .Stager .BuildDir (), "WEB-INF" , "lib" , "spring-boot-3.*.jar" ),
149- filepath .Join (j .context .Stager .BuildDir (), "BOOT-INF" , "lib" , "spring-boot-3.*.jar" ),
150- filepath .Join (j .context .Stager .BuildDir (), "lib" , "spring-boot-3.*.jar" ),
155+ filepath .Join (j .context .Stager .BuildDir (), "**" , jarGlob ),
156+ filepath .Join (j .context .Stager .BuildDir (), "WEB-INF" , "lib" , jarGlob ),
157+ filepath .Join (j .context .Stager .BuildDir (), "BOOT-INF" , "lib" , jarGlob ),
158+ filepath .Join (j .context .Stager .BuildDir (), "lib" , jarGlob ),
151159 }
152160
153161 for _ , pattern := range patterns {
@@ -161,7 +169,7 @@ func (j *JavaCfEnvFramework) isSpringBoot3() bool {
161169 manifestPath := filepath .Join (j .context .Stager .BuildDir (), "META-INF" , "MANIFEST.MF" )
162170 if content , err := os .ReadFile (manifestPath ); err == nil {
163171 manifest := string (content )
164- if strings .Contains (manifest , "Spring-Boot-Version: 3." ) {
172+ if strings .Contains (manifest , fmt . Sprintf ( "Spring-Boot-Version: %d." , major ) ) {
165173 return true
166174 }
167175 }
0 commit comments