Skip to content

Commit

Permalink
Improve java version check to support invalid semantics (#456)
Browse files Browse the repository at this point in the history
Fixes #455
  • Loading branch information
mkanoor authored Mar 20, 2023
2 parents f0e8b80 + 8c7b38a commit d69c88d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ansible_rulebook/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import json
import logging
import os
import re
import shutil
import subprocess
import sys
Expand Down Expand Up @@ -188,7 +189,12 @@ def check_jvm():
sys.exit(1)

java_version = get_java_version()

try:
# Keep only "x.y.z" section
clean_version = re.match(r"(\d+\.\d+\.\d+).*", java_version)
if clean_version:
java_version = clean_version.groups()[0]
if version.parse(java_version) < version.parse("17"):
print(
"The minimum supported Java version is 17. "
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def test_check_jvm_bad_java_home(mock_response):
"11.0.2",
id="lower",
),
pytest.param(
"1.8.0_875",
id="lower_wrong_semantic",
),
pytest.param("Not found", id="not_found"),
],
)
Expand All @@ -57,6 +61,7 @@ def test_check_jvm_bad_version(mock, mocked_version):
id="semantic",
),
pytest.param("17.1.5.3", id="semantic_extended"),
pytest.param("17.1.5_3", id="wrong_semantic"),
],
)
@patch("ansible_rulebook.util.get_java_version")
Expand Down

0 comments on commit d69c88d

Please sign in to comment.