From fc2e1f93a85fc7f8e79e4cf742b3df9f3a155274 Mon Sep 17 00:00:00 2001 From: Manuel Fuchs Date: Wed, 5 Mar 2025 12:22:24 +0100 Subject: [PATCH 1/5] Rename BP_DIR to BUILDPACK_DIR --- bin/compile | 18 +++++++++--------- bin/release | 7 ++++--- bin/test | 13 +++++++------ bin/test-compile | 15 ++++++++------- 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/bin/compile b/bin/compile index 741caf9..a2233c7 100755 --- a/bin/compile +++ b/bin/compile @@ -3,19 +3,19 @@ set -e -BP_DIR=$( - cd "$(dirname "${0}")/".. - pwd -) - BUILD_DIR=$1 CACHE_DIR=$2 ENV_DIR=$3 -source "${BP_DIR}/lib/util.sh" -source "${BP_DIR}/lib/common.sh" -source "${BP_DIR}/lib/maven.sh" -source "${BP_DIR}/lib/metadata.sh" +BUILDPACK_DIR=$( + cd "$(dirname "${0}")"/.. + pwd +) + +source "${BUILDPACK_DIR}/lib/util.sh" +source "${BUILDPACK_DIR}/lib/common.sh" +source "${BUILDPACK_DIR}/lib/maven.sh" +source "${BUILDPACK_DIR}/lib/metadata.sh" # Initialise the buildpack metadata store. # This is used to track state across builds (for cache invalidation and messaging when build diff --git a/bin/release b/bin/release index c1058d1..7d9d64f 100755 --- a/bin/release +++ b/bin/release @@ -3,13 +3,14 @@ set -e -BP_DIR=$( +BUILD_DIR=$1 + +BUILDPACK_DIR=$( cd "$(dirname "${0}")"/.. pwd ) -BUILD_DIR=$1 -source "${BP_DIR}/lib/frameworks.sh" +source "${BUILDPACK_DIR}/lib/frameworks.sh" echo "---" diff --git a/bin/test b/bin/test index 8671981..c0525fd 100755 --- a/bin/test +++ b/bin/test @@ -4,16 +4,17 @@ # fail fast set -e -BP_DIR=$( +BUILD_DIR=$1 +ENV_DIR=$2 + +BUILDPACK_DIR=$( cd "$(dirname "${0}")"/.. pwd ) -BUILD_DIR=$1 -ENV_DIR=$2 -source "${BP_DIR}/lib/util.sh" -source "${BP_DIR}/lib/common.sh" -source "${BP_DIR}/lib/maven.sh" +source "${BUILDPACK_DIR}/lib/util.sh" +source "${BUILDPACK_DIR}/lib/common.sh" +source "${BUILDPACK_DIR}/lib/maven.sh" export_env_dir "${ENV_DIR}" "." "JAVA_OPTS|JAVA_TOOL_OPTIONS" diff --git a/bin/test-compile b/bin/test-compile index 900b00e..9da5ab0 100755 --- a/bin/test-compile +++ b/bin/test-compile @@ -4,17 +4,18 @@ # fail fast set -e -BP_DIR=$( - cd "$(dirname "${0}")"/.. - pwd -) BUILD_DIR=$1 CACHE_DIR=$2 ENV_DIR=$3 -source "${BP_DIR}/lib/util.sh" -source "${BP_DIR}/lib/common.sh" -source "${BP_DIR}/lib/maven.sh" +BUILDPACK_DIR=$( + cd "$(dirname "${0}")"/.. + pwd +) + +source "${BUILDPACK_DIR}/lib/util.sh" +source "${BUILDPACK_DIR}/lib/common.sh" +source "${BUILDPACK_DIR}/lib/maven.sh" export_env_dir "${ENV_DIR}" "." "JAVA_OPTS|JAVA_TOOL_OPTIONS" From 4573fc89a9d90bc51fe426cf763e115906e5a4da Mon Sep 17 00:00:00 2001 From: Manuel Fuchs Date: Wed, 5 Mar 2025 12:27:32 +0100 Subject: [PATCH 2/5] Misc syntax changes --- bin/compile | 8 +++----- bin/release | 4 +--- bin/test | 7 ++----- bin/test-compile | 9 +++------ lib/common.sh | 6 +++--- 5 files changed, 12 insertions(+), 22 deletions(-) diff --git a/bin/compile b/bin/compile index a2233c7..3d0e263 100755 --- a/bin/compile +++ b/bin/compile @@ -1,11 +1,9 @@ #!/usr/bin/env bash -# bin/compile - set -e -BUILD_DIR=$1 -CACHE_DIR=$2 -ENV_DIR=$3 +BUILD_DIR="${1}" +CACHE_DIR="${2}" +ENV_DIR="${3}" BUILDPACK_DIR=$( cd "$(dirname "${0}")"/.. diff --git a/bin/release b/bin/release index 7d9d64f..8f10a1b 100755 --- a/bin/release +++ b/bin/release @@ -1,9 +1,7 @@ #!/usr/bin/env bash -# bin/release - set -e -BUILD_DIR=$1 +BUILD_DIR="${1}" BUILDPACK_DIR=$( cd "$(dirname "${0}")"/.. diff --git a/bin/test b/bin/test index c0525fd..424c60b 100755 --- a/bin/test +++ b/bin/test @@ -1,11 +1,8 @@ #!/usr/bin/env bash -# bin/test - -# fail fast set -e -BUILD_DIR=$1 -ENV_DIR=$2 +BUILD_DIR="${1}" +ENV_DIR="${2}" BUILDPACK_DIR=$( cd "$(dirname "${0}")"/.. diff --git a/bin/test-compile b/bin/test-compile index 9da5ab0..ff6f70f 100755 --- a/bin/test-compile +++ b/bin/test-compile @@ -1,12 +1,9 @@ #!/usr/bin/env bash -# bin/test-compile - -# fail fast set -e -BUILD_DIR=$1 -CACHE_DIR=$2 -ENV_DIR=$3 +BUILD_DIR="${1}" +CACHE_DIR="${2}" +ENV_DIR="${3}" BUILDPACK_DIR=$( cd "$(dirname "${0}")"/.. diff --git a/lib/common.sh b/lib/common.sh index 153bc69..740c2b2 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -3,9 +3,9 @@ export DEFAULT_MAVEN_VERSION="3.9.4" install_maven() { - local installDir=$1 - local buildDir=$2 - mavenHome=$installDir/.maven + local installDir="${1}" + local buildDir="${2}" + mavenHome="${installDir}/.maven" definedMavenVersion=$(detect_maven_version "${buildDir}") From 5b2325960fdf530b35410c1daebcb43ad07c9abb Mon Sep 17 00:00:00 2001 From: Manuel Fuchs Date: Wed, 5 Mar 2025 12:33:45 +0100 Subject: [PATCH 3/5] Convert variables to snake_case --- lib/common.sh | 44 ++++++++++++++++++++--------------------- lib/frameworks.sh | 36 +++++++++++++++++----------------- lib/maven.sh | 50 +++++++++++++++++++++++------------------------ 3 files changed, 65 insertions(+), 65 deletions(-) diff --git a/lib/common.sh b/lib/common.sh index 740c2b2..3b3a379 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -3,18 +3,18 @@ export DEFAULT_MAVEN_VERSION="3.9.4" install_maven() { - local installDir="${1}" - local buildDir="${2}" - mavenHome="${installDir}/.maven" + local install_dir="${1}" + local build_dir="${2}" + local maven_home="${install_dir}/.maven" - definedMavenVersion=$(detect_maven_version "${buildDir}") + defined_maven_version=$(detect_maven_version "${build_dir}") - mavenVersion=${definedMavenVersion:-$DEFAULT_MAVEN_VERSION} + maven_version=${defined_maven_version:-$DEFAULT_MAVEN_VERSION} - status_pending "Installing Maven ${mavenVersion}" - local mavenUrl="https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/${mavenVersion}/apache-maven-${mavenVersion}-bin.tar.gz" - if is_supported_maven_version "${mavenVersion}" "${mavenUrl}"; then - download_maven "${mavenUrl}" "${mavenHome}" + status_pending "Installing Maven ${maven_version}" + local maven_url="https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/${maven_version}/apache-maven-${maven_version}-bin.tar.gz" + if is_supported_maven_version "${maven_version}" "${maven_url}"; then + download_maven "${maven_url}" "${maven_home}" status_done else error_return "Error, you have defined an unsupported Maven version in the system.properties file. @@ -24,21 +24,21 @@ The default supported version is ${DEFAULT_MAVEN_VERSION}" } download_maven() { - local mavenUrl=$1 - local installDir=$2 + local maven_url=$1 + local install_dir=$2 - rm -rf "${installDir}" - mkdir -p "${installDir}" - curl --fail --retry 3 --retry-connrefused --connect-timeout 5 --silent --max-time 60 --location "${mavenUrl}" | tar -xzm --strip-components 1 -C "${installDir}" - chmod +x "${installDir}/bin/mvn" + rm -rf "${install_dir}" + mkdir -p "${install_dir}" + curl --fail --retry 3 --retry-connrefused --connect-timeout 5 --silent --max-time 60 --location "${maven_url}" | tar -xzm --strip-components 1 -C "${install_dir}" + chmod +x "${install_dir}/bin/mvn" } is_supported_maven_version() { - local mavenVersion=${1} - local mavenUrl=${2:?} - if [ "$mavenVersion" = "$DEFAULT_MAVEN_VERSION" ]; then + local maven_version=${1} + local maven_url=${2:?} + if [ "$maven_version" = "$DEFAULT_MAVEN_VERSION" ]; then return 0 - elif curl -I --retry 3 --retry-connrefused --connect-timeout 5 --fail --silent --max-time 5 --location "${mavenUrl}" >/dev/null; then + elif curl -I --retry 3 --retry-connrefused --connect-timeout 5 --fail --silent --max-time 5 --location "${maven_url}" >/dev/null; then return 0 else return 1 @@ -48,9 +48,9 @@ is_supported_maven_version() { detect_maven_version() { local baseDir=${1} if [ -f "${baseDir}/system.properties" ]; then - mavenVersion=$(get_app_system_value "${baseDir}/system.properties" "maven.version") - if [ -n "$mavenVersion" ]; then - echo "${mavenVersion}" + maven_version=$(get_app_system_value "${baseDir}/system.properties" "maven.version") + if [ -n "$maven_version" ]; then + echo "${maven_version}" else echo "" fi diff --git a/lib/frameworks.sh b/lib/frameworks.sh index d99aa85..c3a917b 100644 --- a/lib/frameworks.sh +++ b/lib/frameworks.sh @@ -1,36 +1,36 @@ #!/usr/bin/env bash is_spring_boot() { - local buildDir=${1:?} - test -f "${buildDir}/pom.xml" && - test -n "$(grep "org.springframework.boot" "${buildDir}/pom.xml")" && - test -n "$(grep "spring-boot" "${buildDir}/pom.xml")" + local build_dir=${1:?} + test -f "${build_dir}/pom.xml" && + test -n "$(grep "org.springframework.boot" "${build_dir}/pom.xml")" && + test -n "$(grep "spring-boot" "${build_dir}/pom.xml")" } is_wildfly_swarm() { - local buildDir=${1:?} - test -f "${buildDir}/pom.xml" && - test -n "$(grep "org.wildfly.swarm" "${buildDir}/pom.xml")" + local build_dir=${1:?} + test -f "${build_dir}/pom.xml" && + test -n "$(grep "org.wildfly.swarm" "${build_dir}/pom.xml")" } is_micronaut() { - local buildDir=${1:?} - test -f "${buildDir}/pom.xml" && - test -n "$(grep "io.micronaut" "${buildDir}/pom.xml")" + local build_dir=${1:?} + test -f "${build_dir}/pom.xml" && + test -n "$(grep "io.micronaut" "${build_dir}/pom.xml")" } is_quarkus() { - local buildDir=${1:?} - test -f "${buildDir}/pom.xml" && - test -n "$(grep "io.quarkus" "${buildDir}/pom.xml")" + local build_dir=${1:?} + test -f "${build_dir}/pom.xml" && + test -n "$(grep "io.quarkus" "${build_dir}/pom.xml")" } has_postgres() { - local buildDir=${1:?} + local build_dir=${1:?} # shellcheck disable=SC2235 - test -f "${buildDir}/pom.xml" && ( - test -n "$(grep "org.postgresql" "${buildDir}/pom.xml")" || - test -n "$(grep "postgresql" "${buildDir}/pom.xml")" || - test -n "$(grep "com.impossibl.pgjdbc-ng" "${buildDir}/pom.xml")" + test -f "${build_dir}/pom.xml" && ( + test -n "$(grep "org.postgresql" "${build_dir}/pom.xml")" || + test -n "$(grep "postgresql" "${build_dir}/pom.xml")" || + test -n "$(grep "com.impossibl.pgjdbc-ng" "${build_dir}/pom.xml")" ) } diff --git a/lib/maven.sh b/lib/maven.sh index 7a2437c..2b9f9c7 100644 --- a/lib/maven.sh +++ b/lib/maven.sh @@ -30,16 +30,16 @@ _mvn_cmd_opts() { _mvn_settings_opt() { local home="${1}" - local mavenInstallDir="${2}" + local maven_install_dir="${2}" if [ -n "$MAVEN_SETTINGS_PATH" ]; then echo -n "-s $MAVEN_SETTINGS_PATH" elif [ -n "$MAVEN_SETTINGS_URL" ]; then - local settingsXml="${mavenInstallDir}/.m2/settings.xml" - mkdir -p "$(dirname "${settingsXml}")" - curl --retry 3 --retry-connrefused --connect-timeout 5 --silent --max-time 10 --location "${MAVEN_SETTINGS_URL}" --output "${settingsXml}" - if [ -f "${settingsXml}" ]; then - echo -n "-s ${settingsXml}" + local settings_xml="${maven_install_dir}/.m2/settings.xml" + mkdir -p "$(dirname "${settings_xml}")" + curl --retry 3 --retry-connrefused --connect-timeout 5 --silent --max-time 10 --location "${MAVEN_SETTINGS_URL}" --output "${settings_xml}" + if [ -f "${settings_xml}" ]; then + echo -n "-s ${settings_xml}" else error "Could not download settings.xml from the URL defined in MAVEN_SETTINGS_URL!" return 1 @@ -63,8 +63,8 @@ has_maven_wrapper() { } get_cache_status() { - local cacheDir=${1} - if [ ! -d "${cacheDir}/.m2" ]; then + local cache_dir=${1} + if [ ! -d "${cache_dir}/.m2" ]; then echo "not-found" else echo "valid" @@ -74,41 +74,41 @@ get_cache_status() { run_mvn() { local scope=${1} local home=${2} - local mavenInstallDir=${3} + local maven_install_dir=${3} - mkdir -p "${mavenInstallDir}" + mkdir -p "${maven_install_dir}" if has_maven_wrapper "${home}"; then - cache_copy ".m2/wrapper" "${mavenInstallDir}" "${home}" + cache_copy ".m2/wrapper" "${maven_install_dir}" "${home}" chmod +x "${home}/mvnw" - local mavenExe="./mvnw" + local maven_exe="./mvnw" else # shellcheck disable=SC2164 - cd "${mavenInstallDir}" + cd "${maven_install_dir}" - install_maven "${mavenInstallDir}" "${home}" - PATH="${mavenInstallDir}/.maven/bin:$PATH" - local mavenExe="mvn" + install_maven "${maven_install_dir}" "${home}" + PATH="${maven_install_dir}/.maven/bin:$PATH" + local maven_exe="mvn" # shellcheck disable=SC2164 cd "${home}" fi local mvn_settings_opt - mvn_settings_opt="$(_mvn_settings_opt "${home}" "${mavenInstallDir}")" + mvn_settings_opt="$(_mvn_settings_opt "${home}" "${maven_install_dir}")" - MAVEN_OPTS="$(_mvn_java_opts "${scope}" "${home}" "${mavenInstallDir}")" + MAVEN_OPTS="$(_mvn_java_opts "${scope}" "${home}" "${maven_install_dir}")" export MAVEN_OPTS # shellcheck disable=SC2164 cd "${home}" - local mvnOpts - mvnOpts="$(_mvn_cmd_opts "${scope}")" + local mvn_opts + mvn_opts="$(_mvn_cmd_opts "${scope}")" status "Executing Maven" - echo "$ ${mavenExe} ${mvnOpts}" | indent + echo "$ ${maven_exe} ${mvn_opts}" | indent - # We rely on word splitting for mvn_settings_opt and mvnOpts: + # We rely on word splitting for mvn_settings_opt and mvn_opts: # shellcheck disable=SC2086 - if ! ${mavenExe} -DoutputFile=target/mvn-dependency-list.log -B ${mvn_settings_opt} ${mvnOpts} | indent; then + if ! ${maven_exe} -DoutputFile=target/mvn-dependency-list.log -B ${mvn_settings_opt} ${mvn_opts} | indent; then error "Failed to build app with Maven We're sorry this build is failing! If you can't find the issue in application code, please submit a ticket so we can help: https://help.heroku.com/" @@ -129,9 +129,9 @@ write_mvn_profile() { remove_mvn() { local home=${1} - local mavenInstallDir=${2} + local maven_install_dir=${2} if has_maven_wrapper "${home}"; then - cache_copy ".m2/wrapper" "$home" "$mavenInstallDir" + cache_copy ".m2/wrapper" "$home" "$maven_install_dir" rm -rf "$home/.m2" fi } From c861a2b82d8359c9281d605822230f93ac894cb1 Mon Sep 17 00:00:00 2001 From: Manuel Fuchs Date: Wed, 5 Mar 2025 12:44:30 +0100 Subject: [PATCH 4/5] Prefix framework functions --- bin/release | 10 +++++----- lib/frameworks.sh | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bin/release b/bin/release index 8f10a1b..7b42159 100755 --- a/bin/release +++ b/bin/release @@ -12,7 +12,7 @@ source "${BUILDPACK_DIR}/lib/frameworks.sh" echo "---" -if has_postgres "${BUILD_DIR}"; then +if frameworks::has_postgres "${BUILD_DIR}"; then cat <org.springframework.boot" "${build_dir}/pom.xml")" && test -n "$(grep "spring-boot" "${build_dir}/pom.xml")" } -is_wildfly_swarm() { +frameworks::is_wildfly_swarm() { local build_dir=${1:?} test -f "${build_dir}/pom.xml" && test -n "$(grep "org.wildfly.swarm" "${build_dir}/pom.xml")" } -is_micronaut() { +frameworks::is_micronaut() { local build_dir=${1:?} test -f "${build_dir}/pom.xml" && test -n "$(grep "io.micronaut" "${build_dir}/pom.xml")" } -is_quarkus() { +frameworks::is_quarkus() { local build_dir=${1:?} test -f "${build_dir}/pom.xml" && test -n "$(grep "io.quarkus" "${build_dir}/pom.xml")" } -has_postgres() { +frameworks::has_postgres() { local build_dir=${1:?} # shellcheck disable=SC2235 test -f "${build_dir}/pom.xml" && ( From a3c532778b38afa2da352aeb77590d10e9d00178 Mon Sep 17 00:00:00 2001 From: Manuel Fuchs Date: Wed, 5 Mar 2025 12:55:58 +0100 Subject: [PATCH 5/5] More snake_case conversions --- bin/release | 8 ++++---- lib/common.sh | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bin/release b/bin/release index 7b42159..a1e1d96 100755 --- a/bin/release +++ b/bin/release @@ -26,16 +26,16 @@ if [ ! -f "${BUILD_DIR}/Procfile" ] && [ -d "${BUILD_DIR}/target" ]; then else cd "${BUILD_DIR}" # shellcheck disable=SC2044 - for jarFile in $(find target -maxdepth 1 -name "*.jar" -type f -exec ls -S {} +); do + for jar_file in $(find target -maxdepth 1 -name "*.jar" -type f -exec ls -S {} +); do if frameworks::is_spring_boot "${BUILD_DIR}"; then echo "default_process_types:" - echo " web: java -Dserver.port=\$PORT \$JAVA_OPTS -jar ${jarFile}" + echo " web: java -Dserver.port=\$PORT \$JAVA_OPTS -jar ${jar_file}" elif frameworks::is_wildfly_swarm "${BUILD_DIR}"; then echo "default_process_types:" - echo " web: java -Dswarm.http.port=\$PORT \$JAVA_OPTS -jar ${jarFile}" + echo " web: java -Dswarm.http.port=\$PORT \$JAVA_OPTS -jar ${jar_file}" elif frameworks::is_micronaut "${BUILD_DIR}"; then echo "default_process_types:" - echo " web: java -Dmicronaut.server.port=\$PORT \$JAVA_OPTS -jar ${jarFile}" + echo " web: java -Dmicronaut.server.port=\$PORT \$JAVA_OPTS -jar ${jar_file}" fi break done diff --git a/lib/common.sh b/lib/common.sh index 3b3a379..7dfaec3 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -46,9 +46,9 @@ is_supported_maven_version() { } detect_maven_version() { - local baseDir=${1} - if [ -f "${baseDir}/system.properties" ]; then - maven_version=$(get_app_system_value "${baseDir}/system.properties" "maven.version") + local base_dir=${1} + if [ -f "${base_dir}/system.properties" ]; then + maven_version=$(get_app_system_value "${base_dir}/system.properties" "maven.version") if [ -n "$maven_version" ]; then echo "${maven_version}" else