Merge pull request #202 from vrtdev/bugfix/fact_java_default_home

MODULES-4050: Check if jre is in the path before subsubdir.
This commit is contained in:
Wilson McCoubrey
2016-11-10 16:00:38 +00:00
committed by GitHub
2 changed files with 23 additions and 7 deletions

View File

@@ -15,7 +15,11 @@ Facter.add(:java_default_home) do
setcode do
if Facter::Util::Resolution.which('readlink')
java_bin = Facter::Util::Resolution.exec('readlink -e /usr/bin/java').strip
java_default_home = File.dirname(File.dirname(File.dirname(java_bin)))
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))
end
end
end
end

View File

@@ -8,13 +8,25 @@ describe Facter::Util::Fact do
describe "java_default_home" do
context 'returns java home path when readlink present' do
it do
java_path_output = <<-EOS
context 'when java is in HOME/jre/bin/java' do
it do
java_path_output = <<-EOS
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
EOS
Facter::Util::Resolution.expects(:which).with("readlink").returns(true)
Facter::Util::Resolution.expects(:exec).with("readlink -e /usr/bin/java").returns(java_path_output)
expect(Facter.value(:java_default_home)).to eql "/usr/lib/jvm/java-7-openjdk-amd64"
EOS
Facter::Util::Resolution.expects(:which).with("readlink").returns(true)
Facter::Util::Resolution.expects(:exec).with("readlink -e /usr/bin/java").returns(java_path_output)
expect(Facter.value(:java_default_home)).to eql "/usr/lib/jvm/java-7-openjdk-amd64"
end
end
context 'when java is in HOME/bin/java' do
it do
java_path_output = <<-EOS
/usr/lib/jvm/oracle-java8-jre-amd64/bin/java
EOS
Facter::Util::Resolution.expects(:which).with("readlink").returns(true)
Facter::Util::Resolution.expects(:exec).with("readlink -e /usr/bin/java").returns(java_path_output)
expect(Facter.value(:java_default_home)).to eql "/usr/lib/jvm/oracle-java8-jre-amd64"
end
end
end