Skip to content

Commit 3e2add6

Browse files
committed
Add lib/output.sh and integrate
1 parent 6a2700b commit 3e2add6

10 files changed

Lines changed: 123 additions & 25 deletions

File tree

bin/compile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ENV_DIR="${3}"
88

99
BUILDPACK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd .. && pwd)"
1010

11+
source "${BUILDPACK_DIR}/lib/output.sh"
1112
source "${BUILDPACK_DIR}/lib/util.sh"
1213
source "${BUILDPACK_DIR}/lib/common.sh"
1314
source "${BUILDPACK_DIR}/lib/maven.sh"

bin/release

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ BUILD_DIR="${1}"
66

77
BUILDPACK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd .. && pwd)"
88

9+
source "${BUILDPACK_DIR}/lib/output.sh"
910
source "${BUILDPACK_DIR}/lib/frameworks.sh"
1011

1112
echo "---"

bin/test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ENV_DIR="${2}"
88

99
BUILDPACK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd .. && pwd)"
1010

11+
source "${BUILDPACK_DIR}/lib/output.sh"
1112
source "${BUILDPACK_DIR}/lib/util.sh"
1213
source "${BUILDPACK_DIR}/lib/common.sh"
1314
source "${BUILDPACK_DIR}/lib/maven.sh"

bin/test-compile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ENV_DIR="${3}"
88

99
BUILDPACK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd .. && pwd)"
1010

11+
source "${BUILDPACK_DIR}/lib/output.sh"
1112
source "${BUILDPACK_DIR}/lib/util.sh"
1213
source "${BUILDPACK_DIR}/lib/common.sh"
1314
source "${BUILDPACK_DIR}/lib/maven.sh"

