(MODULES-4050) Check if jre is in the path before subsubdir

This commit is contained in:
Jan Vansteenkiste
2016-11-07 15:00:47 +01:00
parent 91871b1408
commit b5b03e5c00
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
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,6 +8,7 @@ describe Facter::Util::Fact do
describe "java_default_home" do
context 'returns java home path when readlink present' do
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
@@ -17,6 +18,17 @@ describe Facter::Util::Fact do
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
context 'returns nil when readlink not present' do
it do