diff --git a/hooks/boot/01-kafo-hook-extensions.rb b/hooks/boot/01-kafo-hook-extensions.rb index 4695b95f..0b3d2c32 100644 --- a/hooks/boot/01-kafo-hook-extensions.rb +++ b/hooks/boot/01-kafo-hook-extensions.rb @@ -159,9 +159,11 @@ def available_space(directory = nil) end def parse_java_version(output) - output&.match(/version "\d+\.(?\d+)\.\d+/) do |java_match| + output&.match(/version "(?\d+\.\d+)\.\d+/) do |java_match| return unless (version = java_match[:version]) + version = version.delete_prefix('1.') if version.start_with?('1.') + yield version.to_i end end diff --git a/spec/hook_context_extension_spec.rb b/spec/hook_context_extension_spec.rb index 3352c4a7..26d2392b 100644 --- a/spec/hook_context_extension_spec.rb +++ b/spec/hook_context_extension_spec.rb @@ -25,6 +25,48 @@ expect { |block| context.parse_java_version(output, &block) }.to yield_with_args(8) end end + + context 'java-11-openjdk-headless' do + let(:output) do + <<~OUTPUT + openjdk version "11.0.20.1" 2023-08-24 LTS + OpenJDK Runtime Environment (Red_Hat-11.0.20.1.1-2) (build 11.0.20.1+1-LTS) + OpenJDK 64-Bit Server VM (Red_Hat-11.0.20.1.1-2) (build 11.0.20.1+1-LTS, mixed mode, sharing) + OUTPUT + end + + it do + expect { |block| context.parse_java_version(output, &block) }.to yield_with_args(11) + end + end + + context 'java-17-openjdk-headless' do + let(:output) do + <<~OUTPUT + openjdk version "17.0.11" 2024-04-16 LTS + OpenJDK Runtime Environment (Red_Hat-17.0.11.0.9-5) (build 17.0.11+9-LTS) + OpenJDK 64-Bit Server VM (Red_Hat-17.0.11.0.9-5) (build 17.0.11+9-LTS, mixed mode, sharing) + OUTPUT + end + + it do + expect { |block| context.parse_java_version(output, &block) }.to yield_with_args(17) + end + end + + context 'java-21-openjdk-headless' do + let(:output) do + <<~OUTPUT + openjdk version "21.0.4" 2024-07-16 LTS + OpenJDK Runtime Environment (Red_Hat-21.0.4.0.7-1) (build 21.0.4+7-LTS) + OpenJDK 64-Bit Server VM (Red_Hat-21.0.4.0.7-1) (build 21.0.4+7-LTS, mixed mode, sharing) + OUTPUT + end + + it do + expect { |block| context.parse_java_version(output, &block) }.to yield_with_args(21) + end + end end describe '.ensure_packages' do