diff options
Diffstat (limited to 'scripts.new/bin/compare-maven-version')
-rwxr-xr-x | scripts.new/bin/compare-maven-version | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/scripts.new/bin/compare-maven-version b/scripts.new/bin/compare-maven-version new file mode 100755 index 0000000..de0ab47 --- /dev/null +++ b/scripts.new/bin/compare-maven-version @@ -0,0 +1,102 @@ +#!/usr/bin/env python3 +# -*- coding:utf-8 -*- + +import re +import sys +import argparse + +MAVEN_VERSION = f"^v?(\d+)(?:\.(\d+))?(?:(?:\.|b|beta)(\d+))?(?:[\.-]?(.*))?$" +MAVEN_RANGE = f"[\[\(](.*), *(.*?)[\]\)]" + + +class MavenSingleVersion(): + + def __init__(self, version_string): + self.version = [] + version_match = re.match(MAVEN_VERSION, version_string) + for i in range(1, 4): + tmp = 0 if isinstance(version_match[i], type( + None)) else int(version_match[i]) + self.version.append(tmp) + + def __lt__(self, alien): + for i in range(3): + if self.version[i] == alien.version[i]: + continue + else: + return self.version[i] < alien.version[i] + return False + + def __gt__(self, alien): + for i in range(3): + if self.version[i] == alien.version[i]: + continue + else: + return self.version[i] > alien.version[i] + return False + + def __le__(self, alien): + for i in range(3): + if self.version[i] == alien.version[i]: + continue + else: + return self.version[i] < alien.version[i] + return True + + def __ge__(self, alien): + for i in range(3): + if self.version[i] == alien.version[i]: + continue + else: + return self.version[i] > alien.version[i] + return True + + def __eq__(self, alien): + for i in range(3): + if self.version[i] == alien.version[i]: + continue + else: + return False + return True + + +class MavenVersion(): + def __init__(self, version_string): + range_match = re.match(MAVEN_RANGE, version_string) + + if isinstance(range_match, type(None)): + self.min = MavenSingleVersion(version_string) + self.max = MavenSingleVersion("99999999.99999999.99999999") + else: + try: + self.min = MavenSingleVersion(range_match.group(1)) + except: + self.min = MavenSingleVersion("0.0.0") + try: + self.max = MavenSingleVersion(range_match.group(2)) + except: + self.max = MavenSingleVersion("99999999.99999999.99999999") + + def match(self, singleVersion): + if singleVersion <= self.max and singleVersion >= self.min: + return True + else: + return False + + +parser = argparse.ArgumentParser( + description='Compare Maven Version with dependency') +parser.add_argument('--dep', dest='dep', action='store', + required=True, help='the dependency required') +parser.add_argument('--maven-version', dest='mv', action='store', + required=True, help='the maven version to be compared') + +if __name__ == "__main__": + args = parser.parse_args() + + dep = MavenVersion.MavenVersion(args.dep) + mv = MavenVersion.MavenSingleVersion(args.mv) + + if dep.max.version[0] != 99999999: + print(f"SLOT={dep.min.version[0]}.{dep.min.version[1]}") + sys.exit(not dep.match(mv)) |