Fixing java_version fact, because OpenJDK puts a date after version

This commit is contained in:
Tim Eilers
2019-07-17 13:49:37 +02:00
committed by lionce
parent 4dbf9321eb
commit 4f52cee832

View File

@@ -4,7 +4,7 @@
# #
# Resolution: # Resolution:
# Tests for presence of java, returns nil if not present # Tests for presence of java, returns nil if not present
# returns output of "java -version" and splits on \n + '"' # returns output of "java -version" and splits on '"'
# #
# Caveats: # Caveats:
# none # none
@@ -24,8 +24,7 @@ Facter.add(:java_version) do
unless ['darwin'].include? Facter.value(:operatingsystem).downcase unless ['darwin'].include? Facter.value(:operatingsystem).downcase
version = nil version = nil
if Facter::Util::Resolution.which('java') if Facter::Util::Resolution.which('java')
Facter::Util::Resolution.exec('java -Xmx12m -version 2>&1').lines.each { |line| version = $LAST_MATCH_INFO[1] if %r{^.+ version \"(.+)\".*$} =~ line } Facter::Util::Resolution.exec('java -Xmx12m -version 2>&1').lines.each { |line| version = Regexp.last_match(1) if %r{^.+ version \"(.+)\"} =~ line }
end end
version version
end end
@@ -38,7 +37,7 @@ Facter.add(:java_version) do
setcode do setcode do
unless %r{Unable to find any JVMs matching version} =~ Facter::Util::Resolution.exec('/usr/libexec/java_home --failfast 2>&1') unless %r{Unable to find any JVMs matching version} =~ Facter::Util::Resolution.exec('/usr/libexec/java_home --failfast 2>&1')
version = nil version = nil
Facter::Util::Resolution.exec('java -Xmx12m -version 2>&1').lines.each { |line| version = $LAST_MATCH_INFO[1] if %r{^.+ version \"(.+)\"$} =~ line } Facter::Util::Resolution.exec('java -Xmx12m -version 2>&1').lines.each { |line| version = Regexp.last_match(1) if %r{^.+ version \"(.+)\"} =~ line }
version version
end end
end end