Skip to content

Commit d9ba617

Browse files
authored
Improve openjdk::install_openjdk_via_jvm_common_buildpack (#275)
1 parent 3f1a5d8 commit d9ba617

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [Unreleased]
44

5+
* Improve OpenJDK installation via jvm-common buildpack to prevent function overrides and fix environment variable handling ([#275](https://github.com/heroku/heroku-buildpack-java/pull/275))
56
* Improve detection error message with better user experience and guidance for other build tools ([#270](https://github.com/heroku/heroku-buildpack-java/pull/270))
67

78

lib/openjdk.sh

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,17 @@ function openjdk::install_openjdk_via_jvm_common_buildpack() {
2020
local jvm_common_buildpack_dir
2121
jvm_common_buildpack_dir=$(mktemp -d)
2222

23-
curl --silent --show-error --fail --retry 3 --retry-connrefused --connect-timeout 5 --location "${jvm_common_buildpack_tarball_url}" -o "${jvm_common_buildpack_tarball_path}"
23+
curl \
24+
--connect-timeout 3 \
25+
--max-time 60 \
26+
--retry 5 \
27+
--retry-connrefused \
28+
--no-progress-meter \
29+
--fail \
30+
--location \
31+
"${jvm_common_buildpack_tarball_url}" \
32+
-o "${jvm_common_buildpack_tarball_path}"
33+
2434
tar -xzm --directory "${jvm_common_buildpack_dir}" --strip-components=1 -f "${jvm_common_buildpack_tarball_path}"
2535

2636
# This script translates non-JDBC compliant DATABASE_URL (and similar) environment variables into their
@@ -30,9 +40,19 @@ function openjdk::install_openjdk_via_jvm_common_buildpack() {
3040
# shellcheck source=/dev/null
3141
source "${jvm_common_buildpack_dir}/opt/jdbc.sh"
3242

33-
# shellcheck source=/dev/null
34-
source "${jvm_common_buildpack_dir}/bin/java"
43+
# Run the main installation in a sub-shell to avoid it overriding library functions and global
44+
# variables in the host buildpack.
45+
(
46+
# shellcheck source=/dev/null
47+
source "${jvm_common_buildpack_dir}/bin/java"
3548

36-
# See: https://github.com/heroku/heroku-buildpack-jvm-common/blob/main/bin/java
37-
install_openjdk "${build_dir}" "${host_buildpack_dir}"
49+
# See: https://github.com/heroku/heroku-buildpack-jvm-common/blob/main/bin/java
50+
install_openjdk "${build_dir}" "${host_buildpack_dir}"
51+
)
52+
53+
# Since we run install_openjdk in a sub-shell, any environment variables set by it will not be available in this
54+
# (parent) shell. As documented in the jvm buildpack, we can source the modified export script from this (host)
55+
# buildpack to get the necessary changes.
56+
# shellcheck source=/dev/null
57+
source "${host_buildpack_dir}/export"
3858
}

0 commit comments

Comments
 (0)