File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515# limitations under the License.
1616
1717require 'java_buildpack/component/base_component'
18+ require 'java_buildpack/util/cache/internet_availability'
1819require 'java_buildpack/framework'
20+ require 'java_buildpack/util/dash_case'
1921require 'tmpdir'
2022require 'fileutils'
2123require 'uri'
@@ -41,7 +43,9 @@ def detect
4143
4244 # (see JavaBuildpack::Component::BaseComponent#compile)
4345 def compile
44- download ( @version , @uri . chomp ( '/' ) + AGENT_DOWNLOAD_URI_SUFFIX ) { |file | expand file } # TODO: AGENT_DOWNLOAD_URI_SUFFIX To be removed once the full path is included in VCAP_SERVICES see issue 58873498
46+ JavaBuildpack ::Util ::Cache ::InternetAvailability . instance . available ( true , 'The Spring Insight download location is always accessible' ) do
47+ download ( @version , @uri . chomp ( '/' ) + AGENT_DOWNLOAD_URI_SUFFIX ) { |file | expand file } # TODO: AGENT_DOWNLOAD_URI_SUFFIX To be removed once the full path is included in VCAP_SERVICES see issue 58873498
48+ end
4549 end
4650
4751 # (see JavaBuildpack::Component::BaseComponent#release)
Original file line number Diff line number Diff line change @@ -47,10 +47,20 @@ def available?
4747 #
4848 # @param [Boolean] available whether the internet is available
4949 # @param [String, nil] message an optional message to be printed when the availability is set
50+ # @yields an environment with internet availability temporarily overridden if block given
5051 def available ( available , message = nil )
5152 @monitor . synchronize do
52- @available = available
53- @logger . warn { "Internet availability set to #{ available } : #{ message } " } if message
53+ if block_given?
54+ preserve_availability do
55+ @available = available
56+ @logger . warn { "Internet availability temporarily set to #{ available } : #{ message } " } if message
57+
58+ yield
59+ end
60+ else
61+ @available = available
62+ @logger . warn { "Internet availability set to #{ available } : #{ message } " } if message
63+ end
5464 end
5565 end
5666
@@ -60,6 +70,15 @@ def remote_downloads?
6070 JavaBuildpack ::Util ::ConfigurationUtils . load ( 'cache' ) [ 'remote_downloads' ] != 'disabled'
6171 end
6272
73+ def preserve_availability
74+ previous = @available
75+ begin
76+ yield
77+ ensure
78+ @available = previous
79+ end
80+ end
81+
6382 end
6483
6584 end
Original file line number Diff line number Diff line change 1717require 'spec_helper'
1818require 'component_helper'
1919require 'fileutils'
20+ require 'internet_availability_helper'
2021require 'java_buildpack/framework/spring_insight'
2122
2223describe JavaBuildpack ::Framework ::SpringInsight do
2324 include_context 'component_helper'
25+ include_context 'internet_availability_helper'
2426
2527 it 'should not detect without spring-insight-n/a service' do
2628 expect ( component . detect ) . to be_nil
5153 expect ( sandbox + 'insight/conf/insight.properties' ) . to exist
5254 end
5355
56+ it 'should guarantee that internet access is available when downloading' do
57+ expect_any_instance_of ( JavaBuildpack ::Util ::Cache ::InternetAvailability )
58+ . to receive ( :available ) . with ( true , 'The Spring Insight download location is always accessible' )
59+
60+ component . compile
61+ end
62+
5463 it 'should update JAVA_OPTS' ,
5564 app_fixture : 'framework_spring_insight' do
5665
Original file line number Diff line number Diff line change 5555 expect ( log_contents ) . to match ( /Internet availability set to false: test message/ )
5656 end
5757
58+ it 'should temporarily set internet unavailable' do
59+ expect ( described_class . instance . available? ) . to be
60+
61+ described_class . instance . available ( false ) { expect ( described_class . instance . available? ) . not_to be }
62+
63+ expect ( described_class . instance . available? ) . to be
64+ end
65+
66+ it 'should temporarily set internet available' ,
67+ :disable_internet do
68+
69+ expect ( described_class . instance . available? ) . not_to be
70+
71+ described_class . instance . available ( true ) { expect ( described_class . instance . available? ) . to be }
72+
73+ expect ( described_class . instance . available? ) . not_to be
74+ end
75+
5876end
You can’t perform that action at this time.
0 commit comments