This repository was archived by the owner on Dec 2, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +64
-3
lines changed Expand file tree Collapse file tree 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 2626 mode => ' 0755'
2727 }
2828
29- if (versioncmp($::java_version , ' 1.8.0' ) < 0) {
29+ if (versioncmp($::java_jre_version , ' 1.8.0' ) < 0) {
3030 package {
3131 " jre-7u${update_version} .dmg" :
3232 ensure => present ,
3333 alias => ' java-jre' ,
3434 provider => pkgdmg,
3535 source => $jre_url ;
36+ }
37+ }
38+
39+ if (versioncmp($::java_version , ' 1.8.0' ) < 0) {
40+ package {
3641 " jdk-7u${update_version} .dmg" :
3742 ensure => present ,
3843 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 2121 end
2222 end
2323
24- context 'returns nil when java present' do
24+ context 'returns nil when java not present' do
2525 it do
2626 java_version_output = "bash: java: command not found"
2727 allow ( Facter ::Util ::Resolution ) . to receive ( :exec ) . with ( "java -version 2>&1" ) .
3030 end
3131 end
3232 end
33- end
33+ end
You can’t perform that action at this time.
0 commit comments