Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/facter/java_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# Additionally, facter versions prior to 2.0.1 only support
# positive matches, so this needs to be done manually in setcode.
setcode do
unless ['darwin'].include? Facter.value(:operatingsystem).downcase
unless ['darwin'].include? Facter.value(:kernel).downcase
version = nil
if Facter::Util::Resolution.which('java')
Facter::Util::Resolution.exec('java -Xmx12m -version 2>&1').lines.each { |line| version = Regexp.last_match(1) if %r{^.+ version \"(.+)\"} =~ line }
Expand All @@ -34,7 +34,7 @@
end

Facter.add(:java_version) do
confine operatingsystem: 'Darwin'
confine kernel: 'Darwin'
has_weight 100
setcode do
unless Facter::Util::Resolution.exec('/usr/libexec/java_home --failfast 2>&1').include?('Unable to find any JVMs matching version')
Expand Down
8 changes: 4 additions & 4 deletions spec/unit/facter/java_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
end
context 'when on Darwin' do
before(:each) do
allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('Darwin')
allow(Facter.fact(:kernel)).to receive(:value).and_return('Darwin')
end
let(:facts) { { operatingsystem: 'Darwin' } }
let(:facts) { { kernel: 'Darwin' } }

it do
expect(Facter::Util::Resolution).to receive(:exec).with('/usr/libexec/java_home --failfast 2>&1').and_return('/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home')
Expand Down Expand Up @@ -71,9 +71,9 @@
end
context 'when on Darwin' do
before(:each) do
allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('Darwin')
allow(Facter.fact(:kernel)).to receive(:value).and_return('Darwin')
end
let(:facts) { { operatingsystem: 'Darwin' } }
let(:facts) { { kernel: 'Darwin' } }

it do
expect(Facter::Util::Resolution).to receive(:exec).with('/usr/libexec/java_home --failfast 2>&1').at_least(1).and_return('Unable to find any JVMs matching version "(null)".')
Expand Down