This repository was archived by the owner on Dec 2, 2020. It is now read-only.
File tree 4 files changed +64
-3
lines changed
4 files changed +64
-3
lines changed Original file line number Diff line number Diff line change
1
+ # Fact: java_jre_version
2
+ #
3
+ # Purpose: store java jre versions in the config DB
4
+ #
5
+ # Resolution:
6
+ # Tests for presence of java jre, returns nil if not present
7
+ # returns output of "java -version" and splits on \n + '"'
8
+ #
9
+ # Caveats:
10
+ # none
11
+ #
12
+ # Notes:
13
+ # None
14
+ Facter . add ( :java_jre_version ) do
15
+ setcode do
16
+ java_jre = "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java"
17
+ next unless File . exist? java_jre
18
+ t_java_jre = Facter ::Util ::Resolution . exec ( "'#{ java_jre } ' -version 2>&1" )
19
+ java_jre_version = t_java_jre . to_s . lines . first . strip . split ( /version/ ) [ 1 ] . gsub ( /"/ , "" ) . strip
20
+ end
21
+ end
Original file line number Diff line number Diff line change 26
26
mode => ' 0755'
27
27
}
28
28
29
- if (versioncmp($::java_version , ' 1.8.0' ) < 0) {
29
+ if (versioncmp($::java_jre_version , ' 1.8.0' ) < 0) {
30
30
package {
31
31
" jre-7u${update_version} .dmg" :
32
32
ensure => present ,
33
33
alias => ' java-jre' ,
34
34
provider => pkgdmg,
35
35
source => $jre_url ;
36
+ }
37
+ }
38
+
39
+ if (versioncmp($::java_version , ' 1.8.0' ) < 0) {
40
+ package {
36
41
" jdk-7u${update_version} .dmg" :
37
42
ensure => present ,
38
43
alias => ' java' ,
Original file line number Diff line number Diff line change
1
+ require "spec_helper"
2
+
3
+ describe Facter ::Util ::Fact do
4
+ before {
5
+ Facter . clear
6
+ allow ( Facter ::Util ::Resolution ) . to receive ( :exec ) . with ( anything ( ) ) . and_return ( nil )
7
+ allow ( Facter . fact ( :kernel ) ) . to receive ( :value ) . and_return ( "Darwin" )
8
+ }
9
+
10
+ describe "java_jre_version" do
11
+ context 'returns java jre version when java jre present' do
12
+ it do
13
+ allow ( File ) . to receive ( :exist? ) . and_return ( true )
14
+ java_jre_version_output = <<-EOS
15
+ java version "1.7.0_71"
16
+ Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
17
+ Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)
18
+ EOS
19
+ allow ( Facter ::Util ::Resolution ) . to receive ( :exec ) . with ( "'/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java' -version 2>&1" ) .
20
+ and_return ( java_jre_version_output )
21
+ Facter . fact ( :java_jre_version ) . value . should == "1.7.0_71"
22
+ end
23
+ end
24
+
25
+ context 'returns nil when java jre not present' do
26
+ it do
27
+ allow ( File ) . to receive ( :exist? ) . and_return ( false )
28
+ java_jre_version_output = "bash: /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java: No such file or directory"
29
+ allow ( Facter ::Util ::Resolution ) . to receive ( :exec ) . with ( "'/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java' -version 2>&1" ) .
30
+ and_return ( java_jre_version_output )
31
+ Facter . fact ( :java_jre_version ) . value . should be_nil
32
+ end
33
+ end
34
+ end
35
+ end
Original file line number Diff line number Diff line change 21
21
end
22
22
end
23
23
24
- context 'returns nil when java present' do
24
+ context 'returns nil when java not present' do
25
25
it do
26
26
java_version_output = "bash: java: command not found"
27
27
allow ( Facter ::Util ::Resolution ) . to receive ( :exec ) . with ( "java -version 2>&1" ) .
30
30
end
31
31
end
32
32
end
33
- end
33
+ end
You can’t perform that action at this time.
0 commit comments