Skip to content

Miscellaneous code style changes #240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions bin/compile
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
#!/usr/bin/env bash
# bin/compile <build-dir> <cache-dir> <env-dir>

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
Expand Down
27 changes: 13 additions & 14 deletions bin/release
Original file line number Diff line number Diff line change
@@ -1,42 +1,41 @@
#!/usr/bin/env bash
# bin/release <build-dir>

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 <<EOF
addons:
- heroku-postgresql
EOF
fi

if [ ! -f "${BUILD_DIR}/Procfile" ] && [ -d "${BUILD_DIR}/target" ]; then
if is_quarkus "${BUILD_DIR}"; then
if frameworks::is_quarkus "${BUILD_DIR}"; then
echo "default_process_types:"
echo " web: java -Dquarkus.http.port=\$PORT \$JAVA_OPTS -jar target/quarkus-app/quarkus-run.jar"
else
cd "${BUILD_DIR}"
# shellcheck disable=SC2044
for jarFile in $(find target -maxdepth 1 -name "*.jar" -type f -exec ls -S {} +); do
if is_spring_boot "${BUILD_DIR}"; then
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}"
elif is_wildfly_swarm "${BUILD_DIR}"; then
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}"
elif is_micronaut "${BUILD_DIR}"; then
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
Expand Down
16 changes: 7 additions & 9 deletions bin/test
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
#!/usr/bin/env bash
# bin/test <build-dir> <env-dir> <artifact-dir>

# 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"

Expand Down
18 changes: 8 additions & 10 deletions bin/test-compile
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
#!/usr/bin/env bash
# bin/test-compile <build-dir> <cache-dir> <env-dir>

# 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"

Expand Down
48 changes: 24 additions & 24 deletions lib/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -24,33 +24,33 @@ 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
fi
}

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
Expand Down
46 changes: 23 additions & 23 deletions lib/frameworks.sh
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
#!/usr/bin/env bash

is_spring_boot() {
local buildDir=${1:?}
test -f "${buildDir}/pom.xml" &&
test -n "$(grep "<groupId>org.springframework.boot" "${buildDir}/pom.xml")" &&
test -n "$(grep "<artifactId>spring-boot" "${buildDir}/pom.xml")"
frameworks::is_spring_boot() {
local build_dir=${1:?}
test -f "${build_dir}/pom.xml" &&
test -n "$(grep "<groupId>org.springframework.boot" "${build_dir}/pom.xml")" &&
test -n "$(grep "<artifactId>spring-boot" "${build_dir}/pom.xml")"
}

is_wildfly_swarm() {
local buildDir=${1:?}
test -f "${buildDir}/pom.xml" &&
test -n "$(grep "<groupId>org.wildfly.swarm" "${buildDir}/pom.xml")"
frameworks::is_wildfly_swarm() {
local build_dir=${1:?}
test -f "${build_dir}/pom.xml" &&
test -n "$(grep "<groupId>org.wildfly.swarm" "${build_dir}/pom.xml")"
}

is_micronaut() {
local buildDir=${1:?}
test -f "${buildDir}/pom.xml" &&
test -n "$(grep "<groupId>io.micronaut" "${buildDir}/pom.xml")"
frameworks::is_micronaut() {
local build_dir=${1:?}
test -f "${build_dir}/pom.xml" &&
test -n "$(grep "<groupId>io.micronaut" "${build_dir}/pom.xml")"
}

is_quarkus() {
local buildDir=${1:?}
test -f "${buildDir}/pom.xml" &&
test -n "$(grep "<groupId>io.quarkus" "${buildDir}/pom.xml")"
frameworks::is_quarkus() {
local build_dir=${1:?}
test -f "${build_dir}/pom.xml" &&
test -n "$(grep "<groupId>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 "<groupId>org.postgresql" "${buildDir}/pom.xml")" ||
test -n "$(grep "<groupId>postgresql" "${buildDir}/pom.xml")" ||
test -n "$(grep "<groupId>com.impossibl.pgjdbc-ng" "${buildDir}/pom.xml")"
test -f "${build_dir}/pom.xml" && (
test -n "$(grep "<groupId>org.postgresql" "${build_dir}/pom.xml")" ||
test -n "$(grep "<groupId>postgresql" "${build_dir}/pom.xml")" ||
test -n "$(grep "<groupId>com.impossibl.pgjdbc-ng" "${build_dir}/pom.xml")"
)
}
50 changes: 25 additions & 25 deletions lib/maven.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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/"
Expand All @@ -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
}