Skip to content
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

Apply shfmt formatting #231

Merged
merged 1 commit into from
Feb 25, 2025
Merged
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
5 changes: 4 additions & 1 deletion bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ set -e

BPLOG_PREFIX="buildpack.java"

BP_DIR=$(cd $(dirname $0)/..; pwd) # absolute path
BP_DIR=$(
cd $(dirname $0)/..
pwd
) # absolute path
BUILD_DIR=$1
CACHE_DIR=$2
ENV_DIR=$3
Expand Down
22 changes: 11 additions & 11 deletions bin/detect
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/usr/bin/env bash

if [ -f "${1:?}/pom.xml" ] ||
[ -f "${1:?}/pom.atom" ] ||
[ -f "${1:?}/pom.clj" ] ||
[ -f "${1:?}/pom.groovy" ] ||
[ -f "${1:?}/pom.rb" ] ||
[ -f "${1:?}/pom.scala" ] ||
[ -f "${1:?}/pom.yaml" ] ||
[ -f "${1:?}/pom.yml" ] ; then
echo "Java"
exit 0
[ -f "${1:?}/pom.atom" ] ||
[ -f "${1:?}/pom.clj" ] ||
[ -f "${1:?}/pom.groovy" ] ||
[ -f "${1:?}/pom.rb" ] ||
[ -f "${1:?}/pom.scala" ] ||
[ -f "${1:?}/pom.yaml" ] ||
[ -f "${1:?}/pom.yml" ]; then
echo "Java"
exit 0
else
(>&2 echo "Could not find a pom.xml file! Please check that it exists and is committed to Git.")
exit 1
(>&2 echo "Could not find a pom.xml file! Please check that it exists and is committed to Git.")
exit 1
fi
45 changes: 24 additions & 21 deletions bin/release
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
#!/usr/bin/env bash
# bin/release <build-dir>

BP_DIR=$(cd $(dirname $0)/..; pwd) # absolute path
BP_DIR=$(
cd $(dirname $0)/..
pwd
) # absolute path
BUILD_DIR=$1

source $BP_DIR/lib/frameworks.sh

echo "---"

if has_postgres $BUILD_DIR; then
cat <<EOF
cat <<EOF
addons:
- heroku-postgresql
EOF
fi

if [ ! -f $BUILD_DIR/Procfile ] && [ -d $BUILD_DIR/target ]; then
if 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
for jarFile in $(find target -maxdepth 1 -name "*.jar" -type f -exec ls -S {} +); do
if 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 "default_process_types:"
echo " web: java -Dswarm.http.port=\$PORT \$JAVA_OPTS -jar $jarFile"
elif is_micronaut $BUILD_DIR; then
echo "default_process_types:"
echo " web: java -Dmicronaut.server.port=\$PORT \$JAVA_OPTS -jar $jarFile"
fi
break;
done
fi
if 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
for jarFile in $(find target -maxdepth 1 -name "*.jar" -type f -exec ls -S {} +); do
if 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 "default_process_types:"
echo " web: java -Dswarm.http.port=\$PORT \$JAVA_OPTS -jar $jarFile"
elif is_micronaut $BUILD_DIR; then
echo "default_process_types:"
echo " web: java -Dmicronaut.server.port=\$PORT \$JAVA_OPTS -jar $jarFile"
fi
break
done
fi
fi
9 changes: 6 additions & 3 deletions bin/test
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
# fail fast
set -e

BP_DIR=$(cd $(dirname $0)/..; pwd) # absolute path
BP_DIR=$(
cd $(dirname $0)/..
pwd
) # absolute path
BUILD_DIR=$1
ENV_DIR=$2

Expand All @@ -19,7 +22,7 @@ cd $BUILD_DIR
mvn_settings_opt="$(_mvn_settings_opt ${BUILD_DIR} ${BUILD_DIR})"

if has_maven_wrapper $BUILD_DIR; then
./mvnw -B ${mvn_settings_opt} ${MAVEN_HEROKU_CI_GOAL:-test}
./mvnw -B ${mvn_settings_opt} ${MAVEN_HEROKU_CI_GOAL:-test}
else
mvn -B ${mvn_settings_opt} ${MAVEN_HEROKU_CI_GOAL:-test}
mvn -B ${mvn_settings_opt} ${MAVEN_HEROKU_CI_GOAL:-test}
fi
5 changes: 4 additions & 1 deletion bin/test-compile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ set -e

BPLOG_PREFIX="buildpack.java.ci"

