-
Notifications
You must be signed in to change notification settings - Fork 0
/
pom.py
87 lines (80 loc) · 2.3 KB
/
pom.py
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
import os,sys
import re
os.system('sh /tmp/pom.sh')
pattern = re.compile(r'maven-dependency-plugin:2.1:tree')
pom = ''
search = False
file = open('/tmp/pom.tmp','w')
for line in open('/tmp/pom.txt').readlines():
line = line.lstrip('[WARNING]').lstrip('[INFO]')
line = line.lstrip(' ').strip('\n')
if pom and (line.startswith('+') or line.startswith('\\') or line.startswith('|')):
#print("a"+line+"b")
line = line.lstrip('+\\|- ') + ':' + pom + '\n'
file.write(line)
elif pattern.search(line):
search = True
elif search==True:
search = False
pom = line
file.close()
os.system('cat /tmp/pom.tmp | sort > /tmp/pom.xml')
dependencyManagement = []
dependencies = {}
cur = []
print("<!-- list -->")
print("\n")
print("<![CDATA[ ")
print("\n")
for line in open('/tmp/pom.xml').readlines():
line = line.split(":")
if cur==[] or cur[0][0]==line[0] and cur[0][1]==line[1] and cur[0][2]==line[2]:
cur.append(line)
else:
if len(cur)>1 and cur[0][3]!=cur[len(cur)-1][3]:
#print("<!-- list --")
for l in cur:
print(l)
if not l[6] in dependencies:
dependencies[l[6]] = []
dependencies[l[6]].append("""
<dependency>
<groupId>%(g)s</groupId>
<artifactId>%(a)s</artifactId>
</dependency>
""" % {'g':cur[0][0],'a':cur[0][1]})
dependencyManagement.append("""
<dependency>
<groupId>%(g)s</groupId>
<artifactId>%(a)s</artifactId>
<version>%(v)s</version>
<scope>%(s)s</scope>
</dependency>
""" % {'g':cur[0][0],'a':cur[0][1],'v':cur[len(cur)-1][3],'s':cur[0][4]})
# print("""
#<dependency>
# <groupId>%(g)s</groupId>
# <artifactId>%(a)s</artifactId>
# <version>%(v)s</version>
#</dependency>
#""" % {'g':cur[0][0],'a':cur[0][1],'v':cur[0][3]})
#print("-- list -->")
print("\n")
cur = []
cur.append(line)
print("]]>")
print("\n")
print("<!-- dependencyManagement -->")
print("<dependencyManagement>")
print("<dependencies>")
for l in dependencyManagement:
print(l)
print("</dependencies>")
print("</dependencyManagement>")
print("\n<!-- dependencies -->\n")
for k,v in dependencies.items():
print("<!-- %s -->" % (k))
print("<dependencies>")
for l in v:
print(l)
print("</dependencies>")