From bdfc567c1872f621acebf94057016c8fb49b8e59 Mon Sep 17 00:00:00 2001 From: Sebastian Reitenbach Date: Mon, 25 Sep 2017 12:05:00 +0200 Subject: [PATCH] OpenBSD doesn't have /etc/environment, therefore there is no need to fiddle with it. The default case statement, "do nothing" is all fine here. Facter::Util::Resolution.with_env is long time gone since Facter > 2.x. That was even longer before introduced by me. Remove that OpenBSD special case in the java_version fact, and assume that $PATH is properly set in order to find the 'java' binary. Additionally confine the java_default_home and java_libjvm_path to OpenBSD kernel as well. Add some flesh to the java_default_home fact to allow it to find the java binary. --- lib/facter/java_default_home.rb | 15 +++++++++++---- lib/facter/java_libjvm_path.rb | 2 +- lib/facter/java_version.rb | 16 +--------------- manifests/config.pp | 2 +- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/lib/facter/java_default_home.rb b/lib/facter/java_default_home.rb index 330f037..04ae923 100644 --- a/lib/facter/java_default_home.rb +++ b/lib/facter/java_default_home.rb @@ -11,13 +11,20 @@ # Notes: # None Facter.add(:java_default_home) do - confine :kernel => 'Linux' + confine :kernel => [ 'Linux', 'OpenBSD' ] setcode do if Facter::Util::Resolution.which('readlink') - java_bin = Facter::Util::Resolution.exec('readlink -e /usr/bin/java').strip + java_bin = Facter::Util::Resolution.exec('readlink -e /usr/bin/java').to_s.strip if java_bin.empty? - nil - elsif java_bin =~ %r(/jre/) + 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 + if java_bin =~ %r(/jre/) java_default_home = File.dirname(File.dirname(File.dirname(java_bin))) else java_default_home = File.dirname(File.dirname(java_bin)) diff --git a/lib/facter/java_libjvm_path.rb b/lib/facter/java_libjvm_path.rb index 14fd78c..792d494 100644 --- a/lib/facter/java_libjvm_path.rb +++ b/lib/facter/java_libjvm_path.rb @@ -11,7 +11,7 @@ # Notes: # None Facter.add(:java_libjvm_path) do - confine :kernel => "Linux" + confine :kernel => [ "Linux", "OpenBSD" ] setcode do java_default_home = Facter.value(:java_default_home) java_libjvm_file = Dir.glob("#{java_default_home}/jre/lib/**/libjvm.so") diff --git a/lib/facter/java_version.rb b/lib/facter/java_version.rb index e7040e5..4392bfe 100644 --- a/lib/facter/java_version.rb +++ b/lib/facter/java_version.rb @@ -21,21 +21,7 @@ Facter.add(:java_version) do # Additionally, facter versions prior to 2.0.1 only support # positive matches, so this needs to be done manually in setcode. setcode do - unless [ 'openbsd', 'darwin' ].include? Facter.value(:operatingsystem).downcase - version = nil - if Facter::Util::Resolution.which('java') - Facter::Util::Resolution.exec('java -Xmx12m -version 2>&1').lines.each { |line| version = $~[1] if /^.+ version \"(.+)\"$/ =~ line } - end - version - end - end -end - -Facter.add(:java_version) do - confine :operatingsystem => 'OpenBSD' - has_weight 100 - setcode do - Facter::Util::Resolution.with_env("PATH" => '/usr/local/jdk-1.7.0/jre/bin:/usr/local/jre-1.7.0/bin') do + unless [ 'darwin' ].include? Facter.value(:operatingsystem).downcase version = nil if Facter::Util::Resolution.which('java') Facter::Util::Resolution.exec('java -Xmx12m -version 2>&1').lines.each { |line| version = $~[1] if /^.+ version \"(.+)\"$/ =~ line } diff --git a/manifests/config.pp b/manifests/config.pp index 5c7f3fd..6237a8b 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -44,7 +44,7 @@ class java::config ( ) { } } } - 'OpenBSD', 'FreeBSD', 'Suse': { + 'FreeBSD', 'Suse': { if $java::use_java_home != undef { file_line { 'java-home-environment': path => '/etc/environment',