BP_DIR=$(cd $(dirname $0)/..; pwd) # absolute path
BP_DIR=$(
cd $(dirname $0)/..
pwd
) # absolute path
BUILD_DIR=$1
CACHE_DIR=$2
ENV_DIR=$3
Expand Down
6 changes: 3 additions & 3 deletions etc/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ newVersion="v$((curVersion + 1))"

read -p "Deploy as version: $newVersion [y/n]? " choice
case "$choice" in
y|Y ) echo "";;
n|N ) exit 0;;
* ) exit 1;;
y | Y) echo "" ;;
n | N) exit 0 ;;
*) exit 1 ;;
esac

originMain=$(git rev-parse origin/main)
Expand Down
123 changes: 61 additions & 62 deletions lib/buildpack-stdlib-v7.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,83 +8,82 @@ export BUILDPACK_LOG_FILE=${BUILDPACK_LOG_FILE:-/dev/null}

# Buildpack Steps.
puts_step() {
if [[ "$@" == "-" ]]; then
read output
else
output=$@
fi
echo -e "\e[1m\e[36m=== $output\e[0m"
unset output
if [[ "$@" == "-" ]]; then
read output
else
output=$@
fi
echo -e "\e[1m\e[36m=== $output\e[0m"
unset output
}

# Buildpack Error.
puts_error() {
if [[ "$@" == "-" ]]; then
read output
else
output=$@
fi
echo -e "\e[1m\e[31m=!= $output\e[0m"
if [[ "$@" == "-" ]]; then
read output
else
output=$@
fi
echo -e "\e[1m\e[31m=!= $output\e[0m"
}

# Buildpack Warning.
puts_warn() {
if [[ "$@" == "-" ]]; then
read output
else
output=$@
fi
echo -e "\e[1m\e[33m=!= $output\e[0m"
if [[ "$@" == "-" ]]; then
read output
else
output=$@
fi
echo -e "\e[1m\e[33m=!= $output\e[0m"
}


# Buildpack Utilities
# -------------------

# Usage: $ set-env key value
# NOTICE: Expects PROFILE_PATH & EXPORT_PATH to be set!
set_env() {
# TODO: automatically create profile path directory if it doesn't exist.
echo "export $1=$2" >> $PROFILE_PATH
echo "export $1=$2" >> $EXPORT_PATH
# TODO: automatically create profile path directory if it doesn't exist.
echo "export $1=$2" >>$PROFILE_PATH
echo "export $1=$2" >>$EXPORT_PATH
}

# Usage: $ set-default-env key value
# NOTICE: Expects PROFILE_PATH & EXPORT_PATH to be set!
set_default_env() {
echo "export $1=\${$1:-$2}" >> $PROFILE_PATH
echo "export $1=\${$1:-$2}" >> $EXPORT_PATH
echo "export $1=\${$1:-$2}" >>$PROFILE_PATH
echo "export $1=\${$1:-$2}" >>$EXPORT_PATH
}

# Usage: $ un-set-env key
# NOTICE: Expects PROFILE_PATH to be set!
un_set_env() {
echo "unset $1" >> $PROFILE_PATH
echo "unset $1" >>$PROFILE_PATH
}

# Usage: $ _env-blacklist pattern
# Outputs a regex of default blacklist env vars.
_env_blacklist() {
local regex=${1:-''}
if [ -n "$regex" ]; then
regex="|$regex"
fi
echo "^(PATH|GIT_DIR|CPATH|CPPATH|LD_PRELOAD|LIBRARY_PATH$regex)$"
local regex=${1:-''}
if [ -n "$regex" ]; then
regex="|$regex"
fi
echo "^(PATH|GIT_DIR|CPATH|CPPATH|LD_PRELOAD|LIBRARY_PATH$regex)$"
}

# Usage: $ export-env ENV_DIR WHITELIST BLACKLIST
# Exports the environment variables defined in the given directory.
export_env() {
local env_dir=${1:-$ENV_DIR}
local whitelist=${2:-''}
local blacklist="$(_env_blacklist $3)"
if [ -d "$env_dir" ]; then
for e in $(ls $env_dir); do
echo "$e" | grep -E "$whitelist" | grep -qvE "$blacklist" &&
export "$e=$(cat $env_dir/$e)"
:
done
fi
local env_dir=${1:-$ENV_DIR}
local whitelist=${2:-''}
local blacklist="$(_env_blacklist $3)"
if [ -d "$env_dir" ]; then
for e in $(ls $env_dir); do
echo "$e" | grep -E "$whitelist" | grep -qvE "$blacklist" &&
export "$e=$(cat $env_dir/$e)"
:
done
fi
}

