Skip to content

Commit

Permalink
Fixes #38012 - Handle Java versions newer than 8
Browse files Browse the repository at this point in the history
Java < 11 uses version 1.X where X is the major while Java 11 drops the
old 1. prefix.

(cherry picked from commit 4c89c65)
  • Loading branch information
ekohl committed Nov 19, 2024
1 parent 78e4b95 commit e95dd4d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
4 changes: 3 additions & 1 deletion hooks/boot/01-kafo-hook-extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,11 @@ def available_space(directory = nil)
end

def parse_java_version(output)
output&.match(/version "\d+\.(?<version>\d+)\.\d+/) do |java_match|
output&.match(/version "(?<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
Expand Down
42 changes: 42 additions & 0 deletions spec/hook_context_extension_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e95dd4d

Please sign in to comment.