Module: LogStash::Util::JavaVersion

Defined in:
lib/logstash/util/java_version.rb

Class Method Summary collapse

Class Method Details

.bad_java_version?(version_string) ⇒ Boolean

Determine if the given java version string is a bad version of java If it is, return true, if it isn’t return false. Accepts nil, returning nil.

Returns:

  • (Boolean)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/logstash/util/java_version.rb', line 52

def self.bad_java_version?(version_string)
  return nil if version_string.nil?

  parsed = parse_java_version(version_string)
  return false unless parsed

  if parsed[:major] == 1 && parsed[:minor] == 7 && parsed[:patch] == 0 && parsed[:update] < 51
    true
  elsif parsed[:major] == 1 && parsed[:minor] < 7
    true
  else
    false
  end
end

.loggerObject



5
6
7
# File 'lib/logstash/util/java_version.rb', line 5

def self.logger
  @logger ||= Cabin::Channel.get(LogStash)
end

.parse_java_version(version_string) ⇒ Object

Takes a string of a java version ex: “1.8.0_24-beta” and returns a parsed map of the components. nil inputs will be returned as nil.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/logstash/util/java_version.rb', line 27

def self.parse_java_version(version_string)
  return nil if version_string.nil?

  # Crazy java versioning rules @ http://www.oracle.com/technetwork/java/javase/versioning-naming-139433.html
  # The regex below parses this all correctly http://rubular.com/r/sInQc3Nc7f

  match = version_string.match(/\A(\d+)\.(\d+)\.(\d+)(_(\d+))?(-(.+))?\Z/)

  return nil unless match

  major, minor, patch, ufull, update, bfull, build = match.captures

  {
    :full => version_string,
    :major => major.to_i,
    :minor => minor.to_i,
    :patch => patch.to_i,
    :update => update.to_i, # this is always coerced to an int (a nil will be zero) to make comparisons easier
    :build => build # not an integer, could be b06 for instance!,
  }
end

.versionObject

Return the current java version string. Returns nil if this is a non-java platform (e.g. MRI).



19
20
21
22
# File 'lib/logstash/util/java_version.rb', line 19

def self.version
  return nil unless LogStash::Environment.jruby?
  java.lang.System.getProperty("java.runtime.version")
end

.warn_on_bad_java_versionObject

Print a warning if we’re on a bad version of java



10
11
12
13
14
15
16
# File 'lib/logstash/util/java_version.rb', line 10

def self.warn_on_bad_java_version
  if self.bad_java_version?(self.version)
    msg = "!!! Please upgrade your java version, the current version '#{self.version}' may cause problems. We recommend a minimum version of 1.7.0_51"
    STDERR.puts(msg)
    logger.warn(msg)
  end
end