1515import sys
1616import re
1717
18- def modernize_pom (file_path , parent_version ):
18+ def modernize_pom (file_path , parent_version , source_repo_name = None ):
1919 with open (file_path , 'r' ) as f :
2020 lines = f .readlines ()
2121
@@ -29,6 +29,33 @@ def modernize_pom(file_path, parent_version):
2929 has_x_version_update = False
3030
3131 for line in lines :
32+ # URL Modernization
33+ if any (tag in line for tag in ['<url>' , '<connection>' , '<developerConnection>' ]):
34+ if 'github.com' in line and 'googleapis/' in line :
35+ if source_repo_name :
36+ repo_pattern = re .escape (source_repo_name )
37+ else :
38+ repo_pattern = r'[a-zA-Z0-9-]+'
39+
40+ # Replace HTTPS URLs
41+ line = re .sub (
42+ r'https://github\.com/googleapis/' + repo_pattern ,
43+ 'https://github.com/googleapis/google-cloud-java' ,
44+ line
45+ )
46+ # Replace Git SSH URLs
47+ line = re .sub (
48+ r'git@github\.com:googleapis/' + repo_pattern + r'(\.git)?' ,
49+ 'git@github.com:googleapis/google-cloud-java.git' ,
50+ line
51+ )
52+ # Handle scm:git: prefix if it has https
53+ line = re .sub (
54+ r'scm:git:https://github\.com/googleapis/' + repo_pattern ,
55+ 'scm:git:https://github.com/googleapis/google-cloud-java.git' ,
56+ line
57+ )
58+
3259 # Parent section modernization
3360 if '<parent>' in line and not in_parent :
3461 in_parent = True
@@ -110,7 +137,8 @@ def modernize_pom(file_path, parent_version):
110137
111138if __name__ == "__main__" :
112139 if len (sys .argv ) > 2 :
113- modernize_pom (sys .argv [1 ], sys .argv [2 ])
140+ source_repo = sys .argv [3 ] if len (sys .argv ) > 3 else None
141+ modernize_pom (sys .argv [1 ], sys .argv [2 ], source_repo )
114142 else :
115- print ("Usage: python3 modernize_pom.py <file_path> <parent_version>" )
143+ print ("Usage: python3 modernize_pom.py <file_path> <parent_version> [source_repo_name] " )
116144 sys .exit (1 )
0 commit comments