# Usage: $ sub-env command
Expand All @@ -94,11 +93,11 @@ export_env() {
# WHITELIST=${2:-''}
# BLACKLIST=${3:-'^(GIT_DIR|PYTHONHOME|LD_LIBRARY_PATH|LIBRARY_PATH|PATH)$'}
sub_env() {
(
export_env $ENV_DIR $WHITELIST $BLACKLIST
(
export_env $ENV_DIR $WHITELIST $BLACKLIST

$1
)
$1
)
}

# Logging
Expand All @@ -110,55 +109,55 @@ sub_env() {
# Returns now, in milleseconds. Useful for logging.
# Example: $ let start=$(nowms); sleep 30; mtime "glide.install.time" "${start}"
nowms() {
date +%s%3N
date +%s%3N
}

# Log arbitrary data to the logfile (e.g. a packaging file).
# Usage: $ bplog "$(<${vendorJSON})
bplog() {
echo -n ${@} | awk 'BEGIN {printf "msg=\""; f="%s"} {gsub(/"/, "\\\"", $0); printf f, $0} {if (NR == 1) f="\\n%s" } END { print "\"" }' >> ${BUILDPACK_LOG_FILE}
echo -n ${@} | awk 'BEGIN {printf "msg=\""; f="%s"} {gsub(/"/, "\\\"", $0); printf f, $0} {if (NR == 1) f="\\n%s" } END { print "\"" }' >>${BUILDPACK_LOG_FILE}
}

# Measures time elapsed for a specific build step.
# Usage: $ let start=$(nowms); mtime "glide.install.time" "${start}"
# https://github.com/heroku/engineering-docs/blob/master/guides/logs-as-data.md#distributions-measure
mtime() {
local key="${BPLOG_PREFIX}.${1}"
local start="${2}"
local end="${3:-$(nowms)}"
echo "${key} ${start} ${end}" | awk '{ printf "measure#%s=%.3f\n", $1, ($3 - $2)/1000 }' >> ${BUILDPACK_LOG_FILE}
local key="${BPLOG_PREFIX}.${1}"
local start="${2}"
local end="${3:-$(nowms)}"
echo "${key} ${start} ${end}" | awk '{ printf "measure#%s=%.3f\n", $1, ($3 - $2)/1000 }' >>${BUILDPACK_LOG_FILE}
}

# Logs a count for a specific built step.
# Usage: $ mcount "tool.govendor"
# https://github.com/heroku/engineering-docs/blob/master/guides/logs-as-data.md#counting-count
mcount() {
local k="${BPLOG_PREFIX}.${1}"
local v="${2:-1}"
echo "count#${k}=${v}" >> ${BUILDPACK_LOG_FILE}
local k="${BPLOG_PREFIX}.${1}"
local v="${2:-1}"
echo "count#${k}=${v}" >>${BUILDPACK_LOG_FILE}
}

# Logs a measure for a specific build step.
# Usage: $ mmeasure "tool.installed_dependencies" 42
# https://github.com/heroku/engineering-docs/blob/master/guides/logs-as-data.md#distributions-measure
mmeasure() {
local k="${BPLOG_PREFIX}.${1}"
local v="${2}"
echo "measure#${k}=${v}" >> ${BUILDPACK_LOG_FILE}
local k="${BPLOG_PREFIX}.${1}"
local v="${2}"
echo "measure#${k}=${v}" >>${BUILDPACK_LOG_FILE}
}

# Logs a unuique measurement build step.
# Usage: $ munique "versions.count" 2.7.13
# https://github.com/heroku/engineering-docs/blob/master/guides/logs-as-data.md#uniques-unique
munique() {
local k="${BPLOG_PREFIX}.${1}"
local v="${2}"
echo "unique#${k}=${v}" >> ${BUILDPACK_LOG_FILE}
local k="${BPLOG_PREFIX}.${1}"
local v="${2}"
echo "unique#${k}=${v}" >>${BUILDPACK_LOG_FILE}
}

# Measures when an exit path to the buildpack is reached, given a name, then exits 1.
# Usage: $ mcount-exi "binExists"
mcount_exit() {
mcount "error.${1}"
exit 1
mcount "error.${1}"
exit 1
}
Loading
Loading