Method: LogStash::Util::JavaVersion.parse_java_version

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

.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.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/logstash/util/java_version.rb', line 12

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