Skip to content

Commit 26031c0

Browse files
committed
Resolve JRE version late
Previously when detect() was called on the buildpack, it would resolve a version of the JRE, regardless of whether the application was a Java application or not. This meant that any network connectivity problems that might be highlighted by the Java buildpack would show in non-Java projects. An ideal solution to this would be to change the implementation of the VersionedDependcyComponent such that version and uri resolution happened as part of detect, but this would break compatibility for many 3rd-party components. Instead, that resolution is moved to detect, *but only for OpenJDK- like JREs*. This leads to the replication of some of the initialization code, but this is considered a less-bad solution than breaking compatibility. The end result is that the version and uri of VersionedDependencyComponents will happen at initialization time, and be avoided by inspections of the filesystem. The JRE will not resolve as part of initialization, but rather at detect time. [#67329858]
1 parent 7cc0d93 commit 26031c0

4 files changed

Lines changed: 22 additions & 9 deletions

File tree

java-buildpack.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@
288288
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.0.0.beta2, rbenv: 1.9.3-p545) [gem]" level="application" />
289289
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.0.0.beta2, rbenv: 1.9.3-p545) [gem]" level="application" />
290290
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.0.0.beta2, rbenv: 1.9.3-p545) [gem]" level="application" />
291-
<orderEntry type="library" scope="PROVIDED" name="rubocop (v0.19.0, rbenv: 1.9.3-p545) [gem]" level="application" />
291+
<orderEntry type="library" scope="PROVIDED" name="rubocop (v0.19.1, rbenv: 1.9.3-p545) [gem]" level="application" />
292292
<orderEntry type="library" scope="PROVIDED" name="ruby-debug-base19x (v0.11.30.pre15, rbenv: 1.9.3-p545) [gem]" level="application" />
293293
<orderEntry type="library" scope="PROVIDED" name="ruby-debug-ide (v0.4.22, rbenv: 1.9.3-p545) [gem]" level="application" />
294294
<orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.4.2, rbenv: 1.9.3-p545) [gem]" level="application" />

lib/java_buildpack/jre/open_jdk_like.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,20 @@ class OpenJDKLike < JavaBuildpack::Component::VersionedDependencyComponent
2929
#
3030
# @param [Hash] context a collection of utilities used the component
3131
def initialize(context)
32-
super(context)
32+
@application = context[:application]
33+
@component_name = self.class.to_s.space_case
34+
@configuration = context[:configuration]
35+
@droplet = context[:droplet]
36+
3337
@droplet.java_home.root = @droplet.sandbox
3438
end
3539

40+
# (see JavaBuildpack::Component::BaseComponent#detect)
41+
def detect
42+
@version, @uri = JavaBuildpack::Repository::ConfiguredItem.find_item(@component_name, @configuration)
43+
super
44+
end
45+
3646
# (see JavaBuildpack::Component::BaseComponent#compile)
3747
def compile
3848
download_tar
@@ -47,13 +57,6 @@ def release
4757
.concat memory
4858
end
4959

50-
protected
51-
52-
# (see JavaBuildpack::Component::VersionedDependencyComponent#supports?)
53-
def supports?
54-
true
55-
end
56-
5760
private
5861

5962
KEY_MEMORY_HEURISTICS = 'memory_heuristics'.freeze

spec/java_buildpack/jre/open_jdk_jre_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
it 'should extract Java from a GZipped TAR',
3939
cache_fixture: 'stub-java.tar.gz' do
4040

41+
component.detect
4142
component.compile
4243

4344
expect(sandbox + 'bin/java').to exist
@@ -50,13 +51,15 @@
5051
end
5152

5253
it 'should add memory options to java_opts' do
54+
component.detect
5355
component.release
5456

5557
expect(java_opts).to include('opt-1')
5658
expect(java_opts).to include('opt-2')
5759
end
5860

5961
it 'adds OnOutOfMemoryError to java_opts' do
62+
component.detect
6063
component.release
6164

6265
expect(java_opts).to include('-XX:OnOutOfMemoryError=$PWD/.java-buildpack/open_jdk_jre/bin/killjava.sh')
@@ -65,12 +68,14 @@
6568
it 'places the killjava script (with appropriately substituted content) in the diagnostics directory',
6669
cache_fixture: 'stub-java.tar.gz' do
6770

71+
component.detect
6872
component.compile
6973

7074
expect(sandbox + 'bin/killjava.sh').to exist
7175
end
7276

7377
it 'adds java.io.tmpdir to java_opts' do
78+
component.detect
7479
component.release
7580

7681
expect(java_opts).to include('-Djava.io.tmpdir=$TMPDIR')

spec/java_buildpack/jre/oracle_jre_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
it 'should extract Java from a GZipped TAR',
3939
cache_fixture: 'stub-java.tar.gz' do
4040

41+
component.detect
4142
component.compile
4243

4344
expect(sandbox + 'bin/java').to exist
@@ -50,13 +51,15 @@
5051
end
5152

5253
it 'should add memory options to java_opts' do
54+
component.detect
5355
component.release
5456

5557
expect(java_opts).to include('opt-1')
5658
expect(java_opts).to include('opt-2')
5759
end
5860

5961
it 'adds OnOutOfMemoryError to java_opts' do
62+
component.detect
6063
component.release
6164

6265
expect(java_opts).to include('-XX:OnOutOfMemoryError=$PWD/.java-buildpack/oracle_jre/bin/killjava.sh')
@@ -65,12 +68,14 @@
6568
it 'places the killjava script (with appropriately substituted content) in the diagnostics directory',
6669
cache_fixture: 'stub-java.tar.gz' do
6770

71+
component.detect
6872
component.compile
6973

7074
expect(sandbox + 'bin/killjava.sh').to exist
7175
end
7276

7377
it 'adds java.io.tmpdir to java_opts' do
78+
component.detect
7479
component.release
7580

7681
expect(java_opts).to include('-Djava.io.tmpdir=$TMPDIR')

0 commit comments

Comments
 (0)