Skip to content

Commit 2bc54af

Browse files
committed
Refactor OpenJDK installation routine
1 parent 4ed0f1a commit 2bc54af

4 files changed

Lines changed: 42 additions & 17 deletions

File tree

bin/compile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ source "${BUILDPACK_DIR}/lib/util.sh"
1313
source "${BUILDPACK_DIR}/lib/common.sh"
1414
source "${BUILDPACK_DIR}/lib/maven.sh"
1515
source "${BUILDPACK_DIR}/lib/metrics.sh"
16+
source "${BUILDPACK_DIR}/lib/openjdk.sh"
1617

1718
metrics::init "${CACHE_DIR}" "java"
1819
metrics::setup
1920

2021
util::export_env_dir "${ENV_DIR}" "." "JAVA_OPTS|JAVA_TOOL_OPTIONS"
2122

22-
common::install_jdk "${BUILD_DIR}" "${CACHE_DIR}"
23+
openjdk::install_openjdk_via_jvm_common_buildpack "${BUILD_DIR}" "${BUILDPACK_DIR}"
2324

2425
maven::run_mvn "compile" "${BUILD_DIR}" "${CACHE_DIR}"
2526
maven::remove_mvn "${BUILD_DIR}" "${CACHE_DIR}"

bin/test-compile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ source "${BUILDPACK_DIR}/lib/output.sh"
1212
source "${BUILDPACK_DIR}/lib/util.sh"
1313
source "${BUILDPACK_DIR}/lib/common.sh"
1414
source "${BUILDPACK_DIR}/lib/maven.sh"
15+
source "${BUILDPACK_DIR}/lib/openjdk.sh"
1516

1617
util::export_env_dir "${ENV_DIR}" "." "JAVA_OPTS|JAVA_TOOL_OPTIONS"
1718

18-
common::install_jdk "${BUILD_DIR}" "${CACHE_DIR}"
19+
openjdk::install_openjdk_via_jvm_common_buildpack "${BUILD_DIR}" "${BUILDPACK_DIR}"
1920

2021
cd "${BUILD_DIR}"
2122

lib/common.sh

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,3 @@ common::cache_copy() {
9191
cp -pr "${from_dir}/${rel_dir}"/. "${to_dir}/${rel_dir}"
9292
fi
9393
}
94-
95-
common::install_jdk() {
96-
local install_dir="${1}"
97-
local cache_dir="${2}"
98-
99-
JVM_COMMON_BUILDPACK=${JVM_COMMON_BUILDPACK:-https://buildpack-registry.s3.us-east-1.amazonaws.com/buildpacks/heroku/jvm.tgz}
100-
mkdir -p /tmp/jvm-common
101-
curl --fail --retry 3 --retry-connrefused --connect-timeout 5 --silent --location "${JVM_COMMON_BUILDPACK}" | tar xzm -C /tmp/jvm-common --strip-components=1
102-
#shellcheck source=/dev/null
103-
source /tmp/jvm-common/bin/java
104-
#shellcheck source=/dev/null
105-
source /tmp/jvm-common/opt/jdbc.sh
106-
107-
install_java_with_overlay "${install_dir}" "${cache_dir}"
108-
}

lib/openjdk.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
3+
# This is technically redundant, since all consumers of this lib will have enabled these,
4+
# however, it helps Shellcheck realise the options under which these functions will run.
5+
set -euo pipefail
6+
7+
openjdk::install_openjdk_via_jvm_common_buildpack() {
8+
local build_dir="${1}"
9+
# The install_openjdk function from the JVM common buildpack requires the path to the host buildpack to write to the
10+
# export script so that OpenJDK can be found by subsequent buildpacks.
11+
local host_buildpack_dir="${2}"
12+
13+
# Legacy behaviour for customers and testing code can override the download location of the heroku/jvm buildpack
14+
# with JVM_COMMON_BUILDPACK for testing and debugging purposes.
15+
local jvm_common_buildpack_tarball_url="${JVM_COMMON_BUILDPACK:-https://buildpack-registry.s3.us-east-1.amazonaws.com/buildpacks/heroku/jvm.tgz}"
16+
17+
local jvm_common_buildpack_tarball_path
18+
jvm_common_buildpack_tarball_path=$(mktemp)
19+
20+
local jvm_common_buildpack_dir
21+
jvm_common_buildpack_dir=$(mktemp -d)
22+
23+
curl --silent --fail --retry 3 --retry-connrefused --connect-timeout 5 --location "${jvm_common_buildpack_tarball_url}" -o "${jvm_common_buildpack_tarball_path}"
24+
tar -xzm --directory "${jvm_common_buildpack_dir}" --strip-components=1 "${jvm_common_buildpack_tarball_path}"
25+
26+
# This script translates non-JDBC compliant DATABASE_URL (and similar) environment variables into their
27+
# JDBC compatible counterparts and writes them to "JDBC_" prefixed environment variables. We source this script
28+
# here to allow customers to connect to their databases via JDBC during the build. If no database environment
29+
# variables are present, this script does nothing.
30+
# shellcheck source=/dev/null
31+
source "${jvm_common_buildpack_dir}/opt/jdbc.sh"
32+
33+
# shellcheck source=/dev/null
34+
source "${jvm_common_buildpack_dir}/bin/java"
35+
36+
# See: https://github.com/heroku/heroku-buildpack-jvm-common/blob/main/bin/java
37+
install_openjdk "${build_dir}" "${host_buildpack_dir}"
38+
}

0 commit comments

Comments
 (0)