Skip to content

Commit

Permalink
Fix: Versioning semantic for java check.
Browse files Browse the repository at this point in the history
  • Loading branch information
Labbeti committed Jan 11, 2024
1 parent 1e9915e commit 2fd96ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/aac_metrics/utils/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ def _get_java_version(java_path: str) -> str:
def _check_java_version(version_str: str, min_major: int, max_major: int) -> bool:
version = Version.from_str(version_str)

if version.major == "1" and version.minor <= "8":
if version.major == 1 and version.minor <= 8:
# java <= 8 use versioning "1.MAJOR.MINOR" and > 8 use "MAJOR.MINOR.PATCH"
version.major = version.minor
version.minor = version.patch
version.patch = "0" # unknown patch, but it does not matter here
version.patch = 0 # unknown patch, but it does not matter here

return Version(min_major, 0, 0) <= version < Version(max_major, 0, 0)
return Version(min_major) <= version < Version(max_major+1)
29 changes: 13 additions & 16 deletions src/aac_metrics/utils/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ class Version:
str
] = r"(?P<major>[^\.]+)\.(?P<minor>[^\.]+)\.(?P<patch>[^\.]+).*"

major: str
minor: str
patch: str
major: int
minor: int
patch: int

def __init__(self, major: Any, minor: Any, patch: Any) -> None:
major = str(major)
minor = str(minor)
patch = str(patch)
def __init__(self, major: Any, minor: Any = 0, patch: Any = 0) -> None:
major = int(major)
minor = int(minor)
patch = int(patch)

self.major = major
self.minor = minor
Expand All @@ -45,8 +45,8 @@ def __init__(self, major: Any, minor: Any, patch: Any) -> None:
@classmethod
def from_dict(cls, version: Mapping[str, Any]) -> "Version":
major = version["major"]
minor = version["minor"]
patch = version["patch"]
minor = version.get("minor", 0)
patch = version.get("patch", 0)
return Version(major, minor, patch)

@classmethod
Expand All @@ -60,19 +60,16 @@ def from_str(cls, version: str) -> "Version":
return cls.from_dict(matched_dict)

@classmethod
def from_tuple(cls, version: tuple[Any, Any, Any]) -> "Version":
major = version[0]
minor = version[1]
patch = version[2]
return Version(major, minor, patch)
def from_tuple(cls, version: tuple[Any, ...]) -> "Version":
return Version(*version)

def to_dict(self) -> dict[str, str]:
def to_dict(self) -> dict[str, int]:
return asdict(self)

def to_str(self) -> str:
return Version._VERSION_FORMAT.format(**self.to_dict())

def to_tuple(self) -> tuple[str, str, str]:
def to_tuple(self) -> tuple[int, int, int]:
return astuple(self) # type: ignore

def __lt__(self, other: "Version") -> bool:
Expand Down

0 comments on commit 2fd96ab

Please sign in to comment.