Package org.graalvm.home
Class Version
java.lang.Object
org.graalvm.home.Version
- All Implemented Interfaces:
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 TypeMethodDescriptionintcompareTo(int... compareVersions) Compares this version to another GraalVM version.intstatic Versioncreate(int... versions) Constructs a new GraalVM version from a list of version numbers.booleanFormat the GraalVM version with a custom format string.static VersionReturns the current GraalVM version of the installed component.inthashCode()booleanReturnstrueif this is a supported release build of GraalVM elsefalse.booleanReturnstrueif this is an unsupported snapshot build of GraalVM elsefalse.static VersionParses a GraalVM version from its String raw format.toString()
-
Method Details
-
isRelease
public boolean isRelease()Returnstrueif this is a supported release build of GraalVM elsefalse. Use this for implementation assertions that verify that only releases are deployed to production.- Since:
- 19.3
- See Also:
-
isSnapshot
public boolean isSnapshot()Returnstrueif this is an unsupported snapshot build of GraalVM elsefalse. Use this for implementation assertions that verify that only releases are deployed to production.- Since:
- 19.3
- See Also:
-
compareTo
- Specified by:
compareToin interfaceComparable<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
-
hashCode
public int hashCode() -
toString
-
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 ifisRelease()"%[S...]"includes a given part only ifisSnapshot()"%[<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
-
parse
Parses a GraalVM version from its String raw format. ThrowsIllegalArgumentExceptionif the passed string is not a valid GraalVM version.- Throws:
IllegalArgumentException- Since:
- 19.3
-
create
Constructs a new GraalVM version from a list of version numbers. The versions must not benulland 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
Returns the current GraalVM version of the installed component. Nevernull.- Since:
- 19.3
- See Also:
-