@@ -171,7 +171,7 @@ def get_monorepo_versions(monorepo_root='.'):
171171 versions [artifactId ] = version
172172 return versions
173173
174- def 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 , parent_managed_deps = None , keep_parent = False ):
174+ def 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 , parent_managed_deps = None , keep_parent = False , add_bulk_tests_profile = False ):
175175 with open (file_path , 'r' ) as f :
176176 lines = f .readlines ()
177177
@@ -196,6 +196,15 @@ def modernize_pom(file_path, parent_version, source_repo_name=None, parent_artif
196196 should_preserve = False
197197 current_group_id = None
198198 has_version = False
199+ in_profiles = False
200+ has_bulk_tests_profile = False
201+ profiles_lines = []
202+
203+ # Check if bulkTests profile already exists if we might add it
204+ if add_bulk_tests_profile :
205+ bulk_tests_pattern = r'<id>\s*bulkTests\s*</id>'
206+ if re .search (bulk_tests_pattern , "" .join (lines )):
207+ has_bulk_tests_profile = True
199208
200209 for line in lines :
201210 # URL Modernization
@@ -231,6 +240,17 @@ def modernize_pom(file_path, parent_version, source_repo_name=None, parent_artif
231240 if '<id>native-test</id>' in line :
232241 line = line .replace ('<id>native-test</id>' , '<id>native</id>' )
233242
243+ # Track if we are in profiles section to potentially add bulkTests there
244+ if '<profiles>' in line :
245+ in_profiles = True
246+ if '</profiles>' in line :
247+ in_profiles = False
248+ if add_bulk_tests_profile and not has_bulk_tests_profile :
249+ # Add bulkTests profile before closing </profiles>
250+ indent = " "
251+ line = f"{ indent } <profile>\n { indent } <id>bulkTests</id>\n { indent } <properties>\n { indent } <skipTests>true</skipTests>\n { indent } </properties>\n { indent } </profile>\n { line } "
252+ has_bulk_tests_profile = True
253+
234254 # Parent section modernization
235255 if not keep_parent :
236256 if '<parent>' in line and not in_parent :
@@ -469,6 +489,25 @@ def modernize_pom(file_path, parent_version, source_repo_name=None, parent_artif
469489
470490 new_lines .append (line )
471491
492+ # If bulkTests profile was requested but no <profiles> section existed
493+ if add_bulk_tests_profile and not has_bulk_tests_profile :
494+ # Find the last line that isn't </project> and empty space
495+ for i in range (len (new_lines ) - 1 , - 1 , - 1 ):
496+ if '</project>' in new_lines [i ]:
497+ indent = " "
498+ profile_block = (
499+ f"\n { indent } <profiles>\n "
500+ f"{ indent } <profile>\n "
501+ f"{ indent } <id>bulkTests</id>\n "
502+ f"{ indent } <properties>\n "
503+ f"{ indent } <skipTests>true</skipTests>\n "
504+ f"{ indent } </properties>\n "
505+ f"{ indent } </profile>\n "
506+ f"{ indent } </profiles>\n "
507+ )
508+ new_lines .insert (i , profile_block )
509+ break
510+
472511 with open (file_path , 'w' ) as f :
473512 # Clean up double empty lines potentially introduced by pruning
474513 content = "" .join (new_lines )
@@ -483,6 +522,7 @@ def modernize_pom(file_path, parent_version, source_repo_name=None, parent_artif
483522 parser .add_argument ("--parent-artifactId" , default = "google-cloud-jar-parent" , help = "Artifact ID of the parent POM." )
484523 parser .add_argument ("--relative-path" , default = "../google-cloud-jar-parent/pom.xml" , help = "Relative path to the parent POM." )
485524 parser .add_argument ("--keep-parent" , action = "store_true" , help = "Keep the existing parent section." )
525+ parser .add_argument ("--add-bulk-tests-profile" , action = "store_true" , help = "Add bulkTests profile to skip tests." )
486526
487527 args = parser .parse_args ()
488528
@@ -506,6 +546,7 @@ def modernize_pom(file_path, parent_version, source_repo_name=None, parent_artif
506546 args .relative_path ,
507547 monorepo_versions ,
508548 parent_managed_deps ,
509- args .keep_parent
549+ args .keep_parent ,
550+ args .add_bulk_tests_profile
510551 )
511552
0 commit comments