Skip to content

Commit 296a5f4

Browse files
committed
🐛 fix: align supply/finalize with CF buildpack patterns
- add hooks import to supply/cli so Dynatrace BeforeCompile fires in supply phase - make WriteConfigYml failure fatal (Error + return err) instead of silent warning - add WriteEnvFile(JAVA_HOME) for multi-buildpack env propagation - add AddBinDependencyLink(java) so java binary is on PATH for subsequent buildpacks - add LinkDirectoryInDepDir(lib) so JRE native libs are on LD_LIBRARY_PATH - fix bin/finalize PROFILE_DIR=${5:-} to avoid nounset crash without 5th arg - propagate JRE finalization errors instead of swallowing as warning
1 parent 2236da8 commit 296a5f4

5 files changed

Lines changed: 28 additions & 4 deletions

File tree

bin/finalize

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ BUILD_DIR=$1
55
CACHE_DIR=$2
66
DEPS_DIR=$3
77
DEPS_IDX=$4
8-
PROFILE_DIR=$5
8+
PROFILE_DIR=${5:-}
99

1010
export BUILDPACK_DIR=$(dirname $(readlink -f ${BASH_SOURCE%/*}))
1111
source "$BUILDPACK_DIR/scripts/install_go.sh"

src/java/finalize/finalize.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ func (f *Finalizer) finalizeJRE() error {
151151
f.Log.BeginStep("Finalizing JRE: %s", f.JREName)
152152

153153
if err := f.JRE.Finalize(); err != nil {
154-
f.Log.Warning("Failed to finalize JRE: %s (continuing)", err.Error())
155-
// Don't fail the build if JRE finalization fails
154+
return fmt.Errorf("failed to finalize JRE %s: %w", f.JREName, err)
156155
}
157156

158157
f.Log.Info("JRE finalization complete")

src/java/jres/openjdk.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,29 @@ func (o *OpenJDKJRE) Supply() error {
7474
o.ctx.Log.Debug("Created profile.d script: java.sh")
7575
}
7676

77+
// Write JAVA_HOME to the deps env dir so subsequent buildpacks can use it.
78+
// This is the multi-buildpack pattern used by go-buildpack (WriteEnvFile for GOROOT)
79+
// and dotnet-core-buildpack.
80+
if err := o.ctx.Stager.WriteEnvFile("JAVA_HOME", javaHome); err != nil {
81+
o.ctx.Log.Warning("Could not write JAVA_HOME env file: %s", err.Error())
82+
}
83+
84+
// Symlink the java binary into the shared bin directory so it is on PATH
85+
// for subsequent buildpacks — mirrors go-buildpack's AddBinDependencyLink for "go".
86+
javaBin := filepath.Join(javaHome, "bin", "java")
87+
if err := o.ctx.Stager.AddBinDependencyLink(javaBin, "java"); err != nil {
88+
o.ctx.Log.Warning("Could not add java bin dependency link: %s", err.Error())
89+
}
90+
91+
// Link the JRE lib directory into the deps dir so native libraries (.so files)
92+
// are included on LD_LIBRARY_PATH — mirrors dotnet-core-buildpack's LinkDirectoryInDepDir.
93+
libDir := filepath.Join(javaHome, "lib")
94+
if _, err := os.Stat(libDir); err == nil {
95+
if err := o.ctx.Stager.LinkDirectoryInDepDir(libDir, "lib"); err != nil {
96+
o.ctx.Log.Warning("Could not link JRE lib directory: %s", err.Error())
97+
}
98+
}
99+
77100
// Determine Java major version
78101
javaMajorVersion, err := common.DetermineJavaVersion(javaHome)
79102
if err != nil {

src/java/supply/cli/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"path/filepath"
77
"time"
88

9+
_ "github.com/cloudfoundry/java-buildpack/src/java/hooks" // Register hooks (Dynatrace)
910
"github.com/cloudfoundry/java-buildpack/src/java/supply"
1011
"github.com/cloudfoundry/libbuildpack"
1112
)

src/java/supply/supply.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ func Run(s *Supplier) error {
7777
"jre_version": jre.Version(),
7878
"java_home": jre.JavaHome(),
7979
}); err != nil {
80-
s.Log.Warning("Could not write config: %s", err.Error())
80+
s.Log.Error("Could not write config: %s", err.Error())
81+
return err
8182
}
8283

8384
return nil

0 commit comments

Comments
 (0)