Skip to content

Commit 687a9d8

Browse files
authored
Enable Support for Non-From Source Runs to Generate Reduced POMs (Azure#20913)
Enable Support for Non-From Source Runs to Generate Reduced POMs
1 parent dc6726a commit 687a9d8

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

eng/scripts/generate_from_source_pom.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Python version 3.4 or higher is required to run this script.
55

6-
# Use case: Creates an aggregate POM which contains all modules that will be required in a "From Source" run for the passed
6+
# Use case: Creates an aggregate POM which contains all modules that will be required in a "From Source" run for the passed
77
# project list.
88
#
99
# Flags
@@ -69,7 +69,7 @@ def create_from_source_pom(project_list: str):
6969
for project_identifier in project_list_identifiers:
7070
if not project_identifier in project_to_pom_path_mapping:
7171
continue
72-
72+
7373
dependent_modules = resolve_dependent_project(project_identifier, dependent_modules, dependency_to_project_mapping)
7474

7575
# Distinct the dependent modules, even though this should be guarded, to reduce downstream processing requirements.
@@ -92,33 +92,33 @@ def create_from_source_pom(project_list: str):
9292

9393
# Distinct the modules list.
9494
modules = list(set(modules))
95-
95+
9696
# Sort the modules list for easier reading.
9797
modules.sort()
98-
98+
9999
with open(file=client_from_source_pom_path, mode='w') as fromSourcePom:
100100
fromSourcePom.write(pom_file_start)
101101

102102
for module in modules:
103103
fromSourcePom.write(' <module>{}</module>\n'.format(module))
104104

105105
fromSourcePom.write(pom_file_end)
106-
106+
107107
# Function that loads and parses client_versions.txt into a artifact identifier - source version mapping.
108108
def load_client_artifact_identifiers():
109109
artifact_identifiers = {}
110110
with open(file=client_versions_path, mode='r') as f:
111111
for line in f:
112112
stripped_line = line.strip()
113-
114-
# Skip empty lines, comments, and non-standard version lines.
113+
114+
# Skip empty, comment, and non-standard version lines.
115115
if not stripped_line or stripped_line.startswith('#') or line.startswith('beta_') or line.startswith('unreleased_'):
116116
continue
117117

118118
# Split the version line on ';' which should create 3 substrings of artifact identifier - released version - source version.
119119
splitVersionLine = stripped_line.split(";")
120120

121-
# From the split lines create the artifact identitifer - source version map entry.
121+
# From the split lines create the artifact identifier - source version map entry.
122122
artifact_identifiers[splitVersionLine[0]]=splitVersionLine[2]
123123

124124
return artifact_identifiers
@@ -139,7 +139,7 @@ def create_dependency_and_path_mappings(project_list_identifiers: list, artifact
139139

140140
return project_dependencies_mapping, dependency_mapping, module_path_mapping
141141

142-
# Function that constructs the project dependencies map and adds to dependency to project map and project to module relative path map for a track 2 project.
142+
# Function that constructs the project dependencies map and adds to dependency to project map and project to module relative path map for a track 2 project.
143143
def add_project_to_dependency_and_module_mappings(file_path: str, project_dependencies_mapping: dict, project_list_identifiers: list, artifact_identifier_to_source_version: dict, dependency_mapping: dict, module_path_mapping: dict):
144144
if 'eng' in file_path.split(os.sep):
145145
return
@@ -152,7 +152,7 @@ def add_project_to_dependency_and_module_mappings(file_path: str, project_depend
152152
# If the project isn't a track 2 POM skip it and not one of the project list identifiers.
153153
if not project_identifier in project_list_identifiers and not is_track_two_pom(tree_root):
154154
return
155-
155+
156156
module_path_mapping[project_identifier] = os.path.dirname(file_path).replace(root_path, '').replace('\\', '/')
157157

158158
dependencies = tree_root.iter(maven_xml_namespace + 'dependency')
@@ -169,6 +169,10 @@ def add_project_to_dependency_and_module_mappings(file_path: str, project_depend
169169
if not dependency_identifier in artifact_identifier_to_source_version:
170170
continue
171171

172+
dependency_version = get_dependency_version(dependency)
173+
if dependency_version != artifact_identifier_to_source_version[dependency_identifier]:
174+
continue
175+
172176
if not dependency_identifier in dependency_mapping:
173177
dependency_mapping[dependency_identifier] = []
174178

@@ -183,7 +187,7 @@ def resolve_dependent_project(pom_identifier: str, dependent_modules: list, depe
183187
if not dependency in dependent_modules:
184188
dependent_modules = resolve_dependent_project(dependency, dependent_modules, dependency_to_project_mapping)
185189
dependent_modules.append(dependency)
186-
190+
187191
return dependent_modules
188192

189193
# Function which resolves the dependencies of the project.
@@ -214,6 +218,15 @@ def create_artifact_identifier(element: ET.Element):
214218

215219
return group_id.text + ':' + element_find(element, 'artifactId').text
216220

221+
# Gets the dependency version.
222+
def get_dependency_version(element: ET.Element):
223+
dependency_version = element_find(element, 'version')
224+
225+
if dependency_version is None:
226+
return None
227+
228+
return dependency_version.text
229+
217230
# Helper function for finding an XML element which handles adding the namespace.
218231
def element_find(element: ET.Element, path: str):
219232
return element.find(maven_xml_namespace + path)

0 commit comments

Comments
 (0)