This repository has been archived by the owner on Dec 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from boxen/java-8-jre
Don't blow up when Java 8 JRE is installed.
- Loading branch information
Showing
4 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Fact: java_jre_version | ||
# | ||
# Purpose: store java jre versions in the config DB | ||
# | ||
# Resolution: | ||
# Tests for presence of java jre, returns nil if not present | ||
# returns output of "java -version" and splits on \n + '"' | ||
# | ||
# Caveats: | ||
# none | ||
# | ||
# Notes: | ||
# None | ||
Facter.add(:java_jre_version) do | ||
setcode do | ||
java_jre = "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java" | ||
next unless File.exist? java_jre | ||
t_java_jre = Facter::Util::Resolution.exec("'#{java_jre}' -version 2>&1") | ||
java_jre_version = t_java_jre.to_s.lines.first.strip.split(/version/)[1].gsub(/"/, "").strip | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require "spec_helper" | ||
|
||
describe Facter::Util::Fact do | ||
before { | ||
Facter.clear | ||
allow(Facter::Util::Resolution).to receive(:exec).with(anything()).and_return(nil) | ||
allow(Facter.fact(:kernel)).to receive(:value).and_return("Darwin") | ||
} | ||
|
||
describe "java_jre_version" do | ||
context 'returns java jre version when java jre present' do | ||
it do | ||
allow(File).to receive(:exist?).and_return(true) | ||
java_jre_version_output = <<-EOS | ||
java version "1.7.0_71" | ||
Java(TM) SE Runtime Environment (build 1.7.0_71-b14) | ||
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode) | ||
EOS | ||
allow(Facter::Util::Resolution).to receive(:exec).with("'/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java' -version 2>&1"). | ||
and_return(java_jre_version_output) | ||
Facter.fact(:java_jre_version).value.should == "1.7.0_71" | ||
end | ||
end | ||
|
||
context 'returns nil when java jre not present' do | ||
it do | ||
allow(File).to receive(:exist?).and_return(false) | ||
java_jre_version_output = "bash: /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java: No such file or directory" | ||
allow(Facter::Util::Resolution).to receive(:exec).with("'/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java' -version 2>&1"). | ||
and_return(java_jre_version_output) | ||
Facter.fact(:java_jre_version).value.should be_nil | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters