Skip to content

Commit

Permalink
Avoid comparing java versions as strings
Browse files Browse the repository at this point in the history
  • Loading branch information
msimacek committed Aug 6, 2018
1 parent ed548d1 commit d6decbb
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions depgenerators/maven.req
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,7 @@ class TagBuilder(object):
if not rules.get('skip', False):
req_versions = fn(metadata)
if req_versions:
max_version = self._get_java_requires(req_versions)
version_string = "1:{0}".format(max_version)
version_string = self._get_java_requires(req_versions)
parts = {'pkg': rules['package_name'],
'op': rules.get('cmp_operator', '>='),
'version': version_string}
Expand All @@ -294,22 +293,25 @@ class TagBuilder(object):
return requires

def _get_java_requires(self, reqs):
return max([self._normalize_java_requires(x) for x in reqs])

def _normalize_java_requires(self, req):
version = req.split(".")
if len(version) == 1:
try:
if int(req) < 9:
req = "1." + req
except ValueError:
raise ValueError("Unknown Java version {0}".format(req))
# sanity check
try:
float(req)
except ValueError:
major, minor = max([self._parse_java_requires(x) for x in reqs])
if minor:
return "1:{0}.{1}".format(major, minor)
else:
return "1:{0}".format(major)

def _parse_java_requires(self, req):
match = re.match(r'^(\d+)(?:\.(\d+))?$', req)
if not match:
raise ValueError("Unknown Java version {0}".format(req))
return req

major = int(match.group(1))
minor = int(match.group(2) or 0)

if not minor and major < 9:
minor = major
major = 1

return major, minor

def _filter_requires(self, requires):
filters = self.config.get('requires_filter', [])
Expand Down

0 comments on commit d6decbb

Please sign in to comment.