Skip to content

Commit

Permalink
Merge pull request #496 from lchdev/fix-spring-cloud-bindings-disabled
Browse files Browse the repository at this point in the history
Fix spring-cloud-bindings overriding JAVA_TOOL_OPTIONS when disabled
  • Loading branch information
pivotal-david-osullivan authored Jul 17, 2024
2 parents 802d50d + 456cd8f commit bce8e88
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
17 changes: 7 additions & 10 deletions helper/spring_cloud_bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"fmt"
"os"
"strconv"
"strings"

"github.com/paketo-buildpacks/libpak/sherpa"

Expand All @@ -37,7 +36,7 @@ func (s SpringCloudBindings) Execute() (map[string]string, error) {

var err error
enabled := true
opts := []string{}
var opt string

if val, ok := os.LookupEnv("BPL_SPRING_CLOUD_BINDINGS_ENABLED"); ok {
s.Logger.Infof(color.YellowString("WARNING: BPL_SPRING_CLOUD_BINDINGS_ENABLED is deprecated, support will be removed in a coming release. Use BPL_SPRING_CLOUD_BINDINGS_DISABLED instead"))
Expand All @@ -48,15 +47,13 @@ func (s SpringCloudBindings) Execute() (map[string]string, error) {
}
// Switching from "BPL_SPRING_CLOUD_BINDINGS_ENABLED" to "BPL_SPRING_CLOUD_BINDINGS_DISABLED" which defaults to 'false' to follow convention
if sherpa.ResolveBool("BPL_SPRING_CLOUD_BINDINGS_DISABLED") || !enabled {
opts = append(opts, "-Dorg.springframework.cloud.bindings.boot.enable=false")
return map[string]string{"JAVA_TOOL_OPTIONS": strings.Join(opts, " ")}, nil
opt = "-Dorg.springframework.cloud.bindings.boot.enable=false"
} else {
opt = "-Dorg.springframework.cloud.bindings.boot.enable=true"
s.Logger.Info("Spring Cloud Bindings Enabled")
}

s.Logger.Info("Spring Cloud Bindings Enabled")

opts = append(opts, "-Dorg.springframework.cloud.bindings.boot.enable=true")

values := sherpa.AppendToEnvVar("JAVA_TOOL_OPTIONS", " ", opts...)
values := sherpa.AppendToEnvVar("JAVA_TOOL_OPTIONS", " ", opt)

return map[string]string{"JAVA_TOOL_OPTIONS": values}, nil
}
}
17 changes: 17 additions & 0 deletions helper/spring_cloud_bindings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,21 @@ func testSpringCloudBindings(t *testing.T, context spec.G, it spec.S) {
})
})

context("$JAVA_TOOL_OPTIONS", func() {
it.Before(func() {
Expect(os.Setenv("JAVA_TOOL_OPTIONS", "test-java-tool-options"),
os.Setenv("BPL_SPRING_CLOUD_BINDINGS_DISABLED", "true")).To(Succeed())
})

it.After(func() {
Expect(os.Unsetenv("JAVA_TOOL_OPTIONS"), os.Unsetenv("BPL_SPRING_CLOUD_BINDINGS_DISABLED")).To(Succeed())
})

it("contributes configuration appended to existing $JAVA_TOOL_OPTIONS", func() {
Expect(s.Execute()).To(Equal(map[string]string{
"JAVA_TOOL_OPTIONS": "test-java-tool-options -Dorg.springframework.cloud.bindings.boot.enable=false",
}))
})
})

}

0 comments on commit bce8e88

Please sign in to comment.