Skip to content

Commit b6462f7

Browse files
committed
Merge branch '812-config-yml' into main
Signed-off-by: Ben Hale <[email protected]>
2 parents 6a797d7 + 3789c7a commit b6462f7

16 files changed

+53
-102
lines changed

.idea/codeStyles/Project.xml

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/All_Tests__2_3_.xml

-38
This file was deleted.

.idea/runConfigurations/All_Tests__2_5_.xml

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/All_Tests__2_6_.xml

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/All_Tests__2_4_.xml renamed to .idea/runConfigurations/All_Tests__2_7_.xml

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/Without_Integration_Tests__2_3_.xml

-38
This file was deleted.

.idea/runConfigurations/Without_Integration_Tests__2_5_.xml

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/Without_Integration_Tests__2_6_.xml

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/Without_Integration_Tests__2_4_.xml renamed to .idea/runConfigurations/Without_Integration_Tests__2_7_.xml

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/compile

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ require 'java_buildpack/buildpack'
2424

2525
app_dir = ARGV[0]
2626

27-
JavaBuildpack::Buildpack.with_buildpack(app_dir, 'Compile failed with exception %s', &:compile)
27+
JavaBuildpack::Buildpack.with_buildpack(app_dir, nil, nil, 'Compile failed with exception %s', &:compile)

bin/detect

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ require 'java_buildpack/buildpack'
2424

2525
app_dir = ARGV[0]
2626

27-
components = JavaBuildpack::Buildpack.with_buildpack(app_dir, 'Detect failed with exception %s', &:detect).compact
27+
components = JavaBuildpack::Buildpack.with_buildpack(app_dir, nil, nil, 'Detect failed with exception %s',
28+
&:detect).compact
2829

2930
if components.empty?
3031
abort

bin/finalize

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
2222

2323
require 'java_buildpack/buildpack'
2424

25-
app_dir = ARGV[0]
25+
app_dir = ARGV[0]
26+
deps_dir = ARGV[2]
27+
index = ARGV[3]
2628

27-
JavaBuildpack::Buildpack.with_buildpack(app_dir, 'Finalize failed with exception %s', &:compile)
29+
JavaBuildpack::Buildpack.with_buildpack(app_dir, deps_dir, index, 'Finalize failed with exception %s', &:compile)

bin/release

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ require 'java_buildpack/buildpack'
2424

2525
app_dir = ARGV[0]
2626

27-
output = JavaBuildpack::Buildpack.with_buildpack(app_dir, 'Release failed with exception %s', &:release)
27+
output = JavaBuildpack::Buildpack.with_buildpack(app_dir, nil, nil, 'Release failed with exception %s', &:release)
2828

2929
puts output

lib/java_buildpack/buildpack.rb

+13-3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ def compile
7373
container.compile
7474

7575
log_cache_contents
76+
77+
return if @deps_dir.nil? || @index.nil?
78+
79+
FileUtils.mkdir_p File.join(@deps_dir, @index)
80+
File.write(
81+
File.join(@deps_dir, @index, 'config.yml'),
82+
{ 'name' => 'java', 'config' => {}, 'version' => @buildpack_version.to_s(false) }.to_yaml
83+
)
7684
end
7785

7886
# Generates the payload required to run the application. The payload format is defined by the
@@ -114,9 +122,11 @@ def release
114122

115123
private_constant :BUILDPACK_MESSAGE, :LOAD_ROOT
116124

117-
def initialize(app_dir, application)
125+
def initialize(app_dir, deps_dir, index, application)
118126
@logger = Logging::LoggerFactory.instance.get_logger Buildpack
119127
@buildpack_version = BuildpackVersion.new
128+
@deps_dir = deps_dir
129+
@index = index
120130

121131
log_arguments
122132
log_environment_variables
@@ -260,12 +270,12 @@ class << self
260270
# @param [String] message an error message with an insert for the reason for failure
261271
# @yield [Buildpack] the buildpack to work with
262272
# @return [Object] the return value from the given block
263-
def with_buildpack(app_dir, message)
273+
def with_buildpack(app_dir, deps_dir, index, message)
264274
app_dir = Pathname.new(File.expand_path(app_dir))
265275
Logging::LoggerFactory.instance.setup app_dir
266276
application = Component::Application.new(app_dir)
267277

268-
yield new(app_dir, application) if block_given?
278+
yield new(app_dir, deps_dir, index, application) if block_given?
269279
rescue StandardError => e
270280
handle_error(e, message)
271281
end

lib/java_buildpack/buildpack_version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def to_hash
8585
# @return [String] a +String+ representation of the version
8686
def to_s(human_readable = true)
8787
s = []
88-
s << @version.blue if @version
88+
s << (human_readable ? @version.blue : @version) if @version
8989
s << (human_readable ? '(offline)'.blue : 'offline') if @offline
9090

9191
if remote_string

spec/java_buildpack/buildpack_spec.rb

+17-8
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@
3939

4040
let(:stub_jre2) { instance_double('StubJre2', detect: nil, compile: nil, release: nil, component_name: 'StubJre2') }
4141

42+
let(:deps_dir) { Pathname.new Dir.mktmpdir }
43+
4244
let(:buildpack) do
4345
buildpack = nil
44-
described_class.with_buildpack(app_dir, 'Error %s') { |b| buildpack = b }
46+
described_class.with_buildpack(app_dir, deps_dir, '0', 'Error %s') { |b| buildpack = b }
4547
buildpack
4648
end
4749

@@ -64,6 +66,14 @@
6466
allow(Test::StubJre2).to receive(:new).and_return(stub_jre2)
6567
end
6668

69+
after do |example|
70+
if example.metadata[:no_cleanup]
71+
puts "Deps Directory: #{deps_dir}"
72+
else
73+
FileUtils.rm_rf deps_dir
74+
end
75+
end
76+
6777
it 'raises an error if more than one container can run an application' do
6878
allow(stub_container1).to receive(:detect).and_return('stub-container-1')
6979
allow(stub_container2).to receive(:detect).and_return('stub-container-2')
@@ -88,12 +98,11 @@
8898

8999
before do
90100
allow(JavaBuildpack::Util::ConfigurationUtils)
91-
.to receive(:load).with('components')
92-
.and_return(
93-
'containers' => [],
94-
'frameworks' => ['JavaBuildpack::Framework::JavaOpts'],
95-
'jres' => []
96-
)
101+
.to receive(:load).with('components').and_return(
102+
'containers' => [],
103+
'frameworks' => ['JavaBuildpack::Framework::JavaOpts'],
104+
'jres' => []
105+
)
97106
end
98107

99108
it 'requires files needed for components' do
@@ -152,7 +161,7 @@
152161
end
153162

154163
def with_buildpack(&_)
155-
described_class.with_buildpack(app_dir, 'Error %s') { |buildpack| yield buildpack }
164+
described_class.with_buildpack(app_dir, nil, nil, 'Error %s') { |buildpack| yield buildpack }
156165
end
157166

158167
end

0 commit comments

Comments
 (0)