lib/common.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ common::install_maven() {
1616

1717
local maven_version="${defined_maven_version:-${DEFAULT_MAVEN_VERSION}}"
1818

19-
status_pending "Installing Maven ${maven_version}"
19+
output::step "Installing Maven ${maven_version}..."
2020
local maven_url="https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/${maven_version}/apache-maven-${maven_version}-bin.tar.gz"
2121
if common::is_supported_maven_version "${maven_version}" "${maven_url}"; then
2222
common::download_maven "${maven_url}" "${maven_home}"
23-
status_done
2423
else
25-
error_return "Error, you have defined an unsupported Maven version in the system.properties file.
26-
The default supported version is ${DEFAULT_MAVEN_VERSION}"
24+
output::error <<-EOF
25+
ERROR: You have defined an unsupported Maven version in the system.properties file.
26+
27+
The default supported version is ${DEFAULT_MAVEN_VERSION}
28+
EOF
2729
return 1
2830
fi
2931
}
@@ -98,8 +100,6 @@ common::install_jdk() {
98100
mkdir -p /tmp/jvm-common
99101
curl --fail --retry 3 --retry-connrefused --connect-timeout 5 --silent --location "${JVM_COMMON_BUILDPACK}" | tar xzm -C /tmp/jvm-common --strip-components=1
100102
#shellcheck source=/dev/null
101-
source /tmp/jvm-common/bin/util
102-
#shellcheck source=/dev/null
103103
source /tmp/jvm-common/bin/java
104104
#shellcheck source=/dev/null
105105
source /tmp/jvm-common/opt/jdbc.sh

lib/maven.sh

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ maven::mvn_settings_opt() {
4545
if [[ -f "${settings_xml}" ]]; then
4646
echo -n "-s ${settings_xml}"
4747
else
48-
error "Could not download settings.xml from the URL defined in MAVEN_SETTINGS_URL!"
48+
output::error <<-EOF
49+
ERROR: Could not download settings.xml from the URL defined in MAVEN_SETTINGS_URL!
50+
EOF
4951
return 1
5052
fi
5153
elif [[ -f "${home}/settings.xml" ]]; then
@@ -98,15 +100,19 @@ maven::run_mvn() {
98100
local mvn_opts
99101
mvn_opts="$(maven::mvn_cmd_opts "${scope}")"
100102

101-
status "Executing Maven"
102-
echo "$ ${maven_exe} ${mvn_opts}" | indent
103+
output::step "Executing Maven"
104+
echo "$ ${maven_exe} ${mvn_opts}" | output::indent
103105

104106
# We rely on word splitting for mvn_settings_opt and mvn_opts:
105107
# shellcheck disable=SC2086
106-
if ! ${maven_exe} -DoutputFile=target/mvn-dependency-list.log -B ${mvn_settings_opt} ${mvn_opts} | indent; then
107-
error "Failed to build app with Maven
108-
We're sorry this build is failing! If you can't find the issue in application code,
109-
please submit a ticket so we can help: https://help.heroku.com/"
108+
if ! ${maven_exe} -DoutputFile=target/mvn-dependency-list.log -B ${mvn_settings_opt} ${mvn_opts} | output::indent; then
109+
output::error <<-EOF
110+
ERROR: Failed to build app with Maven
111+
112+
We're sorry this build is failing! If you can't find the issue in application code,
113+
please submit a ticket so we can help: https://help.heroku.com/
114+
EOF
115+
return 1
110116
fi
111117
}
112118

lib/output.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env bash
2+
3+
ANSI_BLUE='\033[1;34m'
4+
ANSI_RED='\033[1;31m'
5+
ANSI_YELLOW='\033[1;33m'
6+
ANSI_RESET='\033[0m'
7+
8+
# Output a single line step message to stdout.
9+
#
10+
# Usage:
11+
# ```
12+
# output::step "Installing Python ..."
13+
# ```
14+
function output::step() {
15+
echo "-----> ${1}"
16+
}
17+
18+
# Indent passed stdout. Typically used to indent command output within a step.
19+
#
20+
# Usage:
21+
# ```
22+
# pip install ... | output::indent
23+
# ```
24+
function output::indent() {
25+
sed --unbuffered "s/^/ /"
26+
}
27+
28+
# Output a styled multi-line notice message to stderr.
29+
#
30+
# Usage:
31+
# ```
32+
# output::notice <<-EOF
33+
# Note: The note summary.
34+
#
35+
# Detailed description.
36+
# EOF
37+
# ```
38+
function output::notice() {
39+
local line
40+
echo >&2
41+
while IFS= read -r line; do
42+
echo -e "${ANSI_BLUE} ! ${line}${ANSI_RESET}" >&2
43+
done
44+
echo >&2
45+
}
46+
47+
# Output a styled multi-line warning message to stderr.
48+
#
49+
# Usage:
50+
# ```
51+
# output::warning <<-EOF
52+
# Warning: The warning summary.
53+
#
54+
# Detailed description.
55+
# EOF
56+
# ```
57+
function output::warning() {
58+
local line
59+
echo >&2
60+
while IFS= read -r line; do
61+
echo -e "${ANSI_YELLOW} ! ${line}${ANSI_RESET}" >&2
62+
done
63+
echo >&2
64+
}
65+
66+
# Output a styled multi-line error message to stderr.
67+
#
68+
# Usage:
69+
# ```
70+
# output::error <<-EOF
71+
# Error: The error summary.
72+
#
73+
# Detailed description.
74+
# EOF
75+
# ```
76+
function output::error() {
77+
local line
78+
echo >&2
79+
while IFS= read -r line; do
80+
echo -e "${ANSI_RED} ! ${line}${ANSI_RESET}" >&2
81+
done
82+
echo >&2
83+
}

test/spec/misc_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@
7474
remote: \\[ERROR\\] \\[Help 1\\] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
7575
remote:
7676
remote: ! ERROR: Failed to build app with Maven
77-
remote: We're sorry this build is failing! If you can't find the issue in application code,
78-
remote: please submit a ticket so we can help: https://help.heroku.com/
77+
remote: !
78+
remote: ! We're sorry this build is failing! If you can't find the issue in application code,
79+
remote: ! please submit a ticket so we can help: https://help.heroku.com/
7980
remote:
8081
remote: ! Push rejected, failed to compile Java app.
8182
REGEX

test/spec/settings_xml_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
remote:
2626
remote:
2727
remote: ! ERROR: Failed to build app with Maven
28-
remote: We're sorry this build is failing! If you can't find the issue in application code,
29-
remote: please submit a ticket so we can help: https://help.heroku.com/
28+
remote: !
29+
remote: ! We're sorry this build is failing! If you can't find the issue in application code,
30+
remote: ! please submit a ticket so we can help: https://help.heroku.com/
3031
remote:
3132
remote: ! Push rejected, failed to compile Java app.
3233
OUTPUT

test/spec/versions_spec.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
app.deploy do
2323
expect(clean_output(app.output)).not_to include('$ ./mvnw')
24-
expect(clean_output(app.output)).to include("remote: -----> Installing Maven #{DEFAULT_MAVEN_VERSION}... done")
24+
expect(clean_output(app.output)).to include("remote: -----> Installing Maven #{DEFAULT_MAVEN_VERSION}...")
2525
expect(clean_output(app.output)).to(
2626
include("[BUILDPACK INTEGRATION TEST - MAVEN VERSION] #{DEFAULT_MAVEN_VERSION}")
2727
)
@@ -37,9 +37,11 @@
3737
app.deploy do
3838
expect(clean_output(app.output)).to include(<<~OUTPUT)
3939
remote: -----> Installing Maven #{UNKNOWN_MAVEN_VERSION}...
40-
remote: ! ERROR: Error, you have defined an unsupported Maven version in the system.properties file.
41-
remote: The default supported version is #{DEFAULT_MAVEN_VERSION}
42-
remote:
40+
remote:
41+
remote: ! ERROR: You have defined an unsupported Maven version in the system.properties file.
42+
remote: !
43+
remote: ! The default supported version is #{DEFAULT_MAVEN_VERSION}
44+
remote:
4345
remote: ! Push rejected, failed to compile Java app.
4446
OUTPUT
4547
end
@@ -53,7 +55,7 @@
5355

5456
app.deploy do
5557
expect(clean_output(app.output)).not_to include('$ ./mvnw')
56-
expect(clean_output(app.output)).to include("remote: -----> Installing Maven #{DEFAULT_MAVEN_VERSION}... done")
58+
expect(clean_output(app.output)).to include("remote: -----> Installing Maven #{DEFAULT_MAVEN_VERSION}...")
5759
expect(clean_output(app.output)).to(
5860
include("[BUILDPACK INTEGRATION TEST - MAVEN VERSION] #{DEFAULT_MAVEN_VERSION}")
5961
)
@@ -70,8 +72,9 @@
7072
app.deploy do
7173
expect(clean_output(app.output)).to include(<<~OUTPUT)
7274
remote: -----> Installing Maven #{UNKNOWN_MAVEN_VERSION}...
73-
remote: ! ERROR: Error, you have defined an unsupported Maven version in the system.properties file.
74-
remote: The default supported version is #{DEFAULT_MAVEN_VERSION}
75+
remote: ! ERROR: You have defined an unsupported Maven version in the system.properties file.
76+
remote: !
77+
remote: ! The default supported version is #{DEFAULT_MAVEN_VERSION}
7578
remote:
7679
remote: ! Push rejected, failed to compile Java app.
7780
OUTPUT
@@ -87,7 +90,7 @@
8790

8891
app.deploy do
8992
expect(clean_output(app.output)).not_to include('$ ./mvnw')
90-
expect(clean_output(app.output)).to include('remote: -----> Installing Maven 3.9.4... done')
93+
expect(clean_output(app.output)).to include('remote: -----> Installing Maven 3.9.4...')
9194
expect(clean_output(app.output)).to include('[BUILDPACK INTEGRATION TEST - MAVEN VERSION] 3.9.4')
9295
end
9396
end

0 commit comments

Comments
 (0)