@@ -85,7 +85,7 @@ def get_monorepo_versions(monorepo_root='.'):
8585 versions = {}
8686 for root , dirs , files in os .walk (monorepo_root ):
8787 # Skip common directories to improve performance and avoid noise
88- dirs [:] = [d for d in dirs if d not in ['samples' , 'test' , 'target' , '.git' , '.cloud' , 'verification' , 'test_data' ]]
88+ dirs [:] = [d for d in dirs if d not in ['samples' , 'test' , 'target' , '.git' , '.cloud' , 'verification' , 'test_data' , 'generation' ]]
8989
9090 if 'pom.xml' in files :
9191 pom_path = os .path .join (root , 'pom.xml' )
@@ -95,6 +95,14 @@ def get_monorepo_versions(monorepo_root='.'):
9595 return versions
9696
9797def modernize_pom (file_path , parent_version , source_repo_name = None , parent_artifactId = 'google-cloud-jar-parent' , relative_path = '../google-cloud-jar-parent/pom.xml' , monorepo_versions = None ):
98+ bom_substitutions_env = os .environ .get ('BOM_SUBSTITUTIONS' )
99+ bom_substitutions = {}
100+ if bom_substitutions_env :
101+ for pair in bom_substitutions_env .split (',' ):
102+ if ':' in pair :
103+ old , new = pair .split (':' , 1 )
104+ bom_substitutions [old .strip ()] = new .strip ()
105+
98106 with open (file_path , 'r' ) as f :
99107 lines = f .readlines ()
100108
@@ -182,12 +190,30 @@ def modernize_pom(file_path, parent_version, source_repo_name=None, parent_artif
182190 current_group_id = None
183191 current_artifact_id = None
184192 has_version = False
193+ in_exclusions = False
185194 continue
186195 if '</dependency>' in line :
187196 in_dependency = False
188197 current_dependency_lines .append (line )
189198
190- if current_artifact_id == 'google-cloud-shared-dependencies' :
199+ if current_artifact_id == 'google-cloud-shared-dependencies' and '-deps-bom' not in file_path :
200+ continue
201+
202+ if current_artifact_id in bom_substitutions :
203+ target_bom = bom_substitutions [current_artifact_id ]
204+ target_version = monorepo_versions .get (target_bom , '0.0.1-SNAPSHOT' )
205+ target_marker = target_bom .replace ('-bom' , '' )
206+ indent = " "
207+ current_dependency_lines = [
208+ f"{ indent } <dependency>\n " ,
209+ f"{ indent } <groupId>com.google.cloud</groupId>\n " ,
210+ f"{ indent } <artifactId>{ target_bom } </artifactId>\n " ,
211+ f"{ indent } <version>{ target_version } </version><!-- {{x-version-update:{ target_marker } :current}} -->\n " ,
212+ f"{ indent } <type>pom</type>\n " ,
213+ f"{ indent } <scope>import</scope>\n " ,
214+ f"{ indent } </dependency>\n "
215+ ]
216+ new_lines .extend (current_dependency_lines )
191217 continue
192218
193219 # Preservation logic:
@@ -196,22 +222,29 @@ def modernize_pom(file_path, parent_version, source_repo_name=None, parent_artif
196222 # 3. Is com.google.cloud group AND artifactId starts with google-cloud- AND has a version tag
197223 is_external = current_group_id and not current_group_id .startswith ('com.google' )
198224 is_google_cloud_lib = current_group_id == 'com.google.cloud' and current_artifact_id and current_artifact_id .startswith ('google-cloud-' )
225+ is_truth = current_group_id and current_group_id .startswith ('com.google.truth' )
199226
200- if should_preserve or (is_external and has_version ) or (is_google_cloud_lib and has_version ):
227+ if should_preserve or (is_external and has_version ) or (is_google_cloud_lib and has_version ) or ( is_truth and has_version ) :
201228 new_lines .extend (current_dependency_lines )
202229 continue
203230
204231 if in_dependency :
205- if '<groupId>' in line :
206- match = re .search (r'<groupId>(.*?)</groupId>' , line )
207- if match :
208- current_group_id = match .group (1 ).strip ()
209- if '<artifactId>' in line :
210- match = re .search (r'<artifactId>(.*?)</artifactId>' , line )
211- if match :
212- current_artifact_id = match .group (1 ).strip ()
213- if '<version>' in line :
214- has_version = True
232+ if '<exclusions>' in line :
233+ in_exclusions = True
234+ if '</exclusions>' in line :
235+ in_exclusions = False
236+
237+ if not in_exclusions :
238+ if '<groupId>' in line :
239+ match = re .search (r'<groupId>(.*?)</groupId>' , line )
240+ if match :
241+ current_group_id = match .group (1 ).strip ()
242+ if '<artifactId>' in line :
243+ match = re .search (r'<artifactId>(.*?)</artifactId>' , line )
244+ if match :
245+ current_artifact_id = match .group (1 ).strip ()
246+ if '<version>' in line :
247+ has_version = True
215248
216249 if monorepo_versions and current_artifact_id and current_artifact_id in monorepo_versions :
217250 new_version = monorepo_versions [current_artifact_id ]
0 commit comments