Skip to content

Commit e7aa342

Browse files
committed
Fix trailing whitespace annoyances in library and test code
1 parent 248a94e commit e7aa342

File tree

6 files changed

+129
-38
lines changed

6 files changed

+129
-38
lines changed

lib/output.sh

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ANSI_BLUE='\033[1;34m'
88
ANSI_RED='\033[1;31m'
99
ANSI_YELLOW='\033[1;33m'
1010
ANSI_RESET='\033[0m'
11+
MESSAGE_INDENTATION=' '
1112

1213
# Output a single line step message to stdout.
1314
#
@@ -40,10 +41,15 @@ function output::indent() {
4041
# EOF
4142
# ```
4243
function output::notice() {
43-
local line
44+
local line indentation
4445
echo >&2
4546
while IFS= read -r line; do
46-
echo -e "${ANSI_BLUE} ! ${line}${ANSI_RESET}" >&2
47+
indentation=""
48+
if [[ -n "${line}" ]]; then
49+
indentation="${MESSAGE_INDENTATION}"
50+
fi
51+
52+
echo -e "${ANSI_BLUE} !${indentation}${line}${ANSI_RESET}" >&2
4753
done
4854
echo >&2
4955
}
@@ -59,10 +65,15 @@ function output::notice() {
5965
# EOF
6066
# ```
6167
function output::warning() {
62-
local line
68+
local line indentation
6369
echo >&2
6470
while IFS= read -r line; do
65-
echo -e "${ANSI_YELLOW} ! ${line}${ANSI_RESET}" >&2
71+
indentation=""
72+
if [[ -n "${line}" ]]; then
73+
indentation="${MESSAGE_INDENTATION}"
74+
fi
75+
76+
echo -e "${ANSI_YELLOW} !${indentation}${line}${ANSI_RESET}" >&2
6677
done
6778
echo >&2
6879
}
@@ -78,10 +89,15 @@ function output::warning() {
7889
# EOF
7990
# ```
8091
function output::error() {
81-
local line
92+
local line indentation
8293
echo >&2
8394
while IFS= read -r line; do
84-
echo -e "${ANSI_RED} ! ${line}${ANSI_RESET}" >&2
95+
indentation=""
96+
if [[ -n "${line}" ]]; then
97+
indentation="${MESSAGE_INDENTATION}"
98+
fi
99+
100+
echo -e "${ANSI_RED} !${indentation}${line}${ANSI_RESET}" >&2
85101
done
86102
echo >&2
87103
}

test/spec/cache_spec.rb

Lines changed: 80 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require_relative 'spec_helper'
44

55
describe 'Scala buildpack' do
6-
it 'caches compiled artifacts between builds' do
6+
it 'caches compiled artifacts between builds (Play 3.x)' do
77
new_default_hatchet_runner('sbt-0.11.7-play-3.x-scala-2.13.x').tap do |app|
88
app.deploy do
99
# First build should compile everything from scratch
@@ -35,12 +35,12 @@
3535
remote: \\[info\\] / / / /_/ // // /_/ // /_/ /
3636
remote: \\[info\\] /_/ / .___//_/ \\\\__,_/ \\\\__, /
3737
remote: \\[info\\] /_/ /____/
38-
remote: \\[info\\]
38+
remote: \\[info\\]
3939
remote: \\[info\\] Version 3.0.9 running Java 21.0.[0-9]+
40-
remote: \\[info\\]
40+
remote: \\[info\\]
4141
remote: \\[info\\] Play is run entirely by the community. Please consider contributing and/or donating:
4242
remote: \\[info\\] https://www.playframework.com/sponsors
43-
remote: \\[info\\]
43+
remote: \\[info\\]
4444
remote: \\[info\\] Executing in batch mode. For better performance use sbt's shell
4545
remote: \\[info\\] compiling 7 Scala sources and 1 Java source to /tmp/scala_buildpack_build_dir/target/scala-2.13/classes ...
4646
remote: \\[info\\] done compiling
@@ -55,7 +55,7 @@
5555
remote: -----> Discovering process types
5656
remote: Procfile declares types -> \\(none\\)
5757
remote: Default types for buildpack -> web
58-
remote:
58+
remote:
5959
remote: -----> Compressing...
6060
REGEX
6161

@@ -78,12 +78,12 @@
7878
remote: \\[info\\] / / / /_/ // // /_/ // /_/ /
7979
remote: \\[info\\] /_/ / .___//_/ \\\\__,_/ \\\\__, /
8080
remote: \\[info\\] /_/ /____/
81-
remote: \\[info\\]
81+
remote: \\[info\\]
8282
remote: \\[info\\] Version 3.0.9 running Java 21.0.[0-9]+
83-
remote: \\[info\\]
83+
remote: \\[info\\]
8484
remote: \\[info\\] Play is run entirely by the community. Please consider contributing and/or donating:
8585
remote: \\[info\\] https://www.playframework.com/sponsors
86-
remote: \\[info\\]
86+
remote: \\[info\\]
8787
remote: \\[info\\] Executing in batch mode. For better performance use sbt's shell
8888
remote: \\[success\\] Total time: .* s, completed .*
8989
remote: \\[info\\] Wrote /tmp/scala_buildpack_build_dir/target/scala-2.13/sbt-0-11-7-play-3-x-scala-2-13-x_2.13-1.0-SNAPSHOT.pom
@@ -96,10 +96,81 @@
9696
remote: -----> Discovering process types
9797
remote: Procfile declares types -> \\(none\\)
9898
remote: Default types for buildpack -> web
99-
remote:
99+
remote:
100100
remote: -----> Compressing...
101101
REGEX
102102
end
103103
end
104104
end
105+
106+
it 'caches compiled artifacts between builds (Play 2.4.x)' do
107+
new_default_hatchet_runner('play-2.4.x-scala').tap do |app|
108+
app.deploy do
109+
# First build should compile everything from scratch
110+
expect(clean_output(app.output)).to match(Regexp.new(<<~REGEX, Regexp::MULTILINE))
111+
remote: -----> Scala app detected
112+
remote: -----> Installing Azul Zulu OpenJDK 1.8.0_[0-9]+
113+
remote:
114+
remote: ! Warning: Unsupported sbt version detected.
115+
remote: !
116+
remote: ! This buildpack does not officially support sbt 0.13.9. You are using
117+
remote: ! an end-of-life version that no longer receives security updates or bug fixes.
118+
remote: ! Support for sbt 0.x was ended by the upstream sbt project on November 30, 2018.
119+
remote: !
120+
remote: ! Please upgrade to sbt 1.x for active support.
121+
remote: !
122+
remote: ! The buildpack will attempt to build your application, but compatibility
123+
remote: ! is not guaranteed and may break at any time.
124+
remote: !
125+
remote: ! For more information:
126+
remote: ! - https://web.archive.org/web/20210918065807/https://www.lightbend.com/blog/scala-sbt-127-patchnotes
127+
remote: !
128+
remote: ! Upgrade guide:
129+
remote: ! - https://www.scala-sbt.org/1.x/docs/Migrating-from-sbt-013x.html
130+
remote:
131+
remote: -----> Running: sbt compile stage
132+
remote: Downloading sbt launcher for 0.13.9:
133+
remote: From https://repo1.maven.org/maven2/org/scala-sbt/sbt-launch/0.13.9/sbt-launch-0.13.9.jar
134+
remote: To /tmp/[^/]+/.sbt_home/launchers/0.13.9/sbt-launch.jar
135+
remote: Downloading sbt launcher 0.13.9 md5 hash:
136+
remote: From https://repo1.maven.org/maven2/org/scala-sbt/sbt-launch/0.13.9/sbt-launch-0.13.9.jar.md5
137+
remote: To /tmp/[^/]+/.sbt_home/launchers/0.13.9/sbt-launch.jar.md5
138+
remote: /tmp/[^/]+/.sbt_home/launchers/0.13.9/sbt-launch.jar: OK
139+
remote: \\[info\\] Loading global plugins from /tmp/[^/]+/.sbt_home/plugins
140+
remote: \\[info\\] Compiling 1 Scala source to /tmp/[^/]+/.sbt_home/plugins/target/scala-2.10/sbt-0.13/classes...
141+
remote: \\[info\\] Updating \\{file:/tmp/[^/]+/.sbt_home/plugins/\\}plugins...
142+
remote: \\[info\\] Resolving .* \\.\\.\\.
143+
remote: \\[info\\] Done updating.
144+
remote: \\[info\\] Set current project to play-2.4.x-scala \\(in build file:/tmp/[^/]+/\\)
145+
remote: \\[info\\] Updating \\{file:/tmp/[^/]+/\\}root...
146+
remote: \\[info\\] Resolving .* \\.\\.\\.
147+
remote: \\[info\\] Done updating.
148+
remote: \\[info\\] Compiling [0-9]+ Scala sources? and [0-9]+ Java sources? to /tmp/[^/]+/target/scala-2.11/classes...
149+
remote: \\[success\\] Total time: .*
150+
remote: \\[info\\] Packaging /tmp/[^/]+/target/scala-2.11/play-[^/]+_2.11-1.0-SNAPSHOT.jar ...
151+
remote: \\[info\\] Done packaging.
152+
remote: \\[success\\] Total time: .*
153+
REGEX
154+
155+
app.commit!
156+
app.push!
157+
158+
# Second build should use cached artifacts and doesn't recompile previously compiled application files
159+
expect(clean_output(app.output)).to match(Regexp.new(<<~REGEX, Regexp::MULTILINE))
160+
remote: -----> Scala app detected
161+
remote: -----> Installing Azul Zulu OpenJDK 1.8.0_[0-9]+
162+
remote: -----> Running: sbt compile stage
163+
remote: \\[info\\] Loading global plugins from /tmp/[^/]+/.sbt_home/plugins
164+
remote: \\[info\\] Set current project to play-2.4.x-scala \\(in build file:/tmp/[^/]+/\\)
165+
remote: \\[info\\] Updating \\{file:/tmp/[^/]+/\\}root...
166+
remote: \\[info\\] Resolving .* \\.\\.\\.
167+
remote: \\[info\\] Done updating.
168+
remote: \\[success\\] Total time: .*
169+
remote: \\[info\\] Packaging /tmp/[^/]+/target/scala-2.11/play-[^/]+_2.11-1.0-SNAPSHOT.jar ...
170+
remote: \\[info\\] Done packaging.
171+
remote: \\[success\\] Total time: .*
172+
REGEX
173+
end
174+
end
175+
end
105176
end

test/spec/config_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
expect(clean_output(app.output)).to include('Running: sbt clean compile stage')
2929
expect(clean_output(app.output)).to include(<<~WARNING)
3030
remote: ! Warning: Configuring the Scala buildpack via system.properties is deprecated.
31-
remote: !
31+
remote: !
3232
remote: ! You are using the sbt.clean property in system.properties, which is
3333
remote: ! deprecated and will be removed in a future buildpack release.
34-
remote: !
34+
remote: !
3535
remote: ! Please migrate to using the SBT_CLEAN environment variable instead.
36-
remote: !
36+
remote: !
3737
remote: ! For more information on setting environment variables, see:
3838
remote: ! https://devcenter.heroku.com/articles/config-vars
3939
WARNING

test/spec/detection_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@
99
expect(clean_output(app.output)).to include(<<~OUTPUT)
1010
remote: ! Error: Your app is configured to use the Scala buildpack,
1111
remote: ! but we couldn't find any supported sbt project files.
12-
remote: !
12+
remote: !
1313
remote: ! The Scala buildpack requires a 'build.sbt' or other .sbt file
1414
remote: ! in the root directory of your source code.
15-
remote: !
15+
remote: !
1616
remote: ! IMPORTANT: If your project uses a different build tool:
1717
remote: ! - For Maven projects, use the heroku/java buildpack instead
1818
remote: ! - For Gradle projects, use the heroku/gradle buildpack instead
19-
remote: !
19+
remote: !
2020
remote: ! Currently the root directory of your app contains:
21-
remote: !
21+
remote: !
2222
remote: ! README.md
23-
remote: !
23+
remote: !
2424
remote: ! If your app already has sbt files, check that they:
25-
remote: !
25+
remote: !
2626
remote: ! 1. Are in the correct directory (see requirements above).
2727
remote: ! 2. Have the correct spelling (the filenames are case-sensitive).
2828
remote: ! 3. Aren't listed in '.gitignore' or '.slugignore'.
2929
remote: ! 4. Have been added to the Git repository using 'git add --all'
3030
remote: ! and then committed using 'git commit'.
31-
remote: !
31+
remote: !
3232
remote: ! For help with using sbt on Heroku, see:
3333
remote: ! https://devcenter.heroku.com/articles/scala-support
3434
OUTPUT

test/spec/sbt_version_spec.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88
app.deploy do
99
expect(clean_output(app.output)).to include(<<~OUTPUT)
1010
remote: ! Warning: Unsupported sbt version detected.
11-
remote: !
11+
remote: !
1212
remote: ! This buildpack does not officially support sbt 0.13.18. You are using
1313
remote: ! an end-of-life version that no longer receives security updates or bug fixes.
1414
remote: ! Support for sbt 0.x was ended by the upstream sbt project on November 30, 2018.
15-
remote: !
15+
remote: !
1616
remote: ! Please upgrade to sbt 1.x for active support.
17-
remote: !
17+
remote: !
1818
remote: ! The buildpack will attempt to build your application, but compatibility
1919
remote: ! is not guaranteed and may break at any time.
20-
remote: !
20+
remote: !
2121
remote: ! For more information:
2222
remote: ! - https://web.archive.org/web/20210918065807/https://www.lightbend.com/blog/scala-sbt-127-patchnotes
23-
remote: !
23+
remote: !
2424
remote: ! Upgrade guide:
2525
remote: ! - https://www.scala-sbt.org/1.x/docs/Migrating-from-sbt-013x.html
2626
OUTPUT
@@ -46,14 +46,14 @@
4646
expect(app).not_to be_deployed
4747
expect(clean_output(app.output)).to include(<<~OUTPUT)
4848
remote: ! Error: Unsupported sbt version detected.
49-
remote: !
49+
remote: !
5050
remote: ! This buildpack does not currently support sbt 2.x. You are using sbt 2.0.0-RC6.
51-
remote: !
51+
remote: !
5252
remote: ! Support for sbt 2.x will be added in a future buildpack release. In the
5353
remote: ! meantime, please use the latest stable sbt 1.x version for your deployments.
54-
remote: !
54+
remote: !
5555
remote: ! To continue, update project/build.properties to use sbt 1.x.
56-
remote: !
56+
remote: !
5757
remote: ! For more information:
5858
remote: ! - Latest sbt 1.x releases: https://github.com/sbt/sbt/releases
5959
remote: ! - sbt 2.x changes: https://www.scala-sbt.org/2.x/docs/en/changes/sbt-2.0-change-summary.html
@@ -73,15 +73,15 @@
7373
expect(app).not_to be_deployed
7474
expect(clean_output(app.output)).to include(<<~OUTPUT)
7575
remote: ! Error: sbt version cannot be determined.
76-
remote: !
76+
remote: !
7777
remote: ! As part of your build definition you must specify the version of sbt that
7878
remote: ! your build uses. This ensures consistent results across different environments.
79-
remote: !
79+
remote: !
8080
remote: ! To fix this issue, create a file named project/build.properties that specifies
8181
remote: ! the sbt version as follows:
82-
remote: !
82+
remote: !
8383
remote: ! sbt.version=1.11.7
84-
remote: !
84+
remote: !
8585
remote: ! For more information, see:
8686
remote: ! https://www.scala-sbt.org/1.x/docs/Basic-Def.html#Specifying+the+sbt+version
8787
OUTPUT

test/spec/spec_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,8 @@ def clean_output(output)
5555
.gsub(/ {8}(?=\R)/, '')
5656
# Remove ANSI colour codes used in buildpack output (e.g. error messages).
5757
.gsub(/\e\[[0-9;]+m/, '')
58+
# Remove trailing space from empty "remote: " lines added by Heroku
59+
.gsub(/^remote: $/, 'remote:')
60+
# Remove trailing space from empty sbt log lines (e.g. "remote: [info] ")
61+
.gsub(/^(remote:\s+)\[(info|warn|error|success|debug)\] $/, '\1[\2]')
5862
end

0 commit comments

Comments
 (0)