Skip to content

Commit cd4bd7b

Browse files
authored
Merge pull request #1157 from kiril-keranov/patch-11
Correct framework order for java_cf_env and spring auto reconfiguration
2 parents 7820238 + 9a35623 commit cd4bd7b

5 files changed

Lines changed: 17 additions & 25 deletions

File tree

src/integration/frameworks_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,13 +671,16 @@ func testFrameworks(platform switchblade.Platform, fixtures string) func(*testin
671671
}).
672672
WithEnv(map[string]string{
673673
"BP_JAVA_VERSION": "11",
674+
"JBP_CONFIG_JAVA_CF_ENV": "'{enabled: false}'",
674675
"JBP_CONFIG_SPRING_AUTO_RECONFIGURATION": "'{enabled: true}'",
675676
}).
676677
Execute(name, filepath.Join(fixtures, "frameworks", "auto_reconfiguration_servlet_3"))
677678
Expect(err).NotTo(HaveOccurred(), logs.String)
678679

679680
// Spring Auto-reconfiguration should be detected for Spring apps with services
680681
Expect(logs.String()).To(ContainSubstring("Spring Auto-reconfiguration"))
682+
// Spring Auto-reconfiguration should only be provided in the absence of Java Cf Env
683+
Expect(logs.String()).NotTo(ContainSubstring("Java CF Env"))
681684
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))
682685
})
683686

@@ -695,6 +698,8 @@ func testFrameworks(platform switchblade.Platform, fixtures string) func(*testin
695698
Execute(name, filepath.Join(fixtures, "frameworks", "auto_reconfiguration_servlet_3"))
696699
Expect(err).NotTo(HaveOccurred(), logs.String)
697700

701+
// Java Cf Env should be provided as it is enabled by default for Spring3 apps
702+
Expect(logs.String()).To(ContainSubstring("Java CF Env"))
698703
// Should not install when explicitly disabled
699704
Expect(logs.String()).NotTo(ContainSubstring("Spring Auto-reconfiguration"))
700705
Eventually(deployment).Should(matchers.Serve(ContainSubstring("")))

src/integration/spring_boot_test.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,6 @@ func testSpringBoot(platform switchblade.Platform, fixtures string) func(*testin
4949
})
5050
})
5151

52-
context("with Spring Auto-reconfiguration", func() {
53-
it("detects Spring Framework", func() {
54-
deployment, logs, err := platform.Deploy.
55-
WithEnv(map[string]string{
56-
"BP_JAVA_VERSION": "11",
57-
}).
58-
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_staged"))
59-
Expect(err).NotTo(HaveOccurred(), logs.String)
60-
61-
// Spring auto-reconfiguration should be detected
62-
Expect(logs.String()).To(ContainSubstring("Java Buildpack"))
63-
Eventually(deployment).Should(matchers.Serve(Not(BeEmpty())))
64-
})
65-
})
66-
6752
context("with embedded Tomcat", func() {
6853
it("starts successfully", func() {
6954
deployment, logs, err := platform.Deploy.
@@ -85,11 +70,13 @@ func testSpringBoot(platform switchblade.Platform, fixtures string) func(*testin
8570
it("includes java-cfenv when Spring Boot is detected", func() {
8671
deployment, logs, err := platform.Deploy.
8772
WithEnv(map[string]string{
88-
"BP_JAVA_VERSION": "11",
89-
"JBP_CONFIG_JAVA_CFENV": "{enabled: true}",
73+
"BP_JAVA_VERSION": "11",
74+
"JBP_CONFIG_JAVA_CF_ENV": "{enabled: true}",
9075
}).
9176
Execute(name, filepath.Join(fixtures, "containers", "spring_boot_staged"))
9277
Expect(err).NotTo(HaveOccurred(), logs.String)
78+
// Fixture is not a Spring3 app, so Java CF Env detect should not pass
79+
Expect(logs.String()).NotTo(ContainSubstring("Java CF Env"))
9380

9481
Eventually(deployment).Should(matchers.Serve(Not(BeEmpty())))
9582
})

src/java/frameworks/framework.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ func (r *Registry) RegisterStandardFrameworks() {
5151
r.Register(NewElasticApmAgentFramework(r.context))
5252

5353
// Spring Service Bindings (Priority 1)
54-
r.Register(NewSpringAutoReconfigurationFramework(r.context))
54+
// Note: order matters, Java Cf Env should be registered before StringAutoReconfiguration
5555
r.Register(NewJavaCfEnvFramework(r.context))
56+
r.Register(NewSpringAutoReconfigurationFramework(r.context))
5657

5758
// JDBC Drivers (Priority 1)
5859
r.Register(NewPostgresqlJdbcFramework(r.context))

src/java/frameworks/spring_auto_reconfiguration.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package frameworks
22

33
import (
4-
"github.com/cloudfoundry/java-buildpack/src/java/common"
54
"fmt"
5+
"github.com/cloudfoundry/java-buildpack/src/java/common"
66
"os"
77
"path/filepath"
88
"strings"
@@ -47,6 +47,11 @@ func (s *SpringAutoReconfigurationFramework) Detect() (string, error) {
4747

4848
// Supply installs the Spring Auto-reconfiguration JAR
4949
func (s *SpringAutoReconfigurationFramework) Supply() error {
50+
// Check again if java-cfenv framework is being installed
51+
if s.hasJavaCfEnv() {
52+
s.context.Log.Debug("java-cfenv present, skipping Spring Auto-reconfiguration installation")
53+
return nil
54+
}
5055
s.context.Log.BeginStep("Installing Spring Auto-reconfiguration")
5156

5257
// Log deprecation warnings
@@ -56,12 +61,6 @@ func (s *SpringAutoReconfigurationFramework) Supply() error {
5661
s.context.Log.Warning("Please migrate to java-cfenv immediately. See https://via.vmw.com/EiBW for migration instructions.")
5762
}
5863

59-
// Check again if java-cfenv framework is being installed
60-
if s.hasJavaCfEnv() {
61-
s.context.Log.Debug("java-cfenv present, skipping Spring Auto-reconfiguration installation")
62-
return nil
63-
}
64-
6564
// Get Spring Auto-reconfiguration dependency from manifest
6665
dep, err := s.context.Manifest.DefaultVersion("auto-reconfiguration")
6766
if err != nil {

0 commit comments

Comments
 (0)