File: java_default_home.rb

package info (click to toggle)
puppet-module-puppetlabs-java 11.1.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 524 kB
  • sloc: ruby: 1,718; sh: 10; makefile: 4
file content (32 lines) | stat: -rw-r--r-- 816 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

# Fact: java_default_home
#
# Purpose: get absolute path of java system home
#
# Resolution:
#   Find the real java binary, and return the subsubdir
#
# Caveats:
#   java binary has to be found in $PATH
#
# Notes:
#   None
Facter.add(:java_default_home) do
  confine kernel: ['Linux', 'OpenBSD']
  java_default_home = nil
  setcode do
    java_bin = Facter::Core::Execution.which('java').to_s.strip
    if java_bin.empty?
      nil
    else
      java_path = File.realpath(java_bin)
      java_default_home = if java_path.include?('/jre/')
                            File.dirname(File.dirname(File.dirname(java_path)))
                          else
                            File.dirname(File.dirname(java_path))
                          end
    end
  end
  java_default_home
end