do not use unportable readlink utility to find the java_default_home,

use Ruby in a more portable fashion.

adapt tests as well
This commit is contained in:
Sebastian Reitenbach
2017-09-26 23:35:15 +02:00
committed by Will Meek
parent bdfc567c18
commit e50eb64614
4 changed files with 36 additions and 45 deletions

View File

@@ -3,27 +3,22 @@
# Purpose: get absolute path of java system home
#
# Resolution:
# Uses `readlink` to resolve the path of `/usr/bin/java` then returns subsubdir
# Find the real java binary, and return the subsubdir
#
# Caveats:
# Requires readlink
# java binary has to be found in $PATH
#
# Notes:
# None
Facter.add(:java_default_home) do
confine :kernel => [ 'Linux', 'OpenBSD' ]
setcode do
if Facter::Util::Resolution.which('readlink')
java_bin = Facter::Util::Resolution.exec('readlink -e /usr/bin/java').to_s.strip
if java_bin.empty?
java_bin = Facter::Util::Resolution.exec('readlink -e /usr/local/bin/java').to_s.strip
if java_bin.empty?
java_bin = Facter::Util::Resolution.which('java').to_s.strip
if java_bin.empty?
nil
end
end
end
java_bin = Facter::Util::Resolution.which('java').to_s.strip
if java_bin.empty?
nil
else
# We might have found a symlink instead of the real binary
java_bin = File.realpath(java_bin)
if java_bin =~ %r(/jre/)
java_default_home = File.dirname(File.dirname(File.dirname(java_bin)))
else