Class Version

java.lang.Object
org.graalvm.home.Version
All Implemented Interfaces:
Comparable<Version>

public final class Version extends Object implements Comparable<Version>
A version utility to canonicalize and compare GraalVM versions. The GraalVM version string is not standardized and may change without notice. This class is designed to evolve with GraalVM to cover all used version formats in use. It allows to create, validate and compare GraalVM versions. Do not rely on the format of the raw version string or the result of toString(), only use it to produce output for humans.

To create version instances of a particular version use the create(int...) factory method. Use getCurrent() to lookup the current GraalVM version or parse(String) to parse it from a raw string.

Usage example:

This code example compares the current GraalVM version to be at least 19.3 and fails if it is not.
 if (Version.getCurrent().compareTo(19, 3) < 0) {
     throw new IllegalStateException("Invalid GraalVM version. Must be at least 19.3.");
 }
 

Note: this class has a natural ordering that is inconsistent with equals.

Since:
19.3
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    compareTo(int... compareVersions)
    Compares this version to another GraalVM version.
    int
    static Version
    create(int... versions)
    Constructs a new GraalVM version from a list of version numbers.
    boolean
    format(String format)
    Format the GraalVM version with a custom format string.
    int
    getComponent(int componentIndex)
    Retrieves the numeric value of the version component at the specified index.
    static Version
    Returns the current GraalVM version of the installed component.
    int
    boolean
    Returns true if this is a supported release build of GraalVM else false.
    boolean
    Returns true if this is an unsupported snapshot build of GraalVM else false.
    static Version
    parse(String versionString)
    Parses a GraalVM version from its String raw format.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • isRelease

      public boolean isRelease()
      Returns true if this is a supported release build of GraalVM else false. Use this for implementation assertions that verify that only releases are deployed to production.
      Since:
      19.3
      See Also:
    • isSnapshot

      public boolean isSnapshot()
      Returns true if this is an unsupported snapshot build of GraalVM else false. Use this for implementation assertions that verify that only releases are deployed to production.
      Since:
      19.3
      See Also:
    • compareTo

      public int compareTo(Version o)
      Specified by:
      compareTo in interface Comparable<Version>
      Since:
      19.3
    • compareTo

      public int compareTo(int... compareVersions)
      Compares this version to another GraalVM version. This is equivalent to using: compareTo(Version.create(compareVersions)) .
      Since:
      19.3
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
      Since:
      19.3
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
      Since:
      19.3
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Since:
      19.3
    • format

      public String format(String format)
      Format the GraalVM version with a custom format string.

      The format string can contain any of the standard conversions of Formatter. At least four version components (possibly zero) are available as formatter arguments.

      In addition to the standard conversions, these special conversions are available:

      • "%[R...]" includes a given part only if isRelease()
      • "%[S...]" includes a given part only if isSnapshot()
      • "%[<digit>...]" includes a given part only if the version contains at least <digit> non-zero version components (<digit> can be 0 to 9)

      Examples:

       Version.parse("22.3.0.1").format("%d.%d"); // returns "22.3"
       Version.parse("22.3.0.1").format("%4$d"); // returns "1"
       Version.parse("22.3.0.1").format("%[R%d.%d]%[Sdev]"); // returns "22.3"
       Version.parse("22.3.0.1").format("%[2XX]"); // returns "XX"
       Version.parse("23.0-dev").format("%3$d"); // returns "0"
       Version.parse("23.0-dev").format("%[R%d.%d]%[Sdev]"); // returns "dev"
       Version.parse("23.0-dev").format("%[2XX]"); // returns ""
       
      Since:
      23.0
    • getComponent

      public int getComponent(int componentIndex)
      Retrieves the numeric value of the version component at the specified index.

      Version components are indexed as follows:

      • componentIndex = 0 represents the major version
      • componentIndex = 1 represents the minor version
      • componentIndex = 2 represents the update version
      If the specified componentIndex exceeds the number of available components, the method returns 0. For example, a version 23.1 will return 0 for componentIndex = 2.

      Parameters:
      componentIndex - the index of the version component to retrieve; must be non-negative
      Throws:
      IllegalArgumentException - if componentIndex is negative
      Since:
      24.2
      See Also:
    • parse

      public static Version parse(String versionString) throws IllegalArgumentException
      Parses a GraalVM version from its String raw format. Throws IllegalArgumentException if the passed string is not a valid GraalVM version.
      Throws:
      IllegalArgumentException
      Since:
      19.3
    • create

      public static Version create(int... versions) throws IllegalArgumentException
      Constructs a new GraalVM version from a list of version numbers. The versions must not be null and none of the version numbers must be negative. At least one version number must be non-zero.
      Throws:
      IllegalArgumentException
      Since:
      19.3
      See Also:
    • getCurrent

      public static Version getCurrent()
      Returns the current GraalVM version of the installed component. Never null.
      Since:
      19.3
      See Also: