1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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(args.dep)
mv = 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))
|