Skip to content

Commit

Permalink
Port Python buildpack output.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
Malax committed Feb 7, 2025
1 parent 3b63cc9 commit add8da7
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 32 deletions.
64 changes: 35 additions & 29 deletions bin/java
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,49 @@ if [ -f "${JVM_COMMON_DIR}/lib/jvm.sh" ]; then
source "${JVM_COMMON_DIR}/lib/jvm.sh"
fi

# shellcheck source=lib/output.sh
source "${JVM_COMMON_DIR}/lib/output.sh"

install_java_with_overlay() {
local buildDir="${1}"
local cacheDir="${2:-$(mktemp -d)}"
if [ ! -f "${buildDir}/.jdk/bin/java" ]; then
if [ -z "$(_get_system_property "${buildDir}/system.properties" "java.runtime.version")" ]; then
if [ "${STACK}" == "heroku-24" ]; then
warning "No OpenJDK version specified
Your application does not explicitly specify an OpenJDK
version. The latest long-term support (LTS) version will be
installed. This currently is OpenJDK ${DEFAULT_JDK_VERSION}.
output::warning <<-EOF
WARNING: No OpenJDK version specified
Your application does not explicitly specify an OpenJDK
version. The latest long-term support (LTS) version will be
installed. This currently is OpenJDK ${DEFAULT_JDK_VERSION}.
This default version will change when a new LTS version is
released. Your application might fail to build with the new
version. We recommend explicitly setting the required OpenJDK
version for your application.
This default version will change when a new LTS version is
released. Your application might fail to build with the new
version. We recommend explicitly setting the required OpenJDK
version for your application.
To set the OpenJDK version, add or edit the system.properties
file in the root directory of your application to contain:
To set the OpenJDK version, add or edit the system.properties
file in the root directory of your application to contain:
java.runtime.version = ${DEFAULT_JDK_VERSION}
"
java.runtime.version = ${DEFAULT_JDK_VERSION}
EOF
else
warning "No OpenJDK version specified
Your application does not explicitly specify an OpenJDK
version. OpenJDK ${DEFAULT_JDK_VERSION} will be installed.
output::warning <<-EOF
WARNING: No OpenJDK version specified
Your application does not explicitly specify an OpenJDK
version. OpenJDK ${DEFAULT_JDK_VERSION} will be installed.
This default version will change at some point. Your
application might fail to build with the new version. We
recommend explicitly setting the required OpenJDK version for
your application.
This default version will change at some point. Your
application might fail to build with the new version. We
recommend explicitly setting the required OpenJDK version for
your application.
To set the OpenJDK version, add or edit the system.properties
file in the root directory of your application to contain:
To set the OpenJDK version, add or edit the system.properties
file in the root directory of your application to contain:
java.runtime.version = ${DEFAULT_JDK_VERSION}
"
java.runtime.version = ${DEFAULT_JDK_VERSION}
EOF
fi
fi

Expand All @@ -57,24 +64,23 @@ java.runtime.version = ${DEFAULT_JDK_VERSION}

_jvm_mcount "version.${jdkVersion}"
if [[ "$jdkVersion" == *openjdk* ]]; then
status_pending "Installing Heroku OpenJDK $(_get_openjdk_version "${jdkVersion}")"
output::step "Installing Heroku OpenJDK $(_get_openjdk_version "${jdkVersion}")"
_jvm_mcount "vendor.openjdk"
elif [[ "$jdkVersion" == *heroku* ]]; then
status_pending "Installing Heroku OpenJDK $(_get_heroku_version "${jdkVersion}")"
output::step "Installing Heroku OpenJDK $(_get_heroku_version "${jdkVersion}")"
_jvm_mcount "vendor.openjdk"
elif [[ "$jdkVersion" == *zulu* ]]; then
status_pending "Installing Azul Zulu OpenJDK $(_get_zulu_version "${jdkVersion}")"
output::step "Installing Azul Zulu OpenJDK $(_get_zulu_version "${jdkVersion}")"
_jvm_mcount "vendor.zulu"
else
status_pending "Installing OpenJDK ${jdkVersion}"
output::step "Installing OpenJDK ${jdkVersion}"
_jvm_mcount "vendor.default"
fi
install_java "${buildDir}" "${jdkVersion}" "${jdkUrl}"
install_jdk_overlay "${buildDir}/.jdk" "${buildDir}"
_cache_version "${jdkVersion}" "${cacheDir}"
status_done
else
status "Using provided JDK"
output::step "Using provided JDK"
_jvm_mcount "vendor.provided"
fi
}
Expand Down
2 changes: 1 addition & 1 deletion lib/jvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if [[ -n "${JDK_BASE_URL:-}" ]]; then
# Support for setting JDK_BASE_URL had the issue that it has to contain the stack name. This makes it hard to
# override the bucket for testing with staging binaries by using the existing JVM buildpack integration tests that
# cover all stacks. We will remove support for it in October 2021.
warning_inline "Support for the JDK_BASE_URL environment variable is deprecated and will be removed October 2021!"
warning "WARNING: Support for the JDK_BASE_URL environment variable is deprecated and will be removed October 2021!"
else
JVM_BUILDPACK_ASSETS_BASE_URL="${JVM_BUILDPACK_ASSETS_BASE_URL:-"https://lang-jvm.s3.us-east-1.amazonaws.com"}"
JDK_BASE_URL="${JVM_BUILDPACK_ASSETS_BASE_URL%/}/jdk/${STACK}"
Expand Down
83 changes: 83 additions & 0 deletions lib/output.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env bash

