summaryrefslogtreecommitdiff
path: root/lib/ohai/plugins/java.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ohai/plugins/java.rb')
-rw-r--r--lib/ohai/plugins/java.rb42
1 files changed, 32 insertions, 10 deletions
diff --git a/lib/ohai/plugins/java.rb b/lib/ohai/plugins/java.rb
index 11a5a643..c94a93a9 100644
--- a/lib/ohai/plugins/java.rb
+++ b/lib/ohai/plugins/java.rb
@@ -22,17 +22,12 @@ Ohai.plugin(:Java) do
depends "languages"
collect_data do
- java = Mash.new
-
- so = nil
- if RUBY_PLATFORM.downcase.include?("darwin")
- if File.executable?("#{ Ohai.abs_path( "/usr/libexec/java_home" )}")
- so = shell_out("java -version")
- end
- else
- so = shell_out("java -version")
- end
+ get_java_info if has_real_java?
+ end
+ def get_java_info
+ java = Mash.new
+ so = shell_out("java -version")
if so.exitstatus == 0
so.stderr.split(/\r?\n/).each do |line|
case line
@@ -48,4 +43,31 @@ Ohai.plugin(:Java) do
languages[:java] = java if java[:version]
end
end
+
+ # On Mac OS X, the development tools include "stubs" for JVM executables that
+ # prompt the user to install the JVM if they desire. In our case we simply
+ # wish to detect if the JVM is there and do not want to trigger a popup
+ # window. As a workaround, we can run the java_home executable and check its
+ # exit status to determine if the `java` executable is the real one or the OS
+ # X stub. In the terminal, it looks like this:
+ #
+ # $ /usr/libexec/java_home
+ # Unable to find any JVMs matching version "(null)".
+ # No Java runtime present, try --request to install.
+ #
+ # $ echo $?
+ # 1
+ #
+ # This check always returns true when not on darwin because it is just a
+ # workaround for this particular annoyance.
+ def has_real_java?
+ return true unless on_darwin?
+ shell_out("/usr/libexec/java_home").status.success?
+ end
+
+ def on_darwin?
+ RUBY_PLATFORM.downcase.include?("darwin")
+ end
+
+
end