CompareVersionsMajor Condition

Usage

The CompareVersionsMajor condition (type="compareversionsmajor") can be used to find out, how two given version strings relate, comparing just the most common denominator of the major version parts of both sides.

In comparison, there is implemented a second condition of type "compareversions" which compares two version strings, that can have a different number of version parts, for example 1.0 and 1.0.1.
The compareversions condition assumes missing minor version parts to be 0 effectively, thus comparing 1.0 and 1.0.1 would result in comparing 1.0.0 and 1.0.1, thus evaluating 1.0 < 1.0.1.

For some use cases, this comparison behavior might be changed to comparing just the explicit major version parts of both operands and ignore the rest of the minor parts of the operand with more version parts, thus comparing 1.0 and 1.0.1 would result in comparing 1.0 and 1.0, thus evaluating 1.0 == 1.0.1. This is what compareversionsmajor does.

Example:

Imagine a check of an explicit Java version the user enters in some input panel. There's a definition for the maximum and minimum Java version, thus min <= version <= max.
There should be further said, the Java version should be 1.7 or 1.8, ignoring the minor version parts. The minimum version should be 1.7, the maximum version 1.8. The version number to compare to should be parsed from the output of the 'java -version' command of the JRE the user entered as path. The following expressions should evaluate true in this case:
- 1.7 <= 1.8.0_72 <= 1.8
- 1.7 <= 1.7.0_20 <= 1.8

This would not be possible using the compareversions condition, because it evaluates 1.8.0_72 <= 1.8 -> false and 1.7 <= 1.7.0_20 -> false.

install.xml
...
<dynamicvariables>
  <variable name="java.version" checkonce="true"
            executable="${java.executable}" stderr="true"
            type="process" ignorefailure="true">
      <arg>-version</arg>
      <filters>
        <regex regexp="java version[^\d]+([\d\._]+)" select="\1"/>
      </filters>
    </variable>
</dynamicvariables>
...
<conditions>
  <condition type="compareversionsmajor" id="ValidMinJavaVersion">
    <arg1>${java.version}</arg1>
    <arg2>1.7</arg2>
    <operator>geq</operator>
  </condition>
  <condition type="compareversionsmajor" id="ValidMaxJavaVersion">
    <arg1>${java.version}</arg1>
    <arg2>1.8</arg2>
    <operator>leq</operator>
  </condition>
</conditions>
...


The CompareVersionsMajor condition has been introduced in IzPack 5.0.7.

Nested Elements

arg1

This is a mandatory nested element, defining the left version to compare. Any string is allowed, IzPack will try to resolve it as a version string.

arg2

This is a mandatory nested element, defining the right version to compare. Any string is allowed, IzPack will try to resolve it as a version string.

operator

This is a mandatory nested element, specifying the comparison operation to apply

Allowed values:

  • eq - check whether both versions are equal (=)
  • ne - check whether both versions differ (not equal) (<>)
  • leq - check whether the left version is less than or equal the right version (<=)
  • lt - check whether the left version is less than the right version (<)
  • geq - check whether the left version is greater than or equal the right version (>=)
  • gt - check whether the left version is greater than the right version (>)