Skip to content

Commit 5fc2c4a

Browse files
author
Glyn Normington
committed
Make compile and release robust if detect fails
Compile and release now log errors if no application is detected. [#53862463]
1 parent a15eac6 commit 5fc2c4a

3 files changed

Lines changed: 48 additions & 18 deletions

File tree

lib/java_buildpack/buildpack.rb

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,33 +72,49 @@ def detect
7272
#
7373
# @return [void]
7474
def compile
75-
FileUtils.mkdir_p @lib_directory
75+
the_container = container
76+
if the_container
77+
FileUtils.mkdir_p @lib_directory
78+
79+
jre.compile
80+
frameworks.each { |framework| framework.compile }
81+
container.compile
82+
else
83+
diagnose_detect_failure
84+
end
85+
end
7686

77-
jre.compile
78-
frameworks.each { |framework| framework.compile }
79-
container.compile
87+
def diagnose_detect_failure
88+
logger = JavaBuildpack::Diagnostics::LoggerFactory.get_logger
89+
logger.error 'no supported application type was detected'
8090
end
8191

8292
# Generates the payload required to run the application. The payload format is defined by the
8393
# {Heroku Buildpack API}[https://devcenter.heroku.com/articles/buildpack-api#buildpack-api].
8494
#
8595
# @return [String] The payload required to run the application.
8696
def release
87-
jre.release
88-
frameworks.each { |framework| framework.release }
89-
command = container.release
90-
91-
payload = {
92-
'addons' => [],
93-
'config_vars' => {},
94-
'default_process_types' => {
95-
'web' => command
96-
}
97-
}.to_yaml
98-
99-
@logger.debug { "Release Payload #{payload}" }
97+
the_container = container
98+
if the_container
99+
jre.release
100+
frameworks.each { |framework| framework.release }
101+
command = the_container.release
102+
103+
payload = {
104+
'addons' => [],
105+
'config_vars' => {},
106+
'default_process_types' => {
107+
'web' => command
108+
}
109+
}.to_yaml
110+
111+
@logger.debug { "Release Payload #{payload}" }
112+
113+
payload
114+
else
115+
diagnose_detect_failure
116+
end
100117

101-
payload
102118
end
103119

104120
private_class_method :new

spec/bin/compile_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,11 @@
2020

2121
describe 'compile script', :integration do
2222

23+
it 'should fail to compile when no containers detect' do
24+
Dir.mktmpdir do |root|
25+
error = Open3.capture3("bin/compile #{root}")[1]
26+
expect(error).to match(/no supported application type was detected/)
27+
end
28+
end
29+
2330
end

spec/bin/release_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232
end
3333
end
3434

35+
it 'should fail to release when no containers detect' do
36+
Dir.mktmpdir do |root|
37+
error = Open3.capture3("bin/release #{root}")[1]
38+
expect(error).to match(/no supported application type was detected/)
39+
end
40+
end
41+
3542
def with_memory_limit(memory_limit)
3643
previous_value = ENV['MEMORY_LIMIT']
3744
begin

0 commit comments

Comments
 (0)