-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
97 lines (67 loc) · 2.8 KB
/
build.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
94
95
96
97
#!/usr/bin/env python
from __future__ import print_function
import os.path
import common
import utils.file_utils as file_utils
import utils.mvn_utils as mvn_utils
(ROOT_PROJECT_PATH, MAVEN_REPO_PATH, MVN_OPTS, ROOT_ONLY, TRACK_UNVERSIONED, vcs_gateway) = common.parse_options()
def is_important(file_path):
return not file_path.endswith(".iml")
def get_unique_name(root_project_path):
if os.name == 'nt':
result = root_project_path.replace('\\', "_")
else:
result = root_project_path.replace('/', "_")
result = result.replace(":", "_")
return result
changed_files = vcs_gateway.get_local_changed_files(ROOT_PROJECT_PATH, not TRACK_UNVERSIONED)
important_files = filter(is_important, changed_files)
pom_paths = set([])
for file_path in important_files:
file_path = file_utils.normalize_path(file_path)
if os.path.isdir(file_path):
parent_path = file_path
else:
parent_path = os.path.dirname(file_path)
while parent_path and not (file_utils.is_root(parent_path)):
pom_path = os.path.join(parent_path, "pom.xml")
if os.path.exists(pom_path):
pom_paths.add(pom_path)
break
if parent_path == ROOT_PROJECT_PATH:
break
parent_path = os.path.dirname(parent_path)
new_in_progress = set(pom_paths)
home_folder = os.path.expanduser('~')
unique_name = get_unique_name(ROOT_PROJECT_PATH)
in_progress_file = os.path.join(home_folder, '.incremaven', unique_name)
prev_in_progress = []
if os.path.exists(in_progress_file):
prev_in_progress = file_utils.read_file(in_progress_file).split("\n")
prev_in_progress = filter(lambda line: line != "", prev_in_progress)
for pom_path in prev_in_progress:
if os.path.exists(pom_path):
pom_paths.add(pom_path)
file_utils.write_file(in_progress_file, "\n".join(pom_paths))
projects = common.to_mvn_projects(pom_paths, ROOT_PROJECT_PATH, ROOT_ONLY)
to_rebuild = []
to_install = []
for project in projects:
build_date = mvn_utils.target_build_date(project)
if build_date is None:
print(str(project) + ' needs rebuild. Artifact is missing in target')
to_rebuild.append(project)
continue
project_src_paths = mvn_utils.get_buildable_paths(project)
src_modification = file_utils.last_modification(project_src_paths)
if build_date < src_modification:
print(str(project) + ' needs rebuild. Last build update: ' + str(build_date))
to_rebuild.append(project)
else:
to_install.append(project)
print('Installing non-changed artifacts to local repository...')
for project in to_install:
mvn_utils.fast_install(project, MAVEN_REPO_PATH)
print('Rebuilding projects...')
mvn_utils.rebuild(ROOT_PROJECT_PATH, to_rebuild, MVN_OPTS)
file_utils.write_file(in_progress_file, '\n'.join(new_in_progress))