ANSI_BLUE='\033[1;34m'
ANSI_RED='\033[1;31m'
ANSI_YELLOW='\033[1;33m'
ANSI_RESET='\033[0m'

# Output a single line step message to stdout.
#
# Usage:
# ```
# output::step "Installing Python ..."
# ```
function output::step() {
echo "-----> ${1}"
}

# Indent passed stdout. Typically used to indent command output within a step.
#
# Usage:
# ```
# pip install ... | output::indent
# ```
function output::indent() {
sed --unbuffered "s/^/ /"
}

# Output a styled multi-line notice message to stderr.
#
# Usage:
# ```
# output::notice <<-EOF
# Note: The note summary.
#
# Detailed description.
# EOF
# ```
function output::notice() {
local line
echo >&2
while IFS= read -r line; do
echo -e "${ANSI_BLUE} ! ${line}${ANSI_RESET}" >&2
done
echo >&2
}

# Output a styled multi-line warning message to stderr.
#
# Usage:
# ```
# output::warning <<-EOF
# Warning: The warning summary.
#
# Detailed description.
# EOF
# ```
function output::warning() {
local line
echo >&2
while IFS= read -r line; do
echo -e "${ANSI_YELLOW} ! ${line}${ANSI_RESET}" >&2
done
echo >&2
}

# Output a styled multi-line error message to stderr.
#
# Usage:
# ```
# output::error <<-EOF
# Error: The error summary.
#
# Detailed description.
# EOF
# ```
function output::error() {
local line
echo >&2
while IFS= read -r line; do
echo -e "${ANSI_RED} ! ${line}${ANSI_RESET}" >&2
done
echo >&2
}
4 changes: 2 additions & 2 deletions test/spec/overlay_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
app.deploy do
expect(app.output).to match(Regexp.new(<<~REGEX, Regexp::MULTILINE))
remote: -----> JVM Common app detected
remote: -----> Installing OpenJDK 8... done
remote: -----> Installing OpenJDK 8
REGEX

expect(app.run('cat .jdk/extra.txt')).to eq("extra.txt contents\n")
Expand All @@ -23,7 +23,7 @@
app.deploy do
expect(app.output).to match(Regexp.new(<<~REGEX, Regexp::MULTILINE))
remote: -----> JVM Common app detected
remote: -----> Installing OpenJDK 21... done
remote: -----> Installing OpenJDK 21
REGEX

expect(app.run('cat .jdk/extra.txt')).to eq("extra.txt contents\n")
Expand Down

0 comments on commit add8da7

Please sign in to comment.