diff --git a/bin/compile b/bin/compile index 741caf9..3d0e263 100755 --- a/bin/compile +++ b/bin/compile @@ -1,21 +1,19 @@ #!/usr/bin/env bash -# bin/compile - set -e -BP_DIR=$( - cd "$(dirname "${0}")/".. +BUILD_DIR="${1}" +CACHE_DIR="${2}" +ENV_DIR="${3}" + +BUILDPACK_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" +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..a1e1d96 100755 --- a/bin/release +++ b/bin/release @@ -1,19 +1,18 @@ #!/usr/bin/env bash -# bin/release - 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 "---" -if has_postgres "${BUILD_DIR}"; then +if frameworks::has_postgres "${BUILD_DIR}"; then cat < - -# 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..ff6f70f 100755 --- a/bin/test-compile +++ b/bin/test-compile @@ -1,20 +1,18 @@ #!/usr/bin/env bash -# bin/test-compile - -# fail fast set -e -BP_DIR=$( +BUILD_DIR="${1}" +CACHE_DIR="${2}" +ENV_DIR="${3}" + +BUILDPACK_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 "${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/lib/common.sh b/lib/common.sh index 153bc69..7dfaec3 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 @@ -46,11 +46,11 @@ 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}" + 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 echo "" fi diff --git a/lib/frameworks.sh b/lib/frameworks.sh index d99aa85..a4d1a15 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")" +frameworks::is_spring_boot() { + 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")" +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() { - local buildDir=${1:?} - test -f "${buildDir}/pom.xml" && - test -n "$(grep "io.micronaut" "${buildDir}/pom.xml")" +frameworks::is_micronaut() { + 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")" +frameworks::is_quarkus() { + local build_dir=${1:?} + test -f "${build_dir}/pom.xml" && + test -n "$(grep "io.quarkus" "${build_dir}/pom.xml")" } -has_postgres() { - local buildDir=${1:?} +frameworks::has_postgres() { + 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 }