1313# See the License for the specific language governing permissions and
1414# limitations under the License.
1515
16- require 'digest'
1716require 'fileutils'
1817require 'java_buildpack/component/versioned_dependency_component'
1918require 'java_buildpack/jre'
@@ -47,8 +46,7 @@ def detect
4746
4847 # (see JavaBuildpack::Component::BaseComponent#compile)
4948 def compile
50- download ( @version , @uri [ 'uri' ] , @component_name ) do |file |
51- check_sha256 ( file , @uri [ 'sha256sum' ] )
49+ download ( @version , @uri , @component_name ) do |file |
5250 with_timing "Installing #{ @component_name } to #{ @droplet . sandbox . relative_path_from ( @droplet . root ) } " do
5351 install_bin ( @droplet . sandbox , file )
5452 end
@@ -61,9 +59,11 @@ def release
6159 @droplet
6260 . java_opts
6361 . add_system_property ( 'java.io.tmpdir' , '$TMPDIR' )
64- @droplet . java_opts << '-Xtune:virtualized'
62+ . add_option ( '-XX:OnOutOfMemoryError' , killjava )
63+ . add_preformatted_options ( '-Xtune:virtualized' )
64+ . add_preformatted_options ( '-Xshareclasses:none' )
65+
6566 @droplet . java_opts . concat mem_opts
66- @droplet . java_opts << '-Xshareclasses:none'
6767 end
6868
6969 private
@@ -93,23 +93,15 @@ def install_bin(target_directory, file)
9393 shell "#{ file . path } -i silent -f #{ response_file . path } 2>&1"
9494 end
9595
96- # Checks the SHA256 Checksum of the file
97- #
98- # @param [File] file, The downloaded file
99- # @param [String] checksum, The string containing the SHA256 of the file
100- def check_sha256 ( file , checksum )
101- raise 'sha256 checksum does not match' unless Digest ::SHA256 . hexdigest ( File . read ( file . path ) ) == checksum
102- end
103-
10496 # Returns the max heap size ('-Xmx') value
10597 def mem_opts
106- mopts = [ ]
98+ mopts = [ ]
10799 total_memory = memory_limit_finder
108100 if total_memory . nil?
109101 # if no memory option has been set by cloudfoundry, we just assume defaults
110102 else
111103 calculated_heap_ratio = heap_ratio_verification ( heap_ratio )
112- heap_size = heap_size_calculator ( total_memory , calculated_heap_ratio )
104+ heap_size = heap_size_calculator ( total_memory , calculated_heap_ratio )
113105 mopts . push "-Xmx#{ heap_size } "
114106 end
115107 mopts
@@ -120,6 +112,10 @@ def heap_ratio
120112 @configuration [ 'heap_ratio' ] || HEAP_RATIO
121113 end
122114
115+ def killjava
116+ @droplet . sandbox + 'jre/bin/killjava.sh'
117+ end
118+
123119 # Returns the container total memory limit in bytes
124120 def memory_limit_finder
125121 memory_limit = ENV [ 'MEMORY_LIMIT' ]
@@ -138,7 +134,7 @@ def memory_size_bytes(size)
138134 bytes = 0
139135 else
140136 raise "Invalid memory size '#{ size } '" if !size || size . length < 2
141- unit = size [ -1 ]
137+ unit = size [ -1 ]
142138 value = size [ 0 ..-2 ]
143139 raise "Invalid memory size '#{ size } '" unless check_is_integer? value
144140 value = size . to_i
0 commit comments