-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.py
93 lines (73 loc) · 3.33 KB
/
common.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
88
89
90
91
92
93
import argparse
import os.path
import re
import sys
import utils.file_utils as file_utils
import utils.git_utils as git_utils
import utils.mvn_utils as mvn_utils
import utils.svn_utils as svn_utils
def parse_options():
parser = argparse.ArgumentParser(description="Rebuild of complex maven projects.")
parser.add_argument("-r", "--root_path", help="path to the root project", default=".")
parser.add_argument("-m", "--maven", help="maven parameters to pass to mvn command", default="")
parser.add_argument("-o", "--root_only", help="skip projects, which are not submodules of root project hierarchy",
action='store_true')
parser.add_argument("-t", "--track_unversioned", help="also consider local changes in unversioned files",
action='store_true')
parser.add_argument("-c", "--vcs", help="version control system", choices=['svn', 'git'])
args = vars(parser.parse_args())
if args["root_path"]:
root_project_path = args["root_path"]
else:
root_project_path = "."
mvn_opts = args["maven"]
root_only = args["root_only"]
track_unversioned = args["track_unversioned"]
root_project_path = file_utils.normalize_path(root_project_path)
print("Root project path: " + root_project_path)
print("Additional maven arguments: " + str(mvn_opts))
root_pom_path = os.path.join(root_project_path, "pom.xml")
if not os.path.exists(root_pom_path):
print("ERROR! No root pom.xml find in path", os.path.abspath(root_project_path))
sys.exit(1)
if args['vcs']:
if args['vcs'] == 'git':
vcs_gateway = git_utils.GitGateway()
else:
vcs_gateway = svn_utils.SvnGateway()
else:
if svn_utils.is_svn_repo(root_project_path):
vcs_gateway = svn_utils.SvnGateway()
elif git_utils.is_git_repo(root_project_path):
vcs_gateway = git_utils.GitGateway()
else:
print("Couldn't resolve VCS type, please specify it explicitly using -c argument")
sys.exit(-1)
if '-Dmaven.repo.local=' in mvn_opts:
mvn_repo_path = get_arg_value(mvn_opts, '-Dmaven.repo.local')
else:
mvn_repo_path = mvn_utils.def_repo_path()
return (root_project_path, mvn_repo_path, mvn_opts, root_only, track_unversioned, vcs_gateway)
def get_arg_value(options_string, argument):
pattern = re.compile(argument + '(\s+|=)(.*)')
for match in pattern.finditer(options_string):
opts_end = match.group(2)
if opts_end.startswith('"'):
return opts_end[1:opts_end.index('"', 1)]
elif opts_end.startswith("'"):
return opts_end[1:opts_end.index("'", 1)]
else:
return re.split('[\s\b]', opts_end)[0]
def to_mvn_projects(pom_paths, root_path, root_only):
projects = []
for pom_path in pom_paths:
if root_only:
project_path = os.path.dirname(pom_path)
project_root_path = mvn_utils.get_project_root_path(project_path)
if project_root_path != root_path:
project_relative_path = os.path.relpath(project_path, root_path)
print(project_relative_path + ' is not in root hierarchy. Skipping...')
continue
project = mvn_utils.create_project(pom_path)
projects.append(project)